From nobody Mon Nov 25 15:12:38 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 9FD0F175D4F; Sun, 27 Oct 2024 17:58:52 +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=1730051934; cv=none; b=aNGiH2g10Of3P83lyXE+bjhdLMLWJkgRKRWTyqqDuLNbAFaeOy4ThLZqvHsDc3PCHmJs9qpQjK1x2wbRoJZipQ3K/qhcrcOaOoTeKRSBwM02+suVus/44HYfkl0OQjUDmpJQstmT4Hyy3adHLx3A6OBKbgslRM6hPwy+pxd97wA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730051934; c=relaxed/simple; bh=bRg6shcWqEOstF2hMiJcSwnLDYtqQDduaMntp/XBHYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UyG0Q5jBZhal6buzVIT6RpOwhHhPJy4oiowU6qtD2L7OZr23hJzedjyldnn4+UrGQW8dGKNukYAFU9b3/f1K0Cosr9H2nvw+1p6ywkD1/9mB2IMryWiTTiU8uEDnpMgAU6CPZ+cBtnUZsenIl8i2PXRZEZXRKFnLteVlat2sebw= 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=WgHTtphI; 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="WgHTtphI" 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=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 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> 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. 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=C3=ADra 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/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 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``. =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 44282a296c33..24cdeafd8260 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -582,7 +582,6 @@ static bool shmem_huge_global_enabled(struct inode *ino= de, pgoff_t index, } } =20 -#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 =20 #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 =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, ret =3D 0; + + if (!str) + goto out; + + huge =3D shmem_parse_huge(str); + if (huge =3D=3D -EINVAL) + goto out; + + if (!has_transparent_hugepage() && + huge !=3D SHMEM_HUGE_NEVER && huge !=3D SHMEM_HUGE_DENY) { + ret =3D -EINVAL; + goto out; + } + + /* 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)) { + ret =3D -EINVAL; + goto out; + } + + shmem_huge =3D huge; + return 1; +out: + pr_warn("transparent_hugepage_shmem=3D cannot parse, ignored\n"); + return ret; +} +__setup("transparent_hugepage_shmem=3D", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ =20 /* --=20 2.46.2