Skip to content

Commit

Permalink
vm: Assert that pagesizes[] is sorted
Browse files Browse the repository at this point in the history
Ensure that pmap_init() properly initialized pagesizes[].  In part, we
are making this change to document the requirement that the non-zero
elements of pagesizes[] must be in ascending order.

Reviewed by:	kib, markj
  • Loading branch information
alcriceedu committed Aug 4, 2024
1 parent 82246ac commit fa29085
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sys/vm/vm_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ long physmem;
static void vm_mem_init(void *);
SYSINIT(vm_mem, SI_SUB_VM, SI_ORDER_FIRST, vm_mem_init, NULL);

#ifdef INVARIANTS
/*
* Ensure that pmap_init() correctly initialized pagesizes[].
*/
static void
vm_check_pagesizes(void)
{
int i;

KASSERT(pagesizes[0] == PAGE_SIZE, ("pagesizes[0] != PAGE_SIZE"));
for (i = 1; i < MAXPAGESIZES; i++) {
KASSERT((pagesizes[i - 1] != 0 &&
pagesizes[i - 1] < pagesizes[i]) || pagesizes[i] == 0,
("pagesizes[%d ... %d] are misconfigured", i - 1, i));
}
}
#endif

/*
* vm_mem_init() initializes the virtual memory system.
* This is done only by the first cpu up.
Expand Down Expand Up @@ -140,6 +158,10 @@ vm_mem_init(void *dummy)
kmem_init_zero_region();
pmap_init();
vm_pager_init();

#ifdef INVARIANTS
vm_check_pagesizes();
#endif
}

void
Expand Down

0 comments on commit fa29085

Please sign in to comment.