简体   繁体   English

一个64bit的Linux Kernel占多少memory?

[英]How much memory does a 64bit Linux Kernel take up?

The address space is huge for the x86-64 even though 48-bit addresses are mainly used.尽管主要使用 48 位地址,但 x86-64 的地址空间很大。

On x86 32-bit machines it was pretty clear how much RAM the kernel took up.在 x86 32 位机器上,很清楚 kernel 占用了多少 RAM。 Generally around 1 GB of ZONE_NORMAL is on the bottom of memory while everything else above the 1GB in PHYSICAL (not virtual) addresses were for ZONE_HIGHMEM (for user space).通常大约 1 GB 的ZONE_NORMAL位于 memory 的底部,而物理(非虚拟)地址中 1GB 以上的所有其他内容用于ZONE_HIGHMEM (用于用户空间)。 This would be a 3:1 split.这将是 3:1 的分配。 Of course we can have configurations were we can have a 1:3, 2:2, etc. (by changing VM_SPLIT ).当然,我们可以有配置,我们可以有 1:3、2:2 等(通过更改VM_SPLIT )。

How much memory in RAM is for kernel space for 64 bit kernels? RAM 中的 memory 有多少用于 64 位内核的 kernel 空间?

I know the PAGE_OFFSET is set to a value far above physically addressable memory in x64 (for both 48 and 56).我知道PAGE_OFFSET设置为远高于 x64 中物理可寻址 memory 的值(对于 48 和 56)。 PAGE_OFFSET in x64 just describes the split in virtual address space, not physical (a 48 bit PAGE_OFFSET would be ffff888000000000 ). x64 中的PAGE_OFFSET仅描述虚拟地址空间的拆分,而不是物理地址空间(48 位PAGE_OFFSETffff888000000000 )。

So does 1 GB of memory house kernel space?那么 memory 的 1 GB 是否包含 kernel 空间? 2GB? 2GB? 3? 3? Are there variable or macros that describe the size?是否有描述大小的变量或宏? Is it calculated?是计算出来的吗?

Each user-space process can use its own 2^47 bytes (128 TiB) of virtual address space.每个用户空间进程都可以使用自己的 2^47 字节 (128 TiB) 的虚拟地址空间。 Or more on a system with PML5 support.或者在支持 PML5 的系统上进行更多操作。

The available physical RAM to back those pages is the total size of physical RAM, minus maybe 30 MiB or so that the kernel needs for its own code/data.用于支持这些页面的可用物理 RAM 是物理 RAM 的总大小,减去 kernel 自身代码/数据所需的 30 MiB 左右。 (Not including the pagecache: Linux will use any spare pages as buffers and disk cache). (不包括页面缓存:Linux 将使用任何备用页面作为缓冲区和磁盘缓存)。 This is mostly unrelated to virtual address-space limits.这主要与虚拟地址空间限制无关。


1G is how much virtual address space a kernel used up. 1G是kernel用了多少虚拟地址空间。 Not how much physical RAM.不是多少物理内存。

The address-space question mattered for how much memory a single process could use at the same time, but the kernel can still use all your RAM for caching file data, etc. Unless you're finding the 2^(48-1) or 2^(57-1) bytes of the low half virtual address-space range cramped, there's no equivalent problem.地址空间问题对于单个进程可以同时使用多少 memory 很重要,但是 kernel 仍然可以使用所有 RAM 来缓存文件数据等。除非您找到2^(48-1)2^(57-1)字节的低半虚拟地址空间范围狭窄,没有等效的问题。

See the kernel's Documentation/x86/x86-64/mm.txt for the x86-64 virtual memory map. Also Why 4-level paging can only cover 64 TiB of physical address re: x86-64 Linux not doing inconvenient HIGHMEM stuff - the entire high half of virtual address space is reserved for the kernel, and it maps all the RAM because it's a kernel.请参阅内核的Documentation/x86/x86-64/mm.txt以了解 x86-64 虚拟 memory map。还有为什么 4 级分页只能覆盖 64 TiB 的物理地址回复:x86-64 Linux 不做不方便的 HIGHMEM 东西 - 的虚拟地址空间的整个高半部分都为 kernel 保留,它映射所有RAM,因为它是 kernel。

Virtual address space usage does indirectly set a 64 TiB limit on how much physical RAM the kernel can use, but if you have less than that there's no effect.虚拟地址空间的使用确实间接设置了 kernel 可以使用多少物理 RAM 的 64 TiB 限制,但如果小于该值,则没有任何影响。 Just like how a 32-bit kernel wasn't a problem if your machine had less than 1 or 2 GiB of RAM.就像如果您的机器的 RAM 少于 1 或 2 GiB,32 位 kernel 不是问题一样。


The amount of physical RAM actually reserved by the kernel depends on build options and modules, but might be something like 16 to 32 MiB. kernel 实际保留的物理 RAM 量取决于构建选项和模块,但可能约为 16 到 32 MiB。

Check dmesg output and look for something like this kernel log message from an x86-64 5.16.3-arch1 kernel I found in an old boot-log message.检查dmesg output 并从 x86-64 5.16.3-arch1 kernel 中查找类似 kernel 的日志消息,我在旧的引导日志消息中找到了它。

Memory: 32538176K/33352340K available (14344K kernel code, 2040K rwdata, 8996K rodata, 1652K init, 4336K bss, 813904K reserved, 0K cma-reserved

Don't count the init (freed in after boot) or reserved parts;不要计算init (启动后释放)或reserved部分; I'm pretty sure Linux doesn't actually reserve ~800 MiB in a way that makes it unusable for anything else.我很确定 Linux 实际上并没有以使其无法用于其他任何用途的方式保留 ~800 MiB。

Also look for the later Freeing unused decrypted memory: 2036K / Freeing unused kernel image (initmem) memory: 1652K etc. (That's the same size as the init part listed earlier, which is why you don't have to count it.)还要找后面的Freeing unused decrypted memory: 2036K / Freeing unused kernel image (initmem) memory: 1652K等(这和前面列出的init部分大小相同,这就是为什么你不必计算它的原因。)

It might also dynamically allocate some memory during startup;它也可能在启动期间动态分配一些 memory; that initial "memory" line is just the sum of its .text , .data , and .bss sections, static code+data sizes.最初的“内存”行只是其.text.data.bss部分的总和,static 代码+数据大小。

On 64-Bit systems, the only limitation is on how much physical memory the kernel can use.在 64 位系统上,唯一的限制是 memory 和 kernel 可以使用多少物理空间。 The kernel will map all the available ram, and user space applications should be able to gain access to as much as the kernel can provide while maintaining sufficient for the kernel to operate. kernel 将 map 所有可用的内存,用户空间应用程序应该能够访问 kernel 可以提供的尽可能多的内存,同时保持足以让 kernel 运行。

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

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