linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Remove page_idle and page_young wrappers
@ 2024-04-02 20:12 Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 1/4] proc: Convert clear_refs_pte_range to use a folio Matthew Wilcox (Oracle)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-02 20:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

There are only a couple of places left using the page wrappers for
idle & young tracking.  Convert the two users in proc and then we can
remove the wrappers.  That enables the further simplification of
autogenerating the definitions when CONFIG_PAGE_IDLE_FLAG is disabled.

Matthew Wilcox (Oracle) (4):
  proc: Convert clear_refs_pte_range to use a folio
  proc: Convert smaps_account() to use a folio
  mm: Remove page_idle and page_young wrappers
  mm: Generate PAGE_IDLE_FLAG definitions

 fs/proc/task_mmu.c         | 32 +++++++++++---------
 include/linux/page-flags.h |  9 +++++-
 include/linux/page_idle.h  | 62 ++------------------------------------
 3 files changed, 27 insertions(+), 76 deletions(-)

-- 
2.43.0



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

* [PATCH 1/4] proc: Convert clear_refs_pte_range to use a folio
  2024-04-02 20:12 [PATCH 0/4] Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
@ 2024-04-02 20:12 ` Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 2/4] proc: Convert smaps_account() " Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-02 20:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

Replaces four calls to compound_head() with two.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 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 23fbab954c20..b94101cd2706 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 = pmd_folio(*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.43.0



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

* [PATCH 2/4] proc: Convert smaps_account() to use a folio
  2024-04-02 20:12 [PATCH 0/4] Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 1/4] proc: Convert clear_refs_pte_range to use a folio Matthew Wilcox (Oracle)
@ 2024-04-02 20:12 ` Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 3/4] mm: Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 4/4] mm: Generate PAGE_IDLE_FLAG definitions Matthew Wilcox (Oracle)
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-02 20:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

Replace seven calls to compound_head() with one.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/proc/task_mmu.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index b94101cd2706..e8d1008a838d 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -444,6 +444,7 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
 		bool compound, bool young, bool dirty, bool locked,
 		bool migration)
 {
+	struct folio *folio = page_folio(page);
 	int i, nr = compound ? compound_nr(page) : 1;
 	unsigned long size = nr * PAGE_SIZE;
 
@@ -451,27 +452,28 @@ static void smaps_account(struct mem_size_stats *mss, struct page *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;
 
 	/*
 	 * Then accumulate quantities that may depend on sharing, or that may
 	 * differ page-by-page.
 	 *
-	 * page_count(page) == 1 guarantees the page is mapped exactly once.
+	 * refcount == 1 guarantees the page is mapped exactly once.
 	 * If any subpage of the compound page mapped with PTE it would elevate
-	 * page_count().
+	 * the refcount.
 	 *
 	 * The page_mapcount() is called to get a snapshot of the mapcount.
 	 * Without holding the page lock this snapshot can be slightly wrong as
@@ -480,7 +482,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.43.0



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

* [PATCH 3/4] mm: Remove page_idle and page_young wrappers
  2024-04-02 20:12 [PATCH 0/4] Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 1/4] proc: Convert clear_refs_pte_range to use a folio Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 2/4] proc: Convert smaps_account() " Matthew Wilcox (Oracle)
@ 2024-04-02 20:12 ` Matthew Wilcox (Oracle)
  2024-04-02 20:12 ` [PATCH 4/4] mm: Generate PAGE_IDLE_FLAG definitions Matthew Wilcox (Oracle)
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-02 20:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

All users have now been converted to the folio equivalents, so
remove the page wrappers.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 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 511e22ef459f..6357f1e7918a 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.43.0



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

* [PATCH 4/4] mm: Generate PAGE_IDLE_FLAG definitions
  2024-04-02 20:12 [PATCH 0/4] Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2024-04-02 20:12 ` [PATCH 3/4] mm: Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
@ 2024-04-02 20:12 ` Matthew Wilcox (Oracle)
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-02 20:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel

If CONFIG_PAGE_IDLE_FLAG is not set, we can use FOLIO_FLAG_FALSE()
to generate these definitions.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/page-flags.h |  9 ++++++++-
 include/linux/page_idle.h  | 37 ++-----------------------------------
 2 files changed, 10 insertions(+), 36 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 888353c209c0..a49739a67005 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -626,12 +626,19 @@ PAGEFLAG_FALSE(HWPoison, hwpoison)
 #define __PG_HWPOISON 0
 #endif
 
-#if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT)
+#ifdef CONFIG_PAGE_IDLE_FLAG
+#ifdef CONFIG_64BIT
 FOLIO_TEST_FLAG(young, FOLIO_HEAD_PAGE)
 FOLIO_SET_FLAG(young, FOLIO_HEAD_PAGE)
 FOLIO_TEST_CLEAR_FLAG(young, FOLIO_HEAD_PAGE)
 FOLIO_FLAG(idle, FOLIO_HEAD_PAGE)
 #endif
+/* See page_idle.h for !64BIT workaround */
+#else /* !CONFIG_PAGE_IDLE_FLAG */
+FOLIO_FLAG_FALSE(young)
+FOLIO_TEST_CLEAR_FLAG_FALSE(young)
+FOLIO_FLAG_FALSE(idle)
+#endif
 
 /*
  * PageReported() is used to track reported free pages within the Buddy
diff --git a/include/linux/page_idle.h b/include/linux/page_idle.h
index 6357f1e7918a..89ca0d5dc1e7 100644
--- a/include/linux/page_idle.h
+++ b/include/linux/page_idle.h
@@ -6,9 +6,7 @@
 #include <linux/page-flags.h>
 #include <linux/page_ext.h>
 
-#ifdef CONFIG_PAGE_IDLE_FLAG
-
-#ifndef CONFIG_64BIT
+#if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT)
 /*
  * If there is not enough space to store Idle and Young bits in page flags, use
  * page ext flags instead.
@@ -87,36 +85,5 @@ static inline void folio_clear_idle(struct folio *folio)
 	clear_bit(PAGE_EXT_IDLE, &page_ext->flags);
 	page_ext_put(page_ext);
 }
-#endif /* !CONFIG_64BIT */
-
-#else /* !CONFIG_PAGE_IDLE_FLAG */
-
-static inline bool folio_test_young(const struct folio *folio)
-{
-	return false;
-}
-
-static inline void folio_set_young(struct folio *folio)
-{
-}
-
-static inline bool folio_test_clear_young(struct folio *folio)
-{
-	return false;
-}
-
-static inline bool folio_test_idle(const struct folio *folio)
-{
-	return false;
-}
-
-static inline void folio_set_idle(struct folio *folio)
-{
-}
-
-static inline void folio_clear_idle(struct folio *folio)
-{
-}
-
-#endif /* CONFIG_PAGE_IDLE_FLAG */
+#endif /* CONFIG_PAGE_IDLE_FLAG && !64BIT */
 #endif /* _LINUX_MM_PAGE_IDLE_H */
-- 
2.43.0



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

end of thread, other threads:[~2024-04-02 20:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02 20:12 [PATCH 0/4] Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
2024-04-02 20:12 ` [PATCH 1/4] proc: Convert clear_refs_pte_range to use a folio Matthew Wilcox (Oracle)
2024-04-02 20:12 ` [PATCH 2/4] proc: Convert smaps_account() " Matthew Wilcox (Oracle)
2024-04-02 20:12 ` [PATCH 3/4] mm: Remove page_idle and page_young wrappers Matthew Wilcox (Oracle)
2024-04-02 20:12 ` [PATCH 4/4] mm: Generate PAGE_IDLE_FLAG definitions Matthew Wilcox (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox