All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] mm: remove page idle and young wrapper
@ 2023-11-03  7:29 Kefeng Wang
  2023-11-03  7:29 ` [PATCH 1/5] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03  7:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-fsdevel, linux-mm, Matthew Wilcox,
	David Hildenbrand, Kefeng Wang

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

Kefeng Wang (5):
  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()
  fs/proc/page: use a folio in stable_page_flags()
  page_idle: kill page idle and young wrapper

 fs/proc/page.c            | 22 +++++++++++-----------
 fs/proc/task_mmu.c        | 28 +++++++++++++++-------------
 include/linux/page_idle.h | 25 -------------------------
 mm/huge_memory.c          | 12 ++++++------
 4 files changed, 32 insertions(+), 55 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] mm: huge_memory: use more folio api in __split_huge_page_tail()
  2023-11-03  7:29 [PATCH 0/5] mm: remove page idle and young wrapper Kefeng Wang
@ 2023-11-03  7:29 ` Kefeng Wang
  2023-11-03  7:29 ` [PATCH 2/5] mm: task_mmu: use a folio in smaps_account() Kefeng Wang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03  7:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-fsdevel, linux-mm, Matthew Wilcox,
	David Hildenbrand, Kefeng Wang

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

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/huge_memory.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index f31f02472396..34001ef9d029 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2507,13 +2507,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));
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/5] mm: task_mmu: use a folio in smaps_account()
  2023-11-03  7:29 [PATCH 0/5] mm: remove page idle and young wrapper Kefeng Wang
  2023-11-03  7:29 ` [PATCH 1/5] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
@ 2023-11-03  7:29 ` Kefeng Wang
  2023-11-03  7:29 ` [PATCH 3/5] mm: task_mmu: use a folio in clear_refs_pte_range() Kefeng Wang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03  7:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-fsdevel, linux-mm, Matthew Wilcox,
	David Hildenbrand, Kefeng Wang

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

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 fs/proc/task_mmu.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index ef2eb12906da..5ec06fee1f14 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -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;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/5] mm: task_mmu: use a folio in clear_refs_pte_range()
  2023-11-03  7:29 [PATCH 0/5] mm: remove page idle and young wrapper Kefeng Wang
  2023-11-03  7:29 ` [PATCH 1/5] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
  2023-11-03  7:29 ` [PATCH 2/5] mm: task_mmu: use a folio in smaps_account() Kefeng Wang
@ 2023-11-03  7:29 ` Kefeng Wang
  2023-11-03  7:29 ` [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
  2023-11-03  7:29 ` [PATCH 5/5] page_idle: kill page idle and young wrapper Kefeng Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03  7:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-fsdevel, linux-mm, Matthew Wilcox,
	David Hildenbrand, Kefeng Wang

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

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 fs/proc/task_mmu.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 5ec06fee1f14..869f6bb89230 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -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();
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags()
  2023-11-03  7:29 [PATCH 0/5] mm: remove page idle and young wrapper Kefeng Wang
                   ` (2 preceding siblings ...)
  2023-11-03  7:29 ` [PATCH 3/5] mm: task_mmu: use a folio in clear_refs_pte_range() Kefeng Wang
@ 2023-11-03  7:29 ` Kefeng Wang
  2023-11-03 12:28   ` Matthew Wilcox
  2023-11-03  7:29 ` [PATCH 5/5] page_idle: kill page idle and young wrapper Kefeng Wang
  4 siblings, 1 reply; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03  7:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-fsdevel, linux-mm, Matthew Wilcox,
	David Hildenbrand, Kefeng Wang

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

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 fs/proc/page.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/fs/proc/page.c b/fs/proc/page.c
index 195b077c0fac..94ab0ba13b16 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -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,13 +178,13 @@ 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);
 
 	u |= kpf_copy_bit(k, KPF_SLAB,		PG_slab);
-	if (PageTail(page) && PageSlab(page))
+	if (PageTail(page) && folio_test_slab(folio))
 		u |= 1 << KPF_SLAB;
 
 	u |= kpf_copy_bit(k, KPF_ERROR,		PG_error);
@@ -197,7 +197,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);
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/5] page_idle: kill page idle and young wrapper
  2023-11-03  7:29 [PATCH 0/5] mm: remove page idle and young wrapper Kefeng Wang
                   ` (3 preceding siblings ...)
  2023-11-03  7:29 ` [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
@ 2023-11-03  7:29 ` Kefeng Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03  7:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-fsdevel, linux-mm, Matthew Wilcox,
	David Hildenbrand, Kefeng Wang

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

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/page_idle.h | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/include/linux/page_idle.h b/include/linux/page_idle.h
index d8f344840643..1168d5f58ff2 100644
--- a/include/linux/page_idle.h
+++ b/include/linux/page_idle.h
@@ -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 */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags()
  2023-11-03  7:29 ` [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
@ 2023-11-03 12:28   ` Matthew Wilcox
  2023-11-03 13:07     ` Kefeng Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2023-11-03 12:28 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, linux-kernel, linux-fsdevel, linux-mm, David Hildenbrand

On Fri, Nov 03, 2023 at 03:29:05PM +0800, Kefeng Wang wrote:
> Replace ten compound_head() calls with one page_folio().

This is going to conflict with Gregory Price's work:

https://lore.kernel.org/linux-mm/ZUCD1dsbrFjdZgVv@memverge.com/

Perhaps the two of you can collaborate on a patch series?

>  	u |= kpf_copy_bit(k, KPF_SLAB,		PG_slab);
> -	if (PageTail(page) && PageSlab(page))
> +	if (PageTail(page) && folio_test_slab(folio))
>  		u |= 1 << KPF_SLAB;

This doesn't make sense ...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags()
  2023-11-03 12:28   ` Matthew Wilcox
@ 2023-11-03 13:07     ` Kefeng Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Kefeng Wang @ 2023-11-03 13:07 UTC (permalink / raw)
  To: Matthew Wilcox, gourry.memverge
  Cc: Andrew Morton, linux-kernel, linux-fsdevel, linux-mm, David Hildenbrand



On 2023/11/3 20:28, Matthew Wilcox wrote:
> On Fri, Nov 03, 2023 at 03:29:05PM +0800, Kefeng Wang wrote:
>> Replace ten compound_head() calls with one page_folio().
> 
> This is going to conflict with Gregory Price's work:
> 
> https://lore.kernel.org/linux-mm/ZUCD1dsbrFjdZgVv@memverge.com/
> 
> Perhaps the two of you can collaborate on a patch series?

Will check this patch.

> 
>>   	u |= kpf_copy_bit(k, KPF_SLAB,		PG_slab);
>> -	if (PageTail(page) && PageSlab(page))
>> +	if (PageTail(page) && folio_test_slab(folio))
>>   		u |= 1 << KPF_SLAB;
> 
> This doesn't make sense ...
> 

Yes, after commit dcb351cd095a ("page-flags: define behavior SL*B-
related flags on compound pages"), the slab could not be a tail,
I will drop this line.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-03 13:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-03  7:29 [PATCH 0/5] mm: remove page idle and young wrapper Kefeng Wang
2023-11-03  7:29 ` [PATCH 1/5] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
2023-11-03  7:29 ` [PATCH 2/5] mm: task_mmu: use a folio in smaps_account() Kefeng Wang
2023-11-03  7:29 ` [PATCH 3/5] mm: task_mmu: use a folio in clear_refs_pte_range() Kefeng Wang
2023-11-03  7:29 ` [PATCH 4/5] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
2023-11-03 12:28   ` Matthew Wilcox
2023-11-03 13:07     ` Kefeng Wang
2023-11-03  7:29 ` [PATCH 5/5] page_idle: kill page idle and young wrapper Kefeng Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.