From patchwork Mon Dec 23 09:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13918644 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 224D0E7718B for ; Mon, 23 Dec 2024 09:43:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8CE16B0096; Mon, 23 Dec 2024 04:43:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3BFC6B0098; Mon, 23 Dec 2024 04:43:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B69C6B0099; Mon, 23 Dec 2024 04:43:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6A5FE6B0096 for ; Mon, 23 Dec 2024 04:43:57 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 252AE46586 for ; Mon, 23 Dec 2024 09:43:57 +0000 (UTC) X-FDA: 82925736180.26.A1CF135 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf21.hostedemail.com (Postfix) with ESMTP id DB8241C000D for ; Mon, 23 Dec 2024 09:42:42 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KJHfofVk; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734947006; 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=t6vBY23hDAeU19z0pXyQ9vuAeZavJyfGUN8npoqwlxU=; b=r7lTdCgVXCKsD+X7046fjFwB8eaIffnfaYCxnuN+UqkfzZ7QqOHMilveYkASHUNiEIXMuw rReCvlHbHMzKZewT0tLk7Mj2l/J/VZbOEkYU+nxILP7Q91uiArBsRU/OdFA6yK/2rRp3mN 0ghWNobq9UnCmf7Favvu3KcAcjV/b50= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KJHfofVk; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734947006; a=rsa-sha256; cv=none; b=lUc56VX/eUU8O2sBp2+FuILPn9BfVhE9X1cAEW9SYTi4MRcGtjAXfx3dPLaJhBg0VqgMNr RZEAC92S8FXbzD2DHR7Hp7vleaFvZ+qKnQ7ff8I1e1wUycvBkZ25mhNJhA42yKmlNirwpJ pZa8MVQk/ofQiFfY2e4voPFQ/+dVZy8= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-7242f559a9fso4801211b3a.1 for ; Mon, 23 Dec 2024 01:43:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734947034; x=1735551834; 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=t6vBY23hDAeU19z0pXyQ9vuAeZavJyfGUN8npoqwlxU=; b=KJHfofVkbxghUIAL7pfF0EHoTGLTsMGOp3xTwrkaTFwa35ODDlzNUhtUpVjNkVjxCV URCxayvBaQRtdKD59gWPmP1ZiClIe3/DwPd0nhhYHVjhymnueI8PUtvkk55HZuPAPEWU clEWIpQ11CdZv6GhCa9Scn9SN9KWvX438i+vBDhVV/3uYX5QZxqM+bb4zPrd8RirM01U C9piBDkxfPdUadalA1pVFAjfySKQTSl2zImcXy7NMqXBZQBkeIZLENg1j7FI0vTjnv+l c8RoJ0zRj36e7w3kDRvlu6heqSf957N8o+Px+8Y1haZGz667bgGaO8ebuIPWi4KTgpaV 6p9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734947034; x=1735551834; 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=t6vBY23hDAeU19z0pXyQ9vuAeZavJyfGUN8npoqwlxU=; b=W9EzlTxuJgH5VB/ZERn4oWn85MdZXQBApLzFt+WSNcShv6flNU5QrnJ64hvAQt4gJd LP9MwhxJiHlpUjjUFZabCEoUvrWTSgg+gGXlJFhoRVWiKqIcD528BGqH0YXf18Vlm3wg HNgVMoskLsL9IRNoudHGRYgwoTHJeHSchs52dWqqBg4d7Qc1o9yf9QzJa/PmrHdNeFM5 05ms8046YMtTIHGxxrW6DcjG8byrdpnia6KRYhzkv4LQ8gMvW9kXQkDSFzXf96j1f6UQ Wcmv2/CRLho8+4y12ReDxngnO8oLfUx8NRipx6i7DJx9WoauLh9BHo5KowaCiz+vnufl mCbg== X-Gm-Message-State: AOJu0Ywm+P2Y2lGfE1c5QBH+zKwq9F2xNspRDvtRYN/Y4LC1p0BZQPdk iTS5HiHZbu87EMy80afJ1ujlSmTH2ANFMAYlNVFYWtOMaAomHYMxQ2ycr5GdbYE= X-Gm-Gg: ASbGncvOeohtg8oWteKg4CtsbdXVPsyQpLIqBdlu2aN/z16Y+qrYKDE4u7RdFlCJJOF oss7fNvIWN8btffSvzxtybBE+GQA1TlKPB+rabx/l8cCFbpTkCfdNufj6qGJehPMey+P/l/p1EN 2gFdjuAUv6vbXEi0ClDbX3GiVDEq2B3VhLpDUbxCphGw3qODAPp+bnyifzLuKJLfdX4qLGf2NNI C7cvGJXFq1Yd+qGGCBkCU3lwnoGoFeExEDBAH7x0DyVzC8IlggzJTBrvX/qcW0UN91yZhDNc46i 02gGkngYqhlShDYfX7ON+Q== X-Google-Smtp-Source: AGHT+IGO0+mWINscMdGqF/L7XDe6Dv/dfGXrIYILRYMXJn04aY3ZCG1rf5V2YGuLlSic6wG5VWjqsA== X-Received: by 2002:a05:6a00:4090:b0:72a:a7a4:b4cd with SMTP id d2e1a72fcca58-72abdeb85b1mr18289604b3a.21.1734947034102; Mon, 23 Dec 2024 01:43:54 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8486c6sm7468309b3a.85.2024.12.23.01.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:43:53 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.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 v3 04/17] mm: pgtable: add statistics for P4D level page table Date: Mon, 23 Dec 2024 17:40:50 +0800 Message-Id: <2fa644e37ab917292f5c342e40fa805aa91afbbd.1734945104.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: DB8241C000D X-Rspamd-Server: rspam12 X-Stat-Signature: 8g47u6ghty5wgrxiq7xd9tkj6ta6iknq X-Rspam-User: X-HE-Tag: 1734946962-140771 X-HE-Meta: U2FsdGVkX19AW+lw0DmyxBZj4iNwCsSxUDkvos3Pijt0E0gi/pckUtjv0y7z75eAPw0oBex9JzRLVFsvAT+yceypjgJl/j75hM0byiIjcXsEpz3vofs8zjdUJXYmAmeD7Swx0mbaXxOgcBW9pFv1jDpSqnbzii5Fy43VeHGD0smmQjOK2yMrjiqlGWIm/yeD5VgzDI4jTvy02XNwsQfV0rVigNghIjm6393mepG6f5S36le3jQy0eKCBk7wsi27H6HKc5izvE0uOnVW4SM8aturO2Yk6NAbrHYoQST/dNXP7cClZhtNeJjnKF8679gZJShsTG8XAwRPyHRlB2JgUPlIHZnM8rfVGGcAg9nBTtaLQKdleOw2fDUj/HkeFipNCp+l8fvFW4caKta6ZiDqyquN0n2ecdwzTVmnALIVRPJRDyMmvxSaS2fZqP+06rjkwXWIYhxqS5BgY6vrrA44UrtOsIqZWtQMvQE43YSgtR81FhvuH0VpeKkKA5dFmLH++z3v+Op6sbntpW81XbrjVwRrk2HTSGmZXIWHOMpBAR9nJ1WRk9uH4wGNoG//0bD++DHWEeZvcq1ZCNlbSeaMdDSJ/wFJlkMuwy8vRzAvEjKwuFJDlWJqDgUiC9J6dH85i8LhHCIFb7yybFEE0cEQfrwYiwzbi7mZdpCtfxSTdD/affTc4XQStEHNDmgGku8rjg9wVJzFVdiN0/NGAmceNCf5hHppv9aoiFmY3aHEeuNwCRpAuIcOvnuOgP6fn+P+cwDYf7D2OeEuVwiJ1wx32t1ZNpJ/o76xysY4thnvIj3U65ICaQJLE8D4II6b+NtWq3FbBrJQkNHXhFoNxBrlQ8XrUc/G5z2Fqz9zOvfHRebJ1u3Y1FL1y1oQx3P4V/FRTsaac9ESToKkmCmEB+VvQaz4LBKeZxD4PUTELO9ORShNerchhC5506w1J4oTFp7XvF11edSGe3u3ewBr7v+u r/o6eErS DFFK0560JiMfjSN13P/1NLaib0PHwJWy9BBamKtmCTiqCBA9mtzJN4n8kJUKenp1ZO+ezWUWLO2UEps9IraXONbUQEWPHB4XiafBTcloKV+7sWousbZ/o+i+KDkWZY2Jznoo8Zim7yFX8K6aplvpYqCSfacK7BfRj2iW2lHRg+dS7o5NWr7bacY1YuJUdI+4Y7Qp8oP8xuIqiaCv3TDwdRs79KmS+7quOcdKrRNIm0qB+Gx2awkEqQaXgm1WqRzjpY4h1Fi7FzTmILujiP8LS7y/kcl6rxq8utTAP0iXR1EGbNbdnxFv459S1OSzQ1q4xe16IvJKJW8cGX6qKTezx/4KAN47ndujp5vN/isiZvJtGpxWHchSTx6nFJpGsyHOiofFva8oKZ8U4LttNj6n8Be7Zmx7TupjRI6p2aH84tk2yeAkWY948b1Vsfn02RT/U+pEo 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) --- 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);