Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1822114rdb; Sun, 4 Feb 2024 02:59:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgMbNed62f9oIqooUJ4p+ntXMqJF7NTYLrO8L5SW+qTUoBFRixr4S1I7AhFy8yr6KXIV+L X-Received: by 2002:a92:c56c:0:b0:363:a747:932d with SMTP id b12-20020a92c56c000000b00363a747932dmr9634733ilj.26.1707044353048; Sun, 04 Feb 2024 02:59:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707044353; cv=pass; d=google.com; s=arc-20160816; b=X6TzGwdEQPpiTYRAHInOQqeu2Z4bGJKsSEjCsPtbXqdE8iwb2+CPdkcMx23ymNg0OQ ikrH8mHhU2qSvp4NaBJsDJ1h5iNgys3y+nJGzKxcXttO8smmAWxs4I8g5dKhk/fvYinH cng8XaeOujyaHpix5tYWU5d/BCOAXFqXfdePPSOjXvTBDweyGvFfS9H460lgHEwWg7uT EMf5IQg/f/ppYVmyI8AhBWvmtxar5BH1+lG4P0CHiZNe3KRkjVBi32EiJVbc4WqwwHt4 T+qRL1S7GZpJ4amudpnJ5M9WmMYYeypS2PzVKRjTrlJFdKZbsoX7VgfZeuTx7CkDPye1 sm2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5ckTjBM+i6lP/xytKgIqTJ+2Cl5zE+M0XULDgVmloKQ=; fh=Xw5HE41mfujte8T/g322s3jt4RSsQG6IeDHgHmlrXrw=; b=VG2BKvb8C1CHKmBMVohNEhkZ9OS02wPuYSR/RfwlK6AsodtHURnkZVKPt0IRkvLT7t kIUsDijDU4opABx99SJQfUHQErTOlSx+8RgDXI8+RBtNGHxrTxQBvVvbrjOCHeyjCIWb OqURt5ctmt4Ad9aQz9rMIkqQJFrkRjkGmoSNHjh4Cuu05et/q3nyy8FrqrzuNnP8AO+D TE1ieJvUbZ12SaR4+L7+6+lnvEqMD9fL9U44mYGWDBzsSs2UJCvyDFprYIT9gKnadaXf LOgHwmaE/PQPWqOsW7sHR0UdbAq12YFEyMiO+8KNXOF6oBYQiHZHQ6lz6PhJGZsPV0Dm ecaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sIqwg0mm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51595-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51595-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX1jL08kVYpKWevNAbYAUWk0cFKfjdp1VcZHP3uCytyeEQFbPk/voly4w7wvtzLCte00l8cwY25FNRubuHq2AZ4Nx8AqlC/0+S+B0BPAw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h23-20020a170902ac9700b001d701962b21si4586694plr.490.2024.02.04.02.59.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 02:59:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51595-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sIqwg0mm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51595-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51595-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 679CF283877 for ; Sun, 4 Feb 2024 10:59:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FC2A21A19; Sun, 4 Feb 2024 10:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sIqwg0mm" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD50A21373; Sun, 4 Feb 2024 10:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707044344; cv=none; b=iNDG96PaQjq9yzb/7x95ao/SZfMVzVp3vpK/qPvlRI/UxpjAod+uQTJvS2rUDycdKX/+9qTvUEujjhjMw92qqUWyc98nicSCiK6TmpLAzRXENcr5x+gzMlFBRV9g6blrVTbBFwaWWXWnb7RF0mulSyX4eQrwwlQb9RgexnfKtfo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707044344; c=relaxed/simple; bh=gPTH20pU/DzXXCAXEMnct3tWfsC+YYsXBZazocgU+S8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m9zMwc3q7e8s2/kQoAbBjDGHUTLxxJLpsuA/pO0GFB0w5JXHA85A5OuUXzOuRi+zPRRVuVndFO1Bji6KItwepC82YDBM6n3ugqFrTWDX0AOI2Ss6bVZPSfjCpH/hDdKoL66LwBmLiWTegekCKBrkNOGNUtUfPU1zU7wAOKxMJdI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sIqwg0mm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B4ADC433C7; Sun, 4 Feb 2024 10:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707044344; bh=gPTH20pU/DzXXCAXEMnct3tWfsC+YYsXBZazocgU+S8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sIqwg0mmHnhbdBmB15Jd2Ku+Ap5LAoIwr6QSz7o7M4ZQTYQZNHoVqNxKgnyy6J0sk cQGgupOTlS0eE6ZI6WmrYNYOQY5HtjxzHsyzlmZJO80HZYVWSgNtsrLI2djvpGMY6Q RT6TNTAGHp6/ZPG8+jiB8rdBQYR2m6MgkHb7XGemcewjva4EtldPcruD8mUCs6S0p+ p3tG4JX7atakUDdJDDmkgNCulbCBf9R5YfT2AAtcPUA/aHquPJ2cAKhfvOKpdR7mTv 88hYwbIzhmqf2S9LAoF3AAc4OC5vAJjoAnSnKDvVv1WwveCQf8Z2NKAkzAxvOFRitI h5glOgXAF/1uw== Date: Sun, 4 Feb 2024 11:58:53 +0100 From: Mike Rapoport To: Qi Zheng Cc: akpm@linux-foundation.org, arnd@arndb.de, muchun.song@linux.dev, david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [PATCH 1/2] mm: pgtable: add missing flag and statistics for kernel PTE page Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@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: On Thu, Feb 01, 2024 at 04:05:40PM +0800, Qi Zheng wrote: > For kernel PTE page, we do not need to allocate and initialize its split > ptlock, but as a page table page, it's still necessary to add PG_table > flag and NR_PAGETABLE statistics for it. > > Signed-off-by: Qi Zheng > --- > include/asm-generic/pgalloc.h | 7 ++++++- > include/linux/mm.h | 21 ++++++++++++++++----- > 2 files changed, 22 insertions(+), 6 deletions(-) This should also update the architectures that define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL, otherwise NR_PAGETABLE counts will get wrong. Another related thing is that many architectures have custom allocations for early page tables and these would also benefit form NR_PAGETABLE accounting. > diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h > index 879e5f8aa5e9..908bd9140ac2 100644 > --- a/include/asm-generic/pgalloc.h > +++ b/include/asm-generic/pgalloc.h > @@ -23,6 +23,8 @@ static inline pte_t *__pte_alloc_one_kernel(struct mm_struct *mm) > > if (!ptdesc) > return NULL; > + > + __pagetable_pte_ctor(ptdesc); > return ptdesc_address(ptdesc); > } > > @@ -46,7 +48,10 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) > */ > static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) > { > - pagetable_free(virt_to_ptdesc(pte)); > + struct ptdesc *ptdesc = virt_to_ptdesc(pte); > + > + __pagetable_pte_dtor(ptdesc); > + pagetable_free(ptdesc); > } > > /** > diff --git a/include/linux/mm.h b/include/linux/mm.h > index e442fd0efdd9..e37db032764e 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2922,26 +2922,37 @@ static inline bool ptlock_init(struct ptdesc *ptdesc) { return true; } > static inline void ptlock_free(struct ptdesc *ptdesc) {} > #endif /* USE_SPLIT_PTE_PTLOCKS */ > > -static inline bool pagetable_pte_ctor(struct ptdesc *ptdesc) > +static inline void __pagetable_pte_ctor(struct ptdesc *ptdesc) > { > struct folio *folio = ptdesc_folio(ptdesc); > > - if (!ptlock_init(ptdesc)) > - return false; > __folio_set_pgtable(folio); > lruvec_stat_add_folio(folio, NR_PAGETABLE); > +} > + > +static inline bool pagetable_pte_ctor(struct ptdesc *ptdesc) > +{ > + if (!ptlock_init(ptdesc)) > + return false; > + > + __pagetable_pte_ctor(ptdesc); > return true; > } > > -static inline void pagetable_pte_dtor(struct ptdesc *ptdesc) > +static inline void __pagetable_pte_dtor(struct ptdesc *ptdesc) > { > struct folio *folio = ptdesc_folio(ptdesc); > > - ptlock_free(ptdesc); > __folio_clear_pgtable(folio); > lruvec_stat_sub_folio(folio, NR_PAGETABLE); > } > > +static inline void pagetable_pte_dtor(struct ptdesc *ptdesc) > +{ > + ptlock_free(ptdesc); > + __pagetable_pte_dtor(ptdesc); > +} > + > pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp); > static inline pte_t *pte_offset_map(pmd_t *pmd, unsigned long addr) > { > -- > 2.30.2 > > -- Sincerely yours, Mike.