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-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4CDDD20008 X-Stat-Signature: wyhdj8bcqnrqk933sbxhf455w16dgbcc X-Rspam-User: X-HE-Tag: 1706774762-927981 X-HE-Meta: U2FsdGVkX18NzU1SKKOVQWUg71Q9miW1dU1U1R5fVytmx/uvTnX+ffGM8kI4Abhsfhff8qoHomvWGsYxKkyv9rZ3ogXjZT+iG1GRgZia4BZRVqjk7VXsq80rkZHUC/3iXzxfNqLTzsCncmjIPC4mmZrK0BVfZzH/icL8EKdxsrmbE8jgdpWlxSBrSrBL4fsCbOpmGhEMZUexb4etplHfc9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dT/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