内核页面会被换出吗?
- 2024-11-08 09:04:00
- admin 原创
- 216
问题描述:
对于 Linux 内核,“内核”页面是否会被换出?此外,用户空间页面是否会驻留在 ZONE_NORMAL 中?
解决方案 1:
不可以,内核内存是不可交换的。
解决方案 2:
内核页面不可交换。但可以释放。
用户空间页面可以驻留在 ZONE_NORMAL 中。Linux 系统可以配置为使用 HIGHMEM 或不使用。如果配置了 ZONE_HIGHMEM,则用户空间进程将从 HIGHMEM 获取内存,否则用户空间进程将从 ZONE_NORMAL 获取内存。
解决方案 3:
是的,正常情况下内核页面(即驻留在内核中供内核使用的内存)是不可交换的,事实上,一旦检测到(参见页面错误处理程序源代码),内核就会明确崩溃。
看看这个:
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 }
但是相同的页面错误处理程序 - 可以检测由于不存在的用户模式内存而引起的页面错误(所有硬件页面错误检测始终在内核中完成)将明确地从交换空间中检索数据(如果存在),或者启动内存分配例程以便为进程提供更多内存。
好的,也就是说,内核在软件挂起和休眠操作期间确实会交换内核结构/内存/任务列表等:
https://www.kernel.org/doc/Documentation/power/swsusp.txt
在恢复阶段,它将从交换文件恢复内核内存。
相关推荐
热门文章
项目管理软件有哪些?
热门标签
云禅道AD