gpt4 book ai didi

linux - 换出 LINUX KERNEL 中的特定页面

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:41:16 26 4
gpt4 key购买 nike

我正在使用 add_to_swap换出特定页面。然而,即使在我调用了这个返回成功 (1) 的函数之后,显示页表条目 pte_t 的系统仍然存在。 add_to_swap 是换出页面的正确函数还是我应该查看的 LINUX 内核中的其他函数?我查看了 KSWAPD 模块,但没有找到它使用哪个函数来换出特定页面。

最佳答案

add_to_swap 只是分配空间,而不是将页面移动到交换区。检查功能,which calls add_to_swapmm/vmscan.cshr​​ink_page_list:

http://lxr.free-electrons.com/source/mm/vmscan.c?v=4.4#L1043

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);

因此,在交换区分配空间后,检查页面是否所有映射到进程的 vm(虚拟内存),使用 try_to_unmap 取消映射,检查回写(脏页,页面已被应用程序更改但仍未保存到 FS),检查缓冲区,再次检查映射...您要换出的页面类型是什么?不确定要交换的页面的实际写入位置...可能是 pageout,因为它调用了 mappingwritepage 方法。 pageout 的来源说 http://lxr.free-electrons.com/source/mm/vmscan.c?v=4.4#L530

531  * pageout is called by shrink_page_list() for each dirty page.
532 * Calls ->writepage().
534 static pageout_t pageout(struct page *page, struct address_space *mapping,
535 struct scan_control *sc)
574 if (clear_page_dirty_for_io(page)) {
584 SetPageReclaim(page);
585 res = mapping->a_ops->writepage(page, &wbc);
597 trace_mm_vmscan_writepage(page, trace_reclaim_flags(page));
598 inc_zone_page_state(page, NR_VMSCAN_WRITE);

我们还应该明白什么是swap和linux mm: http://www.tldp.org/LDP/tlk/mm/memory.html

Swap Cache - Only modified (or dirty) pages are saved in the swap file.

So long as these pages are not modified after they have been written to the swap file then the next time the page is swapped out there is no need to write it to the swap file as the page is already in the swap file. Instead the page can simply be discarded. In a heavily swapping system this saves many unnecessary and costly disk operations.

另请查看 http://www.tldp.org/LDP/tlk/mm/memory.html 的“3.8 换出和丢弃页面”部分

关于linux - 换出 LINUX KERNEL 中的特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42534519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com