Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp457246rdb; Mon, 18 Sep 2023 23:48:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhHDrxSS2dGB0NyUIBCRak14nXG7RhSIUbrDrpvwjkkqW1c3rhtPEc0hP1OrDtzs+cWYob X-Received: by 2002:a67:ce0d:0:b0:44d:626b:94da with SMTP id s13-20020a67ce0d000000b0044d626b94damr9969809vsl.32.1695106117547; Mon, 18 Sep 2023 23:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695106117; cv=none; d=google.com; s=arc-20160816; b=WtYKdStbzaFyluE+PJLIGrTXYt3WzQLtC1IZhROZID7kOyFd34KyFsM0w6HCvOAHmy URRia0Kv0964CxHkEiBguzIj4Qea2aM+PezzQnks7PL57xHkD2WPNF2j56FOnzQEfKuZ IAomMfI0mQuHqFBqo197Ktn2zcAzg6cGUL/mgL6W6WDPSSBHi6RTY4uyS/z0s3+dV3ql tMMAkNbsdhmnzwUHdZ3mnKB3CTsNo9nxQwB79hbjY766gbxKIIwcW8oDPIBmowNYH3ov BSUbyKJDtjJz5RMddO7Na8YuOBZEOLkXDZnM9OclFJaIZFTvqc3KIg3/UYTNxshiowps LjLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xqqBZyYojJCL2gtEa/wPUN8y3uBUQvJrGdJDWeWrwJI=; fh=G272A1Uim/dguboGlqgYZp0G6DRRXQaTFc9rGKGkqZo=; b=r1h0IAWAVcbByzituz9sxsARTcgIuFGzcEMCo3F+iAQkyO93rYD+IT7+CjYJmNYPjM gkdVOMWsbppEIg3GMKekFH4TYgCFcxIOjkurQaXnFX3WIRKOO/8kr0pWT5rbzdo4e+Mz jSr3/vqLw0cDeMHKDIvcjqGPEeZNwqwicmFjiAqexXeCjfon3GIf2AMFNRi8pDdemChk O+UBJC4Ld/qDYGJU9gzpeD94IQYAGnfnU0a5AlKugHUDPBp88ItR83nUwtrL3OyofcKW gF1MtE9CGbLoIuPg+nO6L3yzoQd/HiWveH/8YIFowMXvux8TLB/BfJkNDyDGD5XE+CIE FpBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g81Npwhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id l10-20020a654c4a000000b00564c67e66fbsi9205152pgr.842.2023.09.18.23.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 23:48:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g81Npwhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 046C6828E878; Mon, 18 Sep 2023 23:48:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231574AbjISGsi (ORCPT + 99 others); Tue, 19 Sep 2023 02:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjISGsh (ORCPT ); Tue, 19 Sep 2023 02:48:37 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0C79100; Mon, 18 Sep 2023 23:48:31 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45C45C433C8; Tue, 19 Sep 2023 06:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695106111; bh=v1PBG6Gu/3eqRITlKaenIy1Iaq3gKBzyqYlv0ai4zO8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g81NpwhjgWC5UNpbUGov4u227vlRjEbZixKM1tjaZpaM/VY6T9DXSa/NEFVhg41PN vnrRJL/9n7SjreVQLTCw1zfG/HO8EMMJtOSa/z1D/CFbU114nEbsr06aQ520n/3u1j g1ERXarMOaeSRRWVrRVjkj3QcghAZT2RhMDgEx8AQqjIbY6048kFxlHKikjCWSyuLM iuv2rfpWoG3+m+AHxfjjzMFu11ynzIQlPTHtjh2xfDgQPFPLFv48dM8n6h4j5U4CaH Pokk/9WjdSFC6CHoDZa/xnP+QGd+sc3B23/ldGMkARS2g+aCBL6v5tzoijY2vKM65J rxr74ifBr+LMw== Date: Tue, 19 Sep 2023 09:47:44 +0300 From: Mike Rapoport To: Baolin Wang Cc: akpm@linux-foundation.org, will@kernel.org, aneesh.kumar@linux.ibm.com, npiggin@gmail.com, peterz@infradead.org, catalin.marinas@arm.com, chenhuacai@kernel.org, tsbogend@alpha.franken.de, dave.hansen@linux.intel.com, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, arnd@arndb.de, willy@infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org Subject: Re: [PATCH] mm: add statistics for PUD level pagetable Message-ID: <20230919064744.GE3303@kernel.org> References: <876c71c03a7e69c17722a690e3225a4f7b172fb2.1695017383.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <876c71c03a7e69c17722a690e3225a4f7b172fb2.1695017383.git.baolin.wang@linux.alibaba.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 23:48:36 -0700 (PDT) On Mon, Sep 18, 2023 at 02:31:42PM +0800, Baolin Wang wrote: > Recently, we found that cross-die access to pagetable pages on ARM64 > machines can cause performance fluctuations in our business. Currently, > there are no PMU events available to track this situation on our ARM64 > machines, so an accurate pagetable accounting can help to analyze this > issue, but now the PUD level pagetable accounting is missed. > > So introducing pagetable_pud_ctor/dtor() to help to get an accurate > PUD pagetable accounting, as well as converting the architectures with > using generic PUD pagatable allocation to add corresponding PUD pagetable > accounting. Moreover this patch will also mark the PUD level pagetable > with PG_table flag, which will help to do sanity validation in unpoison_memory(). > > On my testing machine, I can see more pagetables statistics after the patch > with page-types tool: > > Before patch: > flags page-count MB symbolic-flags long-symbolic-flags > 0x0000000004000000 27326 106 __________________________g_________________ pgtable > After patch: > 0x0000000004000000 27541 107 __________________________g_________________ pgtable > > Signed-off-by: Baolin Wang Acked-by: Mike Rapoport (IBM) > --- > arch/arm64/include/asm/tlb.h | 5 ++++- > arch/loongarch/include/asm/pgalloc.h | 1 + > arch/mips/include/asm/pgalloc.h | 1 + > arch/x86/mm/pgtable.c | 3 +++ > include/asm-generic/pgalloc.h | 7 ++++++- > include/linux/mm.h | 16 ++++++++++++++++ > 6 files changed, 31 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h > index 2c29239d05c3..846c563689a8 100644 > --- a/arch/arm64/include/asm/tlb.h > +++ b/arch/arm64/include/asm/tlb.h > @@ -96,7 +96,10 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, > static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, > unsigned long addr) > { > - tlb_remove_ptdesc(tlb, virt_to_ptdesc(pudp)); > + struct ptdesc *ptdesc = virt_to_ptdesc(pudp); > + > + pagetable_pud_dtor(ptdesc); > + tlb_remove_ptdesc(tlb, ptdesc); > } > #endif > > diff --git a/arch/loongarch/include/asm/pgalloc.h b/arch/loongarch/include/asm/pgalloc.h > index 79470f0b4f1d..4e2d6b7ca2ee 100644 > --- a/arch/loongarch/include/asm/pgalloc.h > +++ b/arch/loongarch/include/asm/pgalloc.h > @@ -84,6 +84,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) > > if (!ptdesc) > return NULL; > + pagetable_pud_ctor(ptdesc); > pud = ptdesc_address(ptdesc); > > pud_init(pud); > diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h > index 40e40a7eb94a..f4440edcd8fe 100644 > --- a/arch/mips/include/asm/pgalloc.h > +++ b/arch/mips/include/asm/pgalloc.h > @@ -95,6 +95,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) > > if (!ptdesc) > return NULL; > + pagetable_pud_ctor(ptdesc); > pud = ptdesc_address(ptdesc); > > pud_init(pud); > diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c > index 9deadf517f14..0cbc1b8e8e3d 100644 > --- a/arch/x86/mm/pgtable.c > +++ b/arch/x86/mm/pgtable.c > @@ -76,6 +76,9 @@ void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd) > #if CONFIG_PGTABLE_LEVELS > 3 > void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud) > { > + struct ptdesc *ptdesc = virt_to_ptdesc(pud); > + > + pagetable_pud_dtor(ptdesc); > paravirt_release_pud(__pa(pud) >> PAGE_SHIFT); > paravirt_tlb_remove_table(tlb, virt_to_page(pud)); > } > diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h > index c75d4a753849..879e5f8aa5e9 100644 > --- a/include/asm-generic/pgalloc.h > +++ b/include/asm-generic/pgalloc.h > @@ -169,6 +169,8 @@ static inline pud_t *__pud_alloc_one(struct mm_struct *mm, unsigned long addr) > ptdesc = pagetable_alloc(gfp, 0); > if (!ptdesc) > return NULL; > + > + pagetable_pud_ctor(ptdesc); > return ptdesc_address(ptdesc); > } > > @@ -190,8 +192,11 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) > > static inline void __pud_free(struct mm_struct *mm, pud_t *pud) > { > + struct ptdesc *ptdesc = virt_to_ptdesc(pud); > + > BUG_ON((unsigned long)pud & (PAGE_SIZE-1)); > - pagetable_free(virt_to_ptdesc(pud)); > + pagetable_pud_dtor(ptdesc); > + pagetable_free(ptdesc); > } > > #ifndef __HAVE_ARCH_PUD_FREE > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 12335de50140..2232bfebb88a 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -3049,6 +3049,22 @@ static inline spinlock_t *pud_lock(struct mm_struct *mm, pud_t *pud) > return ptl; > } > > +static inline void pagetable_pud_ctor(struct ptdesc *ptdesc) > +{ > + struct folio *folio = ptdesc_folio(ptdesc); > + > + __folio_set_pgtable(folio); > + lruvec_stat_add_folio(folio, NR_PAGETABLE); > +} > + > +static inline void pagetable_pud_dtor(struct ptdesc *ptdesc) > +{ > + struct folio *folio = ptdesc_folio(ptdesc); > + > + __folio_clear_pgtable(folio); > + lruvec_stat_sub_folio(folio, NR_PAGETABLE); > +} > + > extern void __init pagecache_init(void); > extern void free_initmem(void); > > -- > 2.39.3 > > -- Sincerely yours, Mike.