简体   繁体   English

Linux内核如何决定要使用哪个内存区域?

[英]How Linux kernel decide to which memory zone to use?

When I check pagetypeinfo 当我检查pagetypeinfo

cat /proc/pagetypeinfo 猫/ proc / pagetypeinfo

I see three types of memory zones; 我看到三种类型的存储区:

  • DMA DMA
  • DMA32 DMA32
  • Normal 正常

How Linux choose a memory zone to allocate a new page? Linux如何选择一个内存区域来分配新页面?

These memory zones are defined only for the 32 bit systems and not in the 64 bit. 这些存储区仅针对32位系统而不是64位定义。

Rememember these are the kernel accessible main memory we are talking about. 记住这些是我们正在谈论的内核可访问的main memory In a 32 bit (4GB) system, the split between the kernel and the user space is 1:3 . 32 bit (4GB)系统中,内核和用户空间之间的比例为1:3 Meaning kernel can access 1GB and the user space 3GB. 意味着内核可以访问1GB,用户空间可以为3GB。 The kernel's 1GB is split as follows: 内核的1GB划分如下:

Zone_DMA (0-16MB): Permanently mapped into the kernel address space. Zone_DMA(0-16MB): 永久映射到内核地址空间。
For compatibility reasons for older ISA devices that can address only the lower 16MB of main memory. 由于兼容性原因,较旧的ISA设备只能访问较低的16MB主内存。

Zone_Normal (16MB-896MB): Permanently mapped into the kernel address space. Zone_Normal(16MB-896MB): 永久映射到内核地址空间。
Many kernel operations can only take place using ZONE_NORMAL so it is the most performance critical zone and is the memory mostly allocated by the kernel. 许多内核操作只能使用ZONE_NORMAL因此它是性能最关键的区域,并且是大部分由内核分配的内存。

ZONE_HIGH_MEM (896MB-above): not permanently mapped into the kernel's address space. ZONE_HIGH_MEM(896MB以上): 没有永久映射到内核的地址空间。
Kernel can access entire 4GB main memory. 内核可以访问整个4GB主内存。 kernel's 1GB through Zone_DMA & Zone_Normal and user's 3GB through ZONE_HIGH_MEM . 分别通过Zone_DMAZone_Normal 1GB的内核,通过Zone_DMA Zone_Normal用户3GB的ZONE_HIGH_MEM With Intel's Physical Address Extension (PAE) , one gets 4 extra bits to address the main memory resulting in 36 bits, a total of 64GB of memory that can be accessed. 借助Intel的Physical Address Extension (PAE) ,人们可以获得4个额外的位来寻址主内存,从而获得36位,即总共64GB的可访问内存。 The delta address space (36 bit address - 32 bit address) is where ZONE_HIGH_MEM is used to map to the user accessed main memory (ie between 2GB - 4GB). 增量地址空间(36位地址-32位地址)是ZONE_HIGH_MEM用于映射到用户访问的主存储器(即2GB-4GB之间)的地方。

Read more: 阅读更多:

http://www.quora.com/Linux-Kernel/Why-is-there-ZONE_HIGHMEM-in-the-x86-32-Linux-kernel-but-not-in-the-x86-64-kernel http://www.quora.com/Linux-Kernel/Why-is-there-ZONE_HIGHMEM-in-the-x86-32-Linux-kernel-but-not-in-the-x86-64-kernel
http://www.quora.com/Linux-Kernel/What-is-the-difference-between-high-memory-and-normal-memory http://www.quora.com/Linux-Kernel/What-is-the-difference-between-high-memory-and-normal-memory
Linux 3/1 virtual address split Linux 3/1虚拟地址拆分

For every memory allocation request (for eg via kmalloc), based on the flags passed to the function,kernel selects the memory zone. 对于每个内存分配请求(例如,通过kmalloc的请求),内核都会根据传递给函数的标志来选择内存区域。 these requests internally triggers the kernel function alloc_pages(). 这些请求在内部触发内核函数alloc_pages()。

zonelist is an argument that gets passed to alloc_pages(), that Points to a zonelist data structure describing, in order of preference, the mem- ory zones suitable for the memory allocation. zonelist是传递给alloc_pages()的参数,该参数指向zonelist数据结构,该数据结构按优先顺序描述适合于内存分配的内存区域。

refer the memory management chapter in book Understanding the Linux kernel 请参阅《了解Linux内核》一书中的内存管理一章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM