mm: huge_memory: convert split_huge_pages_all() to use a folio
Subsystems (2)
PATCH 1/1 mm: huge_memory: convert split_huge_pages_all() to use a folio
Straightforwardly convert split_huge_pages_all() to use a folio.
--- mm/huge_memory.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
mm/huge_memory.c +17 -8
@@ -2932,6 +2932,7 @@ static void split_huge_pages_all(void) {struct zone *zone;struct page *page; +struct folio *folio;unsigned long pfn, max_zone_pfn;unsigned long total =0 , split =0 ;
@@ -2944,24 +2945,32 @@ static void split_huge_pages_all(void)int nr_pages; page =pfn_to_online_page (pfn); -if (!page || !get_page_unless_zero (page)) +if (!page ||PageTail (page)) +continue ; + folio =page_folio (page); +if (!folio_try_get (folio))continue ; -if (zone !=page_zone (page)) +if (unlikely (page_folio (page) != folio)) + goto next; + +if (zone !=folio_zone (folio)) goto next; -if (!PageHead (page) ||PageHuge (page) || !PageLRU (page)) +if (!folio_test_large (folio) + ||folio_test_hugetlb (folio) + || !folio_test_lru (folio)) goto next; total++; -lock_page (page); - nr_pages =thp_nr_pages (page); -if (!split_huge_page (page)) +folio_lock (folio); + nr_pages =folio_nr_pages (folio); +if (!split_folio (folio)) split++; pfn += nr_pages -1 ; -unlock_page (page); +folio_unlock (folio); next: -put_page (page); +folio_put (folio);cond_resched (); } }
Signature · 1 line
2.35.3
Andrew Morton
maintainerQuoted 20 lines · On Thu, 29 Dec 2022 20:25:03 +0800 Kefeng Wang <[email protected]>…
Straightforwardly convert
split_huge_pages_all()to use a folio.Signed-off-by Kefeng Wang <[email protected]>--- mm/huge_memory.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)mm/huge_memory.c +1
-0@@ -2932,6 +2932,7 @@ static void split_huge_pages_all(void) {struct zone *zone;struct page *page; +struct folio *folio;unsigned long pfn, max_zone_pfn;unsigned long total =0 , split =0 ;
mm/huge_memory.c static void split_huge_pages_all(void) · line 2949
Quoted 6 lines
mm/huge_memory.c +2
-1@@ -2944,24 +2945,32 @@ static void split_huge_pages_all(void)int nr_pages; page =pfn_to_online_page (pfn); -if (!page || !get_page_unless_zero (page)) +if (!page ||PageTail (page)) +continue ;
Why is the PageTail() test added?
mm/huge_memory.c static void split_huge_pages_all(void) · line 2954
Quoted 6 lines
mm/huge_memory.c +3
-1+ folio =page_folio (page); +if (!folio_try_get (folio))continue ; -if (zone !=page_zone (page)) +if (unlikely (page_folio (page) != folio))
And this?
Quoted 28 lines
mm/huge_memory.c +11
-6+ goto next; + +if (zone !=folio_zone (folio)) goto next; -if (!PageHead (page) ||PageHuge (page) || !PageLRU (page)) +if (!folio_test_large (folio) + ||folio_test_hugetlb (folio) + || !folio_test_lru (folio)) goto next; total++; -lock_page (page); - nr_pages =thp_nr_pages (page); -if (!split_huge_page (page)) +folio_lock (folio); + nr_pages =folio_nr_pages (folio); +if (!split_folio (folio)) split++; pfn += nr_pages -1 ; -unlock_page (page); +folio_unlock (folio); next: -put_page (page); +folio_put (folio);cond_resched (); } }
Quoted 24 lines · Andrew Morton
Quoted 22 lines · On Thu, 29 Dec 2022 20:25:03 +0800 Kefeng Wang <[email protected]>…
Straightforwardly convert
split_huge_pages_all()to use a folio.Signed-off-by Kefeng Wang <[email protected]>--- mm/huge_memory.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)mm/huge_memory.c +1
-0@@ -2932,6 +2932,7 @@ static void split_huge_pages_all(void) {struct zone *zone;struct page *page; +struct folio *folio;unsigned long pfn, max_zone_pfn;unsigned long total =0 , split =0 ;@@ -2944,24 +2945,32 @@ static void split_huge_pages_all(void)int nr_pages;
Quoted 6 lines
mm/huge_memory.c static void split_huge_pages_all(void) · line 2949
Quoted 4 lines
mm/huge_memory.c +2
-1page =pfn_to_online_page (pfn); -if (!page || !get_page_unless_zero (page)) +if (!page ||PageTail (page)) +continue ;Why is the
PageTail()test added?
This function is trying to split huge pages, it traverse all the pfn, the huge page already split when we met Head page, most importantly, get_page_unless_zero() will do nothing on Tail page too.
Quoted 9 lines
mm/huge_memory.c static void split_huge_pages_all(void) · line 2954
Quoted 7 lines
mm/huge_memory.c +3
-1+ folio =page_folio (page); +if (!folio_try_get (folio))continue ; -if (zone !=page_zone (page)) +if (unlikely (page_folio (page) != folio))And this?
I think this is a double check in case of page is already changed by someone else, suggested by Matthew[1]
[1] https://lore.kernel.org/linux-mm/[email protected]/T/#m33047c152f6793bfebaa55cb1f4662fed73508d2
mm/huge_memory.c static void split_huge_pages_all(void) · line 2963
Quoted 5 lines · Kefeng Wang
mm/huge_memory.c +3
-1-if (!PageHead (page) ||PageHuge (page) || !PageLRU (page)) +if (!folio_test_large (folio) + ||folio_test_hugetlb (folio) + || !folio_test_lru (folio)) goto next;
That is a completely illegible way of indenting this code! There's no visual cue when the condition stops and when the next statement begins. Try one of these:
if (!folio_test_large(folio) || folio_test_hugetlb(folio) || !folio_test_lru(folio)) goto next; if (!folio_test_large(folio) || folio_test_hugetlb(folio) || !folio_test_lru(folio)) goto next;
Quoted 11 lines · Matthew Wilcox
mm/huge_memory.c static void split_huge_pages_all(void) · line 2963
Quoted 5 lines · Kefeng Wang
mm/huge_memory.c +3
-1-if (!PageHead (page) ||PageHuge (page) || !PageLRU (page)) +if (!folio_test_large (folio) + ||folio_test_hugetlb (folio) + || !folio_test_lru (folio)) goto next;That is a completely illegible way of indenting this code! There's no visual cue when the condition stops and when the next statement begins. Try one of these:
sorry about the bad indenting,
Quoted 5 lines
if (!folio_test_large(folio) || folio_test_hugetlb(folio) || !folio_test_lru(folio)) goto next;
will resend with this one, thanks for your review.