A few cleanup and fixup patches for vmscan
Subsystems (3)
v3 cover A few cleanup and fixup patches for vmscan
Hi everyone,
This series contains a few patches to remove obsolete comment, introduce helper to remove duplicated code and so no. Also we take all base pages of THP into account in rare race condition. More details can be found in the respective changelogs. Thanks!
---
v3:
patch 1/9: collect Reviewed-by tag and add a period in the comment. patch 2/9: dropped
patch 3/9: use folio_putback_lru()
patch 4/9: dropped
patch 5/9: collect Reviewed-by tag
patch 7/9: splitted out to make it easier to move forward
v2:
patch 1/9: drop code change and add a comment about MADV_FREE patch 2/9: simplify the code further and change to goto keep_locked patch 3/9: use folio, remove unneeded inline and break craze long lines patch 5/9: activate swap-backed executable folios after first usage too patch 9/9: new cleanup patch splitted from 5/9
Many thanks Huang Ying, Matthew Wilcox, Christoph Hellwig, Muchun Song for review!
---
Miaohe Lin (6):
mm/vmscan: add a comment about MADV_FREE pages check in
folio_check_dirty_writeback
mm/vmscan: introduce helper function reclaim_page_list() mm/vmscan: activate swap-backed executable folios after first usage mm/vmscan: take all base pages of THP into account when race with
speculative reference
mm/vmscan: remove obsolete comment in kswapd_run mm/vmscan: use helper folio_is_file_lru()
mm/vmscan.c | 64 +++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 31 deletions(-)
Signature · 1 line
2.23.0
PATCH v3 1/6 mm/vmscan: add a comment about MADV_FREE pages check in folio_check_dirty_writeback
The MADV_FREE pages check in folio_check_dirty_writeback is a bit hard to follow. Add a comment to make the code clear.
--- mm/vmscan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/vmscan.c +4 -1
@@ -1438,7 +1438,10 @@ static void folio_check_dirty_writeback(struct folio *folio,/* * Anonymous pages are not handled by flushers and must be written -* from reclaim context. Do not stall reclaim based on them +* from reclaim context. Do not stall reclaim based on them. +* MADV_FREE anonymous pages are put into inactive file list too. +* They could be mistakenly treated as file lru. So further anon +* test is needed. */ if (!folio_is_file_lru (folio) || (folio_test_anon (folio) && !folio_test_swapbacked (folio))) {
Signature · 1 line
2.23.0
PATCH v3 2/6 mm/vmscan: introduce helper function reclaim_page_list()
In reply to Miaohe LinIntroduce helper function reclaim_page_list() to eliminate the duplicated code of doing shrink_page_list() and putback_lru_page. Also We can separate node reclaim from node page list operation this way. No functional change intended.
--- mm/vmscan.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
mm/vmscan.c +25 -25
@@ -2539,14 +2539,12 @@ static void shrink_active_list(unsigned long nr_to_scan, nr_deactivate, nr_rotated, sc->priority, file); } -unsigned long reclaim_pages (struct list_head *page_list) +static unsigned int reclaim_page_list (struct list_head *page_list, +struct pglist_data *pgdat) { -int nid =NUMA_NO_NODE ; -unsigned int nr_reclaimed =0 ; -LIST_HEAD (node_page_list);struct reclaim_stat dummy_stat; -struct page *page; -unsigned int noreclaim_flag; +unsigned int nr_reclaimed; +struct folio *folio;struct scan_control sc = { .gfp_mask =GFP_KERNEL , .may_writepage =1 ,
@@ -2555,6 +2553,24 @@ unsigned long reclaim_pages(struct list_head *page_list) .no_demotion = 1, }; + nr_reclaimed =shrink_page_list (page_list, pgdat, &sc, &dummy_stat, false); +while (!list_empty (page_list)) { + folio =lru_to_folio (page_list); +list_del (&folio->lru); +folio_putback_lru (folio); + } + +return nr_reclaimed; +} + +unsigned long reclaim_pages (struct list_head *page_list) +{ +int nid =NUMA_NO_NODE ; +unsigned int nr_reclaimed =0 ; +LIST_HEAD (node_page_list); +struct page *page; +unsigned int noreclaim_flag; + noreclaim_flag =memalloc_noreclaim_save ();while (!list_empty (page_list)) {
@@ -2570,28 +2586,12 @@ unsigned long reclaim_pages(struct list_head *page_list)continue ; } - nr_reclaimed +=shrink_page_list (&node_page_list, -NODE_DATA (nid), - &sc, &dummy_stat, false); -while (!list_empty (&node_page_list)) { - page =lru_to_page (&node_page_list); -list_del (&page->lru); -putback_lru_page (page); - } - + nr_reclaimed +=reclaim_page_list (&node_page_list,NODE_DATA (nid)); nid =NUMA_NO_NODE ; } -if (!list_empty (&node_page_list)) { - nr_reclaimed +=shrink_page_list (&node_page_list, -NODE_DATA (nid), - &sc, &dummy_stat, false); -while (!list_empty (&node_page_list)) { - page =lru_to_page (&node_page_list); -list_del (&page->lru); -putback_lru_page (page); - } - } +if (!list_empty (&node_page_list)) + nr_reclaimed +=reclaim_page_list (&node_page_list,NODE_DATA (nid));memalloc_noreclaim_restore (noreclaim_flag);
Signature · 1 line
2.23.0
PATCH v3 3/6 mm/vmscan: activate swap-backed executable folios after first usage
In reply to Miaohe LinWe should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
--- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +2 -2
@@ -1415,9 +1415,9 @@ static enum page_references folio_check_references(struct folio *folio,return PAGEREF_ACTIVATE ;/* -* Activate file-backed executable folios after first usage. +* Activate executable folios after first usage. */ -if ((vm_flags &VM_EXEC ) && !folio_test_swapbacked (folio)) +if (vm_flags &VM_EXEC )return PAGEREF_ACTIVATE ;return PAGEREF_KEEP ;
Signature · 1 line
2.23.0
Andrew Morton
maintainerRe: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage
Quoted 2 lines · On Mon, 25 Apr 2022 19:12:29 +0800 Miaohe Lin <[email protected]> wrote:
We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
Does this not erase the intended effect of Joonsoo's b518154e59a ("mm/vmscan: protect the workingset on anonymous LRU")?
Re: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Mon, 25 Apr 2022 19:12:29 +0800 Miaohe Lin <[email protected]> wrote:
We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
Does this not erase the intended effect of Joonsoo's
b518154e59a("mm/vmscan: protect the workingset on anonymous LRU")?
I don't think so. This is only for executable folios (vm_flags & VM_EXEC). The behavior for all other anonymous pages are not affected.
Best Regards,
Huang, Ying
Re: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage
Quoted 12 lines · On 2022/4/26 10:02, [email protected] wrote:
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Mon, 25 Apr 2022 19:12:29 +0800 Miaohe Lin <[email protected]> wrote:
We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
Does this not erase the intended effect of Joonsoo's
b518154e59a("mm/vmscan: protect the workingset on anonymous LRU")?I don't think so. This is only for executable folios (
vm_flags&VM_EXEC). The behavior for all other anonymous pages are not affected.
Agree. Only executable folios are changed! Thanks both!
Quoted 5 lines
Best Regards,
Huang, Ying.
Re: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage
Hello,
2022년 4월 26일 (화) 오후 3:58, Miaohe Lin <[email protected]>님이 작성:
Quoted 7 lines · On 2022/4/26 10:02, [email protected] wrote:
Quoted 5 lines · Andrew Morton
Quoted 4 lines · On Mon, 25 Apr 2022 19:12:29 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 3 lines
We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
Missing activation for swap-backed executable page is the intended operation. So, I disagree with this patch until some numbers are provided. See following discussion.
https://lore.kernel.org/all/[email protected]/T/#u
Thanks.
Re: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage
Quoted 8 lines · Joonsoo Kim
Hello,
2022년 4월 26일 (화) 오후 3:58, Miaohe Lin <[email protected]>님이 작성:
Quoted 5 lines · On 2022/4/26 10:02, [email protected] wrote:
Quoted 3 lines · Andrew Morton
Quoted 2 lines · On Mon, 25 Apr 2022 19:12:29 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
Missing activation for swap-backed executable page is the intended operation. So, I disagree with this patch until some numbers are provided. See following discussion.
Thanks for your pointer. Now I understood more about this. I agree to keep the original behavior unless we can prove the change with numbers.
Best Regards,
Huang, Ying
Re: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage
Quoted 12 lines · On 2022/4/27 14:10, [email protected] wrote:
Quoted 11 lines · Joonsoo Kim
Hello,
2022년 4월 26일 (화) 오후 3:58, Miaohe Lin <[email protected]>님이 작성:
Quoted 7 lines · On 2022/4/26 10:02, [email protected] wrote:
Quoted 5 lines · Andrew Morton
Quoted 4 lines · On Mon, 25 Apr 2022 19:12:29 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 3 lines
We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory.
Quoted 9 lines
Quoted 5 lines
Missing activation for swap-backed executable page is the intended operation. So, I disagree with this patch until some numbers are provided. See following discussion.
Thanks for your pointer. Now I understood more about this. I agree to keep the original behavior unless we can prove the change with numbers.
Many thanks both! I will keep the original behavior. :)
Quoted 6 lines
Best Regards,
Huang, Ying.
PATCH v3 4/6 mm/vmscan: take all base pages of THP into account when race with speculative reference
In reply to Miaohe LinIf the page has buffers, shrink_page_list will try to free the buffer mappings associated with the page and try to free the page as well. In the rare race with speculative reference, the page will be freed shortly by speculative reference. But nr_reclaimed is not incremented correctly when we come across the THP. We need to account all the base pages in this case.
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
@@ -1887,7 +1887,7 @@ static unsigned int shrink_page_list(struct list_head *page_list,* increment nr_reclaimed here (and * leave it off the LRU). */ - nr_reclaimed++; + nr_reclaimed += nr_pages;continue ; } }
Signature · 1 line
2.23.0
PATCH v3 5/6 mm/vmscan: remove obsolete comment in kswapd_run
In reply to Miaohe LinSince commit 6b700b5b3c59 ("mm/vmscan.c: remove cpu online notification for now"), cpu online notification is removed. So kswapd won't move to proper cpus if cpus are hot-added. Remove this obsolete comment.
--- mm/vmscan.c | 1 - 1 file changed, 1 deletion(-)
mm/vmscan.c +0 -1
@@ -4572,7 +4572,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)/* * This kswapd start function will be called by init and node-hot-add. -* On node-hot-add, kswapd will moved to proper cpus if cpus are hot-added. */ void kswapd_run (int nid) {
Signature · 1 line
2.23.0
PATCH v3 6/6 mm/vmscan: use helper folio_is_file_lru()
In reply to Miaohe LinUse helper folio_is_file_lru() to check whether folio is file lru. Minor readability improvement.
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
@@ -1424,7 +1424,7 @@ static enum page_references folio_check_references(struct folio *folio, }/* Reclaim if clean, defer dirty folios to writeback */ -if (referenced_folio && !folio_test_swapbacked (folio)) +if (referenced_folio &&folio_is_file_lru (folio))return PAGEREF_RECLAIM_CLEAN ;return PAGEREF_RECLAIM ;
Signature · 1 line
2.23.0