linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kpageflags: respect folio head-page flag placement
@ 2023-10-25 20:12 Gregory Price
  2023-10-26  1:34 ` Rik van Riel
  2023-10-26 20:00 ` Matthew Wilcox
  0 siblings, 2 replies; 4+ messages in thread
From: Gregory Price @ 2023-10-25 20:12 UTC (permalink / raw)
  To: linux-mm
  Cc: akpm, willy, david, vbabka, naoya.horiguchi, linux-kernel, Gregory Price

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

Update bitchecks to use PAGEFLAG() interfaces to check folio for the
referenced, dirty, lru, active, and unevictable bits.

Signed-off-by: Gregory Price <gregory.price@memverge.com>
---
 fs/proc/page.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/proc/page.c b/fs/proc/page.c
index 195b077c0fac..958fb2311108 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -188,20 +188,31 @@ u64 stable_page_flags(struct page *page)
 		u |= 1 << KPF_SLAB;
 
 	u |= kpf_copy_bit(k, KPF_ERROR,		PG_error);
-	u |= kpf_copy_bit(k, KPF_DIRTY,		PG_dirty);
+
+	if (PageDirty(page))
+		u |= 1 << KPF_DIRTY;
+
 	u |= kpf_copy_bit(k, KPF_UPTODATE,	PG_uptodate);
 	u |= kpf_copy_bit(k, KPF_WRITEBACK,	PG_writeback);
 
-	u |= kpf_copy_bit(k, KPF_LRU,		PG_lru);
-	u |= kpf_copy_bit(k, KPF_REFERENCED,	PG_referenced);
-	u |= kpf_copy_bit(k, KPF_ACTIVE,	PG_active);
+	if (PageLRU(page))
+		u |= 1 << KPF_LRU;
+
+	if (PageReferenced(page))
+		u |= 1 << KPF_REFERENCED;
+
+	if (PageActive(page))
+		u |= 1 << KPF_ACTIVE;
+
 	u |= kpf_copy_bit(k, KPF_RECLAIM,	PG_reclaim);
 
 	if (PageSwapCache(page))
 		u |= 1 << KPF_SWAPCACHE;
 	u |= kpf_copy_bit(k, KPF_SWAPBACKED,	PG_swapbacked);
 
-	u |= kpf_copy_bit(k, KPF_UNEVICTABLE,	PG_unevictable);
+	if (PageUnevictable(page))
+		u |= 1 << KPF_UNEVICTABLE;
+
 	u |= kpf_copy_bit(k, KPF_MLOCKED,	PG_mlocked);
 
 #ifdef CONFIG_MEMORY_FAILURE
-- 
2.39.1



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

* Re: [PATCH] kpageflags: respect folio head-page flag placement
  2023-10-25 20:12 [PATCH] kpageflags: respect folio head-page flag placement Gregory Price
@ 2023-10-26  1:34 ` Rik van Riel
  2023-10-26 19:12   ` Gregory Price
  2023-10-26 20:00 ` Matthew Wilcox
  1 sibling, 1 reply; 4+ messages in thread
From: Rik van Riel @ 2023-10-26  1:34 UTC (permalink / raw)
  To: Gregory Price, linux-mm
  Cc: akpm, willy, david, vbabka, naoya.horiguchi, linux-kernel, Gregory Price

On Wed, 2023-10-25 at 16:12 -0400, Gregory Price wrote:
> 
> +++ b/fs/proc/page.c
> @@ -188,20 +188,31 @@ u64 stable_page_flags(struct page *page)
>                 u |= 1 << KPF_SLAB;
>  
>         u |= kpf_copy_bit(k, KPF_ERROR,         PG_error);
> -       u |= kpf_copy_bit(k, KPF_DIRTY,         PG_dirty);
> +
> +       if (PageDirty(page))
> +               u |= 1 << KPF_DIRTY;
> +
>         u |= kpf_copy_bit(k, KPF_UPTODATE,      PG_uptodate);
>         u |= kpf_copy_bit(k, KPF_WRITEBACK,     PG_writeback);
>  
> -       u |= kpf_copy_bit(k, KPF_LRU,           PG_lru);
> -       u |= kpf_copy_bit(k, KPF_REFERENCED,    PG_referenced);
> -       u |= kpf_copy_bit(k, KPF_ACTIVE,        PG_active);
> +       if (PageLRU(page))
> +               u |= 1 << KPF_LRU;
> +
> +       if (PageReferenced(page))
> +               u |= 1 << KPF_REFERENCED;
> +
> +       if (PageActive(page))
> +               u |= 1 << KPF_ACTIVE;
> +
>         u |= kpf_copy_bit(k, KPF_RECLAIM,       PG_reclaim);
>  
>         if (PageSwapCache(page))
>                 u |= 1 << KPF_SWAPCACHE;
>         u |= kpf_copy_bit(k, KPF_SWAPBACKED,    PG_swapbacked);
> 

Aren't PG_locked, PG_reclaim, and PG_swapbacked also maintained only on
the folio/head?

Would it make sense to convert those over as well?

-- 
All Rights Reversed.

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

* Re: [PATCH] kpageflags: respect folio head-page flag placement
  2023-10-26  1:34 ` Rik van Riel
@ 2023-10-26 19:12   ` Gregory Price
  0 siblings, 0 replies; 4+ messages in thread
From: Gregory Price @ 2023-10-26 19:12 UTC (permalink / raw)
  To: Rik van Riel
  Cc: Gregory Price, linux-mm, akpm, willy, david, vbabka,
	naoya.horiguchi, linux-kernel

On Wed, Oct 25, 2023 at 09:34:15PM -0400, Rik van Riel wrote:
> On Wed, 2023-10-25 at 16:12 -0400, Gregory Price wrote:
> >         u |= kpf_copy_bit(k, KPF_SWAPBACKED,    PG_swapbacked);
> > 
> 
> Aren't PG_locked, PG_reclaim, and PG_swapbacked also maintained only on
> the folio/head?
> 
> Would it make sense to convert those over as well?
> 

I see them registered as PF_NO_TAIL in include/linux/page-flags.h

Certainly i think there are other updates that are likely needed, but
I wasn't quite sure how to handle ONLY_HEAD and NO_TAIL and other
conditionals.  Should the bits always be 0 or should it refer to HEAD?

Just not sure at the moment.

~Gregory


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

* Re: [PATCH] kpageflags: respect folio head-page flag placement
  2023-10-25 20:12 [PATCH] kpageflags: respect folio head-page flag placement Gregory Price
  2023-10-26  1:34 ` Rik van Riel
@ 2023-10-26 20:00 ` Matthew Wilcox
  1 sibling, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2023-10-26 20:00 UTC (permalink / raw)
  To: Gregory Price
  Cc: linux-mm, akpm, david, vbabka, naoya.horiguchi, linux-kernel,
	Gregory Price

On Wed, Oct 25, 2023 at 04:12:37PM -0400, Gregory Price wrote:
> +++ b/fs/proc/page.c
> @@ -188,20 +188,31 @@ u64 stable_page_flags(struct page *page)
>  		u |= 1 << KPF_SLAB;
>  
>  	u |= kpf_copy_bit(k, KPF_ERROR,		PG_error);
> -	u |= kpf_copy_bit(k, KPF_DIRTY,		PG_dirty);
> +
> +	if (PageDirty(page))
> +		u |= 1 << KPF_DIRTY;

This is not the way to do it.

At the beginning of the function, add:

	struct folio *folio = page_folio(page);

Then use folio_test_XXX istead of PageXXX().



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

end of thread, other threads:[~2023-10-26 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-25 20:12 [PATCH] kpageflags: respect folio head-page flag placement Gregory Price
2023-10-26  1:34 ` Rik van Riel
2023-10-26 19:12   ` Gregory Price
2023-10-26 20:00 ` Matthew Wilcox

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