Skip to contentSkip to conversation

mm: avoid endless recursion in dump_page()

PATCH Applied Kirill A. Shutemov 3 participants 4 messages Sep 8, 2016 – Sep 22, 2016

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

PATCH 1/1 mm: avoid endless recursion in dump_page()

dump_page() uses page_mapcount() to get mapcount of the page. page_mapcount() has VM_BUG_ON_PAGE(PageSlab(page)) as mapcount doesn't make sense for slab pages and the field in struct page used for other information.

It leads to recursion if dump_page() called for slub page and DEBUG_VM is enabled:

dump_page() -> page_mapcount() -> VM_BUG_ON_PAGE() -> dump_page -> ...

Let's avoid calling page_mapcount() for slab pages in dump_page().

---
 mm/debug.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/debug.c +4 -2
index 8865bfb41b0b..74c7cae4f683 100644
@@ -42,9 +42,11 @@ const struct trace_print_flags vmaflag_names[] = {
 
 void __dump_page(struct page *page, const char *reason)
 {
+	int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
+
 	pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx",
-		  page, page_ref_count(page), page_mapcount(page),
-		  page->mapping, page->index);
+		  page, page_ref_count(page), mapcount,
+		  page->mapping, page_to_pgoff(page));
 	if (PageCompound(page))
 		pr_cont(" compound_mapcount: %d", compound_mapcount(page));
 	pr_cont("\n");
Signature · 7 lines
2.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 11 lines · Kirill A. Shutemov

dump_page() uses page_mapcount() to get mapcount of the page. page_mapcount() has VM_BUG_ON_PAGE(PageSlab(page)) as mapcount doesn't make sense for slab pages and the field in struct page used for other information.

It leads to recursion if dump_page() called for slub page and DEBUG_VM is enabled:

dump_page() -> page_mapcount() -> VM_BUG_ON_PAGE() -> dump_page -> ...

Let's avoid calling page_mapcount() for slab pages in dump_page().

How about instead splitting page_mapcount() so that there is a version without VM_BUG_ON_PAGE()?

mm/debug.c const struct trace_print_flags vmaflag_names[] = { · line 44

Quoted 13 lines
---
 mm/debug.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/debug.c +0 -0
index 8865bfb41b0b..74c7cae4f683 100644
@@ -42,9 +42,11 @@ const struct trace_print_flags vmaflag_names[] = {
 
 void __dump_page(struct page *page, const char *reason)
 {

At least there should be a comment explaining why.

mm/debug.c const struct trace_print_flags vmaflag_names[] = { · line 52

Quoted 11 lines
mm/debug.c +4 -2
+	int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
+
 	pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx",
-		  page, page_ref_count(page), page_mapcount(page),
-		  page->mapping, page->index);
+		  page, page_ref_count(page), mapcount,
+		  page->mapping, page_to_pgoff(page));
 	if (PageCompound(page))
 		pr_cont(" compound_mapcount: %d", compound_mapcount(page));
 	pr_cont("\n");

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 9 lines · Vlastimil Babka
Quoted 8 lines · Kirill A. Shutemov

dump_page() uses page_mapcount() to get mapcount of the page. page_mapcount() has VM_BUG_ON_PAGE(PageSlab(page)) as mapcount doesn't make sense for slab pages and the field in struct page used for other information.

It leads to recursion if dump_page() called for slub page and DEBUG_VM is enabled:

Quoted 6 lines
Quoted 3 lines

dump_page() -> page_mapcount() -> VM_BUG_ON_PAGE() -> dump_page -> ...

Let's avoid calling page_mapcount() for slab pages in dump_page().

How about instead splitting page_mapcount() so that there is a version without VM_BUG_ON_PAGE()?

Why? page->_mapping is garbage for slab page and might be confusing.

If you want the information from page->_mapping union for slab page to be shown during dump_page() we should present in proper way.

Quoted 12 lines
Quoted 12 lines

---
mm/debug.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
mm/debug.c +0 -0
index 8865bfb41b0b..74c7cae4f683 100644
@@ -42,9 +42,11 @@ const struct trace_print_flags vmaflag_names[] = {
 
Quoted 4 lines

mm/debug.c const struct trace_print_flags vmaflag_names[] = { · line 44

Quoted 2 lines
mm/debug.c +0 -0
 void __dump_page(struct page *page, const char *reason)
 {

At least there should be a comment explaining why.

Fair enough.

Quoted 1 line
Quoted 1 line
mm/debug.c +1 -0
+	int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
#3 lore raw
Quoted 14 lines · Kirill A. Shutemov
Quoted 13 lines · Vlastimil Babka
Quoted 11 lines · Kirill A. Shutemov

dump_page() uses page_mapcount() to get mapcount of the page. page_mapcount() has VM_BUG_ON_PAGE(PageSlab(page)) as mapcount doesn't make sense for slab pages and the field in struct page used for other information.

It leads to recursion if dump_page() called for slub page and DEBUG_VM is enabled:

dump_page() -> page_mapcount() -> VM_BUG_ON_PAGE() -> dump_page -> ...

Let's avoid calling page_mapcount() for slab pages in dump_page().

Quoted 7 lines
Quoted 2 lines

How about instead splitting page_mapcount() so that there is a version without VM_BUG_ON_PAGE()?

Why? page->_mapping is garbage for slab page and might be confusing.

If you want the information from page->_mapping union for slab page to be shown during dump_page() we should present in proper way.

Hmm, fair enough.

Quoted 9 lines
Quoted 2 lines

mm/debug.c const struct trace_print_flags vmaflag_names[] = { · line 45

Quoted 2 lines
mm/debug.c +1 -0
+	int mapcount = PageSlab(page) ? 0 : page_mapcount(page);

From d550530cc40ca2e9d60c84a893901c2dad6e7767 Mon Sep 17 00:00:00 2001
From: "Kirill A. Shutemov" <[email protected]>
Date: Thu, 22 Sep 2016 13:52:40 +0300
Subject: [PATCH] mm: clarify why we avoid page_mapcount() for slab pages in
dump_page()

Quoted 3 lines

Let's add comment on why we skip page_mapcount() for sl[aou]b pages.

Thanks.

Quoted 11 lines
---
 mm/debug.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/debug.c +0 -0
index 74c7cae4f683..9feb699c5d25 100644
@@ -42,6 +42,11 @@ const struct trace_print_flags vmaflag_names[] = {
 

mm/debug.c const struct trace_print_flags vmaflag_names[] = { · line 52

Quoted 10 lines
mm/debug.c +5 -0
 void __dump_page(struct page *page, const char *reason)
 {
+	/*
+	 * Avoid VM_BUG_ON() in page_mapcount().
+	 * page->_mapcount space in struct page is used by sl[aou]b pages to
+	 * encode own info.
+	 */
 	int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
 
 	pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx",

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>