Skip to contentSkip to conversation

mm/mempolicy: failed to disable numa balancing

PATCH NAK tzm 5 participants 5 messages Dec 2, 2022 – Dec 16, 2022

Subsystems (2)
lore
Share & tools
lore

tzm

author
#0 lore raw

PATCH 1/1 mm/mempolicy: failed to disable numa balancing

It will be failed to disable numa balancing policy permanently by passing <numa_balancing=disable> to boot cmdline parameters.
The numabalancing_override variable is int and 1 for enable -1 for disable. So, !enumabalancing_override will always be true, which cause this bug.

---
 mm/mempolicy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempolicy.c +1 -1
index 61aa9aedb728..2789c0920293 100644
@@ -2865,7 +2865,7 @@ static void __init check_numabalancing_enable(void)
 	if (numabalancing_override)
 		set_numabalancing_state(numabalancing_override == 1);
 
-	if (num_online_nodes() > 1 && !numabalancing_override) {
+	if (num_online_nodes() > 1 && (numabalancing_override == 1)) {
 		pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
 			numabalancing_default ? "Enabling" : "Disabling");
 		set_numabalancing_state(numabalancing_default);
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 4 lines · On Fri, 2 Dec 2022 22:16:30 +0800 tzm <[email protected]> wrote:

It will be failed to disable numa balancing policy permanently by passing <numa_balancing=disable> to boot cmdline parameters.
The numabalancing_override variable is int and 1 for enable -1 for disable. So, !enumabalancing_override will always be true, which cause this bug.

That's really old code!

mm/mempolicy.c static void __init check_numabalancing_enable(void) · line 2871

Quoted 11 lines
mm/mempolicy.c +1 -1
@@ -2865,7 +2865,7 @@ static void __init check_numabalancing_enable(void)
 	if (numabalancing_override)
 		set_numabalancing_state(numabalancing_override == 1);
 
-	if (num_online_nodes() > 1 && !numabalancing_override) {
+	if (num_online_nodes() > 1 && (numabalancing_override == 1)) {
 		pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
 			numabalancing_default ? "Enabling" : "Disabling");
 		set_numabalancing_state(numabalancing_default);

Looks right to me. Mel?

After eight years, I wonder if we actually need this.

#2 lore raw
Quoted 16 lines · Andrew Morton
Quoted 4 lines · On Fri, 2 Dec 2022 22:16:30 +0800 tzm <[email protected]> wrote:

It will be failed to disable numa balancing policy permanently by passing <numa_balancing=disable> to boot cmdline parameters.
The numabalancing_override variable is int and 1 for enable -1 for disable. So, !enumabalancing_override will always be true, which cause this bug.

That's really old code!

Quoted 6 lines
mm/mempolicy.c +0 -0
@@ -2865,7 +2865,7 @@ static void __init check_numabalancing_enable(void)
      if (numabalancing_override)
              set_numabalancing_state(numabalancing_override == 1);
 
Quoted 8 lines

mm/mempolicy.c static void __init check_numabalancing_enable(void) · line 2871

Quoted 5 lines
mm/mempolicy.c +1 -1
-     if (num_online_nodes() > 1 && !numabalancing_override) {
+     if (num_online_nodes() > 1 && (numabalancing_override == 1)) {
              pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
                      numabalancing_default ? "Enabling" : "Disabling");
              set_numabalancing_state(numabalancing_default);

Looks right to me. Mel?

Maybe I'm missing something, but it looks wrong to me?

numabalancing_override is default initialized to 0, I think, indicating that no override exists.
numabalancing_override == 1 indicates it has been overridden to true. numabalancing_override == -1 indicates that it has been overridden to false.

The above code reads to me:

if (override_exists)
set_numabalancing_state(override_value)

if (num_online_nodes() > ! && !override_exists)
set_numabalancing_state(numabalancing_default)

A more clear fix for readability would be an early return between these 2 if statements I think.

Quoted 2 lines

After eight years, I wonder if we actually need this.

#3 lore raw
In reply to Andrew Morton
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Fri, 2 Dec 2022 22:16:30 +0800 tzm <[email protected]> wrote:

It will be failed to disable numa balancing policy permanently by passing <numa_balancing=disable> to boot cmdline parameters.
The numabalancing_override variable is int and 1 for enable -1 for disable. So, !enumabalancing_override will always be true, which cause this bug.

!enumabalancing_override is false when enumabalancing_override = -1 (numa_balancing=disable).

Quoted 16 lines

That's really old code!

mm/mempolicy.c static void __init check_numabalancing_enable(void) · line 2871

Quoted 11 lines
mm/mempolicy.c +1 -1
@@ -2865,7 +2865,7 @@ static void __init check_numabalancing_enable(void)
      if (numabalancing_override)
              set_numabalancing_state(numabalancing_override == 1);
 
-     if (num_online_nodes() > 1 && !numabalancing_override) {
+     if (num_online_nodes() > 1 && (numabalancing_override == 1)) {
              pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
                      numabalancing_default ? "Enabling" : "Disabling");
              set_numabalancing_state(numabalancing_default);

Looks right to me. Mel?

Quoted 1 line

After eight years, I wonder if we actually need this.

NAK.

The original code works as intended. This patch breaks my test with CONFIG_NUMA_BALANCING_DEFAULT_ENABLED=n and numa_balancing=enable.

#4 lore raw
In reply to Andrew Morton
Quoted 23 lines · Andrew Morton
Quoted 4 lines · On Fri, 2 Dec 2022 22:16:30 +0800 tzm <[email protected]> wrote:

It will be failed to disable numa balancing policy permanently by passing <numa_balancing=disable> to boot cmdline parameters.
The numabalancing_override variable is int and 1 for enable -1 for disable. So, !enumabalancing_override will always be true, which cause this bug.

That's really old code!

mm/mempolicy.c static void __init check_numabalancing_enable(void) · line 2871

Quoted 11 lines
mm/mempolicy.c +1 -1
@@ -2865,7 +2865,7 @@ static void __init check_numabalancing_enable(void)
 	if (numabalancing_override)
 		set_numabalancing_state(numabalancing_override == 1);
 
-	if (num_online_nodes() > 1 && !numabalancing_override) {
+	if (num_online_nodes() > 1 && (numabalancing_override == 1)) {
 		pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
 			numabalancing_default ? "Enabling" : "Disabling");
 		set_numabalancing_state(numabalancing_default);

Looks right to me. Mel?

Quoted 1 line

After eight years, I wonder if we actually need this.

I don't think the patch is right aside from coding style issues such as real names used in signed-off-by's.

The !numabalancing_override is checking "should the default be changed?", itt's not checking if it should be enabled specifically. A better potential fix would be something like this? (not actually tested)

mm/mempolicy.c +4 -2
index 61aa9aedb728..fc649f8509f7 100644
@@ -2862,10 +2862,12 @@ static void __init check_numabalancing_enable(void)
 		numabalancing_default = true;
 
 	/* Parsed by setup_numabalancing. override == 1 enables, -1 disables */
-	if (numabalancing_override)
+	if (numabalancing_override) {
 		set_numabalancing_state(numabalancing_override == 1);
+		return;
+	}
 
-	if (num_online_nodes() > 1 && !numabalancing_override) {
+	if (num_online_nodes() > 1) {
 		pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
 			numabalancing_default ? "Enabling" : "Disabling");
 		set_numabalancing_state(numabalancing_default);