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

Function kmem_alloc_attr_domain

freebsd/vm/vm_kern.c:210–250  ·  view source on GitHub ↗

* Allocates a region from the kernel address map and physical 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. The allocated pages are not * necessarily physically contiguous. If M_ZERO is specified through the * given flags, then the pages are zeroed before they

Source from the content-addressed store, hash-verified

208 * given flags, then the pages are zeroed before they are mapped.
209 */
210static vm_offset_t
211kmem_alloc_attr_domain(int domain, vm_size_t size, int flags, vm_paddr_t low,
212 vm_paddr_t high, vm_memattr_t memattr)
213{
214 vmem_t *vmem;
215 vm_object_t object;
216 vm_offset_t addr, i, offset;
217 vm_page_t m;
218 int pflags;
219 vm_prot_t prot;
220
221 object = kernel_object;
222 size = round_page(size);
223 vmem = vm_dom[domain].vmd_kernel_arena;
224 if (vmem_alloc(vmem, size, M_BESTFIT | flags, &addr))
225 return (0);
226 offset = addr - VM_MIN_KERNEL_ADDRESS;
227 pflags = malloc2vm_flags(flags) | VM_ALLOC_WIRED;
228 prot = (flags & M_EXEC) != 0 ? VM_PROT_ALL : VM_PROT_RW;
229 VM_OBJECT_WLOCK(object);
230 for (i = 0; i < size; i += PAGE_SIZE) {
231 m = kmem_alloc_contig_pages(object, atop(offset + i),
232 domain, pflags, 1, low, high, PAGE_SIZE, 0, memattr);
233 if (m == NULL) {
234 VM_OBJECT_WUNLOCK(object);
235 kmem_unback(object, addr, i);
236 vmem_free(vmem, addr, size);
237 return (0);
238 }
239 KASSERT(vm_page_domain(m) == domain,
240 ("kmem_alloc_attr_domain: Domain mismatch %d != %d",
241 vm_page_domain(m), domain));
242 if ((flags & M_ZERO) && (m->flags & PG_ZERO) == 0)
243 pmap_zero_page(m);
244 vm_page_valid(m);
245 pmap_enter(kernel_pmap, addr + i, m, prot,
246 prot | PMAP_ENTER_WIRED, 0);
247 }
248 VM_OBJECT_WUNLOCK(object);
249 return (addr);
250}
251
252vm_offset_t
253kmem_alloc_attr(vm_size_t size, int flags, vm_paddr_t low, vm_paddr_t high,

Callers 1

Calls 9

vmem_allocFunction · 0.85
malloc2vm_flagsFunction · 0.85
kmem_alloc_contig_pagesFunction · 0.85
kmem_unbackFunction · 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