vm_kern.c (327701) | vm_kern.c (327785) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 49 unchanged lines hidden (view full) --- 58 * rights to redistribute these changes. 59 */ 60 61/* 62 * Kernel memory management. 63 */ 64 65#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 49 unchanged lines hidden (view full) --- 58 * rights to redistribute these changes. 59 */ 60 61/* 62 * Kernel memory management. 63 */ 64 65#include <sys/cdefs.h> |
66__FBSDID("$FreeBSD: stable/11/sys/vm/vm_kern.c 327701 2018-01-08 16:36:33Z markj $"); | 66__FBSDID("$FreeBSD: stable/11/sys/vm/vm_kern.c 327785 2018-01-10 20:39:26Z markj $"); |
67 68#include <sys/param.h> 69#include <sys/systm.h> 70#include <sys/kernel.h> /* for ticks and hz */ 71#include <sys/eventhandler.h> 72#include <sys/lock.h> 73#include <sys/proc.h> 74#include <sys/malloc.h> --- 92 unchanged lines hidden (view full) --- 167 vm_page_t m; 168 int pflags, tries; 169 170 size = round_page(size); 171 if (vmem_alloc(vmem, size, M_BESTFIT | flags, &addr)) 172 return (0); 173 offset = addr - VM_MIN_KERNEL_ADDRESS; 174 pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED; | 67 68#include <sys/param.h> 69#include <sys/systm.h> 70#include <sys/kernel.h> /* for ticks and hz */ 71#include <sys/eventhandler.h> 72#include <sys/lock.h> 73#include <sys/proc.h> 74#include <sys/malloc.h> --- 92 unchanged lines hidden (view full) --- 167 vm_page_t m; 168 int pflags, tries; 169 170 size = round_page(size); 171 if (vmem_alloc(vmem, size, M_BESTFIT | flags, &addr)) 172 return (0); 173 offset = addr - VM_MIN_KERNEL_ADDRESS; 174 pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED; |
175 pflags &= ~(VM_ALLOC_NOWAIT | VM_ALLOC_WAITOK | VM_ALLOC_WAITFAIL); 176 pflags |= VM_ALLOC_NOWAIT; |
|
175 VM_OBJECT_WLOCK(object); 176 for (i = 0; i < size; i += PAGE_SIZE) { 177 tries = 0; 178retry: 179 m = vm_page_alloc_contig(object, atop(offset + i), 180 pflags, 1, low, high, PAGE_SIZE, 0, memattr); 181 if (m == NULL) { 182 VM_OBJECT_WUNLOCK(object); --- 39 unchanged lines hidden (view full) --- 222 u_long npages; 223 int pflags, tries; 224 225 size = round_page(size); 226 if (vmem_alloc(vmem, size, flags | M_BESTFIT, &addr)) 227 return (0); 228 offset = addr - VM_MIN_KERNEL_ADDRESS; 229 pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED; | 177 VM_OBJECT_WLOCK(object); 178 for (i = 0; i < size; i += PAGE_SIZE) { 179 tries = 0; 180retry: 181 m = vm_page_alloc_contig(object, atop(offset + i), 182 pflags, 1, low, high, PAGE_SIZE, 0, memattr); 183 if (m == NULL) { 184 VM_OBJECT_WUNLOCK(object); --- 39 unchanged lines hidden (view full) --- 224 u_long npages; 225 int pflags, tries; 226 227 size = round_page(size); 228 if (vmem_alloc(vmem, size, flags | M_BESTFIT, &addr)) 229 return (0); 230 offset = addr - VM_MIN_KERNEL_ADDRESS; 231 pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED; |
232 pflags &= ~(VM_ALLOC_NOWAIT | VM_ALLOC_WAITOK | VM_ALLOC_WAITFAIL); 233 pflags |= VM_ALLOC_NOWAIT; |
|
230 npages = atop(size); 231 VM_OBJECT_WLOCK(object); 232 tries = 0; 233retry: 234 m = vm_page_alloc_contig(object, atop(offset), pflags, 235 npages, low, high, alignment, boundary, memattr); 236 if (m == NULL) { 237 VM_OBJECT_WUNLOCK(object); --- 95 unchanged lines hidden (view full) --- 333 vm_page_t m, mpred; 334 int pflags; 335 336 KASSERT(object == kmem_object || object == kernel_object, 337 ("kmem_back: only supports kernel objects.")); 338 339 offset = addr - VM_MIN_KERNEL_ADDRESS; 340 pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED; | 234 npages = atop(size); 235 VM_OBJECT_WLOCK(object); 236 tries = 0; 237retry: 238 m = vm_page_alloc_contig(object, atop(offset), pflags, 239 npages, low, high, alignment, boundary, memattr); 240 if (m == NULL) { 241 VM_OBJECT_WUNLOCK(object); --- 95 unchanged lines hidden (view full) --- 337 vm_page_t m, mpred; 338 int pflags; 339 340 KASSERT(object == kmem_object || object == kernel_object, 341 ("kmem_back: only supports kernel objects.")); 342 343 offset = addr - VM_MIN_KERNEL_ADDRESS; 344 pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED; |
345 pflags &= ~(VM_ALLOC_NOWAIT | VM_ALLOC_WAITOK | VM_ALLOC_WAITFAIL); 346 if (flags & M_WAITOK) 347 pflags |= VM_ALLOC_WAITFAIL; |
|
341 342 i = 0; | 348 349 i = 0; |
343retry: | |
344 VM_OBJECT_WLOCK(object); | 350 VM_OBJECT_WLOCK(object); |
351retry: |
|
345 mpred = vm_radix_lookup_le(&object->rtree, atop(offset + i)); 346 for (; i < size; i += PAGE_SIZE, mpred = m) { 347 m = vm_page_alloc_after(object, atop(offset + i), pflags, 348 mpred); 349 350 /* 351 * Ran out of space, free everything up and return. Don't need 352 * to lock page queues here as we know that the pages we got 353 * aren't on any queues. 354 */ 355 if (m == NULL) { | 352 mpred = vm_radix_lookup_le(&object->rtree, atop(offset + i)); 353 for (; i < size; i += PAGE_SIZE, mpred = m) { 354 m = vm_page_alloc_after(object, atop(offset + i), pflags, 355 mpred); 356 357 /* 358 * Ran out of space, free everything up and return. Don't need 359 * to lock page queues here as we know that the pages we got 360 * aren't on any queues. 361 */ 362 if (m == NULL) { |
356 VM_OBJECT_WUNLOCK(object); 357 if ((flags & M_NOWAIT) == 0) { 358 VM_WAIT; | 363 if ((flags & M_NOWAIT) == 0) |
359 goto retry; | 364 goto retry; |
360 } | 365 VM_OBJECT_WUNLOCK(object); |
361 kmem_unback(object, addr, i); 362 return (KERN_NO_SPACE); 363 } 364 if (flags & M_ZERO && (m->flags & PG_ZERO) == 0) 365 pmap_zero_page(m); 366 KASSERT((m->oflags & VPO_UNMANAGED) != 0, 367 ("kmem_malloc: page %p is managed", m)); 368 m->valid = VM_PAGE_BITS_ALL; --- 190 unchanged lines hidden --- | 366 kmem_unback(object, addr, i); 367 return (KERN_NO_SPACE); 368 } 369 if (flags & M_ZERO && (m->flags & PG_ZERO) == 0) 370 pmap_zero_page(m); 371 KASSERT((m->oflags & VPO_UNMANAGED) != 0, 372 ("kmem_malloc: page %p is managed", m)); 373 m->valid = VM_PAGE_BITS_ALL; --- 190 unchanged lines hidden --- |