9

Does linux kernel make use of virtual memory for its data structures (page tables, descriptors, etc.)? More specifically:

Are kernel space addresses translated in the MMU (pagetable walking)?

Could kernel memory get swapped out?

Could a memory access to a kernel data structure cause a page fault?

Are there differences between linux and other unix in this respect?

1 Answer 1

17

Are kernel space addresses translated in the MMU (pagetable walking)?

Yes, all addresses are translated in the MMU; see Is the MMU inside of Unix/Linux kernel? or just in a hardware device with its own memory? for details.

Could kernel memory get swapped out?

A kernel could theoretically be designed so that it can be swapped out. In practice it’s difficult; the Linux kernel in particular can’t be swapped out. Some code paths in the kernel do have to deal with page-ins however; see Why are `copy_from_user()` and `copy_to_user()` needed, when the kernel is mapped into the same virtual address space as the process itself? for example.

Could a memory access to a kernel data structure cause a page fault?

In most if not all cases, if this were to happen, it would lead to a kernel panic. So yes, it could happen, but it would be a bug.

Are there differences between linux and other unix in this respect?

As far as I’m aware other (current) Unix-style implementations are similar. Early Unix didn’t support virtual-memory-based swapping (i.e. paging out arbitrary pages) anyway so it wasn’t a concern there.

2
  • "Early Unix didn’t support swap anyway". Didn't UNICS on the PDP-7 only keep one process in core at a time and keep the others in swap?
    – Oskar Skog
    Nov 20, 2021 at 9:54
  • @Oskar yes, but that’s not VM-based swapping, so not “swap” as it’s understood nowadays IMO. The kernel couldn’t be swapped out, and processes were entirely present or not at all. Nov 20, 2021 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .