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: 195191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp285766dyc; Thu, 1 Feb 2024 00:07:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyyCMxit8FQ5mQnmAspuHwhrSGjs+FO3B43dnrBniBqZBSyXFscncd+CkMhbHPYeUqurgx X-Received: by 2002:a05:6808:1718:b0:3bd:cd55:d320 with SMTP id bc24-20020a056808171800b003bdcd55d320mr4098981oib.47.1706774827280; Thu, 01 Feb 2024 00:07:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706774827; cv=pass; d=google.com; s=arc-20160816; b=EFYtJ54q5KjXZxfZ9e7+fskuG/qkA4Jhic2oV7V4RwuhTI9/d0UkjdXscs/EJTCUJ6 aUm/EHNzc8BboVWRG8W39XBQ/Eaeo/70/Em1S/fNtL4XjKqKZUJNtDHEzuX7QOgze5FR n8ZT+vgXD0MiscLfwmdknkWQSkOSTTHSz7yZz+FyxSQSp5b9rRx6JpxZlJRqYjwD/QmP VMVvxmXKjL4Row3QLBrAeITsaQ26tmhHK/Z419wE8gg7ihBCCBcu2UGu86EGt9/Vz3wd lwfnoCsw1GdlMQVHnCI62N+hI7QweCjVAXCIG4XkZc++fl95HH7uRevIOKb0hsuXpZih XVQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=xUqkQTp/EejRMwYJr1zUIe1l3Bx/6LHMX3gDVJzEF5k=; fh=WPT+fpfJe8l3vKob42lFtRgKbHMWmWeybfi7IbD2vTA=; b=bah1NFS/2vY5WAPSxWMKlDj60zCOqSOpmOicakRw2AO8/kJP8zYepciu9xM7vjehfD BAo1klfob0kuaE/ap6BEsKJ9jtWY+soFHUypotKD1snyitQbrwtsM7q4zTd4X2Mc76YS HaU90zVGe0IKZ6fS1V2qrlKHbEhW6ucf6I2P1jDQyl7jUpj2l8BPq6QUpkwF5sE6gMiV EztkkQVzvp/PEI75IC7+YZ6GuBdDQ47CBN15mD35HeOzv6OIx9mJMe4arRJ5Z6B+qHbO 6LFlgOMrMemYHVjCX7HExWeizPpiiy9fE+Jl7k+yNNEeFaWKV8K6UYEpqn55s/tOVrwa 3iyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BZLJuWKx; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-47749-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47749-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com X-Forwarded-Encrypted: i=1; AJvYcCUuVKR/qbYiX4+Tjd2KUqJnOvT05zMKa4EyXXYa6d7lTpdo2LebPAVYG02T3JOFjw2RLKms4w+tKJiUMp8fMy+Y2cZFMQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d15-20020ac85d8f000000b0042aa75fee35si8180386qtx.196.2024.02.01.00.07.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:07:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47749-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BZLJuWKx; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-47749-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47749-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 442171C273CA for ; Thu, 1 Feb 2024 08:06:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4CD9158D8A; Thu, 1 Feb 2024 08:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="BZLJuWKx" Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (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 393EE664BE for ; Thu, 1 Feb 2024 08:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706774760; cv=none; b=atU/l2TtZG8EnmU9fmd52OAMHtnsGA6LP0LuCfPp2iqCRac5/5+DDh0bZftXtR7dS9+3Z1Q0vNf6gp0csFy/uzeFsPkITvIsTHouDMUF259X3QiEABjyzgMska0cvqzNkEDzJ0fcjpMkZQF7J1k0qztR20uGgrRtIP+Jr6gNHCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706774760; c=relaxed/simple; bh=UFjVSsl6NY5jcy9u+P6W6fC+epRmU3IECOgX+lhK+Oo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QBOg4bW6vRRzH4SYOuU8uj+h85zPjWYm3e4gfu/MsY7vnO/SF/VpO4KclAhzsOrYwFNu50VHQrzSP+YPPKZxbKmuBs1YxBmZqqras9kTB5LUi7WNFiQS/1XUpVNdiGoSNItgG1sfPLJTcLTLasAAnlAPJr8k1TAYVAbHPL0Cqys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=BZLJuWKx; arc=none smtp.client-ip=209.85.166.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-3639fac1d06so392985ab.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=vger.kernel.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=BZLJuWKxY9cWyv+yJ0YHx5za3LhQ9hTVNOEpTX58KCmWUT25n2mRiVmojAJOTxa7tA 301slMpaQpuezgC7tuEWRcwpvqhEZmTRr0XeClWtay9lmvjsLBVOP+OH24k0cRDMB1im tcQmCo/hthecT9czbi5S6F7VH0+i65tmtKvw2NoXhwUxdtecoXjScLnW8OMwIjHUd7Cb iya8FIUgeHv82hRD7L1p908H2x5fBLCMlRqc+zE0KCwi1jlV0+dIA1LNn6kNJpAAhntP Ce/jZYhbobUDAOYIMAYMuOUA2wANQTRrfrIuCfBl3Yc27Blh4LUV4ldM1ZUd8GZArsqR z10w== 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=nuOVz6tFpduD0prK9QEdnl89yMK8Z/h1E88nHCkgmaDY01/gZV8XxFKbOKmMnUvjJd NQP/hhYAhZND1j6njNkaG/hFdRIQ/ELBc3d6Q4RB3AnjqKHQNQeYtri9g1Xo8NiEnnqT LSPixPXG8+75QxbxpmmyJXUUOvz+VWCBIzT9RyuOiHzbehdNDShSRu3IcrhnkzOk5P2v ld4sbGaz0/u69TsxVfg6XAi3YqBGfY0KAuWvQNPFsnF9ASNAW57dY3YNxKy+HmbSTnZh gwPGoRaDLd66j0dMnhk8tlUhAutLpVH/OWapELy1K9zPH/jzNFl6VdbYYSynnY9kTOQp Kgyw== X-Forwarded-Encrypted: i=0; AJvYcCW/dl7lIka+R3BgcRgU5W/j+BaVZYzWhtoFJqitoI4pCvrRX1+AFUUZMynbtgoCo6aZqfjrYNLL0gm3FTrdWLmYZ/ySy5yYlVPREC0m X-Gm-Message-State: AOJu0Yyp/F4MVu3+UeAbIMDTdjHn8m55NokMGNx90cuYCuxwsBnZLKzB Igqv4fuYG6i1T7a2mJcTjtggHLJkuh3A86WcizGI1YqPYvbo4mMLjqjAUexRfqY= 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789683121438311937 X-GMAIL-MSGID: 1789683121438311937 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: 195190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp285700dyc; Thu, 1 Feb 2024 00:06:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4/eUdHIQZETgu3pC0V2bBKQxWaaVnSW5E8FnS6yiMUOFFn/tH8jibG5favOjXwJeV0foK X-Received: by 2002:a2e:958d:0:b0:2d0:60f0:ce7f with SMTP id w13-20020a2e958d000000b002d060f0ce7fmr2459105ljh.26.1706774819510; Thu, 01 Feb 2024 00:06:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706774819; cv=pass; d=google.com; s=arc-20160816; b=m+M6pRE97K7/nK4S3A8RKsGyJkZproq1tjuBWWgQsicYoXJdXLjSjNvl9Kd0379Q0f 15oa9/VTpuD46EgSoLC6cHb20xDh/bRa2e4G9zdltGLMJ9DovXINBRHB0JzVrIpsnC9l xZ+ZXPf83kcKBMqL+DuJVfI4ZmWqM9pFBuk9kJL+0RvsRu1/yKNnMzZxbG0o6Hj6HMMQ sPOYVCcZgSJJE/6TloDbJSWhAdFxlbhW9MfSGlgMTLEOcigDxRmBScG98OjEaN1PxrE2 /YjhSTUWkj0v2E5F7M3Qz6/FqwT5DDnzeo3UzP+Wkk7aTLlGYeDIRKSCexeDE9+gEhRH iJFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DTPGAhJtcf1MyPZRa7AekzLPzVB6P7R8lGN8K5e/uaY=; fh=RMnP+EJBWxUZnXFzFMbYZDejozmE60WO0FicHkZH55g=; b=oSuQHlGRVVI3b48LDpD9rujJ8EKqFwK0VlKtnRDGzn4V3JPrVpOSx1tZONm2kNmp2D pYrGu1Yn2+mug5T9hm8DdA6DovWyOLDpo6UIy79I348jeCCVGimyXLg+IJuZcvZvqqVM +VWhFXuOZzSo4rqmch1/JcME5WIy8nu2teFwnu4O96g3c6HV+4D63/OqWrYZI/stbVLe 78APDYxOZzuzOGOzZVH9/fQTIIhFLUs+XnBP+r1ABgDVv91ILiP7zLgZyTe0BkfO4+Cy jc8EpN8zcIJuc7lvZkoIapLy6PS++aKr6D1PLYpxiMREkgr5GmXyhR83/7wIn6YAY5yC 9z9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=FIdgrMal; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-47750-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47750-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com X-Forwarded-Encrypted: i=1; AJvYcCXH5Rd8afjwibbNChXUjJ0qOMDGB34YZ4RV2E4m/fdf/cLWXF3a6A7Iiv+hDwGGkPh+OATC3gLL8+uYXktppmfXOlzfhA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z28-20020a50cd1c000000b0055fbd85ab50si257002edi.315.2024.02.01.00.06.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:06:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47750-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=FIdgrMal; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-47750-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47750-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 47EB21F23F21 for ; Thu, 1 Feb 2024 08:06:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20FA215A484; Thu, 1 Feb 2024 08:06:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="FIdgrMal" Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 062A3158D84 for ; Thu, 1 Feb 2024 08:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706774766; cv=none; b=JZs8x+J6fiTfhilbV+NUYMHS0BU6uAgPEzmmMfgBpIuJpirCRm6Jj2lJy8zwHrbvh/SXPuyBp4ebvMyoguEvyDG8wwR6fA81zwfhgaPTf+V2a1xEm82sm8A6QNAHyK/h75vXkT5J5/Uu7BeC3swk5mCADu6C7LkqT+k2x+ebaVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706774766; c=relaxed/simple; bh=fX+LasV85//JB3JqayRg2DaHh21Pzpe/TlzJPEh9Cz8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ic2QN5Z9bKj1/NLfMynF05B05E+XD4qqlgbCPWnvqaggpVfov2a7L5f9ej2ESqL1g2LG7uozxGPJdi6okyCai5bjD4H/4SW02sM7vr1uq5EUUUl4dMdMDCmfOynMWkNEQdhMFGBeQ4MwCbw4Nr3OoEIlnueDoHkr5uiuKjp/UU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=FIdgrMal; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5cfb8126375so135678a12.1 for ; Thu, 01 Feb 2024 00:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1706774761; x=1707379561; darn=vger.kernel.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=FIdgrMalvruH1KXdta8buHKdfstw3XrRDaIWMiR1eZUjXomHIOUpqmWxPkzjTSU2P9 KnenHxF6FFkk5ynjYWdnd+eS0wAv/hzM2k6owZhljiaeySltzkyHY+ZcB4Mfe6hqBOWT MVC1bNuCdQyG8ONUGuX21dtPiojidgfWBlCsgP1ImqDTxvVGIw/HRX+Jx00dvEXn6k8s 3L/4iXvYREEK6S/tC2YZB0FaEvlsOAP/2O7f48o1r6erGClLz8qSPzcH7XLXPQnP2onn h/QKW4Mwa7JRy+b9DXAdrt5aMwIWvvo7XwVlRoS8Hg9UcsvnpdfGEqxhbngXJGQ7qq+u 6LSA== 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=HFzvO6Fti+f9nmLBgZOh+5+iU7QLHhGA/Iqi2yHOfUDlJDLHJeZPEO6YckpzyjMcaJ Uc74eAJt0hbdgBWdsUIM133LWuc37zGVHaSEdcfyM3KIVr9kcANhTru6aZYHP9xhjVF5 2j15BFD8oJjENSGVaHtKrplbxDldlPRHOAjhmn9NVcywwQ4IyuHTHf1HWaTMo+fdsIvc t7q7jNEHwGErfF+Bnl0NftqKUwPTLrxQ+TbTzYUU2tSvOd5x69Ex9bwTZDKpqChoaKpR jaTH4x1VfI64Q+jkCuG/HB2ptU8FxY0NFbgbpzgWDgqRiM3H9SqmZwMWeMfE9rSDCLy9 sWBw== X-Forwarded-Encrypted: i=0; AJvYcCUEGZgZB7I217a9jU030vkImKaoPZKIickrSaQQUEWrmntib5DieoRYOiUQ3F0ZEnDcgyDVlraHofaQSBuS92oeghmBdQHHco1FkYHq X-Gm-Message-State: AOJu0YxF92O7y//nwbfPDo2koUThTrowVCnZ8C3Jqj2KAo0yCLkIoAE7 2NNUK8i1KK0dMqsm0xpjTpDVBayyApxJJtVoc8QFQwJWVOS9Uia3eeSqClUBHn8= 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789683113072390889 X-GMAIL-MSGID: 1789683113072390889 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