From nobody Sun Nov 24 22:37:20 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A46121CBE82; Fri, 1 Nov 2024 16:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730479457; cv=none; b=Q/QW5+vlkormH2P8dQtEMT5h9eTaNbEyW0aoc/aH4xr+EDzu3xqWGsPeQMOxlYMAYj+LJKQQDqQ+6EoTu7pA/awpSu/3F+WaeVZLgQeqtdkermfM2J80RPJv/039SqWy+3HBFc5QZ9ToMdCSiuS0NOL+71hE2hM81d5OcnDBg1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730479457; c=relaxed/simple; bh=rSE9zcJLkMMGgws1yEaZNTSWmvxFHcQmfXpDGn/u1GA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RKVnxJG85V453ivlTlvbkQIVrLt4Qs3JDIZ35PLXd00Md4RDByZADmhpzyPDSzySL8iQ/djWugq6Dq5eN9BuSiL54tsTwnDF9Nm2cGiNtpQzqneUDkjpUWrNXeLG3HqfCsfyt4qTGvnxg3lyLws4b5eRRKW9MniSis+5woqkrpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=qiA7Eq/b; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="qiA7Eq/b" 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=20Canal?= 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=20Canal?= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=3D 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=C3=ADra 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/Documentatio= n/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. =20 + transparent_hugepage_shmem=3D [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=3D [KEYS] Format: This parameter identifies the trust source as a backend diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/adm= in-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``. =20 +Similarly to ``transparent_hugepage``, you can control the hugepage +allocation policy for the internal shmem mount by using the kernel paramet= er +``transparent_hugepage_shmem=3D``, where ```` is one of the +seven valid policies for shmem (``always``, ``within_size``, ``advise``, +``never``, ``deny``, and ``force``). + Hugepages in tmpfs/shmem =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 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 *i= node, pgoff_t index, } } =20 -#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 =3D SHMEM_HUGE_NEVER; + else if (!strcmp(str, "always")) + huge =3D SHMEM_HUGE_ALWAYS; + else if (!strcmp(str, "within_size")) + huge =3D SHMEM_HUGE_WITHIN_SIZE; + else if (!strcmp(str, "advise")) + huge =3D SHMEM_HUGE_ADVISE; + else if (!strcmp(str, "deny")) + huge =3D SHMEM_HUGE_DENY; + else if (!strcmp(str, "force")) + huge =3D SHMEM_HUGE_FORCE; + else + return -EINVAL; + + if (!has_transparent_hugepage() && + huge !=3D SHMEM_HUGE_NEVER && huge !=3D SHMEM_HUGE_DENY) + return -EINVAL; + + /* Do not override huge allocation policy with non-PMD sized mTHP */ + if (huge =3D=3D SHMEM_HUGE_FORCE && + huge_shmem_orders_inherit !=3D BIT(HPAGE_PMD_ORDER)) + return -EINVAL; + + return huge; } -#endif =20 #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 *k= obj, =20 huge =3D shmem_parse_huge(tmp); if (huge =3D=3D -EINVAL) - return -EINVAL; - if (!has_transparent_hugepage() && - huge !=3D SHMEM_HUGE_NEVER && huge !=3D SHMEM_HUGE_DENY) - return -EINVAL; - - /* Do not override huge allocation policy with non-PMD sized mTHP */ - if (huge =3D=3D SHMEM_HUGE_FORCE && - huge_shmem_orders_inherit !=3D BIT(HPAGE_PMD_ORDER)) - return -EINVAL; + return huge; =20 shmem_huge =3D huge; if (shmem_huge > SHMEM_HUGE_DENY) @@ -5171,6 +5178,25 @@ struct kobj_attribute thpsize_shmem_enabled_attr =3D __ATTR(shmem_enabled, 0644, thpsize_shmem_enabled_show, thpsize_shmem_ena= bled_store); #endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */ =20 +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) + +static int __init setup_transparent_hugepage_shmem(char *str) +{ + int huge; + + huge =3D shmem_parse_huge(str); + if (huge =3D=3D -EINVAL) { + pr_warn("transparent_hugepage_shmem=3D cannot parse, ignored\n"); + return huge; + } + + shmem_huge =3D huge; + return 1; +} +__setup("transparent_hugepage_shmem=3D", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ =20 /* --=20 2.46.2