linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/debug: PageAnon() is true for PageKsm() pages
@ 2019-11-13  0:06 Ralph Campbell
  2019-11-14 13:59 ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Ralph Campbell @ 2019-11-13  0:06 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Ralph Campbell

PageAnon() and PageKsm() use the low two bits of the page->mapping pointer
to indicate the page type. PageAnon() only checks the LSB while PageKsm()
checks the least significant 2 bits are equal to 3. Therefore, PageAnon()
is true for KSM pages.
__dump_page() incorrectly will never print "ksm" because it checks
PageAnon() first. Fix this by checking PageKsm() first.

Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
---
 mm/debug.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/debug.c b/mm/debug.c
index 772d4cf0691f..0461df1207cb 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -77,10 +77,10 @@ void __dump_page(struct page *page, const char *reason)
 		pr_warn("page:%px refcount:%d mapcount:%d mapping:%px index:%#lx\n",
 			page, page_ref_count(page), mapcount,
 			page->mapping, page_to_pgoff(page));
-	if (PageAnon(page))
-		pr_warn("anon flags: %#lx(%pGp)\n", page->flags, &page->flags);
-	else if (PageKsm(page))
+	if (PageKsm(page))
 		pr_warn("ksm flags: %#lx(%pGp)\n", page->flags, &page->flags);
+	else if (PageAnon(page))
+		pr_warn("anon flags: %#lx(%pGp)\n", page->flags, &page->flags);
 	else if (mapping) {
 		if (mapping->host && mapping->host->i_dentry.first) {
 			struct dentry *dentry;
-- 
2.20.1


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

* Re: [PATCH] mm/debug: PageAnon() is true for PageKsm() pages
  2019-11-13  0:06 [PATCH] mm/debug: PageAnon() is true for PageKsm() pages Ralph Campbell
@ 2019-11-14 13:59 ` Michal Hocko
  2019-11-15  2:32   ` lixinhai.lxh
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2019-11-14 13:59 UTC (permalink / raw)
  To: Ralph Campbell; +Cc: Andrew Morton, linux-mm, linux-kernel

On Tue 12-11-19 16:06:51, Ralph Campbell wrote:
> PageAnon() and PageKsm() use the low two bits of the page->mapping pointer
> to indicate the page type. PageAnon() only checks the LSB while PageKsm()
> checks the least significant 2 bits are equal to 3. Therefore, PageAnon()
> is true for KSM pages.
> __dump_page() incorrectly will never print "ksm" because it checks
> PageAnon() first. Fix this by checking PageKsm() first.

Thanks for spotting this

Fixes: 1c6fb1d89e73 ("mm: print more information about mapping in __dump_page")

> Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/debug.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/debug.c b/mm/debug.c
> index 772d4cf0691f..0461df1207cb 100644
> --- a/mm/debug.c
> +++ b/mm/debug.c
> @@ -77,10 +77,10 @@ void __dump_page(struct page *page, const char *reason)
>  		pr_warn("page:%px refcount:%d mapcount:%d mapping:%px index:%#lx\n",
>  			page, page_ref_count(page), mapcount,
>  			page->mapping, page_to_pgoff(page));
> -	if (PageAnon(page))
> -		pr_warn("anon flags: %#lx(%pGp)\n", page->flags, &page->flags);
> -	else if (PageKsm(page))
> +	if (PageKsm(page))
>  		pr_warn("ksm flags: %#lx(%pGp)\n", page->flags, &page->flags);
> +	else if (PageAnon(page))
> +		pr_warn("anon flags: %#lx(%pGp)\n", page->flags, &page->flags);
>  	else if (mapping) {
>  		if (mapping->host && mapping->host->i_dentry.first) {
>  			struct dentry *dentry;
> -- 
> 2.20.1

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm/debug: PageAnon() is true for PageKsm() pages
  2019-11-14 13:59 ` Michal Hocko
@ 2019-11-15  2:32   ` lixinhai.lxh
  2019-11-15  5:47     ` lixinhai.lxh
  0 siblings, 1 reply; 4+ messages in thread
From: lixinhai.lxh @ 2019-11-15  2:32 UTC (permalink / raw)
  To: Michal Hocko, Ralph Campbell; +Cc: akpm, linux-mm, linux-kernel

On 2019-11-14 at 21:59 Michal Hocko wrote:
>On Tue 12-11-19 16:06:51, Ralph Campbell wrote:
>> PageAnon() and PageKsm() use the low two bits of the page->mapping pointer
>> to indicate the page type. PageAnon() only checks the LSB while PageKsm()
>> checks the least significant 2 bits are equal to 3. Therefore, PageAnon()
>> is true for KSM pages.
>> __dump_page() incorrectly will never print "ksm" because it checks
>> PageAnon() first. Fix this by checking PageKsm() first.
>
>Thanks for spotting this
>
>Fixes: 1c6fb1d89e73 ("mm: print more information about mapping in __dump_page")
>
>> Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
>
>Acked-by: Michal Hocko <mhocko@suse.com>
>
The four values from those two lowest bits have different meaning, so PageKsm is 
true does not mean we can consider PageAnon is also true or PageMovable is also 
true.
Improve PageAnon() would be better, so users of those APIs do not need to 
remember this implict checking sequence at other places.

- Xinhai

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

* Re: [PATCH] mm/debug: PageAnon() is true for PageKsm() pages
  2019-11-15  2:32   ` lixinhai.lxh
@ 2019-11-15  5:47     ` lixinhai.lxh
  0 siblings, 0 replies; 4+ messages in thread
From: lixinhai.lxh @ 2019-11-15  5:47 UTC (permalink / raw)
  To: Michal Hocko, Ralph Campbell; +Cc: akpm, linux-mm, linux-kernel

On 2019-11-15 at 10:32 lixinhai.lxh wrote:
>On 2019-11-14 at 21:59 Michal Hocko wrote:
>>On Tue 12-11-19 16:06:51, Ralph Campbell wrote:
>>> PageAnon() and PageKsm() use the low two bits of the page->mapping pointer
>>> to indicate the page type. PageAnon() only checks the LSB while PageKsm()
>>> checks the least significant 2 bits are equal to 3. Therefore, PageAnon()
>>> is true for KSM pages.
>>> __dump_page() incorrectly will never print "ksm" because it checks
>>> PageAnon() first. Fix this by checking PageKsm() first.
>>
>>Thanks for spotting this
>>
>>Fixes: 1c6fb1d89e73 ("mm: print more information about mapping in __dump_page")
>>
>>> Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
>>
>>Acked-by: Michal Hocko <mhocko@suse.com>
>>
>The four values from those two lowest bits have different meaning, so PageKsm is
>true does not mean we can consider PageAnon is also true or PageMovable is also
>true.
>Improve PageAnon() would be better, so users of those APIs do not need to
>remember this implict checking sequence at other places.
>
>- Xinhai 

Looked the reference to PageAnon() again, there are many use of PageAnon() to 
cover cases for both Anon without KSM and Anon with KSM. Change PageAnon() 
implementation require change those places, so keep this patch for current issue is 
enough.

- Xinhai


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

end of thread, other threads:[~2019-11-15  5:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13  0:06 [PATCH] mm/debug: PageAnon() is true for PageKsm() pages Ralph Campbell
2019-11-14 13:59 ` Michal Hocko
2019-11-15  2:32   ` lixinhai.lxh
2019-11-15  5:47     ` lixinhai.lxh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).