4

As I understand, " Each process' address space is divided into 3G/1G for user space/kernel space, and 1G (little less) is mapped one to one with physical addresss, called as kernel logical address". Now,my question is, there are multiple processes running on the system, and how does it is possible for all the processes to have one to one mapping with the physical addresses?? For example, when kernel is accessing a kernel logical address on process A's context, and now the preemption happens, and what happens,when kernel access the logical address in process B's context?

on a similar line, what happens for the PC's with only 512MB RAM?. How does the, one-one mapping of 1G kernel space happens for those PC's?

user1762729
  • 61
  • 1
  • 3
  • Only on 32-bit systems it should be noted. The split is, incidentally, often 2GB/2GB on 32-bit ARM systems. – marko Oct 22 '12 at 22:33

3 Answers3

2

It may help first to consider that the kernel part (let's say 1GB) of total virtual address space does not all get used. And the total physical memory isn't all mapped to kernel space.

Kernel space will have virtual memory mappings for the physical RAM that it uses, plus any memory mapped peripherals that are defined. Those aren't paged.

Each process in user space could have as much as 3 GB of virtual memory for its code+data. For physical memory there are two extremes, it may shed light to look at each.

Large physical memory: if the processor supports big physical addressing e.g. 36-bit, there could be 64 GB of physical memory. You could have multiple processes, each with 3 GB code+data, and they would not even have to swap pages out to secondary storage. Each context switch would set up MMU to map the new executing process's physical memory back into user space.

Small physical memory: let's say 512 MB is there, and kernel uses 128 MB of that. The remaining 384 MB will hold user processes' code+data. IF user processes need more than that, pages will swap between secondary storage and RAM as needed.

Joe Kul
  • 2,454
  • 16
  • 16
2

Here is a link, which provides pretty good clarification for my question.

http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory

"In Linux, kernel space is constantly present and maps the same physical memory in all processes. Kernel code and data are always addressable, ready to handle interrupts or system calls at any time. By contrast, the mapping for the user-mode portion of the address space changes whenever a process switch happens:"

Answer to first part of question : Linux kernel space remains same across all processes , and process context switch doesn't matter. Kernel space remain mapped to same RAM pages across all process contexts.

Answer to second part of question : The size of physical RAM size (512 MB or 2GB) is irrelevant for kernel address space. As with rule, kernel has 1G kernel address space available, and whatever allocation it does, its done with those addressses. Mapping of those addresses to available RAM (512MB or 2GB) is the job of MMU. In a 1G or more RAM case, entire 1G will be mapped for kernel address space, whereas in 512 MB RAM case, it will be 512MB. It doesn't hurts the user space addresses, as everything is virtual addresses, and they will be swapped out for demand, including those of kernel space pages.

Note: Here I assume 1G/3G split , and that's not a hard rule.

user1762729
  • 61
  • 1
  • 3
0

Well, in a traditional multi-core system, all processors have access to all RAM. In Linux, each process has it's own address space on the 3GB side, while the 1GB side stays constant (I think) because the kernel is, in a way, a process that's always there. Because the kernel part of virtual memory stays the same (and because of that, there is one kernel address space), the kernels address space doesn't change when it preempts a process.

Quite simply, the kernel only maps those 512 MB. The other 512 MB of virtual address space is just mapped to the nothing page entry, which just tells the CPU that no memory should be accessible at that address, and to raise a CPU exception whenever it is accessed.

Linuxios
  • 34,849
  • 13
  • 91
  • 116
  • Thanks for the answer Linuxios. It helps. I find a link, which gives additional clarity.and i posted a answer based on that as well – user1762729 Nov 20 '12 at 14:19