linux内核如何管理小于1GB的物理内存? [英] How does the linux kernel manage less than 1GB physical memory?

查看:32
本文介绍了linux内核如何管理小于1GB的物理内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 linux 内核内部结构,在阅读了解 Linux 内核"时,很多与内存相关的问题让我印象深刻.其中之一是,如果我的系统上仅安装了 512 MB 的物理内存,则 Linux 内核如何处理内存映射.

I'm learning the linux kernel internals and while reading "Understanding Linux Kernel", quite a few memory related questions struck me. One of them is, how the Linux kernel handles the memory mapping if the physical memory of say only 512 MB is installed on my system.

据我所知,内核将 0(或 16)MB-896MB 物理 RAM 映射到 0xC0000000 线性地址,并且可以直接对其进行寻址.因此,在上述情况下,我只有 512 MB:

As I read, kernel maps 0(or 16) MB-896MB physical RAM into 0xC0000000 linear address and can directly address it. So, in the above described case where I only have 512 MB:

  • 内核如何从 512 MB 映射到 896 MB?在描述的方案中,内核设置了一些东西,以便每个进程的页表将虚拟地址从 0xC0000000 映射到 0xFFFFFFFF (1GB) 直接映射到物理地址从 0x00000000 到 0x3FFFFFFF (1GB).但是,当我只有 512 MB 物理 RAM 时,如何将虚拟地址从 0xC0000000-0xFFFFFFFF 映射到物理地址 0x00000000-0x3FFFFFFF ?重点是我的物理范围只有 0x00000000-0x20000000.

  • How can the kernel map 896 MB from only 512 MB ? In the scheme described, the kernel set things up so that every process's page tables mapped virtual addresses from 0xC0000000 to 0xFFFFFFFF (1GB) directly to physical addresses from 0x00000000 to 0x3FFFFFFF (1GB). But when I have only 512 MB physical RAM, how can I map, virtual addresses from 0xC0000000-0xFFFFFFFF to physical 0x00000000-0x3FFFFFFF ? Point is I have a physical range of only 0x00000000-0x20000000.

在这种情况下,用户模式进程怎么样?

What about user mode processes in this situation?

每篇文章都只解释了当您安装了 4 GB 内存并且内核将 1 GB 映射到内核空间并且用户进程使用剩余 RAM 量时的情况.

Every article explains only the situation, when you've installed 4 GB of memory and the kernel maps the 1 GB into kernel space and user processes uses the remaining amount of RAM.

如果您能帮助我提高理解力,我将不胜感激.

I would appreciate any help in improving my understanding.

谢谢...!

推荐答案

并非所有虚拟(线性)地址都必须映射到任何内容.如果代码访问未映射的页面,则会引发页面错误.

Not all virtual (linear) addresses must be mapped to anything. If the code accesses unmapped page, the page fault is risen.

物理页可以同时映射到多个虚拟地址.

The physical page can be mapped to several virtual addresses simultaneously.

在 4 GB 虚拟内存中有 2 个部分:0x0... 0xbfffffff - 是进程虚拟内存,0xc0000000 .. 0xffffffff 是内核虚拟内存.

In the 4 GB virtual memory there are 2 sections: 0x0... 0xbfffffff - is process virtual memory and 0xc0000000 .. 0xffffffff is a kernel virtual memory.

  • 内核如何从 512 MB 映射到 896 MB?

最多可映射 896 MB.因此,如果您只有 512 个,则将只有 512 MB 映射.

It maps up to 896 MB. So, if you have only 512, there will be only 512 MB mapped.

如果您的物理内存在 0x00000000 到 0x20000000 之间,它将被映射为内核直接访问虚拟地址 0xC0000000 到 0xE0000000(线性映射).

If your physical memory is in 0x00000000 to 0x20000000, it will be mapped for direct kernel access to virtual addresses 0xC0000000 to 0xE0000000 (linear mapping).

  • 在这种情况下,用户模式进程会怎样?

用户进程的物理内存将被映射(不是按顺序而是随机的页到页映射)到虚拟地址 0x0 .... 0xc0000000.此映射将是 0..896MB 页面的第二个映射.这些页面将从免费页面列表中获取.

Phys memory for user processes will be mapped (not sequentially but rather random page-to-page mapping) to virtual addresses 0x0 .... 0xc0000000. This mapping will be the second mapping for pages from 0..896MB. The pages will be taken from free page lists.

  • phys RAM 中的用户模式进程在哪里?

任何地方.

  • 每篇文章都只说明了当您安装了 4 GB 内存

没有.每篇文章都解释了 4 Gb 的虚拟地址空间是如何映射的.虚拟内存的大小始终为 4 GB(对于没有内存扩展的 32 位机器,如 x86 的 PAE/PSE/etc)

No. Every article explains how 4 Gb of virtual address space is mapped. The size of virtual memory is always 4 GB (for 32-bit machine without memory extensions like PAE/PSE/etc for x86)

8.1.3 中所述.Robert Love(我使用第三版)的Linux Kernel Development一书的Memory Zones,有几个物理内存区:

As stated in 8.1.3. Memory Zones of the book Linux Kernel Development by Robert Love (I use third edition), there are several zones of physical memory:

  • ZONE_DMA - 包含低于 16 MB 的内存页帧
  • ZONE_NORMAL - 包含 16 MB 以上和 896 MB 以下的内存页框
  • ZONE_HIGHMEM - 包含 896 MB 及以上的内存页帧

因此,如果您有 512 MB,您的 ZONE_HIGHMEM 将为空,而 ZONE_NORMAL 将映射 496 MB 的物理内存.

So, if you have 512 MB, your ZONE_HIGHMEM will be empty, and ZONE_NORMAL will have 496 MB of physical memory mapped.

另外,看看2.5.5.2.当 RAM 大小小于 896 MB 时的最终内核页表 部分.这是关于情况,当您的内存少于 896 MB 时.

Also, take a look to 2.5.5.2. Final kernel Page Table when RAM size is less than 896 MB section of the book. It is about case, when you have less memory than 896 MB.

另外,对于 ARM 有一些虚拟内存布局的描述:http://www.mjmwired.net/kernel/Documentation/arm/memory.txt

Also, for ARM there is some description of virtual memory layout: http://www.mjmwired.net/kernel/Documentation/arm/memory.txt

第63行PAGE_OFFSET high_memory-1是内存的直接映射部分

The line 63 PAGE_OFFSET high_memory-1 is the direct mapped part of memory

这篇关于linux内核如何管理小于1GB的物理内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆