Search code examples
memory-managementlinux-kerneloperating-systempagingpage-tables

In OSes that use page tables, are page tables ever empty?


In studying shadow paging mechanisms, I learned of a case where a shadow page table starts out empty and only gets filled in as the guest VM accesses memory. It got me thinking about traditional page tables. When the OS is running and a page table becomes empty (perhaps when the page table's process terminates), I would think that page table gets released as a free page of memory.

Is there ever a case where an empty page table or even empty page directory table can exist during normal operations? Three cases I can think of are:

  1. When the OS boots - but my understanding is that modern OSes like Linux start in real mode and then switch to paging mode, during which I would imagine process 1 gets its own page table with kernel mappings among other things. Is this correct?

  2. If the last valid entry in a page table is then unmapped or swapped out - but I've also read that invalid entries could be used to store swap addresses, so not sure exactly.

  3. When a new process is spawned - although I think similar to 1), a new process is started with kernel mappings and linked library mappings, so it would already have a small page table upon starting.

UPDATE: I learned that even in the shadow page table where it starts out "empty", it still has some mappings to hypervisor memory, so even then the page tables are not truly empty.


Solution

  • There's no point in having an empty page table, so I'll say no.

    If you mean one particular table, then leaving it empty is a waste of memory. If you have an empty page table, you can free it, and in the place that pointed to the page table, you tell the CPU that there is no page table. For example, if a level-1 page table is empty, instead of pointing to it in the level-2 page table, you can put an entry in the level-2 page table which says "there is no level-1 page table for this address".

    If you mean the entire set of page tables - so are there no pages at all - the CPU can't run any instructions without page tables (unless paging is turned off) so that's still a no. The CPU would triple-fault (x86) and reboot.