Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp604277pxj; Fri, 28 May 2021 10:57:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwELllLpWUZTOSnZGJnW7JgbHRXeXBh5nhYQlIDiJ9AZsF4AugHjVGTCEyTHjRnpIQnypbR X-Received: by 2002:aa7:d455:: with SMTP id q21mr11050550edr.2.1622224631351; Fri, 28 May 2021 10:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622224631; cv=none; d=google.com; s=arc-20160816; b=CICdOcgvhnIJjyoqJVqD2cGxqssPJ7cbYwtZZqPX7Z2PAoDjxV4Kfy4p9YJR4AcZr/ a4xCUCbrjvhMMbBce247PE8R9nA82YYYMzeS7MdYlBsgmEHi5botgm0NtHCoBHJmU/kv 4t0BRSGZNMkpv9mykpPCfuV0Pepfz7pwRq2M+kTcAx1AFUbel5T7pxun2K+G48NPFEIe bowCM6qavZ3u4atVLy0VeZWpBNxKa1yzRf0Lwf2f7vZDYK3+cvHFj5hbMP9XP2O9uqXb Q2PYlNbyxiDbWJnxASM1uzAkOEcgg1ydNKXQz/c2hZ/foJT3oj4xDkO/o2jzYHOB453L u4WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zX9y6MPWlnZXxy5C+bxFxm0M+cmWizjNoRY22aXGCvk=; b=cc1WUSmC2qLAh6SEqQtdmSBUBYh3mKAMGqV+CcziG+PeMVfaXbkF9IWw389Wb/yXk4 7vUgyrC+xZGnUPOG3cJCHBDwvu3PDijXrVfvW6zSxoGcvnOcUw2GcT5SzSEYlNKta/QI dXN7quZXHjsMPzNjRMIXN3Kuzqe/4jje4y8Z0ubC33ooJd6C5qcBnnllIVA6l3aN00Ee JKZ9tU4fUB4g8nSRj2T+/bsXj0NgY03iQafyWBCGD8/iBbswKgA8o5fuZ1LFX6GA4g8D j7bKI5Qz15H5s4O7eapE0XXYucTr+0SXS2d5xUu1Xa+vIj4aEoApo4F5SLC1wlJ2pKP2 Pu4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HkpKu7AQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si5614565ejy.223.2021.05.28.10.56.43; Fri, 28 May 2021 10:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HkpKu7AQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbhE1Rzp (ORCPT + 99 others); Fri, 28 May 2021 13:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbhE1Rzm (ORCPT ); Fri, 28 May 2021 13:55:42 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86030C061574 for ; Fri, 28 May 2021 10:54:07 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id f22so3850932pfn.0 for ; Fri, 28 May 2021 10:54:07 -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=EYoxqfYXyJDxD9ZXdokAOOuIO+wbNyEr7mk40M6JvTX3TmtadrOV2sfp7NAMkwTS7S Pb/3JILWkrNWEjbd4fGePwm1hzlvUeM82w2rUzasmCdYkhFA6vWAZg/EEMLuVuFvkeX1 My9eQ7rp7KAFywLIXJdinwhTJ0OlZCONop5VG8+pkrUT/6oVVq09ALgk/GMf+tb2Xg0s 0Jz+sqbhKfvsKtj5/UglglkXp5KgHLTbS1uRcEtXUcPzxEsI0H9tr/C0SgXjAdqnmVcN jPedeAZJi4qepWLbCEIPpFX4MLM2RBx5oKim8x7h6kLUyrpWrEGRfKK3zvtbM16pz+dg JCAA== X-Gm-Message-State: AOAM5320jSKGEDUCLOSQcqjLtlrvRL1G4RYTR5hkL3qynrnL134xnPdW wx4961ClWqqTV10DHms+ojE= 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.26.2