From patchwork Tue Oct 29 00:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13854298 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 543CFD5B851 for ; Tue, 29 Oct 2024 00:24:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B25F8D0003; Mon, 28 Oct 2024 20:24:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 414276B00C1; Mon, 28 Oct 2024 20:24:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA0D8D0003; Mon, 28 Oct 2024 20:24:17 -0400 (EDT) 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 E57B56B00C0 for ; Mon, 28 Oct 2024 20:24:16 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A8C6E140890 for ; Tue, 29 Oct 2024 00:24:16 +0000 (UTC) X-FDA: 82724742030.25.CA8CC98 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id D2EDA80003 for ; Tue, 29 Oct 2024 00:23:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=icCQQT2l; spf=pass (imf30.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730161400; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BwshJwo48RIhJnqvpdLmCKcZc0vOflKYESOeF9s3h5g=; b=C9JOoVld5U4jsXlrxr0qyF+ozGgCqA2hM83RUdRNcHrawcsGmjAbqvaVmSV0sViV0Cv/kC D2u6jb4Pp/SC3/e5s93CNjFz904fqtpuipLxrfpcbQUy1fFWfPQnJDygZuf1YnprEqdenf qLYGPbeA0gacBCl2vED2Pd8p6PMLQFg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=icCQQT2l; spf=pass (imf30.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730161400; a=rsa-sha256; cv=none; b=vHs/CQM3PU4e4uy6nBH7uWFMipS0wt7jWNsM4Be33LuF5uRVwJWmqctGaokwbixB5+JbT1 7xdAn9Q04NPioY4u12lwbqR70YCkMca+U+kVh1QEZ8qNimmnUdP7Gm0VDZep/+BiXmZxLr QgIA8OJvPyWHp5IEyajDu40gTZWItAk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BwshJwo48RIhJnqvpdLmCKcZc0vOflKYESOeF9s3h5g=; b=icCQQT2lxYD/Bkswn+kH5dOcQl 4OyL053b9xdV1IU4hvc3z6E6kEqCdEQKIEOC3InqAVEdZmg0nkJYzr+9gIoHMpwBzRVEPPwROwdcz 1raCGT8RCC7Uh3t7hjq/6slsuJgezXZxSUq/LCx//sXBjGDMmcZ7r1nBGM9G1BoVBC2Hq6ZqUHRYk 31RYRo3CfcM+ElquSuLvP2lxg7i46wfBU+3vacpv/2Rd5XwuCzqZksb1AGiXJZJe93JRyWhLd5r1U /P0X6aHHZdihEbdOoe/XLiNuG6lQRhNlmCNnt3Pwcpm5Max35hEfROmuCh3Doo7ExtT6383OxEDOZ /B+mHGrg==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t5a1k-00GIrd-8p; Tue, 29 Oct 2024 01:24:04 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , Lance Yang Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_C?= =?utf-8?q?anal?= Subject: [PATCH v2 4/4] mm: shmem: override mTHP shmem default with a kernel parameter Date: Mon, 28 Oct 2024 21:13:08 -0300 Message-ID: <20241029002324.1062723-5-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241029002324.1062723-1-mcanal@igalia.com> References: <20241029002324.1062723-1-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: i9nff1qbtn66wibjfq3azmui73rfiibz X-Rspamd-Queue-Id: D2EDA80003 X-Rspamd-Server: rspam11 X-HE-Tag: 1730161409-319075 X-HE-Meta: U2FsdGVkX18IXt585UiIc2nw2J742+ilvW/xqdq88eeFd9bO8gKtvCedcamx8BiNz4s8ruHcuj8iHgmgv3f5of0P2jz8ZTSQC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3CtocHrzt1YF5aDVUlxP+Gp/IxyuhuuyMNjlo4G6lfvqKUOROKbL0sunoIJvLXexI4qtTw3fh3Q2boCTGixGl+X1r4ufNff6peIKfMxd9W8RAE+8r5BNEIift8stq3uDM2cZoheCATYd9bIsi4MP7A= 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: Add the ``thp_shmem=`` kernel command line to allow specifying the default policy of each supported shmem hugepage size. The kernel parameter accepts the following format: thp_shmem=[KMG],[KMG]:;[KMG]-[KMG]: For example, thp_shmem=16K-64K:always;128K,512K:inherit;256K:advise;1M-2M:never;4M-8M:within_size By configuring the default policy of several shmem hugepages, the user can take advantage of mTHP before it's been configured through sysfs. Signed-off-by: MaĆ­ra Canal --- .../admin-guide/kernel-parameters.txt | 10 +++++ Documentation/admin-guide/mm/transhuge.rst | 17 +++++++++ mm/shmem.c | 38 ++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index acabb04d0dd4..b48d744d99b0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6700,6 +6700,16 @@ Force threading of all interrupt handlers except those marked explicitly IRQF_NO_THREAD. + thp_shmem= [KNL] + Format: [KMG],[KMG]:;[KMG]-[KMG]: + Control the default policy of each hugepage size for the + internal shmem mount. is one of policies available + for the shmem mount ("always", "inherit", "never", "within_size", + and "advise"). + It can be used multiple times for multiple shmem THP sizes. + See Documentation/admin-guide/mm/transhuge.rst for more + details. + topology= [S390,EARLY] Format: {off | on} Specify if the kernel should make use of the cpu diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 9b5b02c4d1ab..47e7fc30e22d 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -332,6 +332,23 @@ allocation policy for the internal shmem mount by using the kernel parameter seven valid policies for shmem (``always``, ``within_size``, ``advise``, ``never``, ``deny``, and ``force``). +In the same manner as ``thp_anon`` controls each supported anonymous THP +size, ``thp_shmem`` controls each supported shmem THP size. ``thp_shmem`` +has the same format as ``thp_anon``, but also supports the policy +``within_size``. + +``thp_shmem=`` may be specified multiple times to configure all THP sizes +as required. If ``thp_shmem=`` is specified at least once, any shmem THP +sizes not explicitly configured on the command line are implicitly set to +``never``. + +``transparent_hugepage_shmem`` setting only affects the global toggle. If +``thp_shmem`` is not specified, PMD_ORDER hugepage will default to +``inherit``. However, if a valid ``thp_shmem`` setting is provided by the +user, the PMD_ORDER hugepage policy will be overridden. If the policy for +PMD_ORDER is not defined within a valid ``thp_shmem``, its policy will +default to ``never``. + Hugepages in tmpfs/shmem ======================== diff --git a/mm/shmem.c b/mm/shmem.c index 26c1eb1b4b1d..37951bb863dd 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -136,6 +136,7 @@ static unsigned long huge_shmem_orders_always __read_mostly; static unsigned long huge_shmem_orders_madvise __read_mostly; static unsigned long huge_shmem_orders_inherit __read_mostly; static unsigned long huge_shmem_orders_within_size __read_mostly; +static bool shmem_orders_configured __initdata; #endif #ifdef CONFIG_TMPFS @@ -5027,7 +5028,8 @@ void __init shmem_init(void) * Default to setting PMD-sized THP to inherit the global setting and * disable all other multi-size THPs. */ - huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER); + if (!shmem_orders_configured) + huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER); #endif return; @@ -5184,6 +5186,7 @@ struct kobj_attribute thpsize_shmem_enabled_attr = #if defined(CONFIG_TRANSPARENT_HUGEPAGE) + static int __init setup_transparent_hugepage_shmem(char *str) { int huge, ret = 0; @@ -5207,6 +5210,39 @@ static int __init setup_transparent_hugepage_shmem(char *str) } __setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); +static char str_dup[PAGE_SIZE] __initdata; +static int __init setup_thp_shmem(char *str) +{ + struct thp_policy_bitmap policies[] = { + { "always", huge_shmem_orders_always }, + { "inherit", huge_shmem_orders_inherit }, + { "advise", huge_shmem_orders_madvise }, + { "within_size", huge_shmem_orders_within_size } + }; + char *p; + + if (!str || strlen(str) + 1 > PAGE_SIZE) + goto err; + + strscpy(str_dup, str); + p = str_dup; + + if (!parse_huge_orders(p, policies, ARRAY_SIZE(policies), + THP_ORDERS_ALL_FILE_DEFAULT)) + goto err; + + huge_shmem_orders_always = policies[0].bitmap; + huge_shmem_orders_inherit = policies[1].bitmap; + huge_shmem_orders_madvise = policies[2].bitmap; + huge_shmem_orders_within_size = policies[3].bitmap; + shmem_orders_configured = true; + return 1; +err: + pr_warn("thp_shmem=%s: error parsing string, ignoring setting\n", str); + return 0; +} +__setup("thp_shmem=", setup_thp_shmem); + #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #else /* !CONFIG_SHMEM */