Linux physical memory and linear address space layout-1

Source: Internet
Author: User

On a 32-bit processor platform supporting MMU, the addresses of physical and virtual buckets in Linux systems are from 0x00000000 to 0 xffffffff, 4 GB in total, however, the physical storage space is completely different from the virtual storage space layout. Linux runs in a virtual bucket and maps the physical memory that actually exists in the system to the entire 4 GB virtual bucket according to different requirements.

N physical storage space layout

The physical storage space layout of Linux is related to the processor. For details, refer to the storage space distribution table (memory map) section in the processor user manual, here we only list the general layout of Linux physical memory space on the embedded processor platform, as shown in Figure 18-4.

Figure 18-4 general Linux physical memory space layout

Note:

1) The maximum node number N cannot be greater than the MAX_NUMNODES-1.

2) max_numnodes indicates the maximum number of nodes supported by the system. In the arm system, the sharp chip supports up to 16 nodes, and the other chip supports up to 4 nodes.

3) numnodes indicates the actual number of Memory nodes in the current system.

4) in a system that does not support the config_discontigmem option, there is only one memory node.

5) The maximum bank number M cannot be greater than the NR_BANKS-1.

6) nr_banks indicates the maximum number of memory banks supported by the system, which is generally equal to the number of CPU Ram slices. In the arm system, the sharp chip supports up to 16 banks, while other chips support up to 8 banks.

7) The mem_init () function releases the space occupied by the page frame code table of all nodes, the space of the page descriptor of the holes, and the pages of the idle memory.

N virtual storage space layout

In a system that supports MMU, the MMU function is enabled after hardware initialization is completed, so that the entire system runs in a virtual bucket, MMU of the processor is used to map a virtual bucket to a physical bucket, while the ing between a virtual bucket and a five-path bucket is managed by the Linux kernel. In 32-bit systems, physical storage space occupies 4 GB, and virtual storage space also occupies 4 GB, linux maps the memory space that actually exists in the physical space much less than 4 GB to all the space except the I/O space mapped to the entire 4 GB virtual storage space, therefore, the virtual memory space is much larger than the physical memory space, which means that the same physical memory may be mapped to multiple virtual memory address spaces, which is the responsibility of Linux memory management. Figure 18-5 lists the general layout of virtual memory space in the Linux kernel (in fact, I/O space is also in use, usually occupying high-end memory space, which is not marked here ).

Figure 18-5 General Layout of virtual memory space in Linux

Note:

1) linear address space: refers to the entire 4 GB virtual storage space in Linux from 0x00000000 to 0xffffffff.

2) kernel space: the kernel space indicates the code or data running in the supervisor mode of the processor. The kernel space occupies 1 GB linear address space from 0xc0000000 to 0xffffffff, the Kernel linear address space is shared by all processes, but only processes running in the kernel state can access it. User processes can switch to the kernel state to access the kernel space through system calls, the address generated when the process runs in the kernel state belongs to the kernel space.

3) user space: the user space occupies 3 GB linear address space from 0x00000000 to 0xbfffffff. Each process has an independent 3 GB user space. Therefore, the user space is exclusive to each process, however, the kernel thread does not have user space because it does not generate user space addresses. In addition, the user space of the parent process shared (inherited) only uses the ing relationship between the user linear address and the physical memory address of the parent process, rather than sharing the user space of the parent process. Processes running in the user State and kernel state can access the user space.

4) kernel logical address space: Linear address space between page_offset (3G) and high_memory (physical memory size, up to 896). It is the physical memory ing area of the system, it maps all or part of the physical memory (if the system contains high-end memory. The logical address space of the kernel corresponds to the physical address space of the system RAM memory in Figure 18-4 (including the memory holes ), there is only one fixed offset between the address in the kernel logical address space and the address in the physical address space of RAM memory (3 GB). If the physical address space of RAM memory is edited from 0x00000000 address, the offset is page_offset.

5) low-end memory: The physical memory mapped to the kernel logical address space is the low-end memory (the actual physical memory size, but smaller than 896 ), there is always a one-to-one kernel logic address in Linux linear address space at the low end. during system initialization, the low-end memory is permanently mapped to the kernel logic address space, creates a virtual ing page table for the low-end memory. The conversion between physical addresses and linear addresses in the physical memory in the low-end memory can be performed through two macros: _ Pa (X) and _ VA (x). # define
_ Pa (x) (unsigned long) (x)-page_offset) _ Pa (x) converts the address X of the kernel logical address space to the corresponding physical address, equivalent to _ virt_to_phys (unsigned long) (x), __va (x). On the contrary, the address of the low-end physical memory space is converted to the corresponding kernel logic address, equivalent to (void
*) _ Phys_to_virt (unsigned long) (X ))).

6) high-end memory: The physical memory above the low-end memory address is high-end memory (over 896 physical memory ), there is no fixed one-to-one kernel logic address in Linux linear address space in the high-end. during system initialization, A ing page table will not be set up for the memory to map it to the Linux linear address space, instead, you need to use the high-end memory to create a ing page table for the allocated high-end physical memory so that it can be used by the kernel. Otherwise, it cannot be used. The preceding _ Pa (X) and _ VA (x) macros cannot be used for switching between high-end memory physical addresses.

7) concept of high-end memory: As mentioned above, Linux divides the 4 GB linear address space into two parts. From 0x00000000 to 0xbfffffff, a total of 3 GB space is occupied by the user process, this linear address space is not fixed to the physical memory space. The 4gb linear address space from 0xc0000000 to 0xffffffff is used as the kernel space. In the embedded system, in addition to ing physical memory space, this linear address space also maps I/O space such as the peripheral register space inside the processor. 0xc0000000 ~ The kernel logical address space between high_memory is used to fix the physical memory ing in the system, that is, 0xc0000000 ~ The space size between high_memory and the physical memory size of the system are the same (of course, in a non-continuous memory system with the config_discontigmemd option configured, the kernel logical address space may have memory holes like the physical memory space). If the physical memory capacity in the system is much smaller than 1 GB, then the high_memory ~ above the kernel logical address space in the current kernel address space ~ There is enough space between 0xffffffff to fix the ing of some I/O space. However, if the physical memory capacity (including memory holes) in the system is greater than 1 GB, there is not enough Kernel linear address space to fix all the physical memory of the ing system and some I/O space. To solve this problem, we have set an experience value on the x86 processor platform: 896 MB, that is, if the physical memory (including memory holes) in the system is greater than 896 MB, the first MB physical memory is fixed to the kernel logical address space 0xc0000000 ~ 0xc0000000 + 896 MB (= high_memory), while the physical memory after 896mb is not fixed to the Kernel linear address space ing, this part of the memory is called high-end physical memory. In this case, the Kernel linear address space is high_memory ~ The MB space between 0xffffffff is called the high-end memory linear address space, which is used to map high-end physical memory and I/O space. 896mb is an experience on the x86 processor platform. It leaves MB of linear address space to map high-end memory and I/O address space. In the embedded system, we can modify this threshold according to the actual situation. For example, in MIPS, this value is set to 0x20000000b (512 MB). The config_highmem option must be configured only when the physical memory capacity in the system is greater than 0x20000000b, enable the kernel to allocate and map high-end memory. For details about how to set high-end physical memory and high-end physical memory threshold, see the Memory Page area (Zone) concept.

8) high-end linear Address Space: The linear address space from high_memory to 0xffffffff belongs to the high-end linear address space, where vmalloc_start ~ The linear address between vmalloc_end is used by the vmalloc () function to allocate high-end physical memory that is physically discontinuous but linear address space is continuous, or is used by the vmap () function to map high-end or low-end physical memory, or the ioremap () function re-maps the I/O physical space. The linear address space of the last_pkmap (usually equal to 1024) page starting with pkmap_base is used by the kmap () function to permanently map high-end physical memory. The linear address space of the km_type_nr * nr_cpus page starting with fixaddr_start is used by the kmap_atomic () function to temporarily map high-end physical memory, other unused high-end linear address spaces can be used to permanently map I/O address spaces during system initialization.

The ARM processor platform in Linux 2.6.10 does not support high-end memory. Figure 18-6 and Figure 18-7 respectively list the Linux linear address space layout of the sa1100 and ixp4xx processor platforms.

 

On a 32-bit processor platform supporting MMU, the addresses of physical and virtual buckets in Linux systems are from 0x00000000 to 0 xffffffff, 4 GB in total, however, the physical storage space is completely different from the virtual storage space layout. Linux runs in a virtual bucket and maps the physical memory that actually exists in the system to the entire 4 GB virtual bucket according to different requirements.

N physical storage space layout

The physical storage space layout of Linux is related to the processor. For details, refer to the storage space distribution table (memory map) section in the processor user manual, here we only list the general layout of Linux physical memory space on the embedded processor platform, as shown in Figure 18-4.

Figure 18-4 general Linux physical memory space layout

Note:

1) The maximum node number N cannot be greater than the MAX_NUMNODES-1.

2) max_numnodes indicates the maximum number of nodes supported by the system. In the arm system, the sharp chip supports up to 16 nodes, and the other chip supports up to 4 nodes.

3) numnodes indicates the actual number of Memory nodes in the current system.

4) in a system that does not support the config_discontigmem option, there is only one memory node.

5) The maximum bank number M cannot be greater than the NR_BANKS-1.

6) nr_banks indicates the maximum number of memory banks supported by the system, which is generally equal to the number of CPU Ram slices. In the arm system, the sharp chip supports up to 16 banks, while other chips support up to 8 banks.

7) The mem_init () function releases the space occupied by the page frame code table of all nodes, the space of the page descriptor of the holes, and the pages of the idle memory.

N virtual storage space layout

In a system that supports MMU, the MMU function is enabled after hardware initialization is completed, so that the entire system runs in a virtual bucket, MMU of the processor is used to map a virtual bucket to a physical bucket, while the ing between a virtual bucket and a five-path bucket is managed by the Linux kernel. In 32-bit systems, physical storage space occupies 4 GB, and virtual storage space also occupies 4 GB, linux maps the memory space that actually exists in the physical space much less than 4 GB to all the space except the I/O space mapped to the entire 4 GB virtual storage space, therefore, the virtual memory space is much larger than the physical memory space, which means that the same physical memory may be mapped to multiple virtual memory address spaces, which is the responsibility of Linux memory management. Figure 18-5 lists the general layout of virtual memory space in the Linux kernel (in fact, I/O space is also in use, usually occupying high-end memory space, which is not marked here ).

Figure 18-5 General Layout of virtual memory space in Linux

Note:

1) linear address space: refers to the entire 4 GB virtual storage space in Linux from 0x00000000 to 0xffffffff.

2) kernel space: the kernel space indicates the code or data running in the supervisor mode of the processor. The kernel space occupies 1 GB linear address space from 0xc0000000 to 0xffffffff, the Kernel linear address space is shared by all processes, but only processes running in the kernel state can access it. User processes can switch to the kernel state to access the kernel space through system calls, the address generated when the process runs in the kernel state belongs to the kernel space.

3) user space: the user space occupies 3 GB linear address space from 0x00000000 to 0xbfffffff. Each process has an independent 3 GB user space. Therefore, the user space is exclusive to each process, however, the kernel thread does not have user space because it does not generate user space addresses. In addition, the user space of the parent process shared (inherited) only uses the ing relationship between the user linear address and the physical memory address of the parent process, rather than sharing the user space of the parent process. Processes running in the user State and kernel state can access the user space.

4) kernel logical address space: Linear address space between page_offset (3G) and high_memory (physical memory size, up to 896). It is the physical memory ing area of the system, it maps all or part of the physical memory (if the system contains high-end memory. The logical address space of the kernel corresponds to the physical address space of the system RAM memory in Figure 18-4 (including the memory holes ), there is only one fixed offset between the address in the kernel logical address space and the address in the physical address space of RAM memory (3 GB). If the physical address space of RAM memory is edited from 0x00000000 address, the offset is page_offset.

5) low-end memory: The physical memory mapped to the kernel logical address space is the low-end memory (the actual physical memory size, but smaller than 896 ), there is always a one-to-one kernel logic address in Linux linear address space at the low end. during system initialization, the low-end memory is permanently mapped to the kernel logic address space, creates a virtual ing page table for the low-end memory. The conversion between physical addresses and linear addresses in the physical memory in the low-end memory can be performed through two macros: _ Pa (X) and _ VA (x). # define
_ Pa (x) (unsigned long) (x)-page_offset) _ Pa (x) converts the address X of the kernel logical address space to the corresponding physical address, equivalent to _ virt_to_phys (unsigned long) (x), __va (x). On the contrary, the address of the low-end physical memory space is converted to the corresponding kernel logic address, equivalent to (void
*) _ Phys_to_virt (unsigned long) (X ))).

6) high-end memory: The physical memory above the low-end memory address is high-end memory (over 896 physical memory ), there is no fixed one-to-one kernel logic address in Linux linear address space in the high-end. during system initialization, A ing page table will not be set up for the memory to map it to the Linux linear address space, instead, you need to use the high-end memory to create a ing page table for the allocated high-end physical memory so that it can be used by the kernel. Otherwise, it cannot be used. The preceding _ Pa (X) and _ VA (x) macros cannot be used for switching between high-end memory physical addresses.

7) concept of high-end memory: As mentioned above, Linux divides the 4 GB linear address space into two parts. From 0x00000000 to 0xbfffffff, a total of 3 GB space is occupied by the user process, this linear address space is not fixed to the physical memory space. The 4gb linear address space from 0xc0000000 to 0xffffffff is used as the kernel space. In the embedded system, in addition to ing physical memory space, this linear address space also maps I/O space such as the peripheral register space inside the processor. 0xc0000000 ~ The kernel logical address space between high_memory is used to fix the physical memory ing in the system, that is, 0xc0000000 ~ The space size between high_memory and the physical memory size of the system are the same (of course, in a non-continuous memory system with the config_discontigmemd option configured, the kernel logical address space may have memory holes like the physical memory space). If the physical memory capacity in the system is much smaller than 1 GB, then the high_memory ~ above the kernel logical address space in the current kernel address space ~ There is enough space between 0xffffffff to fix the ing of some I/O space. However, if the physical memory capacity (including memory holes) in the system is greater than 1 GB, there is not enough Kernel linear address space to fix all the physical memory of the ing system and some I/O space. To solve this problem, we have set an experience value on the x86 processor platform: 896 MB, that is, if the physical memory (including memory holes) in the system is greater than 896 MB, the first MB physical memory is fixed to the kernel logical address space 0xc0000000 ~ 0xc0000000 + 896 MB (= high_memory), while the physical memory after 896mb is not fixed to the Kernel linear address space ing, this part of the memory is called high-end physical memory. In this case, the Kernel linear address space is high_memory ~ The MB space between 0xffffffff is called the high-end memory linear address space, which is used to map high-end physical memory and I/O space. 896mb is an experience on the x86 processor platform. It leaves MB of linear address space to map high-end memory and I/O address space. In the embedded system, we can modify this threshold according to the actual situation. For example, in MIPS, this value is set to 0x20000000b (512 MB). The config_highmem option must be configured only when the physical memory capacity in the system is greater than 0x20000000b, enable the kernel to allocate and map high-end memory. For details about how to set high-end physical memory and high-end physical memory threshold, see the Memory Page area (Zone) concept.

8) high-end linear Address Space: The linear address space from high_memory to 0xffffffff belongs to the high-end linear address space, where vmalloc_start ~ The linear address between vmalloc_end is used by the vmalloc () function to allocate high-end physical memory that is physically discontinuous but linear address space is continuous, or is used by the vmap () function to map high-end or low-end physical memory, or the ioremap () function re-maps the I/O physical space. The linear address space of the last_pkmap (usually equal to 1024) page starting with pkmap_base is used by the kmap () function to permanently map high-end physical memory. The linear address space of the km_type_nr * nr_cpus page starting with fixaddr_start is used by the kmap_atomic () function to temporarily map high-end physical memory, other unused high-end linear address spaces can be used to permanently map I/O address spaces during system initialization.

The ARM processor platform in Linux 2.6.10 does not support high-end memory. Figure 18-6 and Figure 18-7 respectively list the Linux linear address space layout of the sa1100 and ixp4xx processor platforms.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.