在Linux中,属于内核数据段的物理内存页是否可交换? [英] In Linux, physical memory pages belong to the kernel data segment are swappable or not?

查看:222
本文介绍了在Linux中,属于内核数据段的物理内存页是否可交换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之所以问是因为,我记得所有属于内核的物理页面都固定在内存中,因此无法交换,就像这里所说的那样:

I'm asking because I remember that all physical pages belong to the kernel are pinned in memory and thus are unswappable, like what is said here: http://www.cse.psu.edu/~axs53/spring01/linux/memory.ppt

但是,我正在阅读一份研究论文,感到困惑, (物理)页面经常在内核数据段和用户空间之间移动."

However, I'm reading a research paper and feel confused as it says, "(physical) pages frequently move between the kernel data segment and user space."

它还提到,相比之下,物理页面不会在内核代码段和用户空间之间移动.

It also mentions that, in contrast, physical pages do not move between the kernel code segment and user space.

我认为,如果物理页面有时属于内核数据段,有时又属于用户空间,那必须意味着属于内核数据段的物理页面是可交换的,这与我目前的理解不符.

I think if a physical page sometimes belongs to the kernel data segment and sometimes belongs to user space, it must mean that physical pages belong to the kernel data segment are swappable, which is against my current understanding.

那么,属于内核数据段的物理页是否可以交换?无法交换?

So, physical pages belong to the kernel data segment are swappable? unswappable?

P.S.该研究论文可在此处获得: https://www.cs.cmu.edu/~arvinds/pubs/secvisor .pdf

P.S. The research paper is available here: https://www.cs.cmu.edu/~arvinds/pubs/secvisor.pdf

请搜索在之间移动",您会找到它.

Please search "move between" and you will find it.

P.S.同样,从[3G + 896M]到4G的虚拟内存区域属于内核,用于映射ZONE_HIGHMEM(x86 32位Linux,3G + 1G设置)中的物理页面.在这种情况下,内核可以首先将该区域中的某些虚拟页面映射到承载当前进程的页面表的物理页面,修改某些页面表条目,然后取消映射这些虚拟页面.这样,物理页面有时可能属于内核,有时属于用户空间,因为它们在取消映射后不属于内核,因此可以交换.是这个原因吗?

P.S. again, a virtual memory area ranging from [3G + 896M] to 4G belongs to the kernel and is used for mapping physical pages in ZONE_HIGHMEM (x86 32-bit Linux, 3G + 1G setting). In such a case, the kernel may first map some virtual pages in the area to the physical pages that host the current process's page table, modify some page table entries, and unmap the virtual pages. This way, the physical pages may sometimes belong to the kernel and sometimes belong to user space, because they do not belong to the kernel after the unmapping and thus become swappable. Is this the reason?

推荐答案

tl; dr-内存池和交换是不同的概念.您不能从一个推论另一个推论.

tl;dr - the memory pools and swapping are different concepts. You can not make any deductions from one about the other.

kmalloc()和其他内核数据分配来自 slab/slub 等.内核在同一位置为用户空间获取数据. Ergo 页面经常在内核数据段和用户空间之间移动.这是对的.它没有任何关于交换的内容.那是一个单独的问题,您无法推断出任何东西.

kmalloc() and other kernel data allocation come from slab/slub, etc. The same place that the kernel gets data for user-space. Ergo pages frequently move between the kernel data segment and user space. This is correct. It doesn't say anything about swapping. That is a separate issue and you can not deduce anything.

内核代码通常在引导时填充,并标记为只读,此后再也不会更改. Ergo 物理页面不在内核代码段和用户空间之间移动.

The kernel code is typically populated at boot and marked read-only and never changes after that. Ergo physical pages do not move between the kernel code segment and user space.

您为什么认为因为某些东西来自同一个池,所以它是相同的?网络套接字也来自同一内存池.这是一个关注点分离. linux-mm (内存管理系统)处理交换.可以固定页面(不可交换).检查静态内核内存(其中可能包括 .bss .data )是一种简单的范围检查.通常在 linux-mm 层将内存固定并标记为不可交换.用户数据(其分配来自同一池)可以被 linux-mm 标记为可交换.例如,即使没有交换,用户空间文本仍然可以交换,因为它由 inode 支持.对于只读数据,缓存要简单得多.如果交换了数据,则在MMU表中将其标记为此类,并且故障处理程序必须区分交换和 SIGBUS ;这是 linux-mm 的一部分.

Why do you think because something comes from the same pool, it is the same? The network sockets also come from the same memory pool. It is a seperation of concern. The linux-mm (memory management system) handles swap. A page can be pinned (unswappable). The check for static kernel memory (this may include .bss and .data) is a simple range check. The memory is normally pinned and marked unswappable at the linux-mm layer. The user data (whos allocation come from the same pool) can be marked as swappable by the linux-mm. For instance, even without swap, user-space text is still swappable because it is backed by an inode. Caching is much simpler for read-only data. If data is swapped, it is marked as such in the MMU tables and a fault handler must distinguish between swap and a SIGBUS; which is part of the linux-mm.

也有带有 no-mm (或没有MMU)的Linux版本,它们永远不会交换任何东西.从理论上讲,也许有人可以交换内核数据.但是为什么在内核中呢? Linux的方式是使用模块并仅在需要时加载它们.当然, linux-mm 数据是内核数据,希望您能看到交换该数据的问题.

There are also versions of Linux with no-mm (or no MMU) and these will never swap anything. In theory someone might be able to swap kernel data; but the why is it in the kernel? The Linux way would be to use a module and only load them as needed. Certainly, the linux-mm data is kernel data and hopefully, you can see a problem with swapping that.

诸如此类的概念性问题,

The problem with conceptual questions like this,

  1. 它可能与Linux版本不同.
  2. 它与Linux配置可能不同.
  3. 建议会随着Linux的发展而改变.

可以肯定的是,linux-mm代码不能交换,也不能使用任何中断处理程序.在某个时间点,可能会交换内核代码和/或数据.我认为这不是模块加载/卸载之外的当前情况(关于是否调用此 swapping ,这是很古怪的/深奥的.)

For certain, the linux-mm code can not be swappable, nor any interrupt handler. It is possible that at some point in time, kernel code and/or data could be swapped. I don't think that this is ever the current case outside of module loading/unloading (and it is rather pedantic/esoteric as to whether you call this swapping or not).

这篇关于在Linux中,属于内核数据段的物理内存页是否可交换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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