Understanding the mapping of physical memory to kernel address space
Hello, This is my first mail on this list, so please let me know if I'm erring. I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space. I have several questions from my reading: - My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? - There is a frequent mention of "mapping RAM to the kernel address space". Is the whole RAM mapped to the kernel space? What would happen in the case of a machine having only 1 GiB of RAM? - Related to the above, what exactly is max_low_pfn? It is mentioned it is the "Page frame number of the last page frame directly mapped by the kernel (low memory)". What would it's value be for a machine with 1 GiB RAM? For a machine with 4 GiB RAM, would it be the number of the frame covering the last portion of kernel space (896 MiB)? Sorry if my questions are a bit vague. I'm still new to this and having difficulty relating everything. Thanks, Sunny
Hello Sunny, On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
There is a frequent mention of "mapping RAM to the kernel address space". Is the whole RAM mapped to the kernel space? What would happen in the case of a machine having only 1 GiB of RAM?
If you are using 3:1 user to kernel mapping, your kernel will have 1GB of virutal addres space. And if you have 1GB of RAM, whole ram cannot be mapped to kernel virtual address, because you have to spare some virtual kernel address space for io memory, vmalloc area etc. So you have to map some of DDR memory as HIGH_MEM.
Related to the above, what exactly is max_low_pfn? It is mentioned it is the "Page frame number of the last page frame directly mapped by the kernel (low memory)". What would it's value be for a machine with 1 GiB RAM? For a machine with 4 GiB RAM, would it be the number of the frame covering the last portion of kernel space (896 MiB)?
max_low_pfn is the pfn of the last page mapped as low memory. All the other pfn belongs to HIGH_MEM. They can be dynamically mapped to vmalloc virutal address space or directly to user virutal address space. User space memory is the main consumer of HIGH_MEM. Thanks, Arun
Sorry if my questions are a bit vague. I'm still new to this and having difficulty relating everything.
Thanks, Sunny
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org] On Behalf Of Arun KS Sent: Thursday, March 12, 2015 11:03 AM To: Sunny Shah Cc: kernelnewbies Subject: Re: Understanding the mapping of physical memory to kernel address space Hello Sunny, On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
Just an FYI, I've seen 1:3 mapping too. We had to do that with the kernels we built when I was at one company because we needed 3GB of virtual address space to map all of the memory mapped registers on their ASICs. There's lots of options here. Jeff Haran
Thank you guys! I have two more questions from your replies: - I thought I had understood HIGH_MEM and LOW_MEM, but it appears I was wrong. Does the concept of high memory/low memory correspond to physical address space or virtual address space? Also, does LOW_MEM always have to be 1 GiB maximum? - For a RAM of 896 MiB - 4096 MiB, the book says: "In this case, the RAM cannot be mapped entirely into the kernel linear address space. The best Linux can do during the initialization phase is to map a RAM window of size 896 MB into the kernel linear address space." Why is there a need to map the whole RAM into the kernel space (the usage of the word "entirely") ? Shouldn't it be only LOW_MEM ? Or am I confusing the two things here ? I believe all doubts are pointing to the concepts of LOW_MEM and HIGH_MEM, but I'm still not being able to wrap my head around them. Thanks, Sunny On Thu, Mar 12, 2015 at 11:49 PM, Jeff Haran <Jeff.Haran@citrix.com> wrote:
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto: kernelnewbies-bounces@kernelnewbies.org] On Behalf Of Arun KS Sent: Thursday, March 12, 2015 11:03 AM To: Sunny Shah Cc: kernelnewbies Subject: Re: Understanding the mapping of physical memory to kernel address space
Hello Sunny,
On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
Just an FYI, I've seen 1:3 mapping too. We had to do that with the kernels we built when I was at one company because we needed 3GB of virtual address space to map all of the memory mapped registers on their ASICs.
There's lots of options here.
Jeff Haran
Hello Sunny, On Sat, Mar 14, 2015 at 8:25 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Thank you guys!
I have two more questions from your replies:
I thought I had understood HIGH_MEM and LOW_MEM, but it appears I was wrong. Does the concept of high memory/low memory correspond to physical address space or virtual address space? Also, does LOW_MEM always have to be 1 GiB maximum?
Physical memory is divided into HIGH_MEM and LOW_MEM. Why do we need two memory? To understand this, we need to know who all are consumers of kernel virtual address(KVA) which is limited to 1GB(in case of 3:1 split). 1. low mem( physical ram which has linear mapping to KVA). 2. IO memory address(for eg a DMA controller registers, Memory controller register, etc). When MMU is enabled all the address generated by the cpu are virtual address. Hence io memory should have a valid virtual to physical memory mapping. 3. Vmalloc address space. A dynamic kernel memory allocation mechanism, which only guarantees continuity in virtual address space. 4. Persistent kernel map. (if kernel want to use HIGH memory, it maps high memory to this portion of virtual address). 5. vector table. Let me give a rough calculation for a better understanding. Lets say a system with configuration as follows, 2GB of physical RAM, 40 MB of physical io address space, 240 MB of vmalloc address space, 32 MB for persistent kernel map The maximum RAM which can be mapped as low mem = 1GB - (40 MB + 240 MB + 32MB) = 712MB. Rest of RAM 1336MB( 1GB - 712MB) will fall as HIGH_MEM. Now how system uses HIGH memory. Major user of HIGH mem is user space code. Kernel directly maps high mem to user space virtual address. Hight mem is also used by kernel though PK mappings. Even vmalloc allocation can also fall from HIGH mem region. Now if we decides to use 1:3 user space to kernel space split, high memory is not required. Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it. HTH. Thanks, Arun
For a RAM of 896 MiB - 4096 MiB, the book says: "In this case, the RAM cannot be mapped entirely into the kernel linear address space. The best Linux can do during the initialization phase is to map a RAM window of size 896 MB into the kernel linear address space."
Why is there a need to map the whole RAM into the kernel space (the usage of the word "entirely") ? Shouldn't it be only LOW_MEM ? Or am I confusing the two things here ?
I believe all doubts are pointing to the concepts of LOW_MEM and HIGH_MEM, but I'm still not being able to wrap my head around them.
Thanks, Sunny
On Thu, Mar 12, 2015 at 11:49 PM, Jeff Haran <Jeff.Haran@citrix.com> wrote:
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org] On Behalf Of Arun KS Sent: Thursday, March 12, 2015 11:03 AM To: Sunny Shah Cc: kernelnewbies Subject: Re: Understanding the mapping of physical memory to kernel address space
Hello Sunny,
On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
Just an FYI, I've seen 1:3 mapping too. We had to do that with the kernels we built when I was at one company because we needed 3GB of virtual address space to map all of the memory mapped registers on their ASICs.
There's lots of options here.
Jeff Haran
Hi Arun, Thanks for that excellent explanation. It's more or less clear to me now. However, quoting what you said: Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it. Why should we have to map the whole RAM into the KVA? Shouldn't it be only LOW_MEM? I also read on a stack overflow thread that LOW_MEM is memory that is permanently mapped into KVA, while HIGH_MEM is mapped as required. Is this true? Thanks, Sunny On Sun, Mar 15, 2015 at 1:17 PM, Arun KS <getarunks@gmail.com> wrote:
Hello Sunny,
On Sat, Mar 14, 2015 at 8:25 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Thank you guys!
I have two more questions from your replies:
I thought I had understood HIGH_MEM and LOW_MEM, but it appears I was wrong. Does the concept of high memory/low memory correspond to physical address space or virtual address space? Also, does LOW_MEM always have to be 1 GiB maximum?
Physical memory is divided into HIGH_MEM and LOW_MEM. Why do we need two memory? To understand this, we need to know who all are consumers of kernel virtual address(KVA) which is limited to 1GB(in case of 3:1 split). 1. low mem( physical ram which has linear mapping to KVA). 2. IO memory address(for eg a DMA controller registers, Memory controller register, etc). When MMU is enabled all the address generated by the cpu are virtual address. Hence io memory should have a valid virtual to physical memory mapping. 3. Vmalloc address space. A dynamic kernel memory allocation mechanism, which only guarantees continuity in virtual address space. 4. Persistent kernel map. (if kernel want to use HIGH memory, it maps high memory to this portion of virtual address). 5. vector table.
Let me give a rough calculation for a better understanding. Lets say a system with configuration as follows, 2GB of physical RAM, 40 MB of physical io address space, 240 MB of vmalloc address space, 32 MB for persistent kernel map The maximum RAM which can be mapped as low mem = 1GB - (40 MB + 240 MB + 32MB) = 712MB.
Rest of RAM 1336MB( 1GB - 712MB) will fall as HIGH_MEM.
Now how system uses HIGH memory. Major user of HIGH mem is user space code. Kernel directly maps high mem to user space virtual address. Hight mem is also used by kernel though PK mappings. Even vmalloc allocation can also fall from HIGH mem region.
Now if we decides to use 1:3 user space to kernel space split, high memory is not required. Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it.
HTH.
Thanks, Arun
For a RAM of 896 MiB - 4096 MiB, the book says: "In this case, the RAM cannot be mapped entirely into the kernel linear address space. The best Linux can do during the initialization phase is to map a RAM window of size 896 MB into the kernel linear address space."
Why is there a need to map the whole RAM into the kernel space (the usage of the word "entirely") ? Shouldn't it be only LOW_MEM ? Or am I confusing the two things here ?
I believe all doubts are pointing to the concepts of LOW_MEM and HIGH_MEM, but I'm still not being able to wrap my head around them.
Thanks, Sunny
On Thu, Mar 12, 2015 at 11:49 PM, Jeff Haran <Jeff.Haran@citrix.com> wrote:
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org] On Behalf Of Arun KS Sent: Thursday, March 12, 2015 11:03 AM To: Sunny Shah Cc: kernelnewbies Subject: Re: Understanding the mapping of physical memory to kernel address space
Hello Sunny,
On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm
erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct?
Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
Just an FYI, I've seen 1:3 mapping too. We had to do that with the kernels we built when I was at one company because we needed 3GB of virtual address space to map all of the memory mapped registers on their ASICs.
There's lots of options here.
Jeff Haran
On Mar 15, 2015 8:27 PM, "Sunny Shah" <shahsunny715@gmail.com> wrote:
Hi Arun,
Thanks for that excellent explanation. It's more or less clear to me now.
However, quoting what you said:
Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it.
Why should we have to map the whole RAM into the KVA? Shouldn't it be
only LOW_MEM? We dont need to. I was just telling we can do that aswell. When you go with 2:2 split, you are changing user space virtual memory layout. Which will bring in lot if other problems. So very common approach is to use high mem.
I also read on a stack overflow thread that LOW_MEM is memory that is
permanently mapped into KVA, while HIGH_MEM is mapped as required. Is this true? Absolutely Thanks, Arun
Thanks, Sunny
On Sun, Mar 15, 2015 at 1:17 PM, Arun KS <getarunks@gmail.com> wrote:
Hello Sunny,
On Sat, Mar 14, 2015 at 8:25 PM, Sunny Shah <shahsunny715@gmail.com>
wrote:
Thank you guys!
I have two more questions from your replies:
I thought I had understood HIGH_MEM and LOW_MEM, but it appears I was wrong. Does the concept of high memory/low memory correspond to physical address space or virtual address space? Also, does LOW_MEM always have to be 1 GiB maximum?
Physical memory is divided into HIGH_MEM and LOW_MEM. Why do we need two memory? To understand this, we need to know who all are consumers of kernel virtual address(KVA) which is limited to 1GB(in case of 3:1 split). 1. low mem( physical ram which has linear mapping to KVA). 2. IO memory address(for eg a DMA controller registers, Memory controller register, etc). When MMU is enabled all the address generated by the cpu are virtual address. Hence io memory should have a valid virtual to physical memory mapping. 3. Vmalloc address space. A dynamic kernel memory allocation mechanism, which only guarantees continuity in virtual address space. 4. Persistent kernel map. (if kernel want to use HIGH memory, it maps high memory to this portion of virtual address). 5. vector table.
Let me give a rough calculation for a better understanding. Lets say a system with configuration as follows, 2GB of physical RAM, 40 MB of physical io address space, 240 MB of vmalloc address space, 32 MB for persistent kernel map The maximum RAM which can be mapped as low mem = 1GB - (40 MB + 240 MB + 32MB) = 712MB.
Rest of RAM 1336MB( 1GB - 712MB) will fall as HIGH_MEM.
Now how system uses HIGH memory. Major user of HIGH mem is user space code. Kernel directly maps high mem to user space virtual address. Hight mem is also used by kernel though PK mappings. Even vmalloc allocation can also fall from HIGH mem region.
Now if we decides to use 1:3 user space to kernel space split, high memory is not required. Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it.
HTH.
Thanks, Arun
For a RAM of 896 MiB - 4096 MiB, the book says: "In this case, the RAM cannot be mapped entirely into the kernel linear address space. The best Linux can do during the initialization phase is to map a RAM window of size 896 MB into the kernel linear address space."
Why is there a need to map the whole RAM into the kernel space (the usage of the word "entirely") ? Shouldn't it be only LOW_MEM ? Or am I confusing the two things here ?
I believe all doubts are pointing to the concepts of LOW_MEM and HIGH_MEM, but I'm still not being able to wrap my head around them.
Thanks, Sunny
On Thu, Mar 12, 2015 at 11:49 PM, Jeff Haran <Jeff.Haran@citrix.com> wrote:
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org] On Behalf Of Arun KS Sent: Thursday, March 12, 2015 11:03 AM To: Sunny Shah Cc: kernelnewbies Subject: Re: Understanding the mapping of physical memory to kernel address space
Hello Sunny,
On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm
erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel
Page
Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
Just an FYI, I've seen 1:3 mapping too. We had to do that with the kernels we built when I was at one company because we needed 3GB of virtual address space to map all of the memory mapped registers on their ASICs.
There's lots of options here.
Jeff Haran
Thank you so much !! On Sun, Mar 15, 2015 at 8:48 PM, Arun KS <getarunks@gmail.com> wrote:
On Mar 15, 2015 8:27 PM, "Sunny Shah" <shahsunny715@gmail.com> wrote:
Hi Arun,
Thanks for that excellent explanation. It's more or less clear to me now.
However, quoting what you said:
Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it.
Why should we have to map the whole RAM into the KVA? Shouldn't it be
only LOW_MEM?
We dont need to. I was just telling we can do that aswell. When you go with 2:2 split, you are changing user space virtual memory layout. Which will bring in lot if other problems. So very common approach is to use high mem.
I also read on a stack overflow thread that LOW_MEM is memory that is
permanently mapped into KVA, while HIGH_MEM is mapped as required. Is this true? Absolutely
Thanks, Arun
Thanks, Sunny
On Sun, Mar 15, 2015 at 1:17 PM, Arun KS <getarunks@gmail.com> wrote:
Hello Sunny,
On Sat, Mar 14, 2015 at 8:25 PM, Sunny Shah <shahsunny715@gmail.com>
wrote:
Thank you guys!
I have two more questions from your replies:
I thought I had understood HIGH_MEM and LOW_MEM, but it appears I was wrong. Does the concept of high memory/low memory correspond to physical address space or virtual address space? Also, does LOW_MEM always have to be 1 GiB maximum?
Physical memory is divided into HIGH_MEM and LOW_MEM. Why do we need two memory? To understand this, we need to know who all are consumers of kernel virtual address(KVA) which is limited to 1GB(in case of 3:1 split). 1. low mem( physical ram which has linear mapping to KVA). 2. IO memory address(for eg a DMA controller registers, Memory controller register, etc). When MMU is enabled all the address generated by the cpu are virtual address. Hence io memory should have a valid virtual to physical memory mapping. 3. Vmalloc address space. A dynamic kernel memory allocation mechanism, which only guarantees continuity in virtual address space. 4. Persistent kernel map. (if kernel want to use HIGH memory, it maps high memory to this portion of virtual address). 5. vector table.
Let me give a rough calculation for a better understanding. Lets say a system with configuration as follows, 2GB of physical RAM, 40 MB of physical io address space, 240 MB of vmalloc address space, 32 MB for persistent kernel map The maximum RAM which can be mapped as low mem = 1GB - (40 MB + 240 MB + 32MB) = 712MB.
Rest of RAM 1336MB( 1GB - 712MB) will fall as HIGH_MEM.
Now how system uses HIGH memory. Major user of HIGH mem is user space code. Kernel directly maps high mem to user space virtual address. Hight mem is also used by kernel though PK mappings. Even vmalloc allocation can also fall from HIGH mem region.
Now if we decides to use 1:3 user space to kernel space split, high memory is not required. Because we have plenty of kernel virtual address(3GB) and can easily map 2GB of RAM in to it.
HTH.
Thanks, Arun
For a RAM of 896 MiB - 4096 MiB, the book says: "In this case, the RAM cannot be mapped entirely into the kernel linear address space. The best Linux can do during the initialization phase is to map a RAM window of size 896 MB into the kernel linear address space."
Why is there a need to map the whole RAM into the kernel space (the usage of the word "entirely") ? Shouldn't it be only LOW_MEM ? Or am I confusing the two things here ?
I believe all doubts are pointing to the concepts of LOW_MEM and HIGH_MEM, but I'm still not being able to wrap my head around them.
Thanks, Sunny
On Thu, Mar 12, 2015 at 11:49 PM, Jeff Haran <Jeff.Haran@citrix.com> wrote:
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org] On Behalf Of Arun
KS
Sent: Thursday, March 12, 2015 11:03 AM To: Sunny Shah Cc: kernelnewbies Subject: Re: Understanding the mapping of physical memory to kernel address space
Hello Sunny,
On Thu, Mar 12, 2015 at 10:32 PM, Sunny Shah <shahsunny715@gmail.com
wrote:
Hello,
This is my first mail on this list, so please let me know if I'm erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct? Yes. Incase of 3:1 mapping, kernel virtual address starts at 0xc0000000. You can also have 2:2 mappings aswell. It is a configurable option
Just an FYI, I've seen 1:3 mapping too. We had to do that with the kernels we built when I was at one company because we needed 3GB of virtual address space to map all of the memory mapped registers on their ASICs.
There's lots of options here.
Jeff Haran
On 12-Mar-2015, at 10:02 am, Sunny Shah <shahsunny715@gmail.com> wrote:
Hello,
This is my first mail on this list, so please let me know if I'm erring.
I'm reading Bovet and Cesati's "Understanding the Linux Kernel", specifically the chapter "Memory Addressing", sub-section "Kernel Page Tables". Here they describe how Linux initializes its page tables for various RAM sizes and how much of the physical address space is mapped onto the kernel virtual address space.
I have several questions from my reading:
• My understanding is that the 32 bit virtual address space of a process is split into 2 parts - the first 3 GiB for the user space and the remaining 1GiB for the kernel (with the same kernel mapping being used for all processes. However, although the kernel is mapped into the higher portion of the address space, it resides in the lower 1 GiB of RAM. Is this correct?
Not the lowest 1GB of RAM. This portion is non-contiguous, (video memory , ROM etc…). However, the kernel resides from 0x01000000 (16MB) which is physical address and is mapped to 0xC0000000 (virtual address).
• There is a frequent mention of "mapping RAM to the kernel address space". Is the whole RAM mapped to the kernel space? What would happen in the case of a machine having only 1 GiB of RAM?
Paging. Think of this in reverse order. Instead of looking as whole RAM is mapped, think of the whole process is mapped (which ofcourse is virtual). Now, everytime there is a need to read/write a location that virtual page must be backed by a page in real memory (RAM). Paging allows partial text, bss and data to be executed using swapping to bring in/out pages as and when required. This also allows other process to run in small amount of RAM.
• Related to the above, what exactly is max_low_pfn? It is mentioned it is the "Page frame number of the last page frame directly mapped by the kernel (low memory)". What would it's value be for a machine with 1 GiB RAM? For a machine with 4 GiB RAM, would it be the number of the frame covering the last portion of kernel space (896 MiB)?
Not to _sure_ on this. min and max pfn are closly tied to zones. for both it will be 896MB. (Please read High memory) Thanks
Sorry if my questions are a bit vague. I'm still new to this and having difficulty relating everything.
Thanks, Sunny _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (4)
-
Arshad Hussain -
Arun KS -
Jeff Haran -
Sunny Shah