From patchwork Fri Nov 1 16:38:43 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: 13859597 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 0AEA9E6F06C for ; Fri, 1 Nov 2024 16:44:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 961AB6B007B; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EB106B0098; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78B6D6B0099; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5B1B96B007B for ; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 18BE81C6C11 for ; Fri, 1 Nov 2024 16:44:15 +0000 (UTC) X-FDA: 82738097988.30.A4D125A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id C1A9280010 for ; Fri, 1 Nov 2024 16:43:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="qiA7Eq/b"; 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=1730479371; 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=O29dCXx+phviG21mQhq8obCWSt3spMP5spSqVzL91xU=; b=bXwgm/jSDTpE9I+2mFT7TuPEr+yEX6ONKQIxzHmjeqD1+2BJnMaq5H7BViGI0JVZBln/DL 2jyLh75KPu08Op0skcS553rf5Hh3j+fT4n+uggmIpeaQSM5qLmWRQT19eFP/bodj93ndhS EzFDFo4WrCtICLAwV1iBJ3Bv3L5Oets= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730479371; a=rsa-sha256; cv=none; b=R0xoe/FdyFgTqVSlqF0JclgeMN73ZygxCzwIiYFTXQNxPV+F0/r93iK2GEEpVe20isQFJj tVEMFyYU4I4qtQq8VprwOhV27DLT7QFukNok0GEf5Q1xGxYp6rdpbTmuDUpruxOjbmU1tB teraM28cUF1PPhnv73wYhwZhFFkBkrE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="qiA7Eq/b"; 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 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=O29dCXx+phviG21mQhq8obCWSt3spMP5spSqVzL91xU=; b=qiA7Eq/bD8O0eblUzP9hCRlr5a NsvTgI4r510BprM4uej05UY3od4QuFC/TCQpye+vDEnlnoS4eE8AyoHopD+npkMNo9uVXhTKo9198 +t7CUNvWlZ6G8Ypmxofvy3AqEanBfK81C6JiY51aiE1UPBYBhH/AMnski9wojybXzO57s0xv9xG3c t9tNJDhkZNnZmlUC90Jm8PvZuFQl5RaD3w7G6uMf25KzIB9rPHnBGAZc+BQqYZDy8CuULIXng0c8I BOXJoaB7aTIgGEKJW5/xNaHN2ZQEdmg4kkYWIFP7Jm3+24hOMsX0GOhDjKZLAM71lvWH7QZtyUS0Z 9xjc5yPQ==; 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 1t6ukl-000V38-VM; Fri, 01 Nov 2024 17:44: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, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v4 2/5] mm: shmem: control THP support through the kernel command line Date: Fri, 1 Nov 2024 13:38:43 -0300 Message-ID: <20241101164313.1073238-4-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101164313.1073238-2-mcanal@igalia.com> References: <20241101164313.1073238-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: 3hjdgsfydk31mbttzj7ezm1y1ghs9ozt X-Rspamd-Queue-Id: C1A9280010 X-Rspam-User: X-HE-Tag: 1730479399-721988 X-HE-Meta: U2FsdGVkX1+HQik4xkQ+pu91hsq9jhwVH86yLW8CmV34KTw8eLsIXEA34IVMKfrXcRh6Db1Jo5563ttdaSzRWUWEOqMNr75wq5VCdZ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buzIYoLTQU0NhWvtlPLz53CsBF/Yy0jtlvDwVPMPAv5HraSKGt8p/hi+Ua6fAfKYGHLF+yrraQi/rB2FBSBFu4OAymhKA07WEi2SP838C45WVbF++Oa0NwdGANrOqHbqu3GH7ONMk9sv/plfyzHZxege+5GMa3eCJPD6RXW6TaqHjLj0fhSWO7gcOMOi1c0Dynl8RGYmEMi4u4DI 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. Configuring the default huge page allocation policy for the internal shmem mount can be beneficial for DRM GPU drivers. Just as CPU architectures, GPUs can also take advantage of huge pages, but this is possible only if DRM GEM objects are backed by huge pages. Since GEM uses shmem to allocate anonymous pageable memory, having control over the default huge page allocation policy allows for the exploration of huge pages use on GPUs that rely on GEM objects backed by shmem. Signed-off-by: MaĆ­ra Canal Reviewed-by: Baolin Wang Acked-by: David Hildenbrand --- .../admin-guide/kernel-parameters.txt | 7 ++ Documentation/admin-guide/mm/transhuge.rst | 6 ++ mm/shmem.c | 72 +++++++++++++------ 3 files changed, 62 insertions(+), 23 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 abdf10a1c7db..9c6f6da612c4 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 275251abd596..dfcc88ec6e34 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -582,24 +582,39 @@ static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, } } -#if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { + int huge; + + if (!str) + return -EINVAL; + if (!strcmp(str, "never")) - return SHMEM_HUGE_NEVER; - if (!strcmp(str, "always")) - return SHMEM_HUGE_ALWAYS; - if (!strcmp(str, "within_size")) - return SHMEM_HUGE_WITHIN_SIZE; - if (!strcmp(str, "advise")) - return SHMEM_HUGE_ADVISE; - if (!strcmp(str, "deny")) - return SHMEM_HUGE_DENY; - if (!strcmp(str, "force")) - return SHMEM_HUGE_FORCE; - return -EINVAL; + huge = SHMEM_HUGE_NEVER; + else if (!strcmp(str, "always")) + huge = SHMEM_HUGE_ALWAYS; + else if (!strcmp(str, "within_size")) + huge = SHMEM_HUGE_WITHIN_SIZE; + else if (!strcmp(str, "advise")) + huge = SHMEM_HUGE_ADVISE; + else if (!strcmp(str, "deny")) + huge = SHMEM_HUGE_DENY; + else if (!strcmp(str, "force")) + huge = SHMEM_HUGE_FORCE; + else + 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; + + return huge; } -#endif #if defined(CONFIG_SYSFS) || defined(CONFIG_TMPFS) static const char *shmem_format_huge(int huge) @@ -5066,15 +5081,7 @@ 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; + return huge; shmem_huge = huge; if (shmem_huge > SHMEM_HUGE_DENY) @@ -5171,6 +5178,25 @@ 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; + + huge = shmem_parse_huge(str); + if (huge == -EINVAL) { + pr_warn("transparent_hugepage_shmem= cannot parse, ignored\n"); + return huge; + } + + shmem_huge = huge; + return 1; +} +__setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ /*