内核页面会被换出吗?

发布于 2024-10-09 05:43:05 字数 63 浏览 4 评论 0原文

关于 Linux 内核,“内核”页面是否会被换出?另外,用户空间页面是否可以驻留在 ZONE_NORMAL 中?

Pertaining to the Linux kernel, do "Kernel" pages ever get swapped out ? Also, do User space pages ever get to reside in ZONE_NORMAL ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坏尐絯 2024-10-16 05:43:05

不,内核内存是不可交换的。

No, kernel memory is unswappable.

不弃不离 2024-10-16 05:43:05
  1. 内核页面不可交换。但它可以被释放。

  2. 用户空间页面可以驻留在 ZONE_NORMAL 中。
    Linux 系统 可以配置为使用或不使用 HIGHMEM。
    如果配置了 ZONE_HIGHMEM,则用户空间进程将从 HIGHMEM 获取内存,否则用户空间进程将从 ZONE_NORMAL 获取内存。

  1. Kernel pages are not swappable. But it can be freed.

  2. UserSpace Pages can reside in ZONE_NORMAL.
    Linux System Can be configured either to use HIGHMEM or not.
    If ZONE_HIGHMEM is configured , then the userspace processes will get its memory from the HIGHMEM else userspace processes will get memory from ZONE_NORMAL.

睫毛上残留的泪 2024-10-16 05:43:05

是的,在正常情况下内核页面(即驻留在内核中供内核使用的内存)是不可交换的,事实上,一旦检测到(请参阅页面错误处理程序源代码),内核将显式地自行崩溃。

请参阅:

http://lxr.free-electrons.com/ source/arch/x86/mm/fault.c

和函数:

1205 /*
1206  * This routine handles page faults.  It determines the address,
1207  * and the problem, and then passes it off to one of the appropriate
1208  * routines.
1209  *
1210  * This function must have noinline because both callers
1211  * {,trace_}do_page_fault() have notrace on. Having this an actual function
1212  * guarantees there's a function trace entry.
1213  */
1214 static noinline void
1215 __do_page_fault(struct pt_regs *regs, unsigned long error_code,
1216                 unsigned long address)
1217 {

以及这里的检测:

1246          *
1247          * This verifies that the fault happens in kernel space
1248          * (error_code & 4) == 0, and that the fault was not a
1249          * protection error (error_code & 9) == 0.
1250          */
1251         if (unlikely(fault_in_kernel_space(address))) {
1252                 if (!(error_code & (PF_RSVD | PF_USER | PF_PROT))) {
1253                         if (vmalloc_fault(address) >= 0)
1254                                 return;
1255 
1256                         if (kmemcheck_fault(regs, address, error_code))
1257                                 return;
1258                 }

但是相同的页面错误处理程序 - 可以检测由不存在的用户模式内存引起的页面错误(所有硬件页面错误检测始终在kernel)将显式地从交换空间中检索数据(如果存在),或者启动内存分配例程来为进程提供更多内存。

好吧,也就是说,内核在软件挂起和休眠操作期间确实会交换内核结构/内存/任务列表等:

https://www.kernel.org/doc/Documentation/power/swsusp.txt

在恢复阶段,它将从交换文件恢复内核内存。

Yes, under normal circumstances kernel pages (ie, memory residing in the kernel for kernel usage) are not swappable, in fact, once detected (see the pagefault handler source code), the kernel will explicitly crash itself.

See this:

http://lxr.free-electrons.com/source/arch/x86/mm/fault.c

and the function:

1205 /*
1206  * This routine handles page faults.  It determines the address,
1207  * and the problem, and then passes it off to one of the appropriate
1208  * routines.
1209  *
1210  * This function must have noinline because both callers
1211  * {,trace_}do_page_fault() have notrace on. Having this an actual function
1212  * guarantees there's a function trace entry.
1213  */
1214 static noinline void
1215 __do_page_fault(struct pt_regs *regs, unsigned long error_code,
1216                 unsigned long address)
1217 {

And the detection here:

1246          *
1247          * This verifies that the fault happens in kernel space
1248          * (error_code & 4) == 0, and that the fault was not a
1249          * protection error (error_code & 9) == 0.
1250          */
1251         if (unlikely(fault_in_kernel_space(address))) {
1252                 if (!(error_code & (PF_RSVD | PF_USER | PF_PROT))) {
1253                         if (vmalloc_fault(address) >= 0)
1254                                 return;
1255 
1256                         if (kmemcheck_fault(regs, address, error_code))
1257                                 return;
1258                 }

But the same pagefault handler - which can detect pagefault arising from non-existent usermode memory (all hardware pagefault detection is always done in kernel) will explicitly retrieve the data from swap space if it exists, or start a memory allocation routine to give the process more memory.

Ok, that said, kernel does swap out kernel structures/memory/tasklists etc during software suspend and hibernation operation:

https://www.kernel.org/doc/Documentation/power/swsusp.txt

And during the resume phase it will restore back the kernel memory from swap file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文