Page MenuHomeFreeBSD

vm: Add kva_alloc_aligned
ClosedPublic

Authored by andrew on Nov 28 2023, 4:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 27, 6:25 AM
Unknown Object (File)
Sat, Apr 27, 6:25 AM
Unknown Object (File)
Sat, Apr 27, 6:25 AM
Unknown Object (File)
Mon, Apr 22, 4:05 PM
Unknown Object (File)
Dec 29 2023, 2:28 AM
Unknown Object (File)
Dec 23 2023, 8:24 AM
Unknown Object (File)
Dec 21 2023, 10:54 PM
Unknown Object (File)
Dec 2 2023, 4:15 AM
Subscribers

Details

Summary

Add a function like kva_alloc that allows us to specify the alignment
of the virtual address space returned.

Sponsored by: Arm Ltd

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/vm/vm_kern.c
171

See my comment in D42787 - I think this can simply use vmem_xalloc() when align > PAGE_SIZE. Using vmem_xalloc() unconditionally would also be fine.

sys/vm/vm_kern.c
170

This is unnecessary both here and in kva_alloc() and kva_free() because the kernel_arena is initialized with PAGE_SIZE as the allocation granularity.

171

Agreed. The only catch is that the documentation for vmem says that allocations obtained from vmem_xalloc() must be freed with vmem_xfree() (presumably so that freed allocations don't wind up in the quantum cache where vmem_xalloc() couldn't reallocate them). We don't enable the quantum cache for the kernel_arena, and I don't see us changing that, so we can simply change kva_alloc() and kva_free() to use vmem_xalloc() and vmem_xfree(), respectively.

sys/vm/vm_kern.c
171

The alignment should probably be at least PAGE_SIZE as the smallest allocation is a page. I don't have a check, but could add one.

This revision is now accepted and ready to land.Nov 29 2023, 4:05 PM
alc added inline comments.
sys/vm/vm_kern.c
171

It would be redundant. At initialization, we specify the page size as the granularity of allocation for this arena. Any such allocation will satisfy non-zero alignment values that are less than the page size.

This revision was automatically updated to reflect the committed changes.