Skip to contentSkip to conversation

mm/debug: PageAnon() is true for PageKsm() pages

PATCH In review Ralph Campbell 3 participants 4 messages Nov 13, 2019 – Nov 15, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/debug: PageAnon() is true for PageKsm() pages

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.

---
 mm/debug.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/debug.c +3 -3
index 772d4cf0691f..0461df1207cb 100644
@@ -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;
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · 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.

Thanks for spotting this

Fixes 1c6fb1d89e73 ("mm: print more information about mapping in __dump_page")
Quoted 1 line
Quoted 24 lines
---
 mm/debug.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/debug.c +3 -3
index 772d4cf0691f..0461df1207cb 100644
@@ -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;
Signature · 1 line
2.20.1
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 8 lines · On 2019-11-14 at 21:59 Michal Hocko wrote:
Quoted 6 lines · 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.

Quoted 8 lines

Thanks for spotting this

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

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

#3 lore raw
Quoted 17 lines · On 2019-11-15 at 10:32 lixinhai.lxh wrote:
Quoted 8 lines · On 2019-11-14 at 21:59 Michal Hocko wrote:
Quoted 6 lines · 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.

Quoted 8 lines

Thanks for spotting this

Fixes 1c6fb1d89e73 ("mm: print more information about mapping in __dump_page")
Quoted 1 line
Quoted 7 lines

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