blob: 134e188ae65f08714d0f191d66de8adc00d2fbd6 [file] [log] [blame]
From: Ryan Roberts <ryan.roberts@arm.com>
Subject: mm: override mTHP "enabled" defaults at kernel cmdline
Date: Tue, 20 Aug 2024 22:52:44 +1200
some minor cleanup according to David's comments
Link: https://lkml.kernel.org/r/20240820105244.62703-1-21cnbao@gmail.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Co-developed-by: Barry Song <v-songbaohua@oppo.com>
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Tested-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Lance Yang <ioworker0@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
Documentation/admin-guide/kernel-parameters.txt | 4 -
Documentation/admin-guide/mm/transhuge.rst | 5 +
mm/huge_memory.c | 41 ++++++--------
3 files changed, 25 insertions(+), 25 deletions(-)
--- a/Documentation/admin-guide/kernel-parameters.txt~mm-override-mthp-enabled-defaults-at-kernel-cmdline-v6
+++ a/Documentation/admin-guide/kernel-parameters.txt
@@ -6632,8 +6632,8 @@
thp_anon= [KNL]
Format: <size>,<size>[KMG]:<state>;<size>-<size>[KMG]:<state>
state is one of "always", "madvise", "never" or "inherit".
- Can be used to control the default behavior of the
- system with respect to anonymous transparent hugepages.
+ Control the default behavior of the system with respect
+ to anonymous transparent hugepages.
Can be used multiple times for multiple anon THP sizes.
See Documentation/admin-guide/mm/transhuge.rst for more
details.
--- a/Documentation/admin-guide/mm/transhuge.rst~mm-override-mthp-enabled-defaults-at-kernel-cmdline-v6
+++ a/Documentation/admin-guide/mm/transhuge.rst
@@ -294,8 +294,9 @@ kernel command line.
Alternatively, each supported anonymous THP size can be controlled by
passing ``thp_anon=<size>,<size>[KMG]:<state>;<size>-<size>[KMG]:<state>``,
-where ``<size>`` is the THP size and ``<state>`` is one of ``always``,
-``madvise``, ``never`` or ``inherit``.
+where ``<size>`` is the THP size (must be a power of 2 of PAGE_SIZE and
+supported anonymous THP) and ``<state>`` is one of ``always``, ``madvise``,
+``never`` or ``inherit``.
For example, the following will set 16K, 32K, 64K THP to ``always``,
set 128K, 512K to ``inherit``, set 256K to ``madvise`` and 1M, 2M
--- a/mm/huge_memory.c~mm-override-mthp-enabled-defaults-at-kernel-cmdline-v6
+++ a/mm/huge_memory.c
@@ -81,7 +81,7 @@ unsigned long huge_zero_pfn __read_mostl
unsigned long huge_anon_orders_always __read_mostly;
unsigned long huge_anon_orders_madvise __read_mostly;
unsigned long huge_anon_orders_inherit __read_mostly;
-static bool anon_orders_configured;
+static bool anon_orders_configured __initdata;
unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
unsigned long vm_flags,
@@ -734,10 +734,8 @@ static int __init hugepage_init_sysfs(st
* disable all other sizes. powerpc's PMD_ORDER isn't a compile-time
* constant so we have to do this here.
*/
- if (!anon_orders_configured) {
+ if (!anon_orders_configured)
huge_anon_orders_inherit = BIT(PMD_ORDER);
- anon_orders_configured = true;
- }
*hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj);
if (unlikely(!*hugepage_kobj)) {
@@ -930,10 +928,10 @@ static inline int get_order_from_str(con
size = memparse(size_str, &endptr);
- if (!is_power_of_2(size >> PAGE_SHIFT))
+ if (!is_power_of_2(size))
goto err;
order = get_order(size);
- if ((1 << order) & ~THP_ORDERS_ALL_ANON)
+ if (BIT(order) & ~THP_ORDERS_ALL_ANON)
goto err;
return order;
@@ -942,13 +940,13 @@ err:
return -EINVAL;
}
-static char str_dup[PAGE_SIZE] __meminitdata;
+static char str_dup[PAGE_SIZE] __initdata;
static int __init setup_thp_anon(char *str)
{
char *token, *range, *policy, *subtoken;
unsigned long always, inherit, madvise;
char *start_size, *end_size;
- int start, end;
+ int start, end, nr;
char *p;
if (!str || strlen(str) + 1 > PAGE_SIZE)
@@ -980,22 +978,23 @@ static int __init setup_thp_anon(char *s
if (start < 0 || end < 0 || start > end)
goto err;
+ nr = end - start + 1;
if (!strcmp(policy, "always")) {
- bitmap_set(&always, start, end - start + 1);
- bitmap_clear(&inherit, start, end - start + 1);
- bitmap_clear(&madvise, start, end - start + 1);
+ bitmap_set(&always, start, nr);
+ bitmap_clear(&inherit, start, nr);
+ bitmap_clear(&madvise, start, nr);
} else if (!strcmp(policy, "madvise")) {
- bitmap_set(&madvise, start, end - start + 1);
- bitmap_clear(&inherit, start, end - start + 1);
- bitmap_clear(&always, start, end - start + 1);
+ bitmap_set(&madvise, start, nr);
+ bitmap_clear(&inherit, start, nr);
+ bitmap_clear(&always, start, nr);
} else if (!strcmp(policy, "inherit")) {
- bitmap_set(&inherit, start, end - start + 1);
- bitmap_clear(&madvise, start, end - start + 1);
- bitmap_clear(&always, start, end - start + 1);
+ bitmap_set(&inherit, start, nr);
+ bitmap_clear(&madvise, start, nr);
+ bitmap_clear(&always, start, nr);
} else if (!strcmp(policy, "never")) {
- bitmap_clear(&inherit, start, end - start + 1);
- bitmap_clear(&madvise, start, end - start + 1);
- bitmap_clear(&always, start, end - start + 1);
+ bitmap_clear(&inherit, start, nr);
+ bitmap_clear(&madvise, start, nr);
+ bitmap_clear(&always, start, nr);
} else {
pr_err("invalid policy %s in thp_anon boot parameter\n", policy);
goto err;
@@ -1010,7 +1009,7 @@ static int __init setup_thp_anon(char *s
return 1;
err:
- pr_warn("thp_anon=%s: cannot parse, ignored\n", str);
+ pr_warn("thp_anon=%s: error parsing string, ignoring setting\n", str);
return 0;
}
__setup("thp_anon=", setup_thp_anon);
_