From patchwork Wed Jan 8 06:57:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13930195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D98D5E77199 for ; Wed, 8 Jan 2025 07:00:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69A436B009B; Wed, 8 Jan 2025 02:00:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6495A6B009C; Wed, 8 Jan 2025 02:00:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5119F6B009D; Wed, 8 Jan 2025 02:00:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3462F6B009B for ; Wed, 8 Jan 2025 02:00:23 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D13731209DC for ; Wed, 8 Jan 2025 07:00:22 +0000 (UTC) X-FDA: 82983385884.29.4CB6830 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf12.hostedemail.com (Postfix) with ESMTP id EFBE84000D for ; Wed, 8 Jan 2025 07:00:20 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lWqD+JsM; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736319621; a=rsa-sha256; cv=none; b=6zDtM2Oi7orLUhxBquD2RPOhJDHmsBPkXmhu6giwi/Ao5X+Y8PjHPCPRPYOlaB3vlWLDmq 3eIGaL360MT0pKnxbxKlxpHCXcOSXpKdALRk3zkZSXOs8w9FgyFsyqL/6PT+CLXysykLxn IuzQsB+ti8y7/4/V83d5He0H6Q6hSCk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lWqD+JsM; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736319621; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/cYfjcYM2i48jLO7NuvQJ4j04U6+7fBnrQjgIuvbLyg=; b=IJOMDTv9JYrKLNqhS931em7SrrfMkU1KHaNABbbkLx/c4RqjIDs2FGMTG396GGUMxoIp7L 8QJLjHjeEC/tAqCRRTAwVvMPBO1Z5O/PhnDydvdWlfUPXtfvc8crJI0cxAgD6mnHwxNgVG Bx0KaUbpXJ3hLwWhFisFNR8W511ennQ= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-219f8263ae0so193715245ad.0 for ; Tue, 07 Jan 2025 23:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736319619; x=1736924419; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/cYfjcYM2i48jLO7NuvQJ4j04U6+7fBnrQjgIuvbLyg=; b=lWqD+JsMk1haG/2Qb7RnAGv/jNY2crK3Eud9isz5yR7U3GABuWJRkUZsGiXvOQkTbQ bw3bdDzzE92J15IVWg/yGxomPwKGNUuRWvF4Jc3EuqfIjoKhdQbiD/PSGQc6P9Qgn1/6 yp1X5tMuYL0xv2wfA560fuh72dFUyG+bzR1d78IH7cBnLviQTve5qhkG6JK4bFa23OGA KM9dcdF0YHaUIdrJAY6oHyeKMwm7XjbGNkvufgSEtlHc1SStitN8QjBFk7dggJKLERB0 cZ+2SgSOGiesfGW7LvjYuTY7G4Od2pl3gmgezF99g5AOXSBtRpWWz/EE9yvIpAENuHXK 0D8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736319619; x=1736924419; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/cYfjcYM2i48jLO7NuvQJ4j04U6+7fBnrQjgIuvbLyg=; b=r7yv1Ixl6IdqELSLAqF0MZ8KcYuTyvLoKSgWkx2V8JrYkfPypok5p2/I9Jvb7gKYh6 PmHOljlF55fbs/BYUsA6TOIzAFm/uzL0lmdWFirVf7Iwecoyxh8Ch7XUW2EIoGou1KfA gTZcpdgwhx3Byr8/3XGdEDAHIss4PblSV0a/tSbFd53MfNJXB2tLnGGQi7or2rFMKnfR 8oXivzulMfyPzBqJB8LOOamAnyZE8a3/AR7/suAI0k26iWmKWs3Z4mPPozBuQJaaPFFk ghnyaS6GPzFjrNBWEAqrcmdd0ah4xnmWeUDrA+ili6WeC0ltxVSYVx8m6iQy1OmV/gYk uz/A== X-Gm-Message-State: AOJu0YyyQlHY0A9naiC1P6Jp6J3NMPEDLZuD249QrNFKjOXskfIPD6TA kupCSPJXwxUMRGyZORJa5B7XP1Gh1oEMFMJc66YH+Vm1vVpEoCF6mkRDv5lzXgY= X-Gm-Gg: ASbGnct82kOI6l5pgcID7DwWiIOGieUuRMEu0RgCJ0assLrAtqaFgXgjZLO7+TqZy8z jiiOy7o74QFCKNGsCm9So4QAr8wRNBD8yM45EWHOySlflQoiwjFXl5pXInnTUnzokxDmmaUuuap pj/u9w0nlA0Jrb33tgLMM++PhtXfjGaqslwxamM6iFm9kzy/nYkpI7bkngNHT5QC9broGowTa8B dUMgnbO4SnROQsXTcopc5IRWvjblhR8tTrDwzaNGmdriqSDoHRCaKNyqCcoXtCy3qZSRn6pkYwb 2LwCldFkJj05BYmV8RgeQBJZ3Qg= X-Google-Smtp-Source: AGHT+IExFPt1bVFS1B+HfK/rni8xCakw0mpYmNpiHCGWtvviMVtfvk5MaDovSIdy5xSOdSeWSopXEQ== X-Received: by 2002:a17:903:2311:b0:210:fce4:11ec with SMTP id d9443c01a7336-21a83f42687mr30246255ad.1.1736319619595; Tue, 07 Jan 2025 23:00:19 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca023a3sm320067275ad.250.2025.01.07.23.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 23:00:19 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.com, alex@ghiti.fr, andreas@gaisler.com, palmer@dabbelt.com, tglx@linutronix.de, david@redhat.com, jannh@google.com, hughd@google.com, yuzhao@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, lorenzo.stoakes@oracle.com, akpm@linux-foundation.org, rientjes@google.com, vishal.moola@gmail.com, arnd@arndb.de, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, dave.hansen@linux.intel.com, rppt@kernel.org, ryan.roberts@arm.com Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-um@lists.infradead.org, Qi Zheng Subject: [PATCH v5 04/17] mm: pgtable: add statistics for P4D level page table Date: Wed, 8 Jan 2025 14:57:20 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EFBE84000D X-Stat-Signature: n7zj6gr7i1p57q1t7zbt67ncnz8g7u4n X-Rspam-User: X-HE-Tag: 1736319620-498370 X-HE-Meta: U2FsdGVkX1+KrlXWNtOQ9APli3sIEL/019ihrTIMje0iBu7irS2VI2Zr4BTpnvTPrSdKW0xjud3kv5LUq5kT5IMCv4gOvpj9JmUMaUmu7hXrbOytSnHKPLFNE2MkT+p9gbqDegFMV7iB/tDhM5A2Feh3xcLDF7FgeWAvS8vq6o/Pel74XbIFJC6plbqyek/jltndYl34PauSpwaSubDxI9iYhM2iteIln/GNCuvVtI/lHgqvPGn6b8b2sM8YU2VNVWyBPXLq4EGlMgbTxWDuEZ5OCruDaOwUd/aWszmlg9mqNYGxmHJUIps/XzNTL9uExdwaKKU+bzb7iJs0HoGRqS1pAD0raOglWEfH0w06z6q3DglRwe2yuwpvDg2GUZa1EZNZXo+TFG85bJktLbrIdkm5zzYxN9ZHKZQkGSoYHqI3JrRaV+zL3dYZprSsq1t9+HW1a4dj33iXbx0Jsxwa78kBlGsPoAJIlE08Y+nCN6BBOTg1n5YBCwLAxanvv9pNsZlzSRojX8lWEB795c7SmXUmF+6BRVTf2kH40tUsg5ZmkqFgxfYy9vSAqf9tPehcu2BfskKSfFtjhX6RfVihHYS4B1LFH6qD0+hnQs2lwej+u+6EiIf4+KZPscQfzfJQmeRZtbh1iVeQPHYQO1W0BgP9yu4+zSZGWZKFuck0mXXjNflO7gQdxNSxRxyjkvdSmNd8dcelZUEOc95jqReWAScsDllcNllscz9U7F8/h2Z5CqSYNXlziJZaNa4JhW6EiOXHM6lR1XBGcu52DOTdxwqLRo7fLPQVfByeJ+bryVtvzCF/MLEy8uYO72aJl0B+4GlEoULzilXeR7EExkbPI0+/ah2Ym8dZvou727pxch7BgXyFBkcafq0sOP5pZUFZVzlGJ3PgJtLUllgp+h1BTGlX7FqMp6PFvR3PgBQ1ihBbdOD+NhPUG2S+2SdtjWhCmjyeJpBoujf20DBoF7+ vdOqMN9U IH/8t+omVpzmHe8hUAAMQHsOtSBB4ltmi97i9cNH28VyY3kMRpn4b5vUQAi0pBFLQn6MbzsKhJCkYttxLpL3GtgAjjeufRCo1z4vQfstabhiVz8IItX8WS00LUS9vKwoQcL71AL7c732d2AOVd1cjXwdOK2dpKDtZrkM1KB1fxKjAUBB1LXt5hWwz/fHpgAdIJVPh0n3bhdOWA9MOhraEkrW37SMgEQc1qAYn2RBwjmRrYOApJTEOovEjQU8ACeGWwcMYnX0FOVL7na3JmPlZe6SjDQzw2QW4YAHI6AsdgAF0y1TNlQk7764Wa+gqUGdLna/kA6rcWXSEbIGSyGVtVWBfVVj+UFqrFyjr/wizgTSs9wDgDQoH6GOPE/TrEav9JGe6qALetWB2kvjtQe+e2qGAOj+P/8lKiStq09VLseTPD4IuWhjDtxKiOL9gRCtlEKi7PE5mAfhx7IrrWlx0iHHj9e+6nQ3XVRzXqrS56Mq+fd/ZCQm2GHRg1Q== 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: List-Subscribe: List-Unsubscribe: Like other levels of page tables, add statistics for P4D level page table. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky --- arch/riscv/include/asm/pgalloc.h | 6 +++++- arch/x86/mm/pgtable.c | 3 +++ include/asm-generic/pgalloc.h | 2 ++ include/linux/mm.h | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h index 551d614d3369c..3466fbe2e508d 100644 --- a/arch/riscv/include/asm/pgalloc.h +++ b/arch/riscv/include/asm/pgalloc.h @@ -108,8 +108,12 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d, unsigned long addr) { - if (pgtable_l5_enabled) + if (pgtable_l5_enabled) { + struct ptdesc *ptdesc = virt_to_ptdesc(p4d); + + pagetable_p4d_dtor(ptdesc); riscv_tlb_remove_ptdesc(tlb, virt_to_ptdesc(p4d)); + } } #endif /* __PAGETABLE_PMD_FOLDED */ diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 69a357b15974a..3d6e84da45b24 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -94,6 +94,9 @@ void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud) #if CONFIG_PGTABLE_LEVELS > 4 void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d) { + struct ptdesc *ptdesc = virt_to_ptdesc(p4d); + + pagetable_p4d_dtor(ptdesc); paravirt_release_p4d(__pa(p4d) >> PAGE_SHIFT); paravirt_tlb_remove_table(tlb, virt_to_page(p4d)); } diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h index 59131629ac9cc..bb482eeca0c3e 100644 --- a/include/asm-generic/pgalloc.h +++ b/include/asm-generic/pgalloc.h @@ -230,6 +230,7 @@ static inline p4d_t *__p4d_alloc_one_noprof(struct mm_struct *mm, unsigned long if (!ptdesc) return NULL; + pagetable_p4d_ctor(ptdesc); return ptdesc_address(ptdesc); } #define __p4d_alloc_one(...) alloc_hooks(__p4d_alloc_one_noprof(__VA_ARGS__)) @@ -247,6 +248,7 @@ static inline void __p4d_free(struct mm_struct *mm, p4d_t *p4d) struct ptdesc *ptdesc = virt_to_ptdesc(p4d); BUG_ON((unsigned long)p4d & (PAGE_SIZE-1)); + pagetable_p4d_dtor(ptdesc); pagetable_free(ptdesc); } diff --git a/include/linux/mm.h b/include/linux/mm.h index c49bc7b764535..5d82f42ddd5cc 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3175,6 +3175,22 @@ static inline void pagetable_pud_dtor(struct ptdesc *ptdesc) lruvec_stat_sub_folio(folio, NR_PAGETABLE); } +static inline void pagetable_p4d_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_p4d_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);