From patchwork Thu Feb 1 08:05:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13540769 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 B9D64C47DDB for ; Thu, 1 Feb 2024 08:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E12996B007B; Thu, 1 Feb 2024 03:06:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC2AA6B007D; Thu, 1 Feb 2024 03:06:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C89C26B0080; Thu, 1 Feb 2024 03:06:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B90106B007B for ; Thu, 1 Feb 2024 03:06:01 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4EACAC0C60 for ; Thu, 1 Feb 2024 08:06:01 +0000 (UTC) X-FDA: 81742501722.29.BC25683 Received: from mail-il1-f181.google.com (mail-il1-f181.google.com [209.85.166.181]) by imf12.hostedemail.com (Postfix) with ESMTP id C70F140024 for ; Thu, 1 Feb 2024 08:05:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Xft5MCJo; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.181 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=1706774759; 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:references:dkim-signature; bh=xUqkQTp/EejRMwYJr1zUIe1l3Bx/6LHMX3gDVJzEF5k=; b=7jaN2dH0MxUI3+kuGLqGqci96mRh5vn6dOYfVPjqsiLd2zcP1ZhepiPT4IV15d1tIwYYRY oSYgeAhHlgfIJnZo/IZVC+eb8rJ8dYsSTdKVANMtDxs22vkzDCjNVAtTDdoOzWr0/0KB80 R94xvA7yWKiloIC1vdMT3ECEdyetQPE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Xft5MCJo; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706774759; a=rsa-sha256; cv=none; b=8fGKF/TGa+ru9l6x0R1fbrVCw6GRJEMA3LSRwlTCo8HZ3z74iaCB9WeG7t1TJlGdkUINO4 BuMz+hN+v9Y/WIhmlLVmRxdwUEvSoMXj0crnu4/U/cXlA078sBUB14Dr16oTwqSKr8F11W MWKe9Ad0DefcB+1hSHVlrp03lavpn6A= Received: by mail-il1-f181.google.com with SMTP id e9e14a558f8ab-3639fac1d06so392965ab.1 for ; Thu, 01 Feb 2024 00:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1706774757; x=1707379557; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xUqkQTp/EejRMwYJr1zUIe1l3Bx/6LHMX3gDVJzEF5k=; b=Xft5MCJoRg3qSzhBA9RtmTYEHGbXoMIWmqRWS6chyrF9brwr4RKPZOEOPAPdp15+tB zQAhBn5Oed3NUSdC0I82Wh11dpc8WEmso9BxhAK2FLTFQUvmAk2uTFTIS/1fgpVmcGv7 G0JwJMSy4vfrvHAp3GOezYvS/RQymJBXxf/jOwslnOLJidPzstmlQzloJjxZ0PdpY+/O Rllk2TEs7Q3G3aGkKFfkjFcqVp5nOeRkFuz5gBl2TeVpWQUXarC6YV/3FDWCha+wWye0 FlBaa9DcSbuw5riaRguCCboiKi4yvW3yLTGqER2y/yJsNKB+xY+KpVuyNY/gFroyv2b8 3iRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706774757; x=1707379557; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xUqkQTp/EejRMwYJr1zUIe1l3Bx/6LHMX3gDVJzEF5k=; b=C1wVGAiEPMmFzcV3Cy90YKiAJCg3+x/s/f3Ez14Fn6IBLBAtoHTrbKTypejaGzKNus VOP7tcBOIcjPmnteF+QN9dYSZGDICGZ0faGChUJByfyQuczGM2hnV3RufB+M3SEqaU4s V/7+vBqWOzP9ObWDRj6a+SObxrOZz1wCOyVRS5MHbdJNki0aYjJL3btG4IOcsnciZpq+ UlQZb6rJRf5P5ezALdcjgJ6MZxHhdqrhxBVq7NS53PA9T5IusfyaY4ktZfA7/OLXhgA1 4tkbMVLEH+USv279CxSge+Y0w0RRbEtKVMyFmqnjGyQPRJpwymwz9m4wHK0b0pPbKLft 0caQ== X-Forwarded-Encrypted: i=0; AJvYcCVNaUsbm5Na/fnSYUv1+kpEaN5IB9MdNxJi2AZptigzK/46xmGwwYCQotK8a01xNZl6ZdT4+FmlbOY0YeKch+mz7r0= X-Gm-Message-State: AOJu0Yyq6ppSFwjhaYBZzK2zNcSYCXCMzMgX0mWsJ4oOgdbSDrnqFJtF +CMIGn6WNMJERcWYcr7CuFUUPsLODETzuj/lj3D6MpjezjEwW81WlSZpy6IoOAs= X-Google-Smtp-Source: AGHT+IHNpsxcxBhK+Nhq/jFWZmtjYt1OxzFS7/Ya3k5ZLd6vvFcTq4MCRBXJUPNh31FQmRsEoOWExw== X-Received: by 2002:a6b:c9d8:0:b0:7bf:cc4d:ea53 with SMTP id z207-20020a6bc9d8000000b007bfcc4dea53mr4665474iof.0.1706774757261; Thu, 01 Feb 2024 00:05:57 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.153]) by smtp.gmail.com with ESMTPSA id d14-20020a056a00198e00b006de1da4ca81sm8389738pfl.55.2024.02.01.00.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:05:56 -0800 (PST) From: Qi Zheng To: akpm@linux-foundation.org, arnd@arndb.de Cc: muchun.song@linux.dev, david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Qi Zheng Subject: [PATCH 1/2] mm: pgtable: add missing flag and statistics for kernel PTE page Date: Thu, 1 Feb 2024 16:05:40 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C70F140024 X-Stat-Signature: iqmnx3f49sbobm847gy4o6c5r1kb73zd X-Rspam-User: X-HE-Tag: 1706774758-218945 X-HE-Meta: U2FsdGVkX1+dx9KEJOnegzbIr9N6OgejDZ9fge6T+qH4f7mCGHkipUQpQrgke3Igjjge8kDgeAcHimMJfVDicmX9c7lC/gwwBG04i5quLHPR0L0ZpfwDjYciRXSRQ5hge7CFXHqo6IP9moyQXs163q+aZpD/6RIdbnqBOwpbZQla+PtUr5ZU/L/vLYBEtOeiOmg9z790Ooq+8tp6WMyt/Xr6nId1n8jijKGb6N5qV4DGESHeXuji59V0aX8RMTwR9+9hN8p0y8jfPULl42kvsDA1XweSkHTcnr7+/ALvxrAhHRqHwdL2bB2Ye+7oeKOjQGkioZfqMpesyF2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ests=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: 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 Reviewed-by: Muchun Song --- include/asm-generic/pgalloc.h | 7 ++++++- include/linux/mm.h | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) 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) { From patchwork Thu Feb 1 08:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13540770 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 1753FC47DDF for ; Thu, 1 Feb 2024 08:06:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 820156B0080; Thu, 1 Feb 2024 03:06:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CF366B0083; Thu, 1 Feb 2024 03:06:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 696F76B0085; Thu, 1 Feb 2024 03:06:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5984F6B0080 for ; Thu, 1 Feb 2024 03:06:04 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1D8DA1208AA for ; Thu, 1 Feb 2024 08:06:04 +0000 (UTC) X-FDA: 81742501848.09.C4BA0F7 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf13.hostedemail.com (Postfix) with ESMTP id 4CDDD20008 for ; Thu, 1 Feb 2024 08:06:02 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="ifNvWW/R"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.174 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=1706774762; 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=DTPGAhJtcf1MyPZRa7AekzLPzVB6P7R8lGN8K5e/uaY=; b=QALnhmM48O59IJim5iIeW0vTp9r9LHHOIbT4R8JSo0V0l14XnPJHaa8rhQpOn11HLVU1aY Nk5XUUSF2Y4CTNpyrNNXJ2v3Jgij3A95kXSUOLO49wXnroUJv2nJJhVkxLNXU3f7YXGSGA D8x4rmNyvSLNTtTzesAl6J5Orp9RZZU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="ifNvWW/R"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706774762; a=rsa-sha256; cv=none; b=G9qCAQpuclmWRciKhDvPODJjkf9uGyEXGRZDVAAcbNAMgG49D/lkuuU07hqWlsclC1Ymrx QeWUM5wMYb0aJfWLAGqiZgxisHiYVfFX2yqU4a3+e9g8G0/ZaXARKUCGUjlbff7+hqbk3B 7VTcRkZwwyiFjkVlWx/8rZ+obQybsgc= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5cfb8126375so135676a12.1 for ; Thu, 01 Feb 2024 00:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1706774761; x=1707379561; 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=DTPGAhJtcf1MyPZRa7AekzLPzVB6P7R8lGN8K5e/uaY=; b=ifNvWW/RlGjYKMWpeKzeIhcTl6M0kHtYj/sZBJuha56evyjm0A6s3QE/RcBxNo3pZZ 7Dya+EV+7+KWpaSoHVs/eGYoowA3sLlzkTwBd2OzzHshT4/TNEyJNbm2N/U+xMg1ZCOH hzqz3rer+VPOH3sqcbHdDdRlPctYyUp0lZR8OZT1TGpLn1AumiwhD/5EveVXkkmQOMK+ XwFbGqKHHLNbTKtAslGMZNo2U0kptF+deGeoodmQqsfqQ2J6KzfWuK1OTKF0gVFMrYto gYxZrD3p6m5Du9+VqoYSsRA1AkpBnxf9HbPr2wAVxtbaBd2kYvdRTM/swZQzT2ht5I6H +9OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706774761; x=1707379561; 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=DTPGAhJtcf1MyPZRa7AekzLPzVB6P7R8lGN8K5e/uaY=; b=o1cCIiRbQdjuwZ8y1bv6NA9OuJf+U7qPxkuyEb1Z1c3LBytY7MfFkDWsDolhaShvKB QymzwMh1J348mnG08l/DoH7ngxTE9YWRrxhoJB04L7k0yz4t5CMUSbXJiVEvQmmtMrTl /MBlOh7XQrxzpL5KIe1q+17yZ2I4s6kjPr+rujEqYSHkBgFSrRtZ30wSKa7GKFqRqZ/V /Xa6mRB3bD5crVVluvVoZXRj7rBiEGtAnSOY77FiBRFz3IYcXh5nQQOYmSiQDDddYCrF 8BWJcLdtKbMgX+jj9TFFUJY1AFVQo0PK7vNf3PhNbGX0zUMRpr2Oy3V/xeFkInLA4XOP pygA== X-Forwarded-Encrypted: i=0; AJvYcCUzDyOXm7cwKVFuDxKyv/+tmXxq6eoJk+W6xSAB1vNzqLoaWUU8oGKisH3fP1C0AD0DnA/7ZKvrnc+32f4YnmgkZqQ= X-Gm-Message-State: AOJu0YwIdCdcYUVH/Z6QBeqqdKzFcnvQ+qoOI7uKz+vBIsYRC0un65rY 3SsYbHRKCbLxlekCXLM3x8HTsuTcMpHjwuIVQVCFFHWo9+tXidaBeYGjPq/hRak= X-Google-Smtp-Source: AGHT+IEUnUoM51cECvFG4aDXlm1WeTlTFMHPR0fA3iZmMtXBOgbtIn54HRGZi2CYU2BKNTL6psaVlg== X-Received: by 2002:a62:cf02:0:b0:6dd:c870:2f7c with SMTP id b2-20020a62cf02000000b006ddc8702f7cmr4177620pfg.2.1706774761225; Thu, 01 Feb 2024 00:06:01 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.153]) by smtp.gmail.com with ESMTPSA id d14-20020a056a00198e00b006de1da4ca81sm8389738pfl.55.2024.02.01.00.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:06:00 -0800 (PST) From: Qi Zheng To: akpm@linux-foundation.org, arnd@arndb.de Cc: muchun.song@linux.dev, david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Qi Zheng Subject: [PATCH 2/2] mm: pgtable: remove unnecessary split ptlock for kernel PMD page Date: Thu, 1 Feb 2024 16:05:41 +0800 Message-Id: <63f0b3d2f9124ae5076963fb5505bd36daba0393.1706774109.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-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EdX2qmqR4P2ddCugpaco67YUOEQMPVgQYa4q Lyu1LgEr 6Oqi525H2DFS9pVHwUeNl0PoLCzfqmJRJAcByBRm5Akt2AJmAboRdGGnEKEQbTDVS7Uzwjqtr6FXSCMV9UJsv8ZhT9O/x/4HBC640JOXt3qq/FdkFkRpIspht9BB6LDxA3rvdHULU9Oh0KmxF9RyITcMzqavJgL407ZAlu7nxobH1EGLRW4hgl6p2n7/GhY4X8ILaXf6NJDtIV/Gsc8qC9XUF38/C0aG0wS6m0ClEpoYUhNAug/qphmiilx+gH3CGIxT+zkWPXgJ7wyRgJINxaeHMFIEPqwQLiiV2dT/QpA/b57LP2Bfw+9za3OogfqcWHMpUuyKgMl6VvMqUjWEoVtF5DnDmjbdMYRsXhrvu5ZGs+CcTlQlXJnTFocvbFWi6Y+4BfkkuRgcvbsd3tkEWJwHwwC0cZtkPlnjo 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: For kernel PMD entry, we use init_mm.page_table_lock to protect it, so there is no need to allocate and initialize the split ptlock for kernel PMD page. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- include/asm-generic/pgalloc.h | 10 ++++++++-- include/linux/mm.h | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h index 908bd9140ac2..57bd41adf760 100644 --- a/include/asm-generic/pgalloc.h +++ b/include/asm-generic/pgalloc.h @@ -139,7 +139,10 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) ptdesc = pagetable_alloc(gfp, 0); if (!ptdesc) return NULL; - if (!pagetable_pmd_ctor(ptdesc)) { + + if (mm == &init_mm) { + __pagetable_pmd_ctor(ptdesc); + } else if (!pagetable_pmd_ctor(ptdesc)) { pagetable_free(ptdesc); return NULL; } @@ -153,7 +156,10 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) struct ptdesc *ptdesc = virt_to_ptdesc(pmd); BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); - pagetable_pmd_dtor(ptdesc); + if (mm == &init_mm) + __pagetable_pmd_dtor(ptdesc); + else + pagetable_pmd_dtor(ptdesc); pagetable_free(ptdesc); } #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index e37db032764e..68ca71407177 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3048,26 +3048,37 @@ static inline spinlock_t *pmd_lock(struct mm_struct *mm, pmd_t *pmd) return ptl; } -static inline bool pagetable_pmd_ctor(struct ptdesc *ptdesc) +static inline void __pagetable_pmd_ctor(struct ptdesc *ptdesc) { struct folio *folio = ptdesc_folio(ptdesc); - if (!pmd_ptlock_init(ptdesc)) - return false; __folio_set_pgtable(folio); lruvec_stat_add_folio(folio, NR_PAGETABLE); +} + +static inline bool pagetable_pmd_ctor(struct ptdesc *ptdesc) +{ + if (!pmd_ptlock_init(ptdesc)) + return false; + + __pagetable_pmd_ctor(ptdesc); return true; } -static inline void pagetable_pmd_dtor(struct ptdesc *ptdesc) +static inline void __pagetable_pmd_dtor(struct ptdesc *ptdesc) { struct folio *folio = ptdesc_folio(ptdesc); - pmd_ptlock_free(ptdesc); __folio_clear_pgtable(folio); lruvec_stat_sub_folio(folio, NR_PAGETABLE); } +static inline void pagetable_pmd_dtor(struct ptdesc *ptdesc) +{ + pmd_ptlock_free(ptdesc); + __pagetable_pmd_dtor(ptdesc); +} + /* * No scalability reason to split PUD locks yet, but follow the same pattern * as the PMD locks to make it easier if we decide to. The VM should not be