From mboxrd@z Thu Jan 1 00:00:00 1970 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 40AB7C2B9F7 for ; Fri, 28 May 2021 19:04:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D680D613EB for ; Fri, 28 May 2021 19:04:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D680D613EB 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 343E86B0070; Fri, 28 May 2021 15:04:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F34B6B0071; Fri, 28 May 2021 15:04:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BB1A6B0072; Fri, 28 May 2021 15:04:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id DBE1D6B0070 for ; Fri, 28 May 2021 15:04:06 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7187DC5CF for ; Fri, 28 May 2021 19:04:06 +0000 (UTC) X-FDA: 78191564892.03.B0B5105 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf08.hostedemail.com (Postfix) with ESMTP id 77305801A2C5 for ; Fri, 28 May 2021 19:03:57 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id l3so6876545ejc.4 for ; Fri, 28 May 2021 12:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d3H90fqd+5UIDXvwPduQkwVIcuzpQwHpH8WcJ/XTN58=; b=f9PPfhW0iQtgLGQ95NRFdhS6hXDLrp9kdp62Yc7Q4GjJWv8L6503aRkRgsiGsPbADY gUx3QeLFxcJoQhts6rQwFyKkiEiinwUOgb1oanNyKrVvg5Ds6xq+LDOujEXr/tIcipUw ME3PxxraN255yw6GAPgqZyA8XnHKqGqqBLOpR1+UIQWF9Kb/lPg1nibiKcb24qkWcV9h ONIuiwVAOqFzlaEswMGnBzdHlJLNHjRX4qYdd0ZfxUweeoGQOM3EDt+fdJTKp8RwR4Dy DKtPhM6jVCUJyLm8uOoX6GerJIgF2nO0Ui1ZD3b88pT8XztVnlFR5w12zgUStlLM8f4W PrMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d3H90fqd+5UIDXvwPduQkwVIcuzpQwHpH8WcJ/XTN58=; b=LZdvh4ocqiUJFqbVhNhRnr05YbXVjLsvWfNaI3nBWtU/MA27q//ODk3dg8YV1j3WPY SHwbNXeRsHPxmPwOjPMluriY7HbwmeMcBXf9KD71TvzY1Fo7P3atetMCo8mmS7napI2t qTkC/frNjPZonGYWu+lKy/J2s2zTIKw7GsXZhK3Fe8Uijv/Paj0xzLqeyxI71VMctZeR NY9BNbFT6TjmSP1uidDn5SgkeYENYQrPmnAYHaYry4K4R3J6f8Y07K/dJr/XxbOiNxI9 tDtGrjO3H7rAtY4QN4QnplNF04rMMp6GwMaOIDL9FCIYu7IOVC9cRe1LI85rup+hzose +iPw== X-Gm-Message-State: AOAM533Kd79lZUDuUDJiDB+b9KpIxpcnopjJTkbirwjsUHL5zeyXHTKJ bLlzJ6rNSvKCxe99NyY5hwPkiLZC1b/aWqIlsqU= X-Google-Smtp-Source: ABdhPJwV7Hfd6Mr8wlrF/s9IrFSINeflplJc5OMPKGg7aGzc+OU7DcQjJJ40kOLXRk72q9E+KbkNQPrtCVpCk+UIoFQ= X-Received: by 2002:a17:906:1699:: with SMTP id s25mr10275556ejd.238.1622228644942; Fri, 28 May 2021 12:04:04 -0700 (PDT) MIME-Version: 1.0 References: <20210528175403.4506-1-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Fri, 28 May 2021 12:03:53 -0700 Message-ID: Subject: Re: [RFC PATCH] mm: dump_page: print total mapcount for compound page To: John Hubbard Cc: Hugh Dickins , Matthew Wilcox , "Kirill A. Shutemov" , Vlastimil Babka , Andrew Morton , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 77305801A2C5 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=f9PPfhW0; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Stat-Signature: t3x7egcm9r9y4dtddnx6nyp178ece8ot X-HE-Tag: 1622228637-395430 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: On Fri, May 28, 2021 at 11:26 AM John Hubbard wrote: > > On 5/28/21 10:54 AM, Yang Shi wrote: > > 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. > > If the mapcount calculation were in a separate routine, *and* if something > else in addition to dump_page() used it, then I'd be interested in > calling it from dump_page(). There is. The total_mapcount() is used by mm code. But as I mentioned in the commit log and that discussion email, it is not safe to call it directly in dump_page() path. > > But, just adding a calculation glob like this is not a good idea. If > the reader really needs the calculation, then that person can, as you > say, work it out from the other information. > > Debug and dump routines are actually supposed to remain fairly simple, > so that they themselves do not end up with bugs, or stale assumptions > (which this calculation is very much susceptible to). This goes in the > wrong direction. > > So best to just not do this, IMHO. > > thanks, > -- > John Hubbard > NVIDIA > > > > > 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 > > >