linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Use folio APIs in procfs
@ 2024-04-03 17:14 Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 1/4] proc: Convert gather_stats to use a folio Matthew Wilcox (Oracle)
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-03 17:14 UTC (permalink / raw)
  To: Andrew Morton, Christian Brauner
  Cc: Matthew Wilcox (Oracle), linux-kernel, linux-fsdevel, linux-mm

Not sure whether Andrew or Christian will want to take this set of
fixes.  We're down to very few users of the PageFoo macros, with proc
being a major user.  After this patchset and another patchset I have
for khugepaged, we can get rid of PageActive, PageReadahead and
PageSwapBacked.

This patchset has the usual advantages in its own right of removing
hidden calls to compound_head().  We have the page table lock, so
the mapcount & refcount are stable and there can't be any races with
folios suddenly becoming tail pages.

Matthew Wilcox (Oracle) (4):
  proc: Convert gather_stats to use a folio
  proc: Convert smaps_page_accumulate to use a folio
  proc: Pass a folio to smaps_page_accumulate()
  proc: Convert smaps_pmd_entry to use a folio

 fs/proc/task_mmu.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

-- 
2.43.0



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

* [PATCH 1/4] proc: Convert gather_stats to use a folio
  2024-04-03 17:14 [PATCH 0/4] Use folio APIs in procfs Matthew Wilcox (Oracle)
@ 2024-04-03 17:14 ` Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 2/4] proc: Convert smaps_page_accumulate " Matthew Wilcox (Oracle)
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-03 17:14 UTC (permalink / raw)
  To: Andrew Morton, Christian Brauner
  Cc: Matthew Wilcox (Oracle), linux-kernel, linux-fsdevel, linux-mm

Replaces six calls to compound_head() with one.  Shrinks the function
from 5054 bytes to 1756 bytes in an allmodconfig build.

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

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index e8d1008a838d..5260a2788f74 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -2549,28 +2549,29 @@ struct numa_maps_private {
 static void gather_stats(struct page *page, struct numa_maps *md, int pte_dirty,
 			unsigned long nr_pages)
 {
+	struct folio *folio = page_folio(page);
 	int count = page_mapcount(page);
 
 	md->pages += nr_pages;
-	if (pte_dirty || PageDirty(page))
+	if (pte_dirty || folio_test_dirty(folio))
 		md->dirty += nr_pages;
 
-	if (PageSwapCache(page))
+	if (folio_test_swapcache(folio))
 		md->swapcache += nr_pages;
 
-	if (PageActive(page) || PageUnevictable(page))
+	if (folio_test_active(folio) || folio_test_unevictable(folio))
 		md->active += nr_pages;
 
-	if (PageWriteback(page))
+	if (folio_test_writeback(folio))
 		md->writeback += nr_pages;
 
-	if (PageAnon(page))
+	if (folio_test_anon(folio))
 		md->anon += nr_pages;
 
 	if (count > md->mapcount_max)
 		md->mapcount_max = count;
 
-	md->node[page_to_nid(page)] += nr_pages;
+	md->node[folio_nid(folio)] += nr_pages;
 }
 
 static struct page *can_gather_numa_stats(pte_t pte, struct vm_area_struct *vma,
-- 
2.43.0



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

* [PATCH 2/4] proc: Convert smaps_page_accumulate to use a folio
  2024-04-03 17:14 [PATCH 0/4] Use folio APIs in procfs Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 1/4] proc: Convert gather_stats to use a folio Matthew Wilcox (Oracle)
@ 2024-04-03 17:14 ` Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 3/4] proc: Pass a folio to smaps_page_accumulate() Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-03 17:14 UTC (permalink / raw)
  To: Andrew Morton, Christian Brauner
  Cc: Matthew Wilcox (Oracle), linux-kernel, linux-fsdevel, linux-mm

Replaces three calls to compound_head() with one.  Shrinks the function
from 2614 bytes to 1112 bytes in an allmodconfig build.

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

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 5260a2788f74..2a3133dd47b1 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -414,11 +414,12 @@ static void smaps_page_accumulate(struct mem_size_stats *mss,
 		struct page *page, unsigned long size, unsigned long pss,
 		bool dirty, bool locked, bool private)
 {
+	struct folio *folio = page_folio(page);
 	mss->pss += pss;
 
-	if (PageAnon(page))
+	if (folio_test_anon(folio))
 		mss->pss_anon += pss;
-	else if (PageSwapBacked(page))
+	else if (folio_test_swapbacked(folio))
 		mss->pss_shmem += pss;
 	else
 		mss->pss_file += pss;
@@ -426,7 +427,7 @@ static void smaps_page_accumulate(struct mem_size_stats *mss,
 	if (locked)
 		mss->pss_locked += pss;
 
-	if (dirty || PageDirty(page)) {
+	if (dirty || folio_test_dirty(folio)) {
 		mss->pss_dirty += pss;
 		if (private)
 			mss->private_dirty += size;
-- 
2.43.0



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

* [PATCH 3/4] proc: Pass a folio to smaps_page_accumulate()
  2024-04-03 17:14 [PATCH 0/4] Use folio APIs in procfs Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 1/4] proc: Convert gather_stats to use a folio Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 2/4] proc: Convert smaps_page_accumulate " Matthew Wilcox (Oracle)
@ 2024-04-03 17:14 ` Matthew Wilcox (Oracle)
  2024-04-03 17:14 ` [PATCH 4/4] proc: Convert smaps_pmd_entry to use a folio Matthew Wilcox (Oracle)
  2024-04-03 19:16 ` [PATCH 0/4] Use folio APIs in procfs Andrew Morton
  4 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-03 17:14 UTC (permalink / raw)
  To: Andrew Morton, Christian Brauner
  Cc: Matthew Wilcox (Oracle), linux-kernel, linux-fsdevel, linux-mm

Both callers already have a folio; pass it in instead of doing the
conversion each time.

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

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 2a3133dd47b1..6d4f60bc8824 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -411,10 +411,9 @@ struct mem_size_stats {
 };
 
 static void smaps_page_accumulate(struct mem_size_stats *mss,
-		struct page *page, unsigned long size, unsigned long pss,
+		struct folio *folio, unsigned long size, unsigned long pss,
 		bool dirty, bool locked, bool private)
 {
-	struct folio *folio = page_folio(page);
 	mss->pss += pss;
 
 	if (folio_test_anon(folio))
@@ -484,8 +483,8 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
 	 * as mapcount == 1.
 	 */
 	if ((folio_ref_count(folio) == 1) || migration) {
-		smaps_page_accumulate(mss, page, size, size << PSS_SHIFT, dirty,
-			locked, true);
+		smaps_page_accumulate(mss, folio, size, size << PSS_SHIFT,
+				dirty, locked, true);
 		return;
 	}
 	for (i = 0; i < nr; i++, page++) {
@@ -493,8 +492,8 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
 		unsigned long pss = PAGE_SIZE << PSS_SHIFT;
 		if (mapcount >= 2)
 			pss /= mapcount;
-		smaps_page_accumulate(mss, page, PAGE_SIZE, pss, dirty, locked,
-				      mapcount < 2);
+		smaps_page_accumulate(mss, folio, PAGE_SIZE, pss,
+				dirty, locked, mapcount < 2);
 	}
 }
 
-- 
2.43.0



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

* [PATCH 4/4] proc: Convert smaps_pmd_entry to use a folio
  2024-04-03 17:14 [PATCH 0/4] Use folio APIs in procfs Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2024-04-03 17:14 ` [PATCH 3/4] proc: Pass a folio to smaps_page_accumulate() Matthew Wilcox (Oracle)
@ 2024-04-03 17:14 ` Matthew Wilcox (Oracle)
  2024-04-03 19:16 ` [PATCH 0/4] Use folio APIs in procfs Andrew Morton
  4 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-04-03 17:14 UTC (permalink / raw)
  To: Andrew Morton, Christian Brauner
  Cc: Matthew Wilcox (Oracle), linux-kernel, linux-fsdevel, linux-mm

Replace two calls to compound_head() with one.

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

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 6d4f60bc8824..8ff79bd427ec 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -578,6 +578,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	struct vm_area_struct *vma = walk->vma;
 	bool locked = !!(vma->vm_flags & VM_LOCKED);
 	struct page *page = NULL;
+	struct folio *folio;
 	bool migration = false;
 
 	if (pmd_present(*pmd)) {
@@ -592,11 +593,12 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	}
 	if (IS_ERR_OR_NULL(page))
 		return;
-	if (PageAnon(page))
+	folio = page_folio(page);
+	if (folio_test_anon(folio))
 		mss->anonymous_thp += HPAGE_PMD_SIZE;
-	else if (PageSwapBacked(page))
+	else if (folio_test_swapbacked(folio))
 		mss->shmem_thp += HPAGE_PMD_SIZE;
-	else if (is_zone_device_page(page))
+	else if (folio_is_zone_device(folio))
 		/* pass */;
 	else
 		mss->file_thp += HPAGE_PMD_SIZE;
-- 
2.43.0



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

* Re: [PATCH 0/4] Use folio APIs in procfs
  2024-04-03 17:14 [PATCH 0/4] Use folio APIs in procfs Matthew Wilcox (Oracle)
                   ` (3 preceding siblings ...)
  2024-04-03 17:14 ` [PATCH 4/4] proc: Convert smaps_pmd_entry to use a folio Matthew Wilcox (Oracle)
@ 2024-04-03 19:16 ` Andrew Morton
  2024-04-05 11:02   ` Christian Brauner
  4 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2024-04-03 19:16 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: Christian Brauner, linux-kernel, linux-fsdevel, linux-mm

On Wed,  3 Apr 2024 18:14:51 +0100 "Matthew Wilcox (Oracle)" <willy@infradead.org> wrote:

> Not sure whether Andrew or Christian will want to take this set of
> fixes.

This set has dependencies upon your series "Remove page_idle and
page_young wrappers" and I normally do procfs, so I'll grab.


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

* Re: [PATCH 0/4] Use folio APIs in procfs
  2024-04-03 19:16 ` [PATCH 0/4] Use folio APIs in procfs Andrew Morton
@ 2024-04-05 11:02   ` Christian Brauner
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2024-04-05 11:02 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Matthew Wilcox (Oracle), linux-kernel, linux-fsdevel, linux-mm

On Wed, Apr 03, 2024 at 12:16:50PM -0700, Andrew Morton wrote:
> On Wed,  3 Apr 2024 18:14:51 +0100 "Matthew Wilcox (Oracle)" <willy@infradead.org> wrote:
> 
> > Not sure whether Andrew or Christian will want to take this set of
> > fixes.
> 
> This set has dependencies upon your series "Remove page_idle and

Fine by me in this case.


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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 17:14 [PATCH 0/4] Use folio APIs in procfs Matthew Wilcox (Oracle)
2024-04-03 17:14 ` [PATCH 1/4] proc: Convert gather_stats to use a folio Matthew Wilcox (Oracle)
2024-04-03 17:14 ` [PATCH 2/4] proc: Convert smaps_page_accumulate " Matthew Wilcox (Oracle)
2024-04-03 17:14 ` [PATCH 3/4] proc: Pass a folio to smaps_page_accumulate() Matthew Wilcox (Oracle)
2024-04-03 17:14 ` [PATCH 4/4] proc: Convert smaps_pmd_entry to use a folio Matthew Wilcox (Oracle)
2024-04-03 19:16 ` [PATCH 0/4] Use folio APIs in procfs Andrew Morton
2024-04-05 11:02   ` Christian Brauner

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