From patchwork Fri May 28 17:54:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12287339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 518A6C4708C for ; Fri, 28 May 2021 17:54:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC89F613B5 for ; Fri, 28 May 2021 17:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC89F613B5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 679576B006E; Fri, 28 May 2021 13:54:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 627FD6B0070; Fri, 28 May 2021 13:54:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47C646B0071; Fri, 28 May 2021 13:54:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 018056B006E for ; Fri, 28 May 2021 13:54:08 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6C06E181AEF32 for ; Fri, 28 May 2021 17:54:08 +0000 (UTC) X-FDA: 78191388576.24.5FAC1E6 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf26.hostedemail.com (Postfix) with ESMTP id B59AA41449E3 for ; Fri, 28 May 2021 17:54:03 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id d78so3800391pfd.10 for ; Fri, 28 May 2021 10:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zX9y6MPWlnZXxy5C+bxFxm0M+cmWizjNoRY22aXGCvk=; b=HkpKu7AQ2h4w1EQzRjpuCfIGbTM+bM0karGp5YXM2ZDRYo1qSytAK5pVq9JXW+VFEX ZCc69ulBB/LCzEN+kKFWKxZDfnhOSgEpKjpGlBm5+enzTw2jybXWx7UdzQK26tBrQmvj w2DY2JlwpFJFnRo8qR4P8r+VhPf9OfnPuAZ5FcKSbIzL1qj8jkUd2LzNgQSmZOOHAyEK vLSUeKfcbru+95hgCvy0q4+91VH/N3Lp0wYopC5wL7gwP0UjgwfXCkiAAZSxDqWlQddD C0SQspC2CyQUTocwy7iFuctpCnGxKdmDfMDMDNIdSfoZ1wRpIu7L/mLDMG+Nl1l24aSY Py6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zX9y6MPWlnZXxy5C+bxFxm0M+cmWizjNoRY22aXGCvk=; b=UMgw7ovDhUJ1fIYzpaKZpEGce3hnZWrAMf71q46WQiW3cYlYCpZJETyaFO9Y1jwY1l gh8O0syi00M7OqH+GV0axvSvc4V9chBVnoGWhKGmetVnSpMnaQCedXm20wl8rFUYkjfN /kLvcerbM9rfbY/5M/OeDLUgRxpRi1FAKRG5Z3snMyvbsQuwfzL9OYPlqMvObmSWdkYa uv88lUN0II3FMLUPGHfa1ERWok21URvgrkZOevUag6Jqx5uVhoqoTOgKVWjIaAWMuFQ6 v1mDtyPxgAfhtrwUhsaUguepSSGctYW0VYDLpo+EHeMHC6M7pdj0LFC2cWQLBZaZ82Tk rnkw== X-Gm-Message-State: AOAM531YXrENIqyluWZv660zvegUrlNkYl457SRtauiMDOmqxqrvsXZG 7lFlSOxHWhgCc84kdZFanoc= X-Google-Smtp-Source: ABdhPJxiLD9sWTINf7n0WvcZmjynRqPs6QaJpvfx4v8xxn68piKFViC8EijmF2+R0U/HPuQt8/b2wA== X-Received: by 2002:a65:4d4e:: with SMTP id j14mr36424pgt.343.1622224446965; Fri, 28 May 2021 10:54:06 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id a129sm585079pfa.118.2021.05.28.10.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 10:54:05 -0700 (PDT) From: Yang Shi To: hughd@google.com, willy@infradead.org, jhubbard@nvidia.com, kirill.shutemov@linux.intel.com, vbabka@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm: dump_page: print total mapcount for compound page Date: Fri, 28 May 2021 10:54:03 -0700 Message-Id: <20210528175403.4506-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: B59AA41449E3 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=HkpKu7AQ; spf=pass (imf26.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam04 X-Stat-Signature: mimp18aqbgho4otctccmihb9xkgycygr X-HE-Tag: 1622224443-228891 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The total mapcount is a useful information for debugging, but we can't call total_mapcount() directly since it calls some assertions which may be triggered as commit 6dc5ea16c86f ("mm, dump_page: do not crash with bad compound_mapcount()") met. We could implement yet another implementation for dump_page() but it has the limitation when individual mapcount of subpages is corrupted. Actually the total mapcount could be decoded from refcount, pincount and compound mapcount although it may be not very precise due to some transient references. Signed-off-by: Yang Shi --- I think we are on the same page that the total mapcount is useful information and it would be ideal to print this information when dumpping page if possible. But how to implement it safely seems controversial. Some ideas and potential problems have been discussed by https://lore.kernel.org/linux-mm/alpine.LSU.2.11.2105261733110.16920@eggly.anvils/. So I prepared this patch to show a possible approach to get some feedback. The same thing could be decoded by the reader of page dump as well by using the same formula used by this patch. However it sounds more convenient to have kernel do the math. mm/debug.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index e73fe0a8ec3d..129efcfcaf79 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -54,8 +54,13 @@ static void __dump_page(struct page *page) * inaccuracy here due to racing. */ bool page_cma = is_migrate_cma_page(page); - int mapcount; + int mapcount, total_mapcount; + int nr; + int refcount; + int pincount = 0; + int comp_mapcnt; char *type = ""; + bool is_slab = PageSlab(head); if (page < head || (page >= head + MAX_ORDER_NR_PAGES)) { /* @@ -82,22 +87,40 @@ static void __dump_page(struct page *page) * page->_mapcount space in struct page is used by sl[aou]b pages to * encode own info. */ - mapcount = PageSlab(head) ? 0 : page_mapcount(page); + mapcount = is_slab ? 0 : page_mapcount(page); + + refcount = page_ref_count(head); pr_warn("page:%p refcount:%d mapcount:%d mapping:%p index:%#lx pfn:%#lx\n", - page, page_ref_count(head), mapcount, mapping, + page, refcount, mapcount, mapping, page_to_pgoff(page), page_to_pfn(page)); if (compound) { + comp_mapcnt = head_compound_mapcount(head); if (hpage_pincount_available(page)) { + pincount = head_compound_pincount(head); pr_warn("head:%p order:%u compound_mapcount:%d compound_pincount:%d\n", head, compound_order(head), - head_compound_mapcount(head), - head_compound_pincount(head)); + comp_mapcnt, pincount); } else { pr_warn("head:%p order:%u compound_mapcount:%d\n", head, compound_order(head), - head_compound_mapcount(head)); + comp_mapcnt); + } + + nr = compound_nr(head); + if (is_slab) + total_mapcount = 0; + else if (PageHuge(head)) + total_mapcount = comp_mapcnt; + else { + if (mapping) { + if (!PageAnon(head)) + nr = nr * (comp_mapcnt + 1) - comp_mapcnt; + } else + nr = 0; + total_mapcount = refcount - pincount - nr; } + pr_warn("total_mapcount(estimated):%d\n", total_mapcount); } #ifdef CONFIG_MEMCG