Skip to contentSkip to conversation

mm: remove page idle and young wrapper

PATCH NAK Kefeng Wang 3 participants 18 messages Nov 10, 2023 – Nov 11, 2023

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover mm: remove page idle and young wrapper

Convert to use folio idle and young functions instead of page ones, then remove all page idle and young wrapper.

v2:
- remove useless PageTail && PageSlab check
- collect Gregory Price's work, see patch3

Kefeng Wang (7):
fs/proc/page: remove unneeded PageTail && PageSlab check fs/proc/page: use a folio in stable_page_flags() fs/proc/page: respect folio head-page flag placement
mm: huge_memory: use more folio api in __split_huge_page_tail()
mm: task_mmu: use a folio in smaps_account()
mm: task_mmu: use a folio in clear_refs_pte_range()
page_idle: kill page idle and young wrapper

 fs/proc/page.c            | 41 ++++++++++++++++++---------------------
 fs/proc/task_mmu.c        | 28 +++++++++++++-------------
 include/linux/page_idle.h | 25 ------------------------
 mm/huge_memory.c          | 12 ++++++------
 4 files changed, 40 insertions(+), 66 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/7 fs/proc/page: remove unneeded PageTail && PageSlab check

After commit dcb351cd095a ("page-flags: define behavior SL*B-related flags on compound pages"), the slab could not be a tail, remove unneeded PageTail && PageSlab check.

---
 fs/proc/page.c | 3 ---
 1 file changed, 3 deletions(-)
fs/proc/page.c +0 -3
index 195b077c0fac..466efb0dadf7 100644
@@ -184,9 +184,6 @@ u64 stable_page_flags(struct page *page)
 	u |= kpf_copy_bit(k, KPF_LOCKED,	PG_locked);
 
 	u |= kpf_copy_bit(k, KPF_SLAB,		PG_slab);
-	if (PageTail(page) && PageSlab(page))
-		u |= 1 << KPF_SLAB;
-
 	u |= kpf_copy_bit(k, KPF_ERROR,		PG_error);
 	u |= kpf_copy_bit(k, KPF_DIRTY,		PG_dirty);
 	u |= kpf_copy_bit(k, KPF_UPTODATE,	PG_uptodate);
Signature · 1 line
2.27.0
#2 lore raw

Re: [PATCH v2 1/7] fs/proc/page: remove unneeded PageTail && PageSlab check

Quoted 3 lines · Kefeng Wang

After commit dcb351cd095a ("page-flags: define behavior SL*B-related flags on compound pages"), the slab could not be a tail, remove unneeded PageTail && PageSlab check.

No, that's completely wrong.

* PF_NO_TAIL:
* modifications of the page flag must be done on small or head pages,
* checks can be done on tail pages too.

That's backed up by the code:

#define PF_NO_TAIL(page, enforce) ({                                    \
                VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page);     \
                PF_POISONED_CHECK(compound_head(page)); })

(enforce is set to 0 for the 'test')

Quoted 1 line

NAK

#3 lore raw

PATCH v2 2/7 fs/proc/page: use a folio in stable_page_flags()

In reply to Kefeng Wang

Replace nine compound_head() calls with one page_folio().

---
 fs/proc/page.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
fs/proc/page.c +10 -10
index 466efb0dadf7..dcef02471f91 100644
@@ -109,6 +109,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
 
 u64 stable_page_flags(struct page *page)
 {
+	struct folio *folio;
 	u64 k;
 	u64 u;
 
@@ -119,6 +120,7 @@ u64 stable_page_flags(struct page *page)
 	if (!page)
 		return 1 << KPF_NOPAGE;
 
+	folio = page_folio(page);
 	k = page->flags;
 	u = 0;
 
@@ -128,11 +130,11 @@ u64 stable_page_flags(struct page *page)
 	 * Note that page->_mapcount is overloaded in SLAB, so the
 	 * simple test in page_mapped() is not enough.
 	 */
-	if (!PageSlab(page) && page_mapped(page))
+	if (!folio_test_slab(folio) && folio_mapped(folio))
 		u |= 1 << KPF_MMAP;
-	if (PageAnon(page))
+	if (folio_test_anon(folio))
 		u |= 1 << KPF_ANON;
-	if (PageKsm(page))
+	if (folio_test_ksm(folio))
 		u |= 1 << KPF_KSM;
 
 	/*
@@ -152,11 +154,9 @@ u64 stable_page_flags(struct page *page)
 	 * to make sure a given page is a thp, not a non-huge compound page.
 	 */
 	else if (PageTransCompound(page)) {
-		struct page *head = compound_head(page);
-
-		if (PageLRU(head) || PageAnon(head))
+		if (folio_test_lru(folio) || folio_test_anon(folio))
 			u |= 1 << KPF_THP;
-		else if (is_huge_zero_page(head)) {
+		else if (is_huge_zero_page(&folio->page)) {
 			u |= 1 << KPF_ZERO_PAGE;
 			u |= 1 << KPF_THP;
 		}
@@ -170,7 +170,7 @@ u64 stable_page_flags(struct page *page)
 	 */
 	if (PageBuddy(page))
 		u |= 1 << KPF_BUDDY;
-	else if (page_count(page) == 0 && is_free_buddy_page(page))
+	else if (folio_ref_count(folio) == 0 && is_free_buddy_page(page))
 		u |= 1 << KPF_BUDDY;
 
 	if (PageOffline(page))
@@ -178,7 +178,7 @@ u64 stable_page_flags(struct page *page)
 	if (PageTable(page))
 		u |= 1 << KPF_PGTABLE;
 
-	if (page_is_idle(page))
+	if (folio_test_idle(folio))
 		u |= 1 << KPF_IDLE;
 
 	u |= kpf_copy_bit(k, KPF_LOCKED,	PG_locked);
@@ -194,7 +194,7 @@ u64 stable_page_flags(struct page *page)
 	u |= kpf_copy_bit(k, KPF_ACTIVE,	PG_active);
 	u |= kpf_copy_bit(k, KPF_RECLAIM,	PG_reclaim);
 
-	if (PageSwapCache(page))
+	if (folio_test_swapcache(folio))
 		u |= 1 << KPF_SWAPCACHE;
 	u |= kpf_copy_bit(k, KPF_SWAPBACKED,	PG_swapbacked);
 
Signature · 1 line
2.27.0
#4 lore raw

Re: [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()

Quoted 1 line · Kefeng Wang

Replace nine compound_head() calls with one page_folio().

But that's not all it does. Honestly, when you write these kind of things, I wonder if you understand what you're doing.

After this patch, if we report on a tail page, we set (some of) the flags according to how its head page is set. Before, we would have not reported on it at all.

This was THE ENTIRE POINT of Greg's patch. And why his patch made sense and yours is nonsense. Andrew, please drop this patch series.

#5 lore raw

Re: [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()

Quoted 5 lines · Matthew Wilcox
Quoted 1 line · Kefeng Wang

Replace nine compound_head() calls with one page_folio().

But that's not all it does. Honestly, when you write these kind of things, I wonder if you understand what you're doing.

Oh, yes, I total wrong for some change, the kpagelfags should report per-page.

Quoted 4 lines

After this patch, if we report on a tail page, we set (some of) the flags according to how its head page is set. Before, we would have not reported on it at all.

I should force on the following specific flags in this patch

1) PageKsm
- KSM only normal anon page, also it is wrapper of folio_test_ksm()
2) struct page *head = compound_head(page); PageLRU(head) PageAnon(head)
- they expect to check the head page flags
3) page_count(page) == 0 && is_free_buddy_page(page)
- this is to identify free buddy page, also page_count is a wrapper of folio_ref_count
4) page_is_idle
- a wrapper of folio_test_idle

Matthew and Gregory, correct me if I am still misunderstanding, man thanks.

Quoted 4 lines

This was THE ENTIRE POINT of Greg's patch. And why his patch made sense and yours is nonsense. Andrew, please drop this patch series.

#6 lore raw

Re: [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()

In reply to Kefeng Wang
Quoted 2 lines · Kefeng Wang

Replace nine compound_head() calls with one page_folio().

Sorry to echo Matthew, but this commit message is extremely insufficient and just outright wrong.

Single pass through, here's the real change list:

1) changes PageFLAG() calls to folio_test_FLAG calls
2) changes compound_head() flag checks to folio_test_FLAG checks
3) change page count to folio ref count
-- without even looking... is this even correct? Need more

      explanation here. Is page count === folio ref count?

So there are really 3 changes in this patch set that should be broken out separately, even if they all depend on folio flags, because they need separate explanation and validation for correctness.

Quoted 5 lines
---
 fs/proc/page.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
#7 lore raw

PATCH v2 3/7 fs/proc/page: respect folio head-page flag placement

In reply to Kefeng Wang

kpageflags reads page-flags directly from the page, even when the respective flag is only updated on the headpage of a folio.

Since most flags are stored in head flags, make k = folio->flags, and add new p = page->flags used for per-page flags.

Originally-from: Gregory Price <[email protected]>

---
 fs/proc/page.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
fs/proc/page.c +9 -9
index dcef02471f91..553a7c921cb4 100644
@@ -110,8 +110,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
 u64 stable_page_flags(struct page *page)
 {
 	struct folio *folio;
-	u64 k;
-	u64 u;
+	u64 k, p, u;
 
 	/*
 	 * pseudo flag: KPF_NOPAGE
@@ -121,7 +120,8 @@ u64 stable_page_flags(struct page *page)
 		return 1 << KPF_NOPAGE;
 
 	folio = page_folio(page);
-	k = page->flags;
+	k = folio->flags;
+	p = page->flags;
 	u = 0;
 
 	/*
@@ -202,7 +202,7 @@ u64 stable_page_flags(struct page *page)
 	u |= kpf_copy_bit(k, KPF_MLOCKED,	PG_mlocked);
 
 #ifdef CONFIG_MEMORY_FAILURE
-	u |= kpf_copy_bit(k, KPF_HWPOISON,	PG_hwpoison);
+	u |= kpf_copy_bit(p, KPF_HWPOISON,	PG_hwpoison);
 #endif
 
 #ifdef CONFIG_ARCH_USES_PG_UNCACHED
@@ -211,13 +211,13 @@ u64 stable_page_flags(struct page *page)
 
 	u |= kpf_copy_bit(k, KPF_RESERVED,	PG_reserved);
 	u |= kpf_copy_bit(k, KPF_MAPPEDTODISK,	PG_mappedtodisk);
-	u |= kpf_copy_bit(k, KPF_PRIVATE,	PG_private);
-	u |= kpf_copy_bit(k, KPF_PRIVATE_2,	PG_private_2);
-	u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE,	PG_owner_priv_1);
+	u |= kpf_copy_bit(p, KPF_PRIVATE,	PG_private);
+	u |= kpf_copy_bit(p, KPF_PRIVATE_2,	PG_private_2);
+	u |= kpf_copy_bit(p, KPF_OWNER_PRIVATE,	PG_owner_priv_1);
 	u |= kpf_copy_bit(k, KPF_ARCH,		PG_arch_1);
 #ifdef CONFIG_ARCH_USES_PG_ARCH_X
-	u |= kpf_copy_bit(k, KPF_ARCH_2,	PG_arch_2);
-	u |= kpf_copy_bit(k, KPF_ARCH_3,	PG_arch_3);
+	u |= kpf_copy_bit(p, KPF_ARCH_2,	PG_arch_2);
+	u |= kpf_copy_bit(p, KPF_ARCH_3,	PG_arch_3);
 #endif
 
 	return u;
Signature · 1 line
2.27.0
#8 lore raw

Re: [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement

Quoted 5 lines · Kefeng Wang

kpageflags reads page-flags directly from the page, even when the respective flag is only updated on the headpage of a folio.

Since most flags are stored in head flags, make k = folio->flags, and add new p = page->flags used for per-page flags.

You'd do better to steal Greg's commit message.

fs/proc/page.c u64 stable_page_flags(struct page *page) · line 205

Quoted 10 lines

Originally-from: Gregory Price <[email protected]>

fs/proc/page.c +1 -1
@@ -202,7 +202,7 @@ u64 stable_page_flags(struct page *page)
 	u |= kpf_copy_bit(k, KPF_MLOCKED,	PG_mlocked);
 
 #ifdef CONFIG_MEMORY_FAILURE
-	u |= kpf_copy_bit(k, KPF_HWPOISON,	PG_hwpoison);
+	u |= kpf_copy_bit(p, KPF_HWPOISON,	PG_hwpoison);

This is correct.

fs/proc/page.c u64 stable_page_flags(struct page *page) · line 216

Quoted 10 lines
fs/proc/page.c +3 -3
@@ -211,13 +211,13 @@ u64 stable_page_flags(struct page *page)
 
 	u |= kpf_copy_bit(k, KPF_RESERVED,	PG_reserved);
 	u |= kpf_copy_bit(k, KPF_MAPPEDTODISK,	PG_mappedtodisk);
-	u |= kpf_copy_bit(k, KPF_PRIVATE,	PG_private);
-	u |= kpf_copy_bit(k, KPF_PRIVATE_2,	PG_private_2);
-	u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE,	PG_owner_priv_1);
+	u |= kpf_copy_bit(p, KPF_PRIVATE,	PG_private);
+	u |= kpf_copy_bit(p, KPF_PRIVATE_2,	PG_private_2);
+	u |= kpf_copy_bit(p, KPF_OWNER_PRIVATE,	PG_owner_priv_1);

This is not. PG_private is not, I believe, set on tail pages. Ditto the other two. If you know differently ... ?

fs/proc/page.c u64 stable_page_flags(struct page *page) · line 221

Quoted 6 lines
fs/proc/page.c +2 -2
 #ifdef CONFIG_ARCH_USES_PG_ARCH_X
-	u |= kpf_copy_bit(k, KPF_ARCH_2,	PG_arch_2);
-	u |= kpf_copy_bit(k, KPF_ARCH_3,	PG_arch_3);
+	u |= kpf_copy_bit(p, KPF_ARCH_2,	PG_arch_2);
+	u |= kpf_copy_bit(p, KPF_ARCH_3,	PG_arch_3);
 #endif

I also don't think this is correct, but there are many uses of PG_arch* and I may have missed something.

#9 lore raw

Re: [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement

Quoted 8 lines · Matthew Wilcox
Quoted 5 lines · Kefeng Wang

kpageflags reads page-flags directly from the page, even when the respective flag is only updated on the headpage of a folio.

Since most flags are stored in head flags, make k = folio->flags, and add new p = page->flags used for per-page flags.

You'd do better to steal Greg's commit message.

Sure

Quoted 16 lines

fs/proc/page.c u64 stable_page_flags(struct page *page) · line 205

Quoted 11 lines

Originally-from: Gregory Price <[email protected]>

fs/proc/page.c +1 -1
@@ -202,7 +202,7 @@ u64 stable_page_flags(struct page *page)
  	u |= kpf_copy_bit(k, KPF_MLOCKED,	PG_mlocked);
 
  #ifdef CONFIG_MEMORY_FAILURE
-	u |= kpf_copy_bit(k, KPF_HWPOISON,	PG_hwpoison);
+	u |= kpf_copy_bit(p, KPF_HWPOISON,	PG_hwpoison);

This is correct.

Quoted 2 lines
(quoted diff) +0 -0
@@ -211,13 +211,13 @@ u64 stable_page_flags(struct page *page)
 
Quoted 11 lines

fs/proc/page.c u64 stable_page_flags(struct page *page) · line 216

Quoted 8 lines
fs/proc/page.c +3 -3
  	u |= kpf_copy_bit(k, KPF_RESERVED,	PG_reserved);
  	u |= kpf_copy_bit(k, KPF_MAPPEDTODISK,	PG_mappedtodisk);
-	u |= kpf_copy_bit(k, KPF_PRIVATE,	PG_private);
-	u |= kpf_copy_bit(k, KPF_PRIVATE_2,	PG_private_2);
-	u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE,	PG_owner_priv_1);
+	u |= kpf_copy_bit(p, KPF_PRIVATE,	PG_private);
+	u |= kpf_copy_bit(p, KPF_PRIVATE_2,	PG_private_2);
+	u |= kpf_copy_bit(p, KPF_OWNER_PRIVATE,	PG_owner_priv_1);

This is not. PG_private is not, I believe, set on tail pages. Ditto the other two. If you know differently ... ?

k = folio->flags, p = page->flags
as PG_private/private_2/owner_priv_1 use PF_ANY page policy, so they should per-page check, confused...

See checked page flags,

PG_error        PF_NO_TAIL
PG_dirty        PF_HEAD
PG_uptodate     PF_NO_TAIL
PG_writeback    PF_NO_TAIL
PG_lru          PF_HEAD
PG_referenced 	PF_HEAD
PG_active       PF_HEAD
PG_reclaim      PF_NO_TAIL
PG_swapbacked   PF_NO_TAIL
PG_unevictable  PF_HEAD
PG_mlocked      PF_NO_TAIL
PG_hwpoison     PF_ANY
PG_uncached     PF_NO_COMPOUND	
PG_reserved     PF_NO_COMPOUND

PG_mappedtodisk PF_NO_TAIL
PG_private PF_ANY
PG_private_2 PF_ANY
PG_owner_priv_1 PF_ANY

above part has 4 types,

1) PF_HEAD - should use k

2) PF_ANY - should use p

3) PF_NO_TAIL
- PageXXX will check head page flags, so suppose to use k, but here use bit check, I wonder it should use p?

4) PF_NO_COMPOUND
- should per-page check

Quoted 11 lines

fs/proc/page.c u64 stable_page_flags(struct page *page) · line 221

Quoted 7 lines
fs/proc/page.c +2 -2
  #ifdef CONFIG_ARCH_USES_PG_ARCH_X
-	u |= kpf_copy_bit(k, KPF_ARCH_2,	PG_arch_2);
-	u |= kpf_copy_bit(k, KPF_ARCH_3,	PG_arch_3);
+	u |= kpf_copy_bit(p, KPF_ARCH_2,	PG_arch_2);
+	u |= kpf_copy_bit(p, KPF_ARCH_3,	PG_arch_3);
  #endif

I also don't think this is correct, but there are many uses of PG_arch* and I may have missed something.

And 3 arch page flags,

PG_arch_1
- PG_dcache_clean, from achetlb.rst, I think it is per-folio, use k

PG_arch_2
- only arm64 mte, PG_mte_tagged
PG_arch_3
- only arm64 mte, PG_mte_lock

the two PG_arch only used by arm64 mte, they are per-page flag, use p

Correct me if I am wrong, thanks.

#10 lore raw

PATCH v2 4/7 mm: huge_memory: use more folio api in __split_huge_page_tail()

In reply to Kefeng Wang

Use more folio APIs to save six compound_head() calls in __split_huge_page_tail().

---
 mm/huge_memory.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/huge_memory.c +6 -6
index 3f74a063f7d1..2b03c55ea425 100644
@@ -2509,13 +2509,13 @@ static void __split_huge_page_tail(struct folio *folio, int tail,
 	clear_compound_head(page_tail);
 
 	/* Finally unfreeze refcount. Additional reference from page cache. */
-	page_ref_unfreeze(page_tail, 1 + (!PageAnon(head) ||
-					  PageSwapCache(head)));
+	page_ref_unfreeze(page_tail, 1 + (!folio_test_anon(folio) ||
+					  folio_test_swapcache(folio)));
 
-	if (page_is_young(head))
-		set_page_young(page_tail);
-	if (page_is_idle(head))
-		set_page_idle(page_tail);
+	if (folio_test_young(folio))
+		folio_set_young(new_folio);
+	if (folio_test_idle(folio))
+		folio_set_idle(new_folio);
 
 	folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio));
 
Signature · 1 line
2.27.0
#12 lore raw

Re: [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail()

Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Kefeng Wang

Use more folio APIs to save six compound_head() calls in __split_huge_page_tail().

Thanks, Hi Andrew, please consider only take this one, I will think more about other part as Matthew suggested.

#13 lore raw

PATCH v2 5/7 mm: task_mmu: use a folio in smaps_account()

In reply to Kefeng Wang

Replace seven implicit calls to compound_head() with one page_folio().

---
 fs/proc/task_mmu.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/proc/task_mmu.c +7 -5
index 51e0ec658457..fe15f99a4908 100644
@@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
 {
 	int i, nr = compound ? compound_nr(page) : 1;
 	unsigned long size = nr * PAGE_SIZE;
+	struct folio *folio = page_folio(page);
 
 	/*
 	 * First accumulate quantities that depend only on |size| and the type
 	 * of the compound page.
 	 */
-	if (PageAnon(page)) {
+	if (folio_test_anon(folio)) {
 		mss->anonymous += size;
-		if (!PageSwapBacked(page) && !dirty && !PageDirty(page))
+		if (!folio_test_swapbacked(folio) && !dirty &&
+		    !folio_test_dirty(folio))
 			mss->lazyfree += size;
 	}
 
-	if (PageKsm(page))
+	if (folio_test_ksm(folio))
 		mss->ksm += size;
 
 	mss->resident += size;
 	/* Accumulate the size in pages that have been accessed. */
-	if (young || page_is_young(page) || PageReferenced(page))
+	if (young || folio_test_young(folio) || folio_test_referenced(folio))
 		mss->referenced += size;
 
 	/*
@@ -479,7 +481,7 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
 	 * especially for migration entries.  Treat regular migration entries
 	 * as mapcount == 1.
 	 */
-	if ((page_count(page) == 1) || migration) {
+	if ((folio_ref_count(folio) == 1) || migration) {
 		smaps_page_accumulate(mss, page, size, size << PSS_SHIFT, dirty,
 			locked, true);
 		return;
Signature · 1 line
2.27.0
#14 lore raw

Re: [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account()

Quoted 1 line · Kefeng Wang

Replace seven implicit calls to compound_head() with one page_folio().

You're so focused on trying to accomplish your goal (killing off the page_idle and page_young functions) that you're doing a poor job thinkig about the conversions you're doing along the way.

fs/proc/task_mmu.c static void smaps_account(struct mem_size_stats *mss, struct page *page, · line 448

Quoted 6 lines

+++ b/fs/proc/task_mmu.c

fs/proc/task_mmu.c +1 -0
@@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
 {
 	int i, nr = compound ? compound_nr(page) : 1;
 	unsigned long size = nr * PAGE_SIZE;
+	struct folio *folio = page_folio(page);

Stop right here. The use of compound_nr() should give you pause.

After looking at how smaps_account() is used, it seems to me that the two callers should each pass in PAGE_SIZE or PMD_SIZE instead of doing this calculation.

More generally, step back from this series. Do a good job of transforming fs/proc/task_mmu.c to use folios. Once you've done that, you can approach the young/idle work again.

#15 lore raw

Re: [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account()

Quoted 16 lines · Matthew Wilcox
Quoted 1 line · Kefeng Wang

Replace seven implicit calls to compound_head() with one page_folio().

You're so focused on trying to accomplish your goal (killing off the page_idle and page_young functions) that you're doing a poor job thinkig about the conversions you're doing along the way.

fs/proc/task_mmu.c static void smaps_account(struct mem_size_stats *mss, struct page *page, · line 448

Quoted 6 lines

+++ b/fs/proc/task_mmu.c

fs/proc/task_mmu.c +1 -0
@@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
  {
  	int i, nr = compound ? compound_nr(page) : 1;
  	unsigned long size = nr * PAGE_SIZE;
+	struct folio *folio = page_folio(page);

Stop right here. The use of compound_nr() should give you pause.

Quoted 3 lines

After looking at how smaps_account() is used, it seems to me that the two callers should each pass in PAGE_SIZE or PMD_SIZE instead of doing this calculation.

Yes,this will save extra calculation

Quoted 5 lines

More generally, step back from this series. Do a good job of transforming fs/proc/task_mmu.c to use folios. Once you've done that, you can approach the young/idle work again.

Thanks for you advise,will try this firstly.

Quoted 1 line
#16 lore raw

PATCH v2 6/7 mm: task_mmu: use a folio in clear_refs_pte_range()

In reply to Kefeng Wang

Use a folio to save two compound_head() calls in clear_refs_pte_range().

---
 fs/proc/task_mmu.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
fs/proc/task_mmu.c +8 -8
index fe15f99a4908..740d5c4fa33c 100644
@@ -1161,7 +1161,7 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
 	struct vm_area_struct *vma = walk->vma;
 	pte_t *pte, ptent;
 	spinlock_t *ptl;
-	struct page *page;
+	struct folio *folio;
 
 	ptl = pmd_trans_huge_lock(pmd, vma);
 	if (ptl) {
@@ -1173,12 +1173,12 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
 		if (!pmd_present(*pmd))
 			goto out;
 
-		page = pmd_page(*pmd);
+		folio = page_folio(pmd_page(*pmd));
 
 		/* Clear accessed and referenced bits. */
 		pmdp_test_and_clear_young(vma, addr, pmd);
-		test_and_clear_page_young(page);
-		ClearPageReferenced(page);
+		folio_test_clear_young(folio);
+		folio_clear_referenced(folio);
 out:
 		spin_unlock(ptl);
 		return 0;
@@ -1200,14 +1200,14 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
 		if (!pte_present(ptent))
 			continue;
 
-		page = vm_normal_page(vma, addr, ptent);
-		if (!page)
+		folio = vm_normal_folio(vma, addr, ptent);
+		if (!folio)
 			continue;
 
 		/* Clear accessed and referenced bits. */
 		ptep_test_and_clear_young(vma, addr, pte);
-		test_and_clear_page_young(page);
-		ClearPageReferenced(page);
+		folio_test_clear_young(folio);
+		folio_clear_referenced(folio);
 	}
 	pte_unmap_unlock(pte - 1, ptl);
 	cond_resched();
Signature · 1 line
2.27.0
#17 lore raw

PATCH v2 7/7 page_idle: kill page idle and young wrapper

In reply to Kefeng Wang

Since all the calls of page idle and young functions are gone, let's remove all the wrapper.

---
 include/linux/page_idle.h | 25 -------------------------
 1 file changed, 25 deletions(-)
include/linux/page_idle.h +0 -25
index d8f344840643..1168d5f58ff2 100644
@@ -119,29 +119,4 @@ static inline void folio_clear_idle(struct folio *folio)
 }
 
 #endif /* CONFIG_PAGE_IDLE_FLAG */
-
-static inline bool page_is_young(struct page *page)
-{
-	return folio_test_young(page_folio(page));
-}
-
-static inline void set_page_young(struct page *page)
-{
-	folio_set_young(page_folio(page));
-}
-
-static inline bool test_and_clear_page_young(struct page *page)
-{
-	return folio_test_clear_young(page_folio(page));
-}
-
-static inline bool page_is_idle(struct page *page)
-{
-	return folio_test_idle(page_folio(page));
-}
-
-static inline void set_page_idle(struct page *page)
-{
-	folio_set_idle(page_folio(page));
-}
 #endif /* _LINUX_MM_PAGE_IDLE_H */
Signature · 1 line
2.27.0