remove parameter 'compound' of add_file_rmap
Subsystems (3)
cover remove parameter 'compound' of add_file_rmap
This is follow-up patch of "folio based filemap_map_pages()". Matthew suggested to remove the parameter compound. Compare the folio page number and parameter nr_pages to detect whether it's a 'compound' operation.
Didn't remove 'compound' from page_remove_rmap() because it's not ready yet.
Just did very limited test: boot to xfce GUI and used browser, email client and Linux kernel build.
Yin Fengwei (2):
rmap: Add function to handle entire folio rmap removing
rmap: remove parameter 'compound' from foeio_add_file_rmap_range()
mm/rmap.c | 82 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 26 deletions(-)
Signature · 1 line
2.30.2
RFC PATCH 1/2 rmap: Add function to handle entire folio rmap removing
Add folio_remove_entire_rmap(). It will handle the entire folio rmap removing.
--- mm/rmap.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-)
mm/rmap.c +27 -14
@@ -1394,6 +1394,32 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, nr_pages, vma, compound); } +static void folio_remove_entire_rmap (struct folio *folio, +int *nr,int *nr_pmdmapped) +{ +bool last; +atomic_t *mapped = &folio->_nr_pages_mapped; + + last =atomic_add_negative (-1 , &folio->_entire_mapcount); +if (last) { + *nr =atomic_sub_return_relaxed (COMPOUND_MAPPED , mapped); +if (likely (*nr <COMPOUND_MAPPED )) { + *nr_pmdmapped =folio_nr_pages (folio); + *nr = *nr_pmdmapped - (*nr &FOLIO_PAGES_MAPPED ); + +/* Raced ahead of another remove and an add? */ +if (unlikely (*nr <0 )) + *nr =0 ; + }else { +/* An add of COMPOUND_MAPPED raced ahead */ + *nr =0 ; + } + } + +if (!folio_test_pmd_mappable (folio)) + *nr_pmdmapped =0 ; +} +/** * page_remove_rmap - take down pte mapping from a page * @page: page to remove mapping from
@@ -1431,20 +1457,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, }else if (folio_test_pmd_mappable (folio)) {/* That test is redundant: it's for safety or to optimize out */ - last =atomic_add_negative (-1 , &folio->_entire_mapcount); -if (last) { - nr =atomic_sub_return_relaxed (COMPOUND_MAPPED , mapped); -if (likely (nr <COMPOUND_MAPPED )) { - nr_pmdmapped =folio_nr_pages (folio); - nr = nr_pmdmapped - (nr &FOLIO_PAGES_MAPPED ); -/* Raced ahead of another remove and an add? */ -if (unlikely (nr <0 )) - nr =0 ; - }else { -/* An add of COMPOUND_MAPPED raced ahead */ - nr =0 ; - } - } +folio_remove_entire_rmap (folio, &nr, &nr_pmdmapped); }if (nr_pmdmapped) {
Signature · 1 line
2.30.2
RFC PATCH 2/2 rmap: remove parameter 'compound' from foeio_add_file_rmap_range()
In reply to Yin FengweiRemove parameter 'compound' from folio_add_file_rmap_range().
The parameter nr_pages is checked whether same as folio page numbers to know whether it's entire folio operation.
Convert the folio _entire_mapcount to page mapcount to handle the case the folio is added as entire folio but removed by removing each page.
--- include/linux/rmap.h | 2 +- mm/memory.c | 2 +- mm/rmap.c | 51 ++++++++++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 20 deletions(-)
include/linux/rmap.h +1 -1
@@ -199,7 +199,7 @@ void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *,void page_add_file_rmap (struct page *,struct vm_area_struct *,bool compound);void folio_add_file_rmap_range (struct folio *,unsigned long start, -unsigned int nr_pages,struct vm_area_struct *,bool compound); +unsigned int nr_pages,struct vm_area_struct *);void page_remove_rmap (struct page *,struct vm_area_struct *,bool compound);
mm/memory.c +1 -1
@@ -4270,7 +4270,7 @@ void do_set_pte_range(struct vm_fault *vmf, struct folio *folio,pte_t entry;if (!cow) { -folio_add_file_rmap_range (folio, start, nr, vma, false); +folio_add_file_rmap_range (folio, start, nr, vma);add_mm_counter (vma->vm_mm,mm_counter_file (page), nr); }else {/*
mm/rmap.c +33 -18
108 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [RFC PATCH 2/2] rmap: remove parameter 'compound' from foeio_add_file_rmap_range()
Quoted 4 lines · Yin Fengwei
Remove parameter 'compound' from
folio_add_file_rmap_range().The parameter
nr_pagesis checked whether same as folio page numbers to know whether it's entire folio operation.
We can't do this yet. Even if a folio is large enough to be PMD mapped, it may have been mapped askew (or its PMD mapping may have been split). We still need the caller to tell us whether it's been mapped with a PMD or with PTEs.
Re: [RFC PATCH 2/2] rmap: remove parameter 'compound' from foeio_add_file_rmap_range()
Quoted 10 lines · Matthew Wilcox
Quoted 4 lines · Yin Fengwei
Remove parameter 'compound' from
folio_add_file_rmap_range().The parameter
nr_pagesis checked whether same as folio page numbers to know whether it's entire folio operation.We can't do this yet. Even if a folio is large enough to be PMD mapped, it may have been mapped askew (or its PMD mapping may have been split). We still need the caller to tell us whether it's been mapped with a PMD or with PTEs.
OK. My understand is that the info about PMD mapped is only for statistic update. Maybe move the PMD mapped statistic to caller.
Another thing I am not sure whether it's worthy:
What about maintaining total mapcount for folio? So we don't need to query each page mapcount to know it. So we can use "total_mapoucnt > mapped" to know whether the folio has at least one page mapped more than once.
The payback is that we need update total mapcount when map/unmap the folio.
Regards
Yin, Fengwei
Quoted 1 line
Re: [RFC PATCH 2/2] rmap: remove parameter 'compound' from foeio_add_file_rmap_range()
Quoted 7 lines · Fengwei
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Yin Fengwei
Remove parameter 'compound' from
folio_add_file_rmap_range().The parameter
nr_pagesis checked whether same as folio page numbers to know whether it's entire folio operation.
Quoted 6 lines
Quoted 4 lines
We can't do this yet. Even if a folio is large enough to be PMD mapped, it may have been mapped askew (or its PMD mapping may have been split). We still need the caller to tell us whether it's been mapped with a PMD or with PTEs.
OK. My understand is that the info about PMD mapped is only for statistic update. Maybe move the PMD mapped statistic to caller.
Alas, no. That 'compound' parameter really means "to be mapped by a PMD". And we need to change all of add_file, add_anon and remove at the same time, otherwise we don't know which counter to inc/dec in page_remove_rmap().
Quoted 8 lines
Another thing I am not sure whether it's worthy:
What about maintaining total mapcount for folio? So we don't need to query each page mapcount to know it. So we can use "total_mapoucnt> mapped" to know whether the folio has at least one page mapped more than once.The payback is that we need update total mapcount when map/unmap the folio.
Right, there are lots of mapcounts we _could_ maintain. The important thing to understand is who wants to know what. As I see it, there are three important things we need to know:
1. Is any page in this folio mapped? (everywhere that calls folio_mapped() or page_mapped())
2. Is any page in this folio mapped more than once? (some madvise calls, migration)
3. How many refcounts does the mapcount account for? (splitting, compaction)
Some of the things we use mapcount for today I consider to be unimportant. For example, shrink_folio_list() checks to see if there are any PMD mappings and will split it if there are not. This doesn't fit my vision of how the VM should work; I believe we should swap the entire folio out as a single unit.
So I don't really want to think about maintaining total_mapcount, I want the concept of total_mapcount to go away and just have a single mapcount for each folio, instead of this complex mismash of entire_mapcount, mapcount and total_mapcount.
Re: [RFC PATCH 2/2] rmap: remove parameter 'compound' from foeio_add_file_rmap_range()
Quoted 12 lines · Matthew Wilcox
Quoted 11 lines · Fengwei
Quoted 10 lines · Matthew Wilcox
Quoted 4 lines · Yin Fengwei
Remove parameter 'compound' from
folio_add_file_rmap_range().The parameter
nr_pagesis checked whether same as folio page numbers to know whether it's entire folio operation.We can't do this yet. Even if a folio is large enough to be PMD mapped, it may have been mapped askew (or its PMD mapping may have been split). We still need the caller to tell us whether it's been mapped with a PMD or with PTEs.
Quoted 7 lines
Quoted 2 lines
OK. My understand is that the info about PMD mapped is only for statistic update. Maybe move the PMD mapped statistic to caller.
Alas, no. That 'compound' parameter really means "to be mapped by a PMD". And we need to change all of
add_file,add_anonand remove at the same time, otherwise we don't know which counter to inc/dec inpage_remove_rmap().
OK. I thought that "compound" could mean "mapping the entire folio" when I worked on this patch. Thanks a lot for clarification.
Regards
Yin, Fengwei
Quoted 33 lines
Quoted 9 lines
Another thing I am not sure whether it's worthy:
What about maintaining total mapcount for folio? So we don't need to query each page mapcount to know it. So we can use "total_mapoucnt> mapped" to know whether the folio has at least one page mapped more than once.The payback is that we need update total mapcount when map/unmap the folio.
Right, there are lots of mapcounts we _could_ maintain. The important thing to understand is who wants to know what. As I see it, there are three important things we need to know:
1. Is any page in this folio mapped? (everywhere that calls
folio_mapped()orpage_mapped())2. Is any page in this folio mapped more than once? (some madvise calls, migration)
3. How many refcounts does the mapcount account for? (splitting, compaction)
Some of the things we use mapcount for today I consider to be unimportant. For example,
shrink_folio_list()checks to see if there are any PMD mappings and will split it if there are not. This doesn't fit my vision of how the VM should work; I believe we should swap the entire folio out as a single unit.So I don't really want to think about maintaining
total_mapcount, I want the concept oftotal_mapcountto go away and just have a single mapcount for each folio, instead of this complex mismash ofentire_mapcount, mapcount andtotal_mapcount.