21

This might be a silly question but it just popped up in my mind. All the text about process address space and virtual memory layout mentions that the process address space has space reserved for kernel. For e.g. on 32 bit systems the process address space is 4GB of which 1 GB is reserved for kernel in Linux (Might be different on other OS).

I am just wondering why kernel is said to be in the process address space when a process cannot address the kernel directly. Why don't we say that the kernel has a separate address space than a process and why can't we have a different page table for kernel itself which is separate from the page tables of the processes?

vjain27
  • 3,514
  • 9
  • 41
  • 60
  • Can you identify one or more specific URLs which describe how the process address space has space reserved for the kernel? It certainly isn't universal; I'm tolerably certain that there are 32-bit systems (not necessarily Linux-based) using more than 3 GiB of shared memory in a single process, which doesn't leave 1 GiB for the kernel. – Jonathan Leffler Sep 01 '11 at 20:05
  • I was just giving an example that some space is reserved for kernel. The specifics are not as important to the question. – vjain27 Sep 01 '11 at 20:36

1 Answers1

18

When the process makes a system call, we don't need to switch the page tables (from process address space page table to kernel address space page table) for servicing the system call (which should be done only in kernel mode). This is said to be that the kernel is running in the process context.

Some kernel events which won't run in process context will load the page tables only for kernel.

Got it ?

viji
  • 2,706
  • 5
  • 28
  • 34
  • 1
    ok. but how badly switching pages will affect performance. also according to https://flylib.com/books/en/3.126.1.91/1/ OSX does exactly that. "Mac OS X does not map the kernel into each user address space, and therefore each user/kernel transition (in either direction) requires an address space switch" and it doesn't seem extra slow to me. – mauron85 Apr 30 '18 at 18:22
  • TLB (Transition Lookaside Buffer) would get reset for every page-table switch, and that's a lot of waste time. – viji Dec 23 '18 at 00:11
  • 2
    One update to this since things have changed a little since this question was posted and I just stumbled across it, so others may too. :) What's described in this answer is not entirely the case anymore. A vulnerability called MELTDOWN was discovered, which resulted in the ability to access kernel pages in the page table. This resulted in the kernel switching to using two page tables for each process, one with the kernel mapped (for syscalls) and one without (regular process space). Depending on the CPU, the TLB may get automatically flushed now, or just entries related to that process. – trycatch Jan 08 '22 at 19:06