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-Stat-Signature: 8ybis7xszeyzsf8eqsd44sg4yxocatmm X-Rspamd-Queue-Id: AB28840009 X-Rspamd-Server: rspam02 X-HE-Tag: 1730051915-56563 X-HE-Meta: U2FsdGVkX1+P1Yi4VOv0p87/ehpPNvvKybyEjCCddOAEc7MHjwlaiisoYKH40QwfSHgWceHT9SoPjsWZX2Fx+uD7KAOeFjnz5JdHVQce8s3q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rypfMwHpE9llp0lX48QnY/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 */ /*