MCPcopy Create free account
hub / github.com/F-Stack/f-stack / kmem_alloc_contig_domain

Function kmem_alloc_contig_domain

freebsd/vm/vm_kern.c:288–331  ·  view source on GitHub ↗

* Allocates a region from the kernel address map and physically * contiguous pages within the specified address range to the kernel * object. Creates a wired mapping from this region to these pages, and * returns the region's starting virtual address. If M_ZERO is specified * through the given flags, then the pages are zeroed before they are * mapped. */

Source from the content-addressed store, hash-verified

286 * mapped.
287 */
288static vm_offset_t
289kmem_alloc_contig_domain(int domain, vm_size_t size, int flags, vm_paddr_t low,
290 vm_paddr_t high, u_long alignment, vm_paddr_t boundary,
291 vm_memattr_t memattr)
292{
293 vmem_t *vmem;
294 vm_object_t object;
295 vm_offset_t addr, offset, tmp;
296 vm_page_t end_m, m;
297 u_long npages;
298 int pflags;
299
300 object = kernel_object;
301 size = round_page(size);
302 vmem = vm_dom[domain].vmd_kernel_arena;
303 if (vmem_alloc(vmem, size, flags | M_BESTFIT, &addr))
304 return (0);
305 offset = addr - VM_MIN_KERNEL_ADDRESS;
306 pflags = malloc2vm_flags(flags) | VM_ALLOC_WIRED;
307 npages = atop(size);
308 VM_OBJECT_WLOCK(object);
309 m = kmem_alloc_contig_pages(object, atop(offset), domain,
310 pflags, npages, low, high, alignment, boundary, memattr);
311 if (m == NULL) {
312 VM_OBJECT_WUNLOCK(object);
313 vmem_free(vmem, addr, size);
314 return (0);
315 }
316 KASSERT(vm_page_domain(m) == domain,
317 ("kmem_alloc_contig_domain: Domain mismatch %d != %d",
318 vm_page_domain(m), domain));
319 end_m = m + npages;
320 tmp = addr;
321 for (; m < end_m; m++) {
322 if ((flags & M_ZERO) && (m->flags & PG_ZERO) == 0)
323 pmap_zero_page(m);
324 vm_page_valid(m);
325 pmap_enter(kernel_pmap, tmp, m, VM_PROT_RW,
326 VM_PROT_RW | PMAP_ENTER_WIRED, 0);
327 tmp += PAGE_SIZE;
328 }
329 VM_OBJECT_WUNLOCK(object);
330 return (addr);
331}
332
333vm_offset_t
334kmem_alloc_contig(vm_size_t size, int flags, vm_paddr_t low, vm_paddr_t high,

Callers 1

Calls 8

vmem_allocFunction · 0.85
malloc2vm_flagsFunction · 0.85
kmem_alloc_contig_pagesFunction · 0.85
vmem_freeFunction · 0.85
vm_page_domainFunction · 0.85
vm_page_validFunction · 0.85
pmap_zero_pageFunction · 0.50
pmap_enterFunction · 0.50

Tested by

no test coverage detected