内核页面是否被换出?

The*_*ker 15 linux arm memory-management linux-device-driver linux-kernel

与Linux内核有关,"内核"页面是否会被换出?此外,用户空间页面是否会驻留在ZONE_NORMAL中?

use*_*515 11

不,内核内存是不可逆的.


Pet*_*eoh 6

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

看看这个:

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 {
Run Code Online (Sandbox Code Playgroud)

以及这里的检测:

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                 }
Run Code Online (Sandbox Code Playgroud)

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

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

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

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


Pra*_*ran 5

  1. 内核页面不可交换.但它可以被释放.

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

  • 驱动程序分配的页面呢? (2认同)