f0de0ce9d59b1e31c37205798cfd212915aa04d1
[openwrt/staging/wigyori.git] /
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
5 policy
6
7 Add numa_policy kernel argument to allow overriding the kernel's default
8 NUMA policy at boot time.
9
10 Syntax identical to what tmpfs accepts as it's mpol argument is accepted.
11
12 Some examples:
13
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
18
19 Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
20 ---
21 mm/mempolicy.c | 49 ++++++++++++++++++++++++++++++++++++++++++-------
22 1 file changed, 42 insertions(+), 7 deletions(-)
23
24 --- a/mm/mempolicy.c
25 +++ b/mm/mempolicy.c
26 @@ -2974,7 +2974,9 @@ void __init numa_policy_init(void)
27 /* Reset policy of current process to default */
28 void numa_default_policy(void)
29 {
30 - do_set_mempolicy(MPOL_DEFAULT, 0, NULL);
31 + struct mempolicy *pol = &default_policy;
32 +
33 + do_set_mempolicy(pol->mode, pol->flags, &pol->nodes);
34 }
35
36 /*
37 @@ -2992,7 +2994,6 @@ static const char * const policy_modes[]
38 };
39
40
41 -#ifdef CONFIG_TMPFS
42 /**
43 * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option.
44 * @str: string containing mempolicy to parse
45 @@ -3005,13 +3006,18 @@ static const char * const policy_modes[]
46 */
47 int mpol_parse_str(char *str, struct mempolicy **mpol)
48 {
49 - struct mempolicy *new = NULL;
50 + struct mempolicy *new;
51 unsigned short mode_flags;
52 nodemask_t nodes;
53 char *nodelist = strchr(str, ':');
54 char *flags = strchr(str, '=');
55 int err = 1, mode;
56
57 + if (*mpol)
58 + new = *mpol;
59 + else
60 + new = NULL;
61 +
62 if (flags)
63 *flags++ = '\0'; /* terminate mode string */
64
65 @@ -3090,9 +3096,16 @@ int mpol_parse_str(char *str, struct mem
66 goto out;
67 }
68
69 - new = mpol_new(mode, mode_flags, &nodes);
70 - if (IS_ERR(new))
71 - goto out;
72 + if (!new) {
73 + new = mpol_new(mode, mode_flags, &nodes);
74 + if (IS_ERR(new))
75 + goto out;
76 + } else {
77 + atomic_set(&new->refcnt, 1);
78 + new->mode = mode;
79 + new->flags = mode_flags;
80 + new->home_node = NUMA_NO_NODE;
81 + }
82
83 /*
84 * Save nodes for mpol_to_str() to show the tmpfs mount options
85 @@ -3125,7 +3138,29 @@ out:
86 *mpol = new;
87 return err;
88 }
89 -#endif /* CONFIG_TMPFS */
90 +
91 +static int __init setup_numapolicy(char *str)
92 +{
93 + struct mempolicy pol = { }, *ppol = &pol;
94 + char buf[128];
95 + int ret;
96 +
97 + if (str)
98 + ret = mpol_parse_str(str, &ppol);
99 + else
100 + ret = -EINVAL;
101 +
102 + if (!ret) {
103 + default_policy = pol;
104 + mpol_to_str(buf, sizeof(buf), &pol);
105 + pr_info("NUMA default policy overridden to '%s'\n", buf);
106 + } else {
107 + pr_warn("Unable to parse numa_policy=\n");
108 + }
109 +
110 + return ret == 0;
111 +}
112 +__setup("numa_policy=", setup_numapolicy);
113
114 /**
115 * mpol_to_str - format a mempolicy structure for printing