2017-03-01 67 views
1

我正在使用add_to_swap換出特定頁面。但是,即使在我調用返回成功的函數()之後,系統仍顯示頁表項pte_t仍存在。 add_to_swap是換出頁面的正確函數還是LINUX內核中有其他一些函數,我應該看看? 我看過KSWAPD模塊,並沒有找到它用來交換特定頁面的功能。在LINUX KERNEL中換出特定頁面

回答

1

add_to_swap只是分配空間,不會將頁面移動到交換。檢查功能,which calls add_to_swapmm/vmscan.cshrink_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); 

我們也應該明白什麼是交換和Linux毫米:http://www.tldp.org/LDP/tlk/mm/memory.html

交換緩存 - 只有修改(或髒)的網頁保存在交換文件。

只要他們一直在下一次頁面被換出有 沒有必要將其寫入到交換文件的頁的書面 後,交換文件,然後這些網頁不會被修改已經在 交換文件。相反,頁面可以簡單地被丟棄。在一個沉重的交換系統中,這節省了許多不必要的和昂貴的磁盤 操作。

同時檢查的http://www.tldp.org/LDP/tlk/mm/memory.html

節 「3.8丟棄頁面換出和」