Define simple functions for alignment and boundary checks and use them everywhere instead of having slightly different implementations scattered about. Define them in vm_page.h and use them where possible where vm_page.h is included.
Details
Diff Detail
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
I think that vm/vm_param.h would work for this, similarly how roundup() or powerof2() live in sys/param.h. Not sure about vm_phys_ prefix, might be vm_addr_ is a better choice, also from the functional PoV.
I suggest to commit vm_phys_set_pool() separately.
IMO vm_phys.h makes more sense than vm_page.h for these routines. The vm_page_ prefix is usually for functions that operate on a vm_page_t. Is there some reason these can't live in vm_param.h as kib suggested?
Using vm_phys would require that I include vm_phys.h in more files. vm file already included everywhere are:
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_kern.h>
#include <vm/vm_page.h>
#include <vm/vm_map.h>
If vm_param.h is indirectly included everywhere, I can use that.
It's only included directly. All of the C files in sys/vm already have it, and I think it wouldn't be to onerous to add includes elsewhere where needed.
That said, vm_extern.h makes even more sense since these routines are used outside of sys/vm, and vm_extern.h already assumes that vm_paddr_t is defined. So I would suggest trying to add these routines there.
Move the functions from vm_page.h to vm_extern.h. Rename them, and add a couple of comments.
sys/vm/vm_extern.h | ||
---|---|---|
138 ↗ | (On Diff #100712) | I would add asserts that power of two args are indeed power of two. This probably needs to come under #ifdef _KERNEL. You may do this as a follow-up. |