0% found this document useful (0 votes)
41 views

Kernel Virtual Memory Space and Process Virtual Memory Space - Stack Overflow

The document discusses the differences between kernel virtual memory and process virtual memory in Linux. It answers several questions: 1) Kernel virtual memory is reserved for the kernel to run, while the rest of virtual memory is for user processes. 2) The kernel code and data provide the executable code and information for the kernel. 3) The diagram showing "physical memory" in kernel virtual memory is misleading - physical memory refers to real RAM, not a part of virtual memory. The kernel maps all physical memory into its virtual address space for convenience.

Uploaded by

Rishabh Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Kernel Virtual Memory Space and Process Virtual Memory Space - Stack Overflow

The document discusses the differences between kernel virtual memory and process virtual memory in Linux. It answers several questions: 1) Kernel virtual memory is reserved for the kernel to run, while the rest of virtual memory is for user processes. 2) The kernel code and data provide the executable code and information for the kernel. 3) The diagram showing "physical memory" in kernel virtual memory is misleading - physical memory refers to real RAM, not a part of virtual memory. The kernel maps all physical memory into its virtual address space for convenience.

Uploaded by

Rishabh Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

6/3/22, 11:17 PM Kernel virtual memory space and process virtual memory space - Stack Overflow

Kernel virtual memory space and process virtual memory space


Asked 2 years, 3 months ago Modified 4 months ago Viewed 1k times

I was reading the textbook:Computer Systems A Programmer’s Perspective, in chapter 9.7.2:Linux


Virtual Memory System (third edition) that talks about virtual memory.
2
I was a bit confused by the structure of virtual memory for linux process as shown below:

My question is: does kernel virtual memory preserve for kernel to run and rest of the virtual
memory preserve for user process? What does kernel code and data do? And what does the
physical memory in kernel virtual memory?

memory memory-management linux-kernel virtualization

Share Follow edited Feb 5, 2020 at 14:59 asked Feb 5, 2020 at 13:13
Marco Bonelli yi li
56k 20 106 115 147 9

https://stackoverflow.com/questions/60076669/kernel-virtual-memory-space-and-process-virtual-memory-space 1/4
6/3/22, 11:17 PM Kernel virtual memory space and process virtual memory space - Stack Overflow

Could you please rephrase your question to be clearer? I don't think I understand what you mean by "why
we need to copy the kernel code and data for each process and what does physical memory in the kernel do?"
– Marco Bonelli Feb 5, 2020 at 13:27

Also, could you provide the name/author of the textbook? That image is pretty strange. – Marco Bonelli Feb
5, 2020 at 13:42

Sorted by:
2 Answers
Highest score (default)

does kernel virtual memory preserve for kernel to run and rest of the virtual memory
preserve for user process?
4

Yes, there is a part of virtual memory that is always reserved for the kernel and another part that is
left available to userspace processes. Every single process has its own virtual memory, but the
kernel is always mapped in the higher part (higher addresses) of virtual memory. Whether or not
this mapping is visible to the process depends on Kernel Page Table Isolation.

See also: Do the virtual address spaces of all the processes have the same content in their “Kernel”
parts?

What does kernel code and data do?

Part of the high virtual memory is a direct mapping of the actual kernel image. That is, the kernel
executable and all its data. You can see it in more detail here in this page of the kernel
documentation, marked as "kernel text mapping, mapped to physical address 0".

See also: What's the use of having a kernel part in the virtual memory space of Linux processes?

And what does the physical memory in kernel virtual memory?

That part of the image is totally misleading. I don't know precisely what information the authors
of the book were trying to convey, but physical memory is definitely not a part of kernel virtual
memory. They were probably trying to address the fact that there is a direct mapping of all
physical memory in the kernel virtual memory, which can be seen again on the same page of the
kernel documentation, marked as "direct mapping of all physical memory".

Physical memory refers to the real memory of the system (i.e. the RAM). Each region of virtual
memory is mapped to some region of physical memory. This virtual-to-physical mapping is totally
transparent to processes and is managed by the kernel. For example, two executables that have
the same file open in read-only mode are usually sharing the same physical memory region, while
seeing two different virtual address.

https://stackoverflow.com/questions/60076669/kernel-virtual-memory-space-and-process-virtual-memory-space 2/4
6/3/22, 11:17 PM Kernel virtual memory space and process virtual memory space - Stack Overflow

This is a more accurate depiction of the relationship between virtual and physical memory:

Source: https://computationstructures.org/lectures/vm/vm.html

Share Follow edited Feb 5, 2020 at 15:43 answered Feb 5, 2020 at 14:58
Marco Bonelli
56k 20 106 115

Thanks,I have two questions left. I don't understand why each process need to load the kernel executable
and all its data to it's virtual address. And the motivation to design the direct mapping of all physical
memory in the virtual memory. – yi li Feb 5, 2020 at 15:43

1 @yi_li read the post I linked: unix.stackexchange.com/a/472229/272806 – Marco Bonelli Feb 5, 2020 at
15:44

cited from the CSAPP book, 3rd version, section 9.7.2, where the picture is shown.

0 Interestingly, Linux also maps a set of contiguous virtual pages (equal in size to the
total amount of DRAM in the system) to the corresponding set of contiguous
physical pages. This provides the kernel with a convenient way to access any specific
location in physical memory—for example, when it needs to access page tables or to
perform memory-mapped I/O operations on devices that are mapped to particular
physical memory locations.

I think the Physical memory in the picture just reflects what's described above: a virtual memory
area that maps to the entire physical memory.

Share Follow answered Jan 14 at 5:47


Izana
1,949 22 26

https://stackoverflow.com/questions/60076669/kernel-virtual-memory-space-and-process-virtual-memory-space 3/4
6/3/22, 11:17 PM Kernel virtual memory space and process virtual memory space - Stack Overflow

https://stackoverflow.com/questions/60076669/kernel-virtual-memory-space-and-process-virtual-memory-space 4/4

You might also like