From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D36A495531 for ; Tue, 14 Jul 2026 15:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784042184; cv=none; b=oPT1MhjVq3uxZAOb1HnJylaBRxMnMDet4TbVu4RFm1erzUV2tt0qmsA4hE8MCE+2rcKxA+SpC7wj0C9bMKcewvAz4MwVcsvjcl7XQWafHVvkLaKD+fjmyTTR2odJyO/aZ3aBz2QvOobm2uL1CzLrOuOx/fBUnzsVRyFh1zLDWbg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784042184; c=relaxed/simple; bh=b+EJlyZCjRd+zn9R4Sh1X4jRP+azN9ASK6QXE0fMCOg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EKCVQhWkCc962xZdAqDXWnrT9h4lVeduQAgDOH07mRlkpjE7AcwPCrAg29PPdHTeCrMRIXjAPTHgl90DUJ3LSeuOtDi5tNVXk404Jvo6Vw1AJvnpASP9D6pEUbJoUN5E30DzhtK+6lo6dcJMlYTFe8J2YCcqKfl3vKo1nuYKqyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KPPAUCP4; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KPPAUCP4" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-37e0a189b0bso997621a91.1 for ; Tue, 14 Jul 2026 08:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784042182; x=1784646982; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=fwuFYnIFntaeyFiFTCtuOmdD45sxN5bbxj7Gff2yTa4=; b=KPPAUCP4LIdjO5XJ0zjy2zAJBq10fBFDDwlJY9GTpiAxYnLIYddoRSL3J3DqiV2P6y +ku+Y5iejEVZh74yQXu/qXHGwYG5tW7DUPanHDeomUKhLvdQ9xVYaRVbrSddbLJOI0ad Qa3CN2PzZmtaETC8zO5yZkKtPICmsqoVsAjJTpPBDiVw91s3T/y1PMupM2jzbtWqABLc vuMkMEHNPjyjGBPp96D51ljj1HiXb5xNpmWEkTe5pRWRrWkxeNs3m/dCydtAoDLnHP6C yMrnw4pGDOFin2LSg/EILdO6tpkQIxtwxT8Aq/YMZplq4BBxszdXGzHEbNOqUuiMfQt6 xyWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784042182; x=1784646982; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fwuFYnIFntaeyFiFTCtuOmdD45sxN5bbxj7Gff2yTa4=; b=AlXM1srm4bGTsx3/toqt9jlMvHrgUrLxldqYli7jcEtb8uHlJ2Zk5W8y2e0HhhrH6A v5g4079VpeacSXsnv9Ht/Id8GLOnmJweRlnVqjJaRZj3JAzDizx7Av51VOezaOmmqLW4 I2/WA21jquiiXYbLxdRkWjQChNSOIzpshx0JvFWo+yRG3Z1g/OmIn7i1SGNNjTA3RPZR ddjQO4J1RfabMsAoP/7Am3oS1JMmquEkbjPWOoVz7zmzAx2Hk8wpJQrn90XpOuN39t/V QAofQLwruDYjg4cuFrOXZp4WFjPf+ntjvIkwNHaFeaDbZqqau7bKwZLeEpxmGhPLnMGq HYGw== X-Forwarded-Encrypted: i=1; AHgh+Rp8pyGKVNO9HU3p+wRofP2yTn+jyUOuCFVqNzbmxrSdhiQQLD0WdwYRKaYipHdUYp+gFPcjUZqhAs4z@vger.kernel.org X-Gm-Message-State: AOJu0Yzy6oKjVEViExAh5byWdp/aAC1sDVMHwbVIwy4g5kPyc99SQ2l2 kWwUgVfFWmIU2hjFoGC2dZWpTwbEcPIf5Iuu0t468sBr6qk3hCla65iH X-Gm-Gg: AfdE7cnps1PfphLZ61tbhlXtMaxyf1y01QnJ9Ol7mrUz8AybpUqcR/LtOufjLJAphaI gnFnUM+SFgw/w+m+LucKe3LA/p6PYw3UgClHYnvs1JrYaPL/CqeqvKVGMa6fmxGjFCFsDZ/2K/v 14q1+LHKqHe63ba8hj9vZK9ppBgaEabL0iLpJWvLoijMKv6H3QzFZ3BDmY+NI1SFlRQsSoTVKLA K+OXDMpxKtT/m7OoOZ4nYh3jjkH57Yo0be+C896II4UPguyVfLBbRZ1qQfmZh4D9eQUgBU+3zRK fYiucTUo9cZjVmN5NMoaaEmxs329dqA6e7hd0aMxIxOy9jLg1wbXoKYUZuiB4rGn8TnVN+fOIfB WuO9+bLJyYLe/JYtoY1+qFzk6BKIhDJiaVHJAIHGzp9DEiC1MgKDsCrQGJKhkxebroaaauLOMJJ 9gDExFWRkgNAyxsfOGUAMM3SBRnzAtXum8V9JSoXOuUT/C X-Received: by 2002:a17:90b:2e8f:b0:380:8b14:d8e1 with SMTP id 98e67ed59e1d1-38dc7b3f8ccmr13234040a91.24.1784042181685; Tue, 14 Jul 2026 08:16:21 -0700 (PDT) Received: from fedora ([2601:644:937c:6c90:6d4e:7b2d:4a39:fb0c]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-313b4b97661sm49794403eec.7.2026.07.14.08.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 08:16:20 -0700 (PDT) Date: Tue, 14 Jul 2026 08:16:16 -0700 From: Vishal Moola To: Kevin Brodsky Cc: linux-mm@kvack.org, Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Pasha Tatashin , Russell King , Catalin Marinas , Will Deacon , Ryan Roberts , linux-arm-kernel@lists.infradead.org, Huacai Chen , loongarch@lists.linux.dev, "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Gerald Schaefer , linux-s390@vger.kernel.org, "David S. Miller" , Andreas Larsson , sparclinux@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Ning Sun , x86@kernel.org, tboot-devel@lists.sourceforge.net, Ard Biesheuvel , Ilias Apalodimas , linux-efi@vger.kernel.org, Alistair Popple , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [PATCH 14/22] mm: set page table page type when allocated Message-ID: References: <20260714-remove_pgtable_cdtor-v1-0-44be8a7685d7@arm.com> <20260714-remove_pgtable_cdtor-v1-14-44be8a7685d7@arm.com> Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260714-remove_pgtable_cdtor-v1-14-44be8a7685d7@arm.com> On Tue, Jul 14, 2026 at 03:04:03PM +0100, Kevin Brodsky wrote: > As a step towards removing pagetable ctor/dtor calls for kernel > mm's, move the page type updates from the ctor/dtor to > pagetable_{alloc,free}. Thanks for doing this patchset. We should switch over from __folio_set_pgtable() to __SetPagePgtable() in this patch. Ptdescs and folios should be treated as distinctly independent of each other. Eventually, we want to replace the memcg accounting as well, but there's no existing API for that right now. Lets leave that as is for now; this patchset is big enough already ;) > __pagetable_ctor() is now empty so remove it; > pagetable_{pud,p4d,pgd}_ctor() will be removed at a later stage. > > The ctor is normally called after pagetable_alloc() (and dtor before > pagetable_free()) so this patch should have no functional effect in > most cases. Where calls to ctor/dtor are currently missing (e.g. > x86's split_large_page()), this patch will ensure the page type is > set correctly. > > This patch is based on Matthew's earlier implementation linked > below, with the difference that when freeing the page type is > cleared in __pagetable_free(), meaning that the update is delayed > until the pages are actually freed in the > CONFIG_ASYNC_KERNEL_PGTABLE_FREE case. This shouldn't matter in > practice. > > Suggested-by: "Matthew Wilcox (Oracle)" > Link: https://lore.kernel.org/r/20251113140448.1814860-4-willy@infradead.org > Signed-off-by: Kevin Brodsky > --- > include/linux/mm.h | 17 ++--------------- > 1 file changed, 2 insertions(+), 15 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 361a0d7b74c5..94f0fb1c662a 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -3684,6 +3684,7 @@ static inline struct ptdesc *pagetable_alloc_noprof(gfp_t gfp, unsigned int orde > if (!page) > return NULL; > > + __folio_set_pgtable(page_folio(page)); > lruvec_stat_add_folio(page_folio(page), NR_PAGETABLE); > > return page_ptdesc(page); > @@ -3694,6 +3695,7 @@ static inline void __pagetable_free(struct ptdesc *pt) > { > struct page *page = ptdesc_page(pt); > > + __folio_clear_pgtable(page_folio(page)); > lruvec_stat_sub_folio(page_folio(page), NR_PAGETABLE); > > __free_pages(page, compound_order(page)); > @@ -3799,19 +3801,9 @@ static inline bool ptlock_init(struct ptdesc *ptdesc) { return true; } > static inline void ptlock_free(struct ptdesc *ptdesc) {} > #endif /* defined(CONFIG_SPLIT_PTE_PTLOCKS) */ > > -static inline void __pagetable_ctor(struct ptdesc *ptdesc) > -{ > - struct folio *folio = ptdesc_folio(ptdesc); > - > - __folio_set_pgtable(folio); > -} > - > static inline void pagetable_dtor(struct ptdesc *ptdesc) > { > - struct folio *folio = ptdesc_folio(ptdesc); > - > ptlock_free(ptdesc); > - __folio_clear_pgtable(folio); > } > > static inline void pagetable_dtor_free(struct ptdesc *ptdesc) > @@ -3825,7 +3817,6 @@ static inline bool pagetable_pte_ctor(struct mm_struct *mm, > { > if (!mm_is_kernel(mm) && !ptlock_init(ptdesc)) > return false; > - __pagetable_ctor(ptdesc); > return true; > } > > @@ -3917,7 +3908,6 @@ static inline bool pagetable_pmd_ctor(struct mm_struct *mm, > if (!mm_is_kernel(mm) && !pmd_ptlock_init(ptdesc)) > return false; > ptdesc_pmd_pts_init(ptdesc); > - __pagetable_ctor(ptdesc); > return true; > } > > @@ -3942,17 +3932,14 @@ static inline spinlock_t *pud_lock(struct mm_struct *mm, pud_t *pud) > > static inline void pagetable_pud_ctor(struct ptdesc *ptdesc) > { > - __pagetable_ctor(ptdesc); > } > > static inline void pagetable_p4d_ctor(struct ptdesc *ptdesc) > { > - __pagetable_ctor(ptdesc); > } > > static inline void pagetable_pgd_ctor(struct ptdesc *ptdesc) > { > - __pagetable_ctor(ptdesc); > } > > extern void __init pagecache_init(void); > > -- > 2.51.2 >