Skip to contentSkip to conversation

cpuset: Enable cpuset controller in default hierarchy

PATCH Superseded Waiman Long 3 participants 10 messages Oct 6, 2017 – Nov 27, 2017

Subsystems (3)

v3 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Waiman Long

author maintainer
#0 lore raw

PATCH v3 1/1 cpuset: Enable cpuset controller in default hierarchy

Given the fact that thread mode had been merged into 4.14, it is now time to enable cpuset to be used in the default hierarchy (cgroup v2) as it is clearly threaded.

The cpuset controller had experienced feature creep since its introduction more than a decade ago. Besides the core cpus and mems control files to limit cpus and memory nodes, there are a bunch of additional features that can be controlled from the userspace. Some of the features are of doubtful usefulness and may not be actively used.

After examining the source code of some sample users like systemd, libvirt and lxc for their use of those additional features, only memory_migrate is used by libvirt.

This patch enables cpuset controller in the default hierarchy with a minimal set of features. Currently, only memory_migrate is supported. We can certainly add more features to the default hierarchy if there is a real user need for them later on.

For features that are actually flags which are set internally, they are being combined into a single "cpuset.flags" control file. That includes the memory_migrate feature which is the only flag that is currently supported. When the "cpuset.flags" file is read, it contains either "+mem_migrate" (enabled) or "-mem_migrate" (disabled).

To enable it, use

  # echo +mem_migrate > cpuset.flags

To disable it, use

  # echo -mem_migrate > cpuset.flags

Note that the flag name is changed to "mem_migrate" for better naming consistency.

v3:
- Further trim the additional features down to just memory_migrate.
- Update Documentation/cgroup-v2.txt.

---
 Documentation/cgroup-v2.txt | 122 ++++++++++++++++++++++++++++++++++++++++----
 kernel/cgroup/cpuset.c      | 112 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 223 insertions(+), 11 deletions(-)
Documentation/cgroup-v2.txt +113 -9
index 0bbdc72..f9fea87 100644
@@ -48,15 +48,17 @@ v1 is available under Documentation/cgroup-v1/.
        5-2-1. Memory Interface Files
        5-2-2. Usage Guidelines
        5-2-3. Memory Ownership
-     5-3. IO
-       5-3-1. IO Interface Files
-       5-3-2. Writeback
-     5-4. PID
-       5-4-1. PID Interface Files
-     5-5. RDMA
-       5-5-1. RDMA Interface Files
-     5-6. Misc
-       5-6-1. perf_event
+     5-3. Cpuset
+       5.3-1. Cpuset Interface Files
+     5-4. IO
+       5-4-1. IO Interface Files
+       5-4-2. Writeback
+     5-5. PID
+       5-5-1. PID Interface Files
+     5-6. RDMA
+       5-6-1. RDMA Interface Files
+     5-7. Misc
+       5-7-1. perf_event
    6. Namespace
      6-1. Basics
      6-2. The Root and Views
@@ -1235,6 +1237,108 @@ POSIX_FADV_DONTNEED to relinquish the ownership of memory areas
 belonging to the affected files to ensure correct memory ownership.
 
 
+Cpuset
+------
+
+The "cpuset" controller provides a mechanism for constraining
+the CPU and memory node placement of tasks to only the resources
+specified in the cpuset interface files in a task's current cgroup.
+This is especially valuable on large NUMA systems where placing jobs
+on properly sized subsets of the systems with careful processor and
+memory placement to reduce cross-node memory access and contention
+can improve overall system performance.
+
+The "cpuset" controller is hierarchical.  That means the controller
+cannot use CPUs or memory nodes not allowed in its parent.
+
+
+Cpuset Interface Files
+~~~~~~~~~~~~~~~~~~~~~~
+
+  cpuset.cpus
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the CPUs allowed to be used by tasks within this
+	cgroup.  The CPU numbers are comma-separated numbers or
+	ranges.  For example:
+
+	  # cat cpuset.cpus
+	  0-4,6,8-10
+
+	An empty value indicates that the cgroup is using the same
+	setting as the nearest cgroup ancestor with a non-empty
+	"cpuset.cpus" or all the available CPUs if none is found.
+
+	The value of "cpuset.cpus" stays constant until the next update
+	and won't be affected by any CPU hotplug events.
+
+  cpuset.effective_cpus
+	A read-only multiple values file which exists on non-root
+	cgroups.
+
+	It lists the onlined CPUs that are actually allowed to be
+	used by tasks within the current cgroup. It is a subset of
+	"cpuset.cpus". Its value will be affected by CPU hotplug
+	events.
+
+  cpuset.mems
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the memory nodes allowed to be used by tasks within
+	this cgroup.  The memory node numbers are comma-separated
+	numbers or ranges.  For example:
+
+	  # cat cpuset.mems
+	  0-1,3
+
+	An empty value indicates that the cgroup is using the same
+	setting as the nearest cgroup ancestor with a non-empty
+	"cpuset.mems" or all the available memory nodes if none
+	is found.
+
+	The value of "cpuset.mems" stays constant until the next update
+	and won't be affected by any memory nodes hotplug events.
+
+  cpuset.effective_mems
+	A read-only multiple values file which exists on non-root
+	cgroups.
+
+	It lists the onlined memory nodes that are actually allowed
+	to be used by tasks within the current cgroup. It is a subset
+	of "cpuset.mems". Its value will be affected by memory nodes
+	hotplug events.
+
+  cpuset.flags
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the flags that are set (with a '+' prefix) and those
+	that are not set (with a '-' prefix).	The currently supported
+	flag is:
+
+	  mem_migrate
+		When it is not set, an allocated memory page will
+		stay in whatever node it was allocated independent
+		of changes in "cpuset.mems".
+
+		When it is set, tasks with memory pages not in
+		"cpuset.mems" will have those pages migrated over to
+		memory nodes specified in "cpuset.mems".  Any changes
+		to "cpuset.mems" will cause pages in nodes that are
+		no longer valid to be migrated over to the newly
+		valid nodes.
+
+	To set a flag, use the '+' prefix:
+
+	  # echo +mem_migrate > cpuset.flags
+
+	To clear a flag, use the '-' prefix:
+
+	  # echo -mem_migrate > cpuset.flags
+
+
 IO
 --
 
kernel/cgroup/cpuset.c +110 -2

142 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw
Quoted 33 lines · Waiman Long

Given the fact that thread mode had been merged into 4.14, it is now time to enable cpuset to be used in the default hierarchy (cgroup v2) as it is clearly threaded.

The cpuset controller had experienced feature creep since its introduction more than a decade ago. Besides the core cpus and mems control files to limit cpus and memory nodes, there are a bunch of additional features that can be controlled from the userspace. Some of the features are of doubtful usefulness and may not be actively used.

After examining the source code of some sample users like systemd, libvirt and lxc for their use of those additional features, only memory_migrate is used by libvirt.

This patch enables cpuset controller in the default hierarchy with a minimal set of features. Currently, only memory_migrate is supported. We can certainly add more features to the default hierarchy if there is a real user need for them later on.

For features that are actually flags which are set internally, they are being combined into a single "cpuset.flags" control file. That includes the memory_migrate feature which is the only flag that is currently supported. When the "cpuset.flags" file is read, it contains either "+mem_migrate" (enabled) or "-mem_migrate" (disabled).

To enable it, use

  # echo +mem_migrate > cpuset.flags

To disable it, use

  # echo -mem_migrate > cpuset.flags
Quoted 8 lines

Note that the flag name is changed to "mem_migrate" for better naming consistency.

v3:
- Further trim the additional features down to just memory_migrate.
- Update Documentation/cgroup-v2.txt.

Ping! Any comment on this patch?

Cheers,
Longman

maintainer
#2 lore raw

Hello, Waiman.

Quoted 1 line · Waiman Long

Ping! Any comment on this patch?

Sorry about the lack of response. Here are my two thoughts.

1. I'm not really sure about the memory part. Mostly because of the way it's configured and enforced is completely out of step with how mm behaves in general. I'd like to get more input from mm folks on this.

2. I want to think more about how we expose the effective settings. Not that anything is wrong with what cpuset does, but more that I wanna ensure that it's something we can follow in other cases where we have similar hierarchical property propagation.

We're likely too late for the coming merge window. Let's handle it during the next window.

Thanks and my apologies for the delay.

Signature · 1 line
tejun
author maintainer
#3 lore raw
Quoted 10 lines · Tejun Heo

Hello, Waiman.

Quoted 1 line · Waiman Long

Ping! Any comment on this patch?

Sorry about the lack of response. Here are my two thoughts.

1. I'm not really sure about the memory part. Mostly because of the way it's configured and enforced is completely out of step with how mm behaves in general. I'd like to get more input from mm folks on this.

Yes, I also have doubt about which of the additional features are being actively used. That is why the current patch exposes only the memory_migrate flag in addition to the core *cpus and *mems control files. All the other v1 features are not exposed waiting for further investigation and feedback. One way to get more feedback is to have something that people can play with. Maybe we could somehow tag it as experimental so that we can change the interface later on, when necessary, if you have concern about setting the APIs in stone.

Quoted 4 lines

2. I want to think more about how we expose the effective settings. Not that anything is wrong with what cpuset does, but more that I wanna ensure that it's something we can follow in other cases where we have similar hierarchical property propagation.

Currently, the effective setting is exposed via the effective_cpus and effective_mems control files. Unlike other controllers that control resources, cpuset is unique in the sense that it is propagating hierarchical constraints on CPUs and memory nodes down the tree. I understand your desire to have a unified framework that can be applied to most controllers, but I doubt cpuset is a good model in this regard.

Cheers,
Longman

#4 lore raw
Quoted 5 lines · Waiman Long
Quoted 4 lines · Tejun Heo

Hello, Waiman.

Quoted 1 line · Waiman Long

Ping! Any comment on this patch?

Fwiw, I just saw this patch today for some weird reason.

Quoted 7 lines
Quoted 6 lines

Sorry about the lack of response. Here are my two thoughts.

1. I'm not really sure about the memory part. Mostly because of the way it's configured and enforced is completely out of step with how mm behaves in general. I'd like to get more input from mm folks on this.

Quoted 8 lines

Yes, I also have doubt about which of the additional features are being actively used. That is why the current patch exposes only the memory_migrate flag in addition to the core *cpus and *mems control files. All the other v1 features are not exposed waiting for further investigation and feedback. One way to get more feedback is to have something that people can play with. Maybe we could somehow tag it as experimental so that we can change the interface later on, when necessary, if you have concern about setting the APIs in stone.

This sounds like a reasonable approach to me. The cpuset controller is quite important from a userspace (especially container) perspective. So making this an experimental feature for a while to gather feedback seems worth it. I'd be happy to carry/receive some experimental patches in a liblxc branch for cgroup v2 to see where the current cpuset controller implementation currently gets us and send/discuss patches where needed.

Quoted 16 lines
Quoted 5 lines

2. I want to think more about how we expose the effective settings. Not that anything is wrong with what cpuset does, but more that I wanna ensure that it's something we can follow in other cases where we have similar hierarchical property propagation.

Currently, the effective setting is exposed via the effective_cpus and effective_mems control files. Unlike other controllers that control resources, cpuset is unique in the sense that it is propagating hierarchical constraints on CPUs and memory nodes down the tree. I understand your desire to have a unified framework that can be applied to most controllers, but I doubt cpuset is a good model in this regard.

Cheers,
Longman

author maintainer
#5 lore raw
In reply to Waiman Long
Quoted 24 lines · Waiman Long
Quoted 10 lines · Tejun Heo

Hello, Waiman.

Quoted 1 line · Waiman Long

Ping! Any comment on this patch?

Sorry about the lack of response. Here are my two thoughts.

1. I'm not really sure about the memory part. Mostly because of the way it's configured and enforced is completely out of step with how mm behaves in general. I'd like to get more input from mm folks on this.

Yes, I also have doubt about which of the additional features are being actively used. That is why the current patch exposes only the memory_migrate flag in addition to the core *cpus and *mems control files. All the other v1 features are not exposed waiting for further investigation and feedback. One way to get more feedback is to have something that people can play with. Maybe we could somehow tag it as experimental so that we can change the interface later on, when necessary, if you have concern about setting the APIs in stone.

Quoted 4 lines

2. I want to think more about how we expose the effective settings. Not that anything is wrong with what cpuset does, but more that I wanna ensure that it's something we can follow in other cases where we have similar hierarchical property propagation.

Quoted 6 lines

Currently, the effective setting is exposed via the effective_cpus and effective_mems control files. Unlike other controllers that control resources, cpuset is unique in the sense that it is propagating hierarchical constraints on CPUs and memory nodes down the tree. I understand your desire to have a unified framework that can be applied to most controllers, but I doubt cpuset is a good model in this regard.

What do you think we can do for the 4.16 development cycle? I really like to see some kind of at least experimental support for cpuset v2. That may be the best way to gather feedback and decide what to do next.

Cheers,
Longman

maintainer
#6 lore raw
In reply to Waiman Long

Hello, Waiman.

Sorry about the long delay.

Quoted 12 lines · Waiman Long
Documentation/cgroup-v2.txt +12 -0
+Cpuset Interface Files
+~~~~~~~~~~~~~~~~~~~~~~
+
+  cpuset.cpus
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the CPUs allowed to be used by tasks within this
+	cgroup.  The CPU numbers are comma-separated numbers or
+	ranges.  For example:
+
+	  # cat cpuset.cpus

Documentation/cgroup-v2.txt POSIX_FADV_DONTNEED to relinquish the ownership of memory areas · line 1276

Quoted 10 lines
Documentation/cgroup-v2.txt +10 -0
+	  0-4,6,8-10
+
+	An empty value indicates that the cgroup is using the same
+	setting as the nearest cgroup ancestor with a non-empty
+	"cpuset.cpus" or all the available CPUs if none is found.
+
+	The value of "cpuset.cpus" stays constant until the next update
+	and won't be affected by any CPU hotplug events.
+
+  cpuset.effective_cpus

Can we do cpuset.ecpus in the fashion of euid, egid..?

Quoted 1 line

+ cpuset.effective_mems

Ditto.

Quoted 9 lines
Documentation/cgroup-v2.txt +9 -0
+  cpuset.flags
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the flags that are set (with a '+' prefix) and those
+	that are not set (with a '-' prefix).	The currently supported
+	flag is:
+
+	  mem_migrate

Documentation/cgroup-v2.txt POSIX_FADV_DONTNEED to relinquish the ownership of memory areas · line 1331

Quoted 10 lines
Documentation/cgroup-v2.txt +10 -0
+		When it is not set, an allocated memory page will
+		stay in whatever node it was allocated independent
+		of changes in "cpuset.mems".
+
+		When it is set, tasks with memory pages not in
+		"cpuset.mems" will have those pages migrated over to
+		memory nodes specified in "cpuset.mems".  Any changes
+		to "cpuset.mems" will cause pages in nodes that are
+		no longer valid to be migrated over to the newly
+		valid nodes.

Let's start just with [e]cpus and [e]mems. The flags interface looks fine but the implementations of these features are really bad and cgroup2 doesn't migrate resources for other controllers either anyway.

Thanks.

Signature · 1 line
tejun
author maintainer
#7 lore raw
Quoted 20 lines · Tejun Heo

Hello, Waiman.

Sorry about the long delay.

Quoted 15 lines · Waiman Long
Documentation/cgroup-v2.txt +15 -0
+Cpuset Interface Files
+~~~~~~~~~~~~~~~~~~~~~~
+
+  cpuset.cpus
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the CPUs allowed to be used by tasks within this
+	cgroup.  The CPU numbers are comma-separated numbers or
+	ranges.  For example:
+
+	  # cat cpuset.cpus
+	  0-4,6,8-10
+
+	An empty value indicates that the cgroup is using the same
Quoted 8 lines

Documentation/cgroup-v2.txt POSIX_FADV_DONTNEED to relinquish the ownership of memory areas · line 1276

Quoted 7 lines
Documentation/cgroup-v2.txt +7 -0
+	setting as the nearest cgroup ancestor with a non-empty
+	"cpuset.cpus" or all the available CPUs if none is found.
+
+	The value of "cpuset.cpus" stays constant until the next update
+	and won't be affected by any CPU hotplug events.
+
+  cpuset.effective_cpus

Can we do cpuset.ecpus in the fashion of euid, egid..?

Sure.

Quoted 2 lines
Quoted 1 line

+ cpuset.effective_mems

Ditto.

Sure.

Quoted 14 lines
Quoted 14 lines
Documentation/cgroup-v2.txt +14 -0
+  cpuset.flags
+	A read-write multiple values file which exists on non-root
+	cgroups.
+
+	It lists the flags that are set (with a '+' prefix) and those
+	that are not set (with a '-' prefix).	The currently supported
+	flag is:
+
+	  mem_migrate
+		When it is not set, an allocated memory page will
+		stay in whatever node it was allocated independent
+		of changes in "cpuset.mems".
+
+		When it is set, tasks with memory pages not in
Quoted 8 lines

Documentation/cgroup-v2.txt POSIX_FADV_DONTNEED to relinquish the ownership of memory areas · line 1331

Quoted 5 lines
Documentation/cgroup-v2.txt +5 -0
+		"cpuset.mems" will have those pages migrated over to
+		memory nodes specified in "cpuset.mems".  Any changes
+		to "cpuset.mems" will cause pages in nodes that are
+		no longer valid to be migrated over to the newly
+		valid nodes.

Let's start just with [e]cpus and [e]mems. The flags interface looks fine but the implementations of these features are really bad and cgroup2 doesn't migrate resources for other controllers either anyway.

That is added because the mem_migrate feature is used in libvirt, I think. I am thinking of add a "[EXPERIMENTAL]" tag to the flags to indicate that it is subject to change.

Cheers,
Longman

maintainer
#8 lore raw

Hello, Waiman.

Quoted 7 lines · Waiman Long
Quoted 3 lines

Let's start just with [e]cpus and [e]mems. The flags interface looks fine but the implementations of these features are really bad and cgroup2 doesn't migrate resources for other controllers either anyway.

That is added because the mem_migrate feature is used in libvirt, I think. I am thinking of add a "[EXPERIMENTAL]" tag to the flags to indicate that it is subject to change.

I see. Do you happen to know what it's used for and why that's necessary just so that we can evaluate it better? I'm not quite sure what adding [EXPERIMENTAL] tag would achieve. If we expose the feature and people use it, we just have to keep it anyway.

Thanks.

Signature · 1 line
tejun
author maintainer
#9 lore raw
Quoted 6 lines · Tejun Heo

Hello, Waiman.

Quoted 3 lines · Waiman Long
Quoted 3 lines

Let's start just with [e]cpus and [e]mems. The flags interface looks fine but the implementations of these features are really bad and cgroup2 doesn't migrate resources for other controllers either anyway.

Quoted 7 lines
Quoted 3 lines

That is added because the mem_migrate feature is used in libvirt, I think. I am thinking of add a "[EXPERIMENTAL]" tag to the flags to indicate that it is subject to change.

I see. Do you happen to know what it's used for and why that's necessary just so that we can evaluate it better? I'm not quite sure what adding [EXPERIMENTAL] tag would achieve. If we expose the feature and people use it, we just have to keep it anyway.

The mem_migrate feature will probably enforce better NUMA locality as the vCPU may move from one physical CPU to another if it is not pinned.

I want to add the experimental tag more in the sense that we are going to add to the list of the flags in the future than removing an existing one. Well, I guess we can just say it in the text instead of adding a tag.

Cheers,
Longman