From patchwork Sun Oct 27 17:36:37 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: 13852707 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 7C2F6D13572 for ; Sun, 27 Oct 2024 17:58:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 770DD6B009C; Sun, 27 Oct 2024 13:58:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CFA56B009D; Sun, 27 Oct 2024 13:58:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 524C76B009E; Sun, 27 Oct 2024 13:58:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1E1396B009C for ; Sun, 27 Oct 2024 13:58:46 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BF24A141BC2 for ; Sun, 27 Oct 2024 17:58:22 +0000 (UTC) X-FDA: 82720141518.03.170F88A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf26.hostedemail.com (Postfix) with ESMTP id 539B0140008 for ; Sun, 27 Oct 2024 17:58:27 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=AWGsfkbf; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf26.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730051870; a=rsa-sha256; cv=none; b=ULW4sUFS/dBQpm3fIPLGNga3ER3yppQNfmhdO/+9bUZNcIuy2YbtDDD9B+DHj39zBEcrnS jUnonyIs9rUQs94FZTvTXnUS4Zhyu3+HOAJNsLBmG/wfTBgX1KSgWCgH2ClNEB1iwcrk6T y4hM9GoCZXKD/6kyYW2X2vizNukjUPo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=AWGsfkbf; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf26.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730051870; 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=7HBELsvSiP+CccX0d5orY/4TAyEDWFWAwNxu03tnWpk=; b=Co+qSTtVvLpkHIseT14beJP2OI/3zR4Qe9xRiXPvG2dMJY38sNT7G6pb0MA9Si9ohRPjXQ bf5lCW6tSI9gbdKhXPymINn2605ao1zZVBIHhw2yDBqlW3uGj5MnaFl9tggfMrA1vy9E9E xug/ib0x+qnMP98x+W13GmQSVlUE9xk= 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=7HBELsvSiP+CccX0d5orY/4TAyEDWFWAwNxu03tnWpk=; b=AWGsfkbfnZzKYEA5W0gFbtsOmv sfwFfpwdBF2FXih87naNogfmWnfyrfoWY9IAahCrgeJXO9yd5ho08XdIVQ2CHZ1VzLagSOm2Q0q/+ IhPa0/clDwwDKWoQbdL8IgdEVO+64eN4fgl2nOV2UZS1ohS1gZt1OMw7sdn1qdZpWu8unrmTDu/Pk A972Oq7X+LIC3umUq5viUKIgJf8wKFitNSCXqtTfcmfhY/i7kMs8m5U0iPUqq4uilm9C0J1YPTgk8 S288Ll88BlrXWVAmAcZYpHfwhnXexb3tzlAAdkeq+JAnn9D0G7MWKyeTnBn+ogDz8v/2akbuu1fr8 gqJVXuUQ==; 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 1t57Wz-00Fn6f-M7; Sun, 27 Oct 2024 18:58:26 +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 1/3] mm: fix the format of the kernel parameter ``thp_anon=`` Date: Sun, 27 Oct 2024 14:36:37 -0300 Message-ID: <20241027175743.1056710-2-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241027175743.1056710-1-mcanal@igalia.com> References: <20241027175743.1056710-1-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 539B0140008 X-Rspamd-Server: rspam01 X-Stat-Signature: jb9ug35jshshe3aatxjbjosnqkztyygu X-HE-Tag: 1730051907-360822 X-HE-Meta: U2FsdGVkX19OWj/W5bo0INa7V2IbFmg8xiFIccr/Tkp8HcdPIFUqyMSZRX9bC7lviImk2lbFY+4Wx1QWYg7EYBy/zDg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5TfoAkGQFH8/HNffPtkOXtx3WWjALGHTopTDuu8GJlfPrC80smryDNaM1pqyVP8u4r+yjRdFt9TfReX0fP5pBoUS+bzzXB9KluiLXTadCRoyDwTzlMUDJnThXcmjuOHU1lV4RaTzlbRl8PN5Atjn8YqsgiKUb6HTb+32mKegsU5VtJJ5vD7CjV/v3uq0ovgs9O2uevX93x 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: If we add ``thp_anon=32,64KB:always`` to the kernel command line, we will see the following error: [ 0.000000] huge_memory: thp_anon=32,64K:always: error parsing string, ignoring setting This happens because the correct format isn't ``thp_anon=,[KMG]:```, as [KMG] must follow each number to especify its unit. So, the correct format is ``thp_anon=[KMG],[KMG]:```. Therefore, adjust the documentation to reflect the correct format of the parameter ``thp_anon=``. Fixes: dd4d30d1cdbe ("mm: override mTHP "enabled" defaults at kernel cmdline") Signed-off-by: Maíra Canal Acked-by: Barry Song Acked-by: David Hildenbrand --- Documentation/admin-guide/kernel-parameters.txt | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1518343bbe22..1666576acc0e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6688,7 +6688,7 @@ 0: no polling (default) thp_anon= [KNL] - Format: ,[KMG]:;-[KMG]: + Format: [KMG],[KMG]:;[KMG]-[KMG]: state is one of "always", "madvise", "never" or "inherit". Control the default behavior of the system with respect to anonymous transparent hugepages. diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 203ba7aaf5fc..745055c3dc09 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -303,7 +303,7 @@ control by passing the parameter ``transparent_hugepage=always`` or kernel command line. Alternatively, each supported anonymous THP size can be controlled by -passing ``thp_anon=,[KMG]:;-[KMG]:``, +passing ``thp_anon=[KMG],[KMG]:;[KMG]-[KMG]:``, where ```` is the THP size (must be a power of 2 of PAGE_SIZE and supported anonymous THP) and ```` is one of ``always``, ``madvise``, ``never`` or ``inherit``. From patchwork Sun Oct 27 17:36:38 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: 13852708 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 1E8BED13578 for ; Sun, 27 Oct 2024 17:58:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 796866B009D; Sun, 27 Oct 2024 13:58:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 720CE6B009E; Sun, 27 Oct 2024 13:58:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FC9F6B00A0; Sun, 27 Oct 2024 13:58:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 23AF66B009D for ; Sun, 27 Oct 2024 13:58:48 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 61C71ADD57 for ; Sun, 27 Oct 2024 17:58:04 +0000 (UTC) X-FDA: 82720142232.16.09577BD Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf12.hostedemail.com (Postfix) with ESMTP id AB28840009 for ; Sun, 27 Oct 2024 17:58:35 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=WgHTtphI; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf12.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730051884; a=rsa-sha256; cv=none; b=Ik/D388zfIMDOZDAb6aspCWuBeDPri4znlsrn6mQY18XMR4lafCsokEaISWwWGDl5RzBqy /wYxIS7oP8XfFgp56x8f/N2mCFfGQBGZ83gPJ9thUMj8h3nvmbfuWjzf6q+kP6Iwco5itH VMC+95H2IjaijK8ubYXhIL3JjZaTAnk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=WgHTtphI; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf12.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730051884; 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=Yyz6kYIELEJoOnjWDKYJClByK+fKp+OmRRnLmStbr7g=; b=UsZWLpY2/tfosuGbX1dfz0uM5p7RLmVLvEhB2zD37Gj7NvwjNw0JGXdJVObDdk+WRaQFGR FMum3tuZeB9uoL9ydR8R5zgPoEqrMugIC8P1dCK3dTU2/GZuymU70z61hHsZSgpmH5+5EA yB/tChUmIrDhWsRP1udLLtn3hXVa6w4= 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=Yyz6kYIELEJoOnjWDKYJClByK+fKp+OmRRnLmStbr7g=; b=WgHTtphIixmc7GzZ8EM5opkMOx 4dpaZaDygQq2yGyUYHGR9RH60zqNWA0KmCuGgdgnB4+DOWRZCaRLjHZAwblndN8dJC216aqEVFjHP Ed6aQVUwJ3fD8gLNMojvuoq8FcNmNrp/rwWMosf2YSvXZKWyhHGpAO5l9GagA117zzgCKpjNCbSGL NRlNo0FhfV3Y7QyxCwh6zOmuRmX/5oxR7LeHx8TvloLvxX2CwPfZRRmREGOwE6/O+yMJBoQKvLjgr dzoo0BTPC7KM29FI9begPRpOxZfCa7ICjsZuhjfhodfDPt3QQ5798Niph6jxe+JxZ/8g8hJmG1Ksq pN1R3IYQ==; 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 1t57X4-00Fn6f-NI; Sun, 27 Oct 2024 18:58:31 +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 2/3] mm: shmem: control THP support through the kernel command line Date: Sun, 27 Oct 2024 14:36:38 -0300 Message-ID: <20241027175743.1056710-3-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241027175743.1056710-1-mcanal@igalia.com> References: <20241027175743.1056710-1-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-St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NEi658fz83Z YAjXLpWM TrZh6CzA8aZRsoEtZtNviSI5qOpiQJP0EBEnfXbBZx/x7IkmkXKsAq/MRskWIzxCOo3E0PUw5D2J7h8pJccJJlRlknCTXXgIGmwV8DcTmoKpOrgCrWd9f1O75j37ErbuCZaG1qzYYH8v4vJRz2tRsaTFn3Hm6zIhqlg6ceeFoXkVz205y5Q+zwncBivMA0woRrypfMwHpE9llp0lX48QnY/qKUoVO4ZBo3ilOxGB6zQ2sZdQcJtjJqz5gYGUC4SQuDyNd3ib51j1qfJmiU9MNlPaPw0wTCW/u6zbLOmJvdRd4GBhGPGD6DQ7FPxVcNMIBBitr+iMn+byo/Rc= 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 a new kernel command line to control the hugepage allocation policy for the internal shmem mount, ``transparent_hugepage_shmem``. The parameter is similar to ``transparent_hugepage`` and has the following format: transparent_hugepage_shmem= where ```` is one of the seven valid policies available for shmem. By configuring the default hugepage allocation policy for the internal shmem mount, applications that use shmem, such as the DRM GEM objects, can take advantage of mTHP before it's been configured through sysfs. Signed-off-by: Maíra Canal --- .../admin-guide/kernel-parameters.txt | 7 ++++ Documentation/admin-guide/mm/transhuge.rst | 6 +++ mm/shmem.c | 38 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1666576acc0e..acabb04d0dd4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6926,6 +6926,13 @@ See Documentation/admin-guide/mm/transhuge.rst for more details. + transparent_hugepage_shmem= [KNL] + Format: [always|within_size|advise|never|deny|force] + Can be used to control the hugepage allocation policy for + the internal shmem mount. + See Documentation/admin-guide/mm/transhuge.rst + for more details. + trusted.source= [KEYS] Format: This parameter identifies the trust source as a backend diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 745055c3dc09..9b5b02c4d1ab 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -326,6 +326,12 @@ PMD_ORDER THP policy will be overridden. If the policy for PMD_ORDER is not defined within a valid ``thp_anon``, its policy will default to ``never``. +Similarly to ``transparent_hugepage``, you can control the hugepage +allocation policy for the internal shmem mount by using the kernel parameter +``transparent_hugepage_shmem=``, where ```` is one of the +seven valid policies for shmem (``always``, ``within_size``, ``advise``, +``never``, ``deny``, and ``force``). + Hugepages in tmpfs/shmem ======================== diff --git a/mm/shmem.c b/mm/shmem.c index 44282a296c33..24cdeafd8260 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -582,7 +582,6 @@ static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, } } -#if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { if (!strcmp(str, "never")) @@ -599,7 +598,6 @@ static int shmem_parse_huge(const char *str) return SHMEM_HUGE_FORCE; return -EINVAL; } -#endif #if defined(CONFIG_SYSFS) || defined(CONFIG_TMPFS) static const char *shmem_format_huge(int huge) @@ -5174,6 +5172,42 @@ struct kobj_attribute thpsize_shmem_enabled_attr = __ATTR(shmem_enabled, 0644, thpsize_shmem_enabled_show, thpsize_shmem_enabled_store); #endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */ +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) + +static int __init setup_transparent_hugepage_shmem(char *str) +{ + int huge, ret = 0; + + if (!str) + goto out; + + huge = shmem_parse_huge(str); + if (huge == -EINVAL) + goto out; + + if (!has_transparent_hugepage() && + huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) { + ret = -EINVAL; + goto out; + } + + /* Do not override huge allocation policy with non-PMD sized mTHP */ + if (huge == SHMEM_HUGE_FORCE && + huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) { + ret = -EINVAL; + goto out; + } + + shmem_huge = huge; + return 1; +out: + pr_warn("transparent_hugepage_shmem= cannot parse, ignored\n"); + return ret; +} +__setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ /* From patchwork Sun Oct 27 17:36:39 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: 13852709 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 AF9F8D13572 for ; Sun, 27 Oct 2024 17:58:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3760B6B009E; Sun, 27 Oct 2024 13:58:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FE8F6B00A0; Sun, 27 Oct 2024 13:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12BE96B00A2; Sun, 27 Oct 2024 13:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E57B66B009E for ; Sun, 27 Oct 2024 13:58:52 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AD6494035F for ; Sun, 27 Oct 2024 17:58:40 +0000 (UTC) X-FDA: 82720142064.25.6552234 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf14.hostedemail.com (Postfix) with ESMTP id 98910100013 for ; Sun, 27 Oct 2024 17:58:25 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=LWOACRw+; spf=pass (imf14.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=1730051851; a=rsa-sha256; cv=none; b=MVS5/dnnURXvawEk1NmQDeG+LtlIl2ac6NRG51mZwfYun9vUZMtAXEChnKdgLNEUGarVNM q0ABeT8Cxaf4Rqso4xweFJCvC+A/0lgJXLEfyy/zIARknTLApspQZyJXuyR5SZ9NjT6hAY 5xj011TgScgneeJuew7l9WOmKOF0nZc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=LWOACRw+; spf=pass (imf14.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=1730051851; 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=EjvE5ECkO4a4IWIH2md5SXeAC7aZ8rGsxgHC6JRzPsc=; b=w+KdMq9mUIm5YulPxUD8lHCNIPw4C++NSarQUzbeHDzifiENcMnlokHHdcElMjp8Gjhx1x H2PreGE9WmXDG2SvdM1E6064ybY4tOvZZWYoi8qsa3djPK0oAIDKGlsjNPSY6m6L//EGyq 4rIQXPdHcwhaM7sgbcYcqdkgO0xtYlA= 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=EjvE5ECkO4a4IWIH2md5SXeAC7aZ8rGsxgHC6JRzPsc=; b=LWOACRw+dPktdCnjBVPNnav3wG J412nBd0B+W3uFXYRYz5YMfapM74Y+LsSfRSbsb1J0iKD+9MlPz/bJT71PTbbaN0oIS+57F4drsed IHASrgssG6FW3L2dR1Zle2wbESYJneUhGRsWbjgWvXVa0dIDIH6ueDJ1D0di1VYcDMQ6ssKtk9Xx6 QLZOHz+6NdPIDz57IsedMvnSginavJhCTEa/jJVF6rjGAqMBqIvJuScPDp88UCVwO0CFiQ92mVsE+ D4bs1vZDGXa/91LPiT3Y87ft+OUv6JU1u9Km17P5zrXoGboGG5GIuP8lWss4AZ+ZdeLPGkkWTwjOt +t2o+55g==; 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 1t57X9-00Fn6f-UU; Sun, 27 Oct 2024 18:58:36 +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 3/3] mm: shmem: override mTHP shmem default with a kernel parameter Date: Sun, 27 Oct 2024 14:36:39 -0300 Message-ID: <20241027175743.1056710-4-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241027175743.1056710-1-mcanal@igalia.com> References: <20241027175743.1056710-1-mcanal@igalia.com> MIME-Version: 1.0 X-Stat-Signature: f6rg4impi6ga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pCp96/oo 3y0VULqsG380fPSQn+fUNNtj3PEX+toau3AJ0E+GggRrd3wAI7JhlbI3e/ms0vRpkbz2aaMb1gcfI50AT5hn541lYDcWW9JE64n0vb6hupVs0/TNhCI8BI0hvbua4uLwA6pUvXWwv+uGTN/m/tr5/cLP2kDfE2C7eP2qTtbx+bMiZrkavIvIkEX4+bljwrul2riFd9HTGfurKJTMLk60y1kvSxq3RwvOsoCUcVNIaksDvau1s1b/pRARnDfQX01lM/3YBItqjHJagQ/d5nnnM96mXH0vpJ7Y//nqW00GX8B2OGrF9iyGOktRqjP7RplZTUKMRTA8i30CNx00= 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 huge pages, 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 | 109 +++++++++++++++++- 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index acabb04d0dd4..595fa096e28b 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. + shmem_anon= [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 24cdeafd8260..0a7a7d04f725 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 @@ -5013,7 +5014,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; @@ -5174,6 +5176,26 @@ struct kobj_attribute thpsize_shmem_enabled_attr = #if defined(CONFIG_TRANSPARENT_HUGEPAGE) +static inline int get_order_from_str(const char *size_str) +{ + unsigned long size; + char *endptr; + int order; + + size = memparse(size_str, &endptr); + + if (!is_power_of_2(size)) + goto err; + order = get_order(size); + if (BIT(order) & ~THP_ORDERS_ALL_FILE_DEFAULT) + goto err; + + return order; +err: + pr_err("invalid size %s in thp_shmem boot parameter\n", size_str); + return -EINVAL; +} + static int __init setup_transparent_hugepage_shmem(char *str) { int huge, ret = 0; @@ -5206,6 +5228,91 @@ 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) +{ + char *token, *range, *policy, *subtoken; + unsigned long always, inherit, madvise, within_size; + char *start_size, *end_size; + int start, end, nr; + char *p; + + if (!str || strlen(str) + 1 > PAGE_SIZE) + goto err; + strcpy(str_dup, str); + + always = huge_shmem_orders_always; + inherit = huge_shmem_orders_inherit; + madvise = huge_shmem_orders_madvise; + within_size = huge_shmem_orders_within_size; + p = str_dup; + while ((token = strsep(&p, ";")) != NULL) { + range = strsep(&token, ":"); + policy = token; + + if (!policy) + goto err; + + while ((subtoken = strsep(&range, ",")) != NULL) { + if (strchr(subtoken, '-')) { + start_size = strsep(&subtoken, "-"); + end_size = subtoken; + + start = get_order_from_str(start_size); + end = get_order_from_str(end_size); + } else { + start = end = get_order_from_str(subtoken); + } + + if (start < 0 || end < 0 || start > end) + goto err; + + nr = end - start + 1; + if (!strcmp(policy, "always")) { + bitmap_set(&always, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "advise")) { + bitmap_set(&madvise, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "inherit")) { + bitmap_set(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "within_size")) { + bitmap_set(&within_size, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + } else if (!strcmp(policy, "never")) { + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else { + pr_err("invalid policy %s in thp_shmem boot parameter\n", policy); + goto err; + } + } + } + + huge_shmem_orders_always = always; + huge_shmem_orders_madvise = madvise; + huge_shmem_orders_inherit = inherit; + huge_shmem_orders_within_size = within_size; + 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 */