From mboxrd@z Thu Jan 1 00:00:00 1970 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 E7C6FD5B852 for ; Tue, 29 Oct 2024 00:24:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 221656B00BF; Mon, 28 Oct 2024 20:24:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A4438D0006; Mon, 28 Oct 2024 20:24:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F155A8D0003; Mon, 28 Oct 2024 20:24:12 -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 C8A746B00BF for ; Mon, 28 Oct 2024 20:24:12 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 80087AC0BC for ; Tue, 29 Oct 2024 00:24:12 +0000 (UTC) X-FDA: 82724741106.17.5B96EC6 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf01.hostedemail.com (Postfix) with ESMTP id F0B5240004 for ; Tue, 29 Oct 2024 00:23:51 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=bTdXTTpk; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf01.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=1730161334; a=rsa-sha256; cv=none; b=koKIFGQowIdA6+dL4Vk+vsugXG4vMVfSod0oDOHUlDzw24nEygBOYmd/ZCiajxX75dG3LM A5Mc/K5hzaB/eFB/zkSCohrTNOr7xx/5KBP0Lk1kkg8Aus/iAyapMTj2UA+aWkEIfC6r5R KjlSxMwJAExx8vbvc0zzs8uPSplni8k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=bTdXTTpk; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf01.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=1730161334; 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=f8gjxek9e09f6K3wtJdNM5s9pyafMNTnPC2fusopxIU=; b=Yz7sQppd+e7iNUkC9L5XlHHcCoT2E1b1gtz1doUYVgqYyNulfHusw76W4WK2gIY9QLaaQg O2f8ZqNrtzl8HjjzO+g43ZPDQKEzbzRRiHn/S3LuCYZMHUSfnf8K54PghjOXCndjYroS0e XFInr4BmKnPOkNu5BbvbiJL6e4jH4NA= 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=f8gjxek9e09f6K3wtJdNM5s9pyafMNTnPC2fusopxIU=; b=bTdXTTpkXCmQP+P7vIFB9/gVW5 q6pgvxDrtE0mWPVomEbGVstuXNZsRkNV9ZEFtTqYfYuGDSRsXA9Pgx0FLw7D770Qi0mSaxnkqeXM+ RLbnLEuYpUUxQe5JQ6Bf99l/dCpjqnCgEl+AS1FOpqj2/+ihN6K1jjf+q8hVMB25f1ni71wDtz4/1 cmiqN7ToZQCDuSjpsQ3xSnSeBUdV+faRG6Jy09C1DdxOLAgUOlC5HLpNxDZB+VUncT0p+MFUgtEmB uN6wWULCJjf+7D03vrK3hGIXYdTC9lg/9yt0Pr278kRwmWREl6D+JAKJBjVa23jE3Ec79yFI/sheN XJAAHk7Q==; 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 1t5a1a-00GIrd-1C; Tue, 29 Oct 2024 01:23:54 +0100 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= 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=20Canal?= Subject: [PATCH v2 2/4] mm: shmem: control THP support through the kernel command line Date: Mon, 28 Oct 2024 21:13:06 -0300 Message-ID: <20241029002324.1062723-3-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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F0B5240004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oh9zbdyek9hoea7k1k7goozqszer9uaw X-HE-Tag: 1730161431-105119 X-HE-Meta: U2FsdGVkX1+aMENKUiZ7U8UXDAazYOizjkRsC+SyborqxndI9opueo9pWgrxhAOKCeTBJ88uDjSRl309qu/h9bZOgwCD4I+JbKyFAVHxkY36A+dLLOVJrbYgJUWCV5ByXrtPnq+FDNJ+R2/AZewNRkSN0h/q31X+WpqDI+FMlG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WYqUG1f+Jdz9kbxR02cu5AEY76O3dAY1bUJD/RdFTmtGfsIYLnLQt2aeSzg03J7DiOySzT8ksfkTz91VoTeZ+YkU= 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 | 53 +++++++++++++++---- 3 files changed, 57 insertions(+), 9 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..26c1eb1b4b1d 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) @@ -624,6 +622,20 @@ static const char *shmem_format_huge(int huge) } #endif +static int shmem_valid_huge(int huge) +{ + if (!has_transparent_hugepage() && + huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) + return -EINVAL; + + /* Do not override huge allocation policy with non-PMD sized mTHP */ + if (huge == SHMEM_HUGE_FORCE && + huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) + return -EINVAL; + + return 0; +} + static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, struct shrink_control *sc, unsigned long nr_to_free) { @@ -5070,14 +5082,10 @@ static ssize_t shmem_enabled_store(struct kobject *kobj, huge = shmem_parse_huge(tmp); if (huge == -EINVAL) return -EINVAL; - if (!has_transparent_hugepage() && - huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) - return -EINVAL; - /* Do not override huge allocation policy with non-PMD sized mTHP */ - if (huge == SHMEM_HUGE_FORCE && - huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) - return -EINVAL; + err = shmem_valid_huge(huge); + if (err) + return err; shmem_huge = huge; if (shmem_huge > SHMEM_HUGE_DENY) @@ -5174,6 +5182,33 @@ 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; + + ret = shmem_valid_huge(huge); + if (ret) + 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 */ /* -- 2.46.2