From nobody Mon Nov 25 13:13:36 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 4F7A316ABC6; 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=K7wRsuTPNlbZmWrZ6JNLk9x+IhSlWejqYG3pLKAb8PpKiB0lzyqZrUQXHcXs1C2cn24wVWmqVw2oVFen89JZBkiRpPEOuuTf6SkAWgPo3gzE0YMYj7pUAbGuCs4JTvROjxD3BPGFXqZ3OYRoZ70kQBccx4kzuFMxrFsJr2a6lS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730051934; c=relaxed/simple; bh=sK0a+a4wJciNwlB8+OTYdvkTBIYhNad+chd+XQzh5YQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nAFXR79vcIvftwjPebH5E5NTwA5ZoEyK8IqI9Mjh7JH43okIUWq5xaB3Pfx6A6GtOOFgbWbRgqfce5DoMTr7Y7ErDwoEU74pkbQXHBFmxy0BrunHJ6MNFN/82opQTLbLRLC4Ih4BJyuYRsaMu7q+Eemfml1uOndqofKZ4wbJIiA= 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=AWGsfkbf; 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="AWGsfkbf" 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=7HBELsvSiP+CccX0d5orY/4TAyEDWFWAwNxu03tnWpk=; b=AWGsfkbfnZzKYEA5W0gFbtsOmv sfwFfpwdBF2FXih87naNogfmWnfyrfoWY9IAahCrgeJXO9yd5ho08XdIVQ2CHZ1VzLagSOm2Q0q/+ IhPa0/clDwwDKWoQbdL8IgdEVO+64eN4fgl2nOV2UZS1ohS1gZt1OMw7sdn1qdZpWu8unrmTDu/Pk A972Oq7X+LIC3umUq5viUKIgJf8wKFitNSCXqtTfcmfhY/i7kMs8m5U0iPUqq4uilm9C0J1YPTgk8 S288Ll88BlrXWVAmAcZYpHfwhnXexb3tzlAAdkeq+JAnn9D0G7MWKyeTnBn+ogDz8v/2akbuu1fr8 gqJVXuUQ==; 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 1t57Wz-00Fn6f-M7; Sun, 27 Oct 2024 18:58:26 +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 1/3] mm: fix the format of the kernel parameter ``thp_anon=`` Date: Sun, 27 Oct 2024 14:36:37 -0300 Message-ID: <20241027175743.1056710-2-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 If we add ``thp_anon=3D32,64KB:always`` to the kernel command line, we will see the following error: [ 0.000000] huge_memory: thp_anon=3D32,64K:always: error parsing string,= ignoring setting This happens because the correct format isn't ``thp_anon=3D,[KM= G]:```, as [KMG] must follow each number to especify its unit. So, the correct format is ``thp_anon=3D[KMG],[KMG]:```. Therefore, adjust the documentation to reflect the correct format of the parameter ``thp_anon=3D``. Fixes: dd4d30d1cdbe ("mm: override mTHP "enabled" defaults at kernel cmdlin= e") Signed-off-by: Ma=C3=ADra Canal Acked-by: Barry Song Acked-by: David Hildenbrand --- Documentation/admin-guide/kernel-parameters.txt | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 1518343bbe22..1666576acc0e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6688,7 +6688,7 @@ 0: no polling (default) =20 thp_anon=3D [KNL] - Format: ,[KMG]:;-[KMG]: + Format: [KMG],[KMG]:;[KMG]-[KMG]: state is one of "always", "madvise", "never" or "inherit". Control the default behavior of the system with respect to anonymous transparent hugepages. diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/adm= in-guide/mm/transhuge.rst index 203ba7aaf5fc..745055c3dc09 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -303,7 +303,7 @@ control by passing the parameter ``transparent_hugepage= =3Dalways`` or kernel command line. =20 Alternatively, each supported anonymous THP size can be controlled by -passing ``thp_anon=3D,[KMG]:;-[KMG]:= ``, +passing ``thp_anon=3D[KMG],[KMG]:;[KMG]-[KM= G]:``, where ```` is the THP size (must be a power of 2 of PAGE_SIZE and supported anonymous THP) and ```` is one of ``always``, ``madvise`= `, ``never`` or ``inherit``. --=20 2.46.2 From nobody Mon Nov 25 13:13:36 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 From nobody Mon Nov 25 13:13:36 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 8C44917C213; Sun, 27 Oct 2024 17:58:56 +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=1730051939; cv=none; b=ae5OOZSenWAGYeofoR/e0vMRprw1I1lqb0MQzQI7ZzlbloLxAm5LwgW9FmHv/boVYc62DQb4zKpB/J6yaeROQz/YHOntkwpqk4kiPmPvxuD3R0ML8uIwTQtz+HhPLy18hstbHF4ffjgLrfCbDBvVyIB8NNme2CYmDfa09+EEqCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730051939; c=relaxed/simple; bh=ZG1FfEjGllD/phuvR3uOMeVGzSPc7fDfEJoiaGQStYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YYUAJVx1cums525qoACqha2zQWj6FkB9nEOO9yniJWt76K3vjugTxqctC4ykau0mSn+5TuxhZ3WS6S+exjsHHF3Nuziwy3e5EXs0dS04/6H1ikx01BdaH3+sOXUpTtYbgKIIHEWQ+9ZwVAy7Uyh2mdWurqhEXQFbEffvYrzBagE= 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=LWOACRw+; 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="LWOACRw+" 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=EjvE5ECkO4a4IWIH2md5SXeAC7aZ8rGsxgHC6JRzPsc=; b=LWOACRw+dPktdCnjBVPNnav3wG J412nBd0B+W3uFXYRYz5YMfapM74Y+LsSfRSbsb1J0iKD+9MlPz/bJT71PTbbaN0oIS+57F4drsed IHASrgssG6FW3L2dR1Zle2wbESYJneUhGRsWbjgWvXVa0dIDIH6ueDJ1D0di1VYcDMQ6ssKtk9Xx6 QLZOHz+6NdPIDz57IsedMvnSginavJhCTEa/jJVF6rjGAqMBqIvJuScPDp88UCVwO0CFiQ92mVsE+ D4bs1vZDGXa/91LPiT3Y87ft+OUv6JU1u9Km17P5zrXoGboGG5GIuP8lWss4AZ+ZdeLPGkkWTwjOt +t2o+55g==; 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 1t57X9-00Fn6f-UU; Sun, 27 Oct 2024 18:58:36 +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 3/3] mm: shmem: override mTHP shmem default with a kernel parameter Date: Sun, 27 Oct 2024 14:36:39 -0300 Message-ID: <20241027175743.1056710-4-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 the ``thp_shmem=3D`` kernel command line to allow specifying the default policy of each supported shmem hugepage size. The kernel parameter accepts the following format: thp_shmem=3D[KMG],[KMG]:;[KMG]-[KMG]: For example, thp_shmem=3D16K-64K:always;128K,512K:inherit;256K:advise;1M-2M:never;4M-8M:= within_size By configuring the default policy of several shmem huge pages, the user can take advantage of mTHP before it's been configured through sysfs. Signed-off-by: Ma=C3=ADra Canal --- .../admin-guide/kernel-parameters.txt | 10 ++ Documentation/admin-guide/mm/transhuge.rst | 17 +++ mm/shmem.c | 109 +++++++++++++++++- 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index acabb04d0dd4..595fa096e28b 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6700,6 +6700,16 @@ Force threading of all interrupt handlers except those marked explicitly IRQF_NO_THREAD. =20 + shmem_anon=3D [KNL] + Format: [KMG],[KMG]:;[KMG]-[KMG]: + Control the default policy of each hugepage size for the + internal shmem mount. is one of policies available + for the shmem mount ("always", "inherit", "never", "within_size", + and "advise"). + It can be used multiple times for multiple shmem THP sizes. + See Documentation/admin-guide/mm/transhuge.rst for more + details. + topology=3D [S390,EARLY] Format: {off | on} Specify if the kernel should make use of the cpu diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/adm= in-guide/mm/transhuge.rst index 9b5b02c4d1ab..47e7fc30e22d 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -332,6 +332,23 @@ allocation policy for the internal shmem mount by usin= g the kernel parameter seven valid policies for shmem (``always``, ``within_size``, ``advise``, ``never``, ``deny``, and ``force``). =20 +In the same manner as ``thp_anon`` controls each supported anonymous THP +size, ``thp_shmem`` controls each supported shmem THP size. ``thp_shmem`` +has the same format as ``thp_anon``, but also supports the policy +``within_size``. + +``thp_shmem=3D`` may be specified multiple times to configure all THP sizes +as required. If ``thp_shmem=3D`` is specified at least once, any shmem THP +sizes not explicitly configured on the command line are implicitly set to +``never``. + +``transparent_hugepage_shmem`` setting only affects the global toggle. If +``thp_shmem`` is not specified, PMD_ORDER hugepage will default to +``inherit``. However, if a valid ``thp_shmem`` setting is provided by the +user, the PMD_ORDER hugepage policy will be overridden. If the policy for +PMD_ORDER is not defined within a valid ``thp_shmem``, its policy will +default to ``never``. + 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 24cdeafd8260..0a7a7d04f725 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -136,6 +136,7 @@ static unsigned long huge_shmem_orders_always __read_mo= stly; static unsigned long huge_shmem_orders_madvise __read_mostly; static unsigned long huge_shmem_orders_inherit __read_mostly; static unsigned long huge_shmem_orders_within_size __read_mostly; +static bool shmem_orders_configured __initdata; #endif =20 #ifdef CONFIG_TMPFS @@ -5013,7 +5014,8 @@ void __init shmem_init(void) * Default to setting PMD-sized THP to inherit the global setting and * disable all other multi-size THPs. */ - huge_shmem_orders_inherit =3D BIT(HPAGE_PMD_ORDER); + if (!shmem_orders_configured) + huge_shmem_orders_inherit =3D BIT(HPAGE_PMD_ORDER); #endif return; =20 @@ -5174,6 +5176,26 @@ struct kobj_attribute thpsize_shmem_enabled_attr =3D =20 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) =20 +static inline int get_order_from_str(const char *size_str) +{ + unsigned long size; + char *endptr; + int order; + + size =3D memparse(size_str, &endptr); + + if (!is_power_of_2(size)) + goto err; + order =3D get_order(size); + if (BIT(order) & ~THP_ORDERS_ALL_FILE_DEFAULT) + goto err; + + return order; +err: + pr_err("invalid size %s in thp_shmem boot parameter\n", size_str); + return -EINVAL; +} + static int __init setup_transparent_hugepage_shmem(char *str) { int huge, ret =3D 0; @@ -5206,6 +5228,91 @@ static int __init setup_transparent_hugepage_shmem(c= har *str) } __setup("transparent_hugepage_shmem=3D", setup_transparent_hugepage_shmem); =20 +static char str_dup[PAGE_SIZE] __initdata; +static int __init setup_thp_shmem(char *str) +{ + char *token, *range, *policy, *subtoken; + unsigned long always, inherit, madvise, within_size; + char *start_size, *end_size; + int start, end, nr; + char *p; + + if (!str || strlen(str) + 1 > PAGE_SIZE) + goto err; + strcpy(str_dup, str); + + always =3D huge_shmem_orders_always; + inherit =3D huge_shmem_orders_inherit; + madvise =3D huge_shmem_orders_madvise; + within_size =3D huge_shmem_orders_within_size; + p =3D str_dup; + while ((token =3D strsep(&p, ";")) !=3D NULL) { + range =3D strsep(&token, ":"); + policy =3D token; + + if (!policy) + goto err; + + while ((subtoken =3D strsep(&range, ",")) !=3D NULL) { + if (strchr(subtoken, '-')) { + start_size =3D strsep(&subtoken, "-"); + end_size =3D subtoken; + + start =3D get_order_from_str(start_size); + end =3D get_order_from_str(end_size); + } else { + start =3D end =3D get_order_from_str(subtoken); + } + + if (start < 0 || end < 0 || start > end) + goto err; + + nr =3D end - start + 1; + if (!strcmp(policy, "always")) { + bitmap_set(&always, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "advise")) { + bitmap_set(&madvise, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "inherit")) { + bitmap_set(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "within_size")) { + bitmap_set(&within_size, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + } else if (!strcmp(policy, "never")) { + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else { + pr_err("invalid policy %s in thp_shmem boot parameter\n", policy); + goto err; + } + } + } + + huge_shmem_orders_always =3D always; + huge_shmem_orders_madvise =3D madvise; + huge_shmem_orders_inherit =3D inherit; + huge_shmem_orders_within_size =3D within_size; + shmem_orders_configured =3D true; + return 1; + +err: + pr_warn("thp_shmem=3D%s: error parsing string, ignoring setting\n", str); + return 0; +} +__setup("thp_shmem=3D", setup_thp_shmem); + #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 #else /* !CONFIG_SHMEM */ --=20 2.46.2