Skip to contentSkip to conversation

cgroup/cpuset: check effective mems for a movable-only configuration

PATCH Applied Gregory Price (Meta) 4 participants 4 messages Oct 22 – Oct 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup/cpuset: check effective mems for a movable-only configuration

check_insane_mems_config() warns and enables cpusets_insane_config_key when a cpuset's tasks can allocate only from movable memory.

In cgroup v2 the request may name a memoryless node, which has no zones and cpusets reports it as a movable-only nodemask.

For example, with node 2 a CPU-only node:

  # echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control
  # mkdir /sys/fs/cgroup/test
  # echo 2 > /sys/fs/cgroup/test/cpuset.mems
  # cat /sys/fs/cgroup/test/cpuset.mems.effective
    0-1
  # dmesg
    Unsupported (movable nodes only) cpuset configuration detected (nmask=2)!

This is a bit confusing, especially consider mems.effective ends up with a valid nodemask by-design (cpuset.mems is treated as-if it were empty).

Check each new effective mask in update_nodemasks_hier() instead, as the hotplug path already does. The allocator's bail-out tests the task's mems_allowed, which comes from the effective mask.

A request naming a movable-only not present in the parent's nodemask no longer warns (since, again, the cpuset.mems gets overridden and treated as empty). However, it will warn if the parent's mems include the node later.

For Example, with node 3 a movable-only node:

  # echo 0 > /sys/fs/cgroup/test/cpuset.mems
  # echo 3 > /sys/fs/cgroup/test/child/cpuset.mems
  # cat /sys/fs/cgroup/test/child/cpuset.mems.effective
    0
  # dmesg
    { empty }
  # echo 0,3 > /sys/fs/cgroup/test/cpuset.mems
  # cat /sys/fs/cgroup/test/child/cpuset.mems.effective
    3
  # dmesg
    Unsupported (movable nodes only) cpuset configuration detected (nmask=3)!
Fixes 8ca1b5a49885 ("mm/page_alloc: detect allocation forbidden by cpuset and bail out early")
---
 kernel/cgroup/cpuset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +2 -2
index 8ee239d5c6b48..70fbece1b9399 100644
@@ -2795,6 +2795,8 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
 			continue;
 		rcu_read_unlock();
 
+		check_insane_mems_config(new_mems);
+
 		spin_lock_irq(&callback_lock);
 		cp->effective_mems = *new_mems;
 		spin_unlock_irq(&callback_lock);
@@ -2848,8 +2850,6 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
 	if (retval < 0)
 		return retval;
 
-	check_insane_mems_config(&trialcs->mems_allowed);
-
 	spin_lock_irq(&callback_lock);
 	cs->mems_allowed = trialcs->mems_allowed;
 	spin_unlock_irq(&callback_lock);
Signature · 1 line
2.53.0-Meta
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 62 lines · Gregory Price (Meta)

check_insane_mems_config() warns and enables cpusets_insane_config_key when a cpuset's tasks can allocate only from movable memory.

In cgroup v2 the request may name a memoryless node, which has no zones and cpusets reports it as a movable-only nodemask.

For example, with node 2 a CPU-only node:

   # echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control
   # mkdir /sys/fs/cgroup/test
   # echo 2 > /sys/fs/cgroup/test/cpuset.mems
   # cat /sys/fs/cgroup/test/cpuset.mems.effective
     0-1
   # dmesg
     Unsupported (movable nodes only) cpuset configuration detected (nmask=2)!

This is a bit confusing, especially consider mems.effective ends up with a valid nodemask by-design (cpuset.mems is treated as-if it were empty).

Check each new effective mask in update_nodemasks_hier() instead, as the hotplug path already does. The allocator's bail-out tests the task's mems_allowed, which comes from the effective mask.

A request naming a movable-only not present in the parent's nodemask no longer warns (since, again, the cpuset.mems gets overridden and treated as empty). However, it will warn if the parent's mems include the node later.

For Example, with node 3 a movable-only node:

   # echo 0 > /sys/fs/cgroup/test/cpuset.mems
   # echo 3 > /sys/fs/cgroup/test/child/cpuset.mems
   # cat /sys/fs/cgroup/test/child/cpuset.mems.effective
     0
   # dmesg
     { empty }
   # echo 0,3 > /sys/fs/cgroup/test/cpuset.mems
   # cat /sys/fs/cgroup/test/child/cpuset.mems.effective
     3
   # dmesg
     Unsupported (movable nodes only) cpuset configuration detected (nmask=3)!
Fixes 8ca1b5a49885 ("mm/page_alloc: detect allocation forbidden by cpuset and bail out early")
---
  kernel/cgroup/cpuset.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +2 -0
index 8ee239d5c6b48..70fbece1b9399 100644
@@ -2795,6 +2795,8 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
  			continue;
  		rcu_read_unlock();
 
+		check_insane_mems_config(new_mems);
+
  		spin_lock_irq(&callback_lock);
  		cp->effective_mems = *new_mems;
  		spin_unlock_irq(&callback_lock);

kernel/cgroup/cpuset.c static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs, · line 2855

Quoted 8 lines
kernel/cgroup/cpuset.c +0 -2
@@ -2848,8 +2850,6 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
  	if (retval < 0)
  		return retval;
 
-	check_insane_mems_config(&trialcs->mems_allowed);
-
  	spin_lock_irq(&callback_lock);
  	cs->mems_allowed = trialcs->mems_allowed;
  	spin_unlock_irq(&callback_lock);
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Gregory Price (Meta)
Quoted 62 lines · Gregory Price (Meta)

check_insane_mems_config() warns and enables cpusets_insane_config_key when a cpuset's tasks can allocate only from movable memory.

In cgroup v2 the request may name a memoryless node, which has no zones and cpusets reports it as a movable-only nodemask.

For example, with node 2 a CPU-only node:

   # echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control
   # mkdir /sys/fs/cgroup/test
   # echo 2 > /sys/fs/cgroup/test/cpuset.mems
   # cat /sys/fs/cgroup/test/cpuset.mems.effective
     0-1
   # dmesg
     Unsupported (movable nodes only) cpuset configuration detected (nmask=2)!

This is a bit confusing, especially consider mems.effective ends up with a valid nodemask by-design (cpuset.mems is treated as-if it were empty).

Check each new effective mask in update_nodemasks_hier() instead, as the hotplug path already does. The allocator's bail-out tests the task's mems_allowed, which comes from the effective mask.

A request naming a movable-only not present in the parent's nodemask no longer warns (since, again, the cpuset.mems gets overridden and treated as empty). However, it will warn if the parent's mems include the node later.

For Example, with node 3 a movable-only node:

   # echo 0 > /sys/fs/cgroup/test/cpuset.mems
   # echo 3 > /sys/fs/cgroup/test/child/cpuset.mems
   # cat /sys/fs/cgroup/test/child/cpuset.mems.effective
     0
   # dmesg
     { empty }
   # echo 0,3 > /sys/fs/cgroup/test/cpuset.mems
   # cat /sys/fs/cgroup/test/child/cpuset.mems.effective
     3
   # dmesg
     Unsupported (movable nodes only) cpuset configuration detected (nmask=3)!
Fixes 8ca1b5a49885 ("mm/page_alloc: detect allocation forbidden by cpuset and bail out early")
---
  kernel/cgroup/cpuset.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +2 -0
index 8ee239d5c6b48..70fbece1b9399 100644
@@ -2795,6 +2795,8 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
  			continue;
  		rcu_read_unlock();
 
+		check_insane_mems_config(new_mems);
+
  		spin_lock_irq(&callback_lock);
  		cp->effective_mems = *new_mems;
  		spin_unlock_irq(&callback_lock);

kernel/cgroup/cpuset.c static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs, · line 2855

Quoted 8 lines
kernel/cgroup/cpuset.c +0 -2
@@ -2848,8 +2850,6 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
  	if (retval < 0)
  		return retval;
 
-	check_insane_mems_config(&trialcs->mems_allowed);
-
  	spin_lock_irq(&callback_lock);
  	cs->mems_allowed = trialcs->mems_allowed;
  	spin_unlock_irq(&callback_lock);

LGTM.

Thanks.

Signature · 2 lines
Best regards
Ridong