我正在使用add_to_swap来换出特定页面。但是,即使在我调用此函数并返回成功( 1 )之后,显示页表条目 pte_t 的系统仍然存在。 add_to_swap是换出页面的正确函数还是LINUX内核中还有其他函数我应该看一下? 我查看了KSWAPD模块,但没有找到用于交换特定页面的函数。
答案 0 :(得分:1)
add_to_swap
只是分配空间,而不是将页面移动到交换。检查函数which calls add_to_swap
,shrink_page_list
的{{1}}:
http://lxr.free-electrons.com/source/mm/vmscan.c?v=4.4#L1043
mm/vmscan.c
因此,在swap中分配空间后,检查页面是否所有映射到进程的vm(虚拟内存),未映射到903 while (!list_empty(page_list)) {
1043 /*
1044 * Anonymous process memory has backing store?
1045 * Try to allocate it some swap space here.
1046 */
1047 if (PageAnon(page) && !PageSwapCache(page)) {
1050 if (!add_to_swap(page, page_list))
1051 goto activate_locked;
1052 may_enter_fs = 1;
1054 /* Adding to swap updated mapping */
1055 mapping = page_mapping(page);
1056 }
1058 /*
1059 * The page is mapped into the page tables of one or more
1060 * processes. Try to unmap it here.
1061 */
1062 if (page_mapped(page) && mapping) {
1063 switch (try_to_unmap(page,
1064 ttu_flags|TTU_BATCH_FLUSH))
1076 if (PageDirty(page)) {
1078 * Only kswapd can writeback filesystem pages to
1109 try_to_unmap_flush_dirty();
1110 switch (pageout(page, mapping, sc)) {
1136 * If the page has buffers, try to free the buffer mappings
1177 if (!mapping || !__remove_mapping(mapping, page, true))
1178 goto keep_locked;
1180 /*
1181 * At this point, we have no other references and there is
1182 * no way to pick any more up (removed from LRU, removed
1183 * from pagecache). Can use non-atomic bitops now (and
1184 * we obviously don't have to worry about waking up a process
1185 * waiting on the page lock, because there are no references.
1186 */
1187 __clear_page_locked(page);
,检查是否写回(脏页,页面由应用程序更改但仍未保存到FS),检查缓冲区,再次检查映射...您尝试换出的页面类型是什么?不确定交换页面的实际写入位置...可能try_to_unmap
因为它调用了pageout
的{{1}}方法。 writepage
的来源说http://lxr.free-electrons.com/source/mm/vmscan.c?v=4.4#L530
mapping
我们还应该了解什么是swap和linux mm:http://www.tldp.org/LDP/tlk/mm/memory.html
交换缓存 - 只有修改过的(或脏的)页面才会保存在交换文件中。
只要这些页面在编写后没有被修改 到交换文件然后下次页面被换出时 无需将其写入交换文件,因为页面已经在 交换文件。相反,页面可以简单地丢弃。在沉重的 交换系统可以节省许多不必要且昂贵的磁盘 操作
同时检查" 3.8交换和丢弃页面" http://www.tldp.org/LDP/tlk/mm/memory.html
的部分