USER SPACE & KERNEL SPACE IN LINUX – By Mythila
User Space & Kernel Space in Linux: Kernel space used when Kernel is executing the programme on the behalf of the user program i.e. System Call? Or is it the address space for all the Kernel threads (for example scheduler)?
When it is the first one, than does it mean that normal user program cannot have more than 3GB of memory (if the division is 3GB + 1GB)? Also, in that case how can kernel use High Memory, because to what virtual memory address will the pages from high memory be mapped to, as 1GB of kernel space will be logically mapped?
Processes running below the user space have access only to a restricted part of memory, whereas the kernel has a way to all of the memory. Processes operating in user space also don’t have access to the kernel space. Userspace methods can only access a small part of the kernel via an interface exposed by the kernel – the system calls. If a process executes a system call, a software interrupt is sent to the kernel, which then expresses the appropriate interrupt handler and extends its work after the handler has finished.
Kernel space code has the property to run in “kernel mode”, which (in your typical desktop -x86- computer) is what you call code that executes under ring 0. Typically in the x86 architecture, there are 4 rings of protection. Ring 0 (kernel mode), Ring 1 (may be used by virtual machine hypervisors or drivers), Ring 2 (may be used by drivers, I am not so sure about that though). Ring 3 is what typical applications run under. It is the least privileged ring, and applications running on it have access to a subset of the processor’s instructions. Ring 0 (kernel space) is the most privileged ring and has access to all of the machine’s instructions. For example to this, a “plain” application (like a browser) cannot use x86 assembly instructions to load the global descriptor table or hit to halt a processor.