xv6 KERNBASE limitation of process memory xv6 KERNBASE limitation of process memory unix unix

xv6 KERNBASE limitation of process memory


Well, there is an issue here.

All physical addresses which are supposed to be used are mapped to virtual addresses0x80000000 and up.

So, if you move KERNBASE upawards, the OS can use less physical memory.


I've been thinking about this as well. Here are my conclusions—though I can't really vouch for them. It's mostly deductive.

The first thing is that your proposed explanation is technically wrong. xv6 can work with both higher and lower KERNBASE values. You can test this by changing KERNBASE to, say, 0x90000000 and then changing the relevant value in kernel.ld (the linker script which puts things in expected addresses).

The real issue here, as far as I've been able to gather, is that xv6 doesn't do any paging to disk. Now, remember that in xv6 addresses 0x80000000 (KERNBASE) and up map linearly to 0x00000000..0xffffffff. This means that any byte of memory you allocate in the whole system maps to 2 different physical addresses in 32-bit space. Since xv6 does no paging to disk, this means that if it allocates memory for the user process (using the sbrk() system call, used by malloc() in userspace), then it keeps it around in memory the whole time. So again, since we have 2 "copies", or more precisely 2 mappings to the same address, we can't ever actually use more than half the memory available in 32-bit address space.

Now, recall that KERNBASE is defined as 0x80000000, which is exactly that: half of the available memory. So no, raising KERNBASE under these conditions can't give us more userspace memory.