On 1/29/20 2:59 PM, Matthew Wilcox wrote:
...
I have a hunk in my current tree which looks like this:
@@ -77,6 +77,11 @@ 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 (PageTail(page)) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct page *head = compound_head(page);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pr_warn("head:%px mapping:%px index:%#lx\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ head, head->mapping, page_to_pgoff(head));
+ÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ if (PageKsm(page))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pr_warn("ksm flags: %#lx(%pGp)\n", page->flags, &page->flags);
ÂÂÂÂÂÂÂÂ else if (PageAnon(page))
I wonder if we can combine these two patches in some more useful way?
I also think we probably want a sanity check that 'head' and 'page'
are within a sane range of each other (ie head < page and head +
MAX_ORDER_NR_PAGES > page) to protect against a struct page that contains
complete garbage.
OK, here's a go at combining those. I like the observation, implicit in your
diffs, that PageTail rather than PageCompound is the key differentiator in
deciding what to print. How's this look:
diff --git a/mm/debug.c b/mm/debug.c
index a90da5337c14..944652843e7b 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -75,12 +75,31 @@ void __dump_page(struct page *page, const char *reason)
ÂÂÂÂÂ */
ÂÂÂÂ mapcount = PageSlab(page) ? 0 : page_mapcount(page);
-ÂÂÂ if (PageCompound(page))
-ÂÂÂÂÂÂÂ pr_warn("page:%px refcount:%d mapcount:%d mapping:%px "
-ÂÂÂÂÂÂÂÂÂÂÂ "index:%#lx compound_mapcount: %d\n",
-ÂÂÂÂÂÂÂÂÂÂÂ page, page_ref_count(page), mapcount,
-ÂÂÂÂÂÂÂÂÂÂÂ page->mapping, page_to_pgoff(page),
-ÂÂÂÂÂÂÂÂÂÂÂ compound_mapcount(page));
+ÂÂÂ if (PageTail(page)) {
+ÂÂÂÂÂÂÂ struct page *head = compound_head(page);
+
+ÂÂÂÂÂÂÂ if ((page < head) || (page >= head + MAX_ORDER_NR_PAGES)) {
+ÂÂÂÂÂÂÂÂÂÂÂ /*
+ÂÂÂÂÂÂÂÂÂÂÂÂ * Page is hopelessly corrupted, so limit any reporting
+ÂÂÂÂÂÂÂÂÂÂÂÂ * to information about the page itself. Do not attempt
+ÂÂÂÂÂÂÂÂÂÂÂÂ * to look at the head page.
+ÂÂÂÂÂÂÂÂÂÂÂÂ */
+ÂÂÂÂÂÂÂÂÂÂÂ pr_warn("page:%px refcount:%d mapcount:%d mapping:%px "
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "index:%#lx (corrupted tail page case)\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ page, page_ref_count(page), mapcount,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ page->mapping, page_to_pgoff(page));
+ÂÂÂÂÂÂÂ } else {
+ÂÂÂÂÂÂÂÂÂÂÂ pr_warn("page:%px compound refcount:%d mapcount:%d "
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "mapping:%px index:%#lx compound_mapcount:%d\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ page, page_ref_count(head),
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mapcount, head->mapping, page_to_pgoff(head),
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ compound_mapcount(page));
+
+ÂÂÂÂÂÂÂÂÂÂÂ if (page_ref_count(page) != 0)
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pr_warn("page:%px PROBLEM: non-zero refcount (==%d) on "
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "this tail page\n", page, page_ref_count(page));