mm/huge_memory: use end_folio to terminate anonymous folio remapping
Subsystems (2)
PATCH 1/1 mm/huge_memory: use end_folio to terminate anonymous folio remapping
After splitting a large folio, it is necessary to remap the resulting anonymous folios.
The current implementation determines the end of the remapping process by counting the number of pages that have been processed.
Since the final folio in the sequence, end_folio, is already known and tracked, this commit refactors the remapping loop to leverage end_folio as the termination marker.
--- mm/huge_memory.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
mm/huge_memory.c +4 -10
@@ -3414,20 +3414,14 @@ bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,return __discard_anon_folio_pmd_locked (vma, addr, pmdp, folio); } -static void remap_page (struct folio *folio,unsigned long nr,int flags) +static void remap_page (struct folio *folio,struct folio *end_folio,int flags) { -int i =0 ; -/* If unmap_folio() uses try_to_migrate() on file, remove this check */ if (!folio_test_anon (folio))return ; -for (;;) { +do {remove_migration_ptes (folio, folio,RMP_LOCKED | flags); - i +=folio_nr_pages (folio); -if (i >= nr) -break ; - folio =folio_next (folio); - } + }while ((folio =folio_next (folio)) != end_folio); } static void lru_add_split_folio(struct folio *folio, struct folio *new_folio,
@@ -4066,7 +4060,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (!ret && is_anon && !folio_is_device_private (folio)) remap_flags =RMP_USE_SHARED_ZEROPAGE ; -remap_page (folio,1 << old_order, remap_flags); +remap_page (folio, end_folio, remap_flags);/* * Unlock all after-split folios except the one containing
Signature · 1 line
2.34.1
Sorry Wei,
I know this is small, but can we not be doing these kinds of fiddly patches late in -rc7 please?
Thanks, Lorenzo
Quoted 57 lines · Wei Yang
After splitting a large folio, it is necessary to remap the resulting anonymous folios.
The current implementation determines the end of the remapping process by counting the number of pages that have been processed.
Since the final folio in the sequence,
end_folio, is already known and tracked, this commit refactors the remapping loop to leverageend_folioas the termination marker.Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- mm/huge_memory.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)mm/huge_memory.c +4
-11@@ -3414,20 +3414,14 @@ bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,return __discard_anon_folio_pmd_locked (vma, addr, pmdp, folio); } -static void remap_page (struct folio *folio,unsigned long nr,int flags) +static void remap_page (struct folio *folio,struct folio *end_folio,int flags) { -int i =0 ; -/* If unmap_folio() uses try_to_migrate() on file, remove this check */ if (!folio_test_anon (folio))return ; -for (;;) { +do {remove_migration_ptes (folio, folio,RMP_LOCKED | flags); - i +=folio_nr_pages (folio); -if (i >= nr) -break ; - folio =folio_next (folio); - } + }while ((folio =folio_next (folio)) != end_folio); } static void lru_add_split_folio(struct folio *folio, struct folio *new_folio,@@ -4066,7 +4060,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (!ret && is_anon && !folio_is_device_private (folio)) remap_flags =RMP_USE_SHARED_ZEROPAGE ; -remap_page (folio,1 << old_order, remap_flags); +remap_page (folio, end_folio, remap_flags);/* * Unlock all after-split folios except the one containing -- 2.34.1
David Hildenbrand (Red Hat)
maintainerQuoted 31 lines · Wei Yang
After splitting a large folio, it is necessary to remap the resulting anonymous folios.
The current implementation determines the end of the remapping process by counting the number of pages that have been processed.
Since the final folio in the sequence,
end_folio, is already known and tracked, this commit refactors the remapping loop to leverageend_folioas the termination marker.Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- mm/huge_memory.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)mm/huge_memory.c +1
-3@@ -3414,20 +3414,14 @@ bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,return __discard_anon_folio_pmd_locked (vma, addr, pmdp, folio); } -static void remap_page (struct folio *folio,unsigned long nr,int flags) +static void remap_page (struct folio *folio,struct folio *end_folio,int flags) { -int i =0 ; -/* If unmap_folio() uses try_to_migrate() on file, remove this check */ if (!folio_test_anon (folio))
mm/huge_memory.c bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr, · line 3424
Quoted 10 lines
mm/huge_memory.c +2
-6return ; -for (;;) { +do {remove_migration_ptes (folio, folio,RMP_LOCKED | flags); - i +=folio_nr_pages (folio); -if (i >= nr) -break ; - folio =folio_next (folio); - } + }while ((folio =folio_next (folio)) != end_folio);
Rather ugly.
Nothing lost by just keeping "folio = folio_next(folio);" in the loop and focusing on what your patch documents.
But as Lorenzo said, the time for such cleanups is after most of the current stuff was merged in the upcoming merge window.
Signature · 3 lines
Cheers David
Quoted 44 lines · David Hildenbrand (Red Hat)
Quoted 30 lines · Wei Yang
After splitting a large folio, it is necessary to remap the resulting anonymous folios.
The current implementation determines the end of the remapping process by counting the number of pages that have been processed.
Since the final folio in the sequence,
end_folio, is already known and tracked, this commit refactors the remapping loop to leverageend_folioas the termination marker.Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- mm/huge_memory.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)mm/huge_memory.c +1
-3@@ -3414,20 +3414,14 @@ bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,return __discard_anon_folio_pmd_locked (vma, addr, pmdp, folio); } -static void remap_page (struct folio *folio,unsigned long nr,int flags) +static void remap_page (struct folio *folio,struct folio *end_folio,int flags) { -int i =0 ; -/* If unmap_folio() uses try_to_migrate() on file, remove this check */ if (!folio_test_anon (folio))mm/huge_memory.c bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr, · line 3423
Quoted 10 lines
mm/huge_memory.c +2
-6return ; -for (;;) { +do {remove_migration_ptes (folio, folio,RMP_LOCKED | flags); - i +=folio_nr_pages (folio); -if (i >= nr) -break ; - folio =folio_next (folio); - } + }while ((folio =folio_next (folio)) != end_folio);Rather ugly.
Quoted 5 lines
Nothing lost by just keeping "folio =
folio_next(folio);" in the loop and focusing on what your patch documents.But as Lorenzo said, the time for such cleanups is after most of the current stuff was merged in the upcoming merge window.
Sure.
Quoted 5 lines
Signature · 4 lines
-- Cheers David
Signature · 2 lines
Wei Yang Help you, Help me