1 From 4bbdd9335a4784743a5ac30697f24972219559c2 Mon Sep 17 00:00:00 2001
2 From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
3 Date: Wed, 22 May 2024 17:12:16 +0100
4 Subject: [PATCH 1340/1350] mm/numa: Allow override of kernel's default NUMA
7 Add numa_policy kernel argument to allow overriding the kernel's default
8 NUMA policy at boot time.
10 Syntax identical to what tmpfs accepts as it's mpol argument is accepted.
14 numa_policy=interleave
15 numa_policy=interleave=skip-interleave
16 numa_policy=bind:0-3,5,7,9-15
17 numa_policy=bind=static:1-2
19 Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
21 mm/mempolicy.c | 49 ++++++++++++++++++++++++++++++++++++++++++-------
22 1 file changed, 42 insertions(+), 7 deletions(-)
26 @@ -2963,7 +2963,9 @@ void __init numa_policy_init(void)
27 /* Reset policy of current process to default */
28 void numa_default_policy(void)
30 - do_set_mempolicy(MPOL_DEFAULT, 0, NULL);
31 + struct mempolicy *pol = &default_policy;
33 + do_set_mempolicy(pol->mode, pol->flags, &pol->nodes);
37 @@ -2981,7 +2983,6 @@ static const char * const policy_modes[]
43 * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option.
44 * @str: string containing mempolicy to parse
45 @@ -2994,13 +2995,18 @@ static const char * const policy_modes[]
47 int mpol_parse_str(char *str, struct mempolicy **mpol)
49 - struct mempolicy *new = NULL;
50 + struct mempolicy *new;
51 unsigned short mode_flags;
53 char *nodelist = strchr(str, ':');
54 char *flags = strchr(str, '=');
63 *flags++ = '\0'; /* terminate mode string */
65 @@ -3079,9 +3085,16 @@ int mpol_parse_str(char *str, struct mem
69 - new = mpol_new(mode, mode_flags, &nodes);
73 + new = mpol_new(mode, mode_flags, &nodes);
77 + atomic_set(&new->refcnt, 1);
79 + new->flags = mode_flags;
80 + new->home_node = NUMA_NO_NODE;
84 * Save nodes for mpol_to_str() to show the tmpfs mount options
85 @@ -3114,7 +3127,29 @@ out:
89 -#endif /* CONFIG_TMPFS */
91 +static int __init setup_numapolicy(char *str)
93 + struct mempolicy pol = { }, *ppol = &pol;
98 + ret = mpol_parse_str(str, &ppol);
103 + default_policy = pol;
104 + mpol_to_str(buf, sizeof(buf), &pol);
105 + pr_info("NUMA default policy overridden to '%s'\n", buf);
107 + pr_warn("Unable to parse numa_policy=\n");
112 +__setup("numa_policy=", setup_numapolicy);
115 * mpol_to_str - format a mempolicy structure for printing