Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages
@ 2026-06-26  1:32 Jinjiang Tu
  2026-06-26  2:09 ` xu.xin16
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jinjiang Tu @ 2026-06-26  1:32 UTC (permalink / raw)
  To: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
	xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
  Cc: wangkefeng.wang, sunnanyong, tujinjiang

Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even
when KSM is not in use. As a result, tools misclassify all anonymous pages
as KSM merged.

In stable_page_flags(), if the page is anonymous, then use (mapping &
FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page.
However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM,
(mapping & FOLIO_MAPPING_KSM) check returns true for all nonymous pages.

To fix it, use FOLIO_MAPPING_ANON_KSM instead.

Fixes: dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
Changelog in v2:
 * use FOLIO_MAPPING_KSM to match explictly instead of use FOLIO_MAPPING_ANON_KSM
only.

 fs/proc/page.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/page.c b/fs/proc/page.c
index f9b2c2c906cd..7d9387143435 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -173,7 +173,7 @@ u64 stable_page_flags(const struct page *page)
 		u |= 1 << KPF_MMAP;
 	if (is_anon) {
 		u |= 1 << KPF_ANON;
-		if (mapping & FOLIO_MAPPING_KSM)
+		if ((mapping & FOLIO_MAPPING_FLAGS) == FOLIO_MAPPING_KSM)
 			u |= 1 << KPF_KSM;
 	}
 
-- 
2.43.0



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

* Re: [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages
  2026-06-26  1:32 [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages Jinjiang Tu
@ 2026-06-26  2:09 ` xu.xin16
  2026-06-26  6:28   ` Jinjiang Tu
  2026-06-26  8:13 ` David Hildenbrand (Arm)
  2026-06-26 14:08 ` Zi Yan
  2 siblings, 1 reply; 6+ messages in thread
From: xu.xin16 @ 2026-06-26  2:09 UTC (permalink / raw)
  To: tujinjiang
  Cc: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
	chengming.zhou, linux-fsdevel, linux-mm, wangkefeng.wang,
	sunnanyong, tujinjiang

> Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even
> when KSM is not in use. As a result, tools misclassify all anonymous pages
> as KSM merged.
> 
> In stable_page_flags(), if the page is anonymous, then use (mapping &
> FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page.
> However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM,
> (mapping & FOLIO_MAPPING_KSM) check returns true for all nonymous pages.

"returns true for all nonymous pages."

should %s/nonymous/anonymous ?

> 
> To fix it, use FOLIO_MAPPING_ANON_KSM instead.
> 
> Fixes: dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
> ---
> Changelog in v2:
>  * use FOLIO_MAPPING_KSM to match explictly instead of use FOLIO_MAPPING_ANON_KSM
> only.
> 
>  fs/proc/page.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/proc/page.c b/fs/proc/page.c
> index f9b2c2c906cd..7d9387143435 100644
> --- a/fs/proc/page.c
> +++ b/fs/proc/page.c
> @@ -173,7 +173,7 @@ u64 stable_page_flags(const struct page *page)
>          u |= 1 << KPF_MMAP;
>      if (is_anon) {
>          u |= 1 << KPF_ANON;
> -        if (mapping & FOLIO_MAPPING_KSM)
> +        if ((mapping & FOLIO_MAPPING_FLAGS) == FOLIO_MAPPING_KSM)
>              u |= 1 << KPF_KSM;
>      }
>  
> -- 
> 2.43.0


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

* Re: [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages
  2026-06-26  2:09 ` xu.xin16
@ 2026-06-26  6:28   ` Jinjiang Tu
  0 siblings, 0 replies; 6+ messages in thread
From: Jinjiang Tu @ 2026-06-26  6:28 UTC (permalink / raw)
  To: xu.xin16
  Cc: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
	chengming.zhou, linux-fsdevel, linux-mm, wangkefeng.wang,
	sunnanyong


在 2026/6/26 10:09, xu.xin16@zte.com.cn 写道:
>> Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even
>> when KSM is not in use. As a result, tools misclassify all anonymous pages
>> as KSM merged.
>>
>> In stable_page_flags(), if the page is anonymous, then use (mapping &
>> FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page.
>> However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM,
>> (mapping & FOLIO_MAPPING_KSM) check returns true for all nonymous pages.
> "returns true for all nonymous pages."
>
> should %s/nonymous/anonymous ?

Ah, yes

>
>> To fix it, use FOLIO_MAPPING_ANON_KSM instead.
>>
>> Fixes: dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
>> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
>> ---
>> Changelog in v2:
>>   * use FOLIO_MAPPING_KSM to match explictly instead of use FOLIO_MAPPING_ANON_KSM
>> only.
>>
>>   fs/proc/page.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/proc/page.c b/fs/proc/page.c
>> index f9b2c2c906cd..7d9387143435 100644
>> --- a/fs/proc/page.c
>> +++ b/fs/proc/page.c
>> @@ -173,7 +173,7 @@ u64 stable_page_flags(const struct page *page)
>>           u |= 1 << KPF_MMAP;
>>       if (is_anon) {
>>           u |= 1 << KPF_ANON;
>> -        if (mapping & FOLIO_MAPPING_KSM)
>> +        if ((mapping & FOLIO_MAPPING_FLAGS) == FOLIO_MAPPING_KSM)
>>               u |= 1 << KPF_KSM;
>>       }
>>   
>> -- 
>> 2.43.0


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

* Re: [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages
  2026-06-26  1:32 [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages Jinjiang Tu
  2026-06-26  2:09 ` xu.xin16
@ 2026-06-26  8:13 ` David Hildenbrand (Arm)
  2026-06-26  9:02   ` Jinjiang Tu
  2026-06-26 14:08 ` Zi Yan
  2 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-26  8:13 UTC (permalink / raw)
  To: Jinjiang Tu, akpm, ziy, luizcap, willy, linmiaohe, svetly.todorov,
	xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
  Cc: wangkefeng.wang, sunnanyong

On 6/26/26 03:32, Jinjiang Tu wrote:
> Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even
> when KSM is not in use. As a result, tools misclassify all anonymous pages
> as KSM merged.
> 
> In stable_page_flags(), if the page is anonymous, then use (mapping &
> FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page.
> However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM,
> (mapping & FOLIO_MAPPING_KSM) check returns true for all nonymous pages.
> 
> To fix it, use FOLIO_MAPPING_ANON_KSM instead.
> 
> Fixes: dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
> ---

With spelling fix

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

And I'd appreciate if someone could look into cleaning up the code to switch
back to folio helpers now that we have folio+page snapshots.

-- 
Cheers,

David


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

* Re: [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages
  2026-06-26  8:13 ` David Hildenbrand (Arm)
@ 2026-06-26  9:02   ` Jinjiang Tu
  0 siblings, 0 replies; 6+ messages in thread
From: Jinjiang Tu @ 2026-06-26  9:02 UTC (permalink / raw)
  To: David Hildenbrand (Arm), akpm, ziy, luizcap, willy, linmiaohe,
	svetly.todorov, xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
  Cc: wangkefeng.wang, sunnanyong


在 2026/6/26 16:13, David Hildenbrand (Arm) 写道:
> On 6/26/26 03:32, Jinjiang Tu wrote:
>> Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even
>> when KSM is not in use. As a result, tools misclassify all anonymous pages
>> as KSM merged.
>>
>> In stable_page_flags(), if the page is anonymous, then use (mapping &
>> FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page.
>> However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM,
>> (mapping & FOLIO_MAPPING_KSM) check returns true for all nonymous pages.
>>
>> To fix it, use FOLIO_MAPPING_ANON_KSM instead.
>>
>> Fixes: dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
>> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
>> ---
> With spelling fix
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>

Thanks.

> And I'd appreciate if someone could look into cleaning up the code to switch
> back to folio helpers now that we have folio+page snapshots.

I would like to do it.

>


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

* Re: [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages
  2026-06-26  1:32 [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages Jinjiang Tu
  2026-06-26  2:09 ` xu.xin16
  2026-06-26  8:13 ` David Hildenbrand (Arm)
@ 2026-06-26 14:08 ` Zi Yan
  2 siblings, 0 replies; 6+ messages in thread
From: Zi Yan @ 2026-06-26 14:08 UTC (permalink / raw)
  To: Jinjiang Tu, akpm, david, luizcap, willy, linmiaohe,
	svetly.todorov, xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
  Cc: wangkefeng.wang, sunnanyong

On Thu Jun 25, 2026 at 9:32 PM EDT, Jinjiang Tu wrote:
> Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even
> when KSM is not in use. As a result, tools misclassify all anonymous pages
> as KSM merged.
>
> In stable_page_flags(), if the page is anonymous, then use (mapping &
> FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page.
> However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM,
> (mapping & FOLIO_MAPPING_KSM) check returns true for all nonymous pages.
>
> To fix it, use FOLIO_MAPPING_ANON_KSM instead.
>
> Fixes: dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
> ---
> Changelog in v2:
>  * use FOLIO_MAPPING_KSM to match explictly instead of use FOLIO_MAPPING_ANON_KSM
> only.
>
>  fs/proc/page.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

LGTM. Thanks.

Acked-by: Zi Yan <ziy@nvidia.com>

-- 
Best Regards,
Yan, Zi



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

end of thread, other threads:[~2026-06-26 14:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26  1:32 [PATCH v2] fs/proc: fix KPF_KSM reported for all anonymous pages Jinjiang Tu
2026-06-26  2:09 ` xu.xin16
2026-06-26  6:28   ` Jinjiang Tu
2026-06-26  8:13 ` David Hildenbrand (Arm)
2026-06-26  9:02   ` Jinjiang Tu
2026-06-26 14:08 ` Zi Yan

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