Skip to content

Commit 78567e2

Browse files
committed
Merge tag 'cgroup-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup updates from Tejun Heo: - cpuset isolation improvements - cpuset cgroup1 support is split into its own file behind the new config option CONFIG_CPUSET_V1. This makes it the second controller which makes cgroup1 support optional after memcg - Handling of unavailable v1 controller handling improved during cgroup1 mount operations - union_find applied to cpuset. It makes code simpler and more efficient - Reduce spurious events in pids.events - Cleanups and other misc changes - Contains a merge of cgroup/for-6.11-fixes to receive cpuset fixes that further changes build upon * tag 'cgroup-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: (34 commits) cgroup: Do not report unavailable v1 controllers in /proc/cgroups cgroup: Disallow mounting v1 hierarchies without controller implementation cgroup/cpuset: Expose cpuset filesystem with cpuset v1 only cgroup/cpuset: Move cpu.h include to cpuset-internal.h cgroup/cpuset: add sefltest for cpuset v1 cgroup/cpuset: guard cpuset-v1 code under CONFIG_CPUSETS_V1 cgroup/cpuset: rename functions shared between v1 and v2 cgroup/cpuset: move v1 interfaces to cpuset-v1.c cgroup/cpuset: move validate_change_legacy to cpuset-v1.c cgroup/cpuset: move legacy hotplug update to cpuset-v1.c cgroup/cpuset: add callback_lock helper cgroup/cpuset: move memory_spread to cpuset-v1.c cgroup/cpuset: move relax_domain_level to cpuset-v1.c cgroup/cpuset: move memory_pressure to cpuset-v1.c cgroup/cpuset: move common code to cpuset-internal.h cgroup/cpuset: introduce cpuset-v1.c selftest/cgroup: Make test_cpuset_prs.sh deal with pre-isolated CPUs cgroup/cpuset: Account for boot time isolated CPUs cgroup/cpuset: remove use_parent_ecpus of cpuset cgroup/cpuset: remove fetch_xcpus ...
2 parents 2f27fce + af000ce commit 78567e2

File tree

23 files changed

+1569
-1069
lines changed

23 files changed

+1569
-1069
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,12 @@ cgroup namespace on namespace creation.
533533
Because the resource control interface files in a given directory
534534
control the distribution of the parent's resources, the delegatee
535535
shouldn't be allowed to write to them. For the first method, this is
536-
achieved by not granting access to these files. For the second, the
537-
kernel rejects writes to all files other than "cgroup.procs" and
538-
"cgroup.subtree_control" on a namespace root from inside the
539-
namespace.
536+
achieved by not granting access to these files. For the second, files
537+
outside the namespace should be hidden from the delegatee by the means
538+
of at least mount namespacing, and the kernel rejects writes to all
539+
files on a namespace root from inside the cgroup namespace, except for
540+
those files listed in "/sys/kernel/cgroup/delegate" (including
541+
"cgroup.procs", "cgroup.threads", "cgroup.subtree_control", etc.).
540542

541543
The end results are equivalent for both delegation types. Once
542544
delegated, the user can build sub-hierarchy under the directory,
@@ -981,6 +983,14 @@ All cgroup core files are prefixed with "cgroup."
981983
A dying cgroup can consume system resources not exceeding
982984
limits, which were active at the moment of cgroup deletion.
983985

986+
nr_subsys_<cgroup_subsys>
987+
Total number of live cgroup subsystems (e.g memory
988+
cgroup) at and beneath the current cgroup.
989+
990+
nr_dying_subsys_<cgroup_subsys>
991+
Total number of dying cgroup subsystems (e.g. memory
992+
cgroup) at and beneath the current cgroup.
993+
984994
cgroup.freeze
985995
A read-write single value file which exists on non-root cgroups.
986996
Allowed values are "0" and "1". The default is "0".
@@ -2940,8 +2950,8 @@ Deprecated v1 Core Features
29402950

29412951
- "cgroup.clone_children" is removed.
29422952

2943-
- /proc/cgroups is meaningless for v2. Use "cgroup.controllers" file
2944-
at the root instead.
2953+
- /proc/cgroups is meaningless for v2. Use "cgroup.controllers" or
2954+
"cgroup.stat" files at the root instead.
29452955

29462956

29472957
Issues with v1 and Rationales for v2

Documentation/core-api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Library functionality that is used throughout the kernel.
4949
wrappers/atomic_t
5050
wrappers/atomic_bitops
5151
floating-point
52+
union_find
5253

5354
Low level entry and exit
5455
========================

Documentation/core-api/union_find.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
====================
4+
Union-Find in Linux
5+
====================
6+
7+
8+
:Date: June 21, 2024
9+
:Author: Xavier <[email protected]>
10+
11+
What is union-find, and what is it used for?
12+
------------------------------------------------
13+
14+
Union-find is a data structure used to handle the merging and querying
15+
of disjoint sets. The primary operations supported by union-find are:
16+
17+
Initialization: Resetting each element as an individual set, with
18+
each set's initial parent node pointing to itself.
19+
20+
Find: Determine which set a particular element belongs to, usually by
21+
returning a “representative element” of that set. This operation
22+
is used to check if two elements are in the same set.
23+
24+
Union: Merge two sets into one.
25+
26+
As a data structure used to maintain sets (groups), union-find is commonly
27+
utilized to solve problems related to offline queries, dynamic connectivity,
28+
and graph theory. It is also a key component in Kruskal's algorithm for
29+
computing the minimum spanning tree, which is crucial in scenarios like
30+
network routing. Consequently, union-find is widely referenced. Additionally,
31+
union-find has applications in symbolic computation, register allocation,
32+
and more.
33+
34+
Space Complexity: O(n), where n is the number of nodes.
35+
36+
Time Complexity: Using path compression can reduce the time complexity of
37+
the find operation, and using union by rank can reduce the time complexity
38+
of the union operation. These optimizations reduce the average time
39+
complexity of each find and union operation to O(α(n)), where α(n) is the
40+
inverse Ackermann function. This can be roughly considered a constant time
41+
complexity for practical purposes.
42+
43+
This document covers use of the Linux union-find implementation. For more
44+
information on the nature and implementation of union-find, see:
45+
46+
Wikipedia entry on union-find
47+
https://en.wikipedia.org/wiki/Disjoint-set_data_structure
48+
49+
Linux implementation of union-find
50+
-----------------------------------
51+
52+
Linux's union-find implementation resides in the file "lib/union_find.c".
53+
To use it, "#include <linux/union_find.h>".
54+
55+
The union-find data structure is defined as follows::
56+
57+
struct uf_node {
58+
struct uf_node *parent;
59+
unsigned int rank;
60+
};
61+
62+
In this structure, parent points to the parent node of the current node.
63+
The rank field represents the height of the current tree. During a union
64+
operation, the tree with the smaller rank is attached under the tree with the
65+
larger rank to maintain balance.
66+
67+
Initializing union-find
68+
-----------------------
69+
70+
You can complete the initialization using either static or initialization
71+
interface. Initialize the parent pointer to point to itself and set the rank
72+
to 0.
73+
Example::
74+
75+
struct uf_node my_node = UF_INIT_NODE(my_node);
76+
77+
or
78+
79+
uf_node_init(&my_node);
80+
81+
Find the Root Node of union-find
82+
--------------------------------
83+
84+
This operation is mainly used to determine whether two nodes belong to the same
85+
set in the union-find. If they have the same root, they are in the same set.
86+
During the find operation, path compression is performed to improve the
87+
efficiency of subsequent find operations.
88+
Example::
89+
90+
int connected;
91+
struct uf_node *root1 = uf_find(&node_1);
92+
struct uf_node *root2 = uf_find(&node_2);
93+
if (root1 == root2)
94+
connected = 1;
95+
else
96+
connected = 0;
97+
98+
Union Two Sets in union-find
99+
----------------------------
100+
101+
To union two sets in the union-find, you first find their respective root nodes
102+
and then link the smaller node to the larger node based on the rank of the root
103+
nodes.
104+
Example::
105+
106+
uf_union(&node_1, &node_2);

Documentation/translations/zh_CN/core-api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
generic-radix-tree
5050
packing
5151
this_cpu_ops
52+
union_find
5253

5354
=======
5455

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
.. include:: ../disclaimer-zh_CN.rst
3+
4+
:Original: Documentation/core-api/union_find.rst
5+
6+
=============================
7+
Linux中的并查集(Union-Find)
8+
=============================
9+
10+
11+
:日期: 2024年6月21日
12+
:作者: Xavier <[email protected]>
13+
14+
何为并查集,它有什么用?
15+
------------------------
16+
17+
并查集是一种数据结构,用于处理一些不交集的合并及查询问题。并查集支持的主要操作:
18+
初始化:将每个元素初始化为单独的集合,每个集合的初始父节点指向自身。
19+
20+
查询:查询某个元素属于哪个集合,通常是返回集合中的一个“代表元素”。这个操作是为
21+
了判断两个元素是否在同一个集合之中。
22+
23+
合并:将两个集合合并为一个。
24+
25+
并查集作为一种用于维护集合(组)的数据结构,它通常用于解决一些离线查询、动态连通性和
26+
图论等相关问题,同时也是用于计算最小生成树的克鲁斯克尔算法中的关键,由于最小生成树在
27+
网络路由等场景下十分重要,并查集也得到了广泛的引用。此外,并查集在符号计算,寄存器分
28+
配等方面也有应用。
29+
30+
空间复杂度: O(n),n为节点数。
31+
32+
时间复杂度:使用路径压缩可以减少查找操作的时间复杂度,使用按秩合并可以减少合并操作的
33+
时间复杂度,使得并查集每个查询和合并操作的平均时间复杂度仅为O(α(n)),其中α(n)是反阿
34+
克曼函数,可以粗略地认为并查集的操作有常数的时间复杂度。
35+
36+
本文档涵盖了对Linux并查集实现的使用方法。更多关于并查集的性质和实现的信息,参见:
37+
38+
维基百科并查集词条
39+
https://en.wikipedia.org/wiki/Disjoint-set_data_structure
40+
41+
并查集的Linux实现
42+
------------------
43+
44+
Linux的并查集实现在文件“lib/union_find.c”中。要使用它,需要
45+
“#include <linux/union_find.h>”。
46+
47+
并查集的数据结构定义如下::
48+
49+
struct uf_node {
50+
struct uf_node *parent;
51+
unsigned int rank;
52+
};
53+
54+
其中parent为当前节点的父节点,rank为当前树的高度,在合并时将rank小的节点接到rank大
55+
的节点下面以增加平衡性。
56+
57+
初始化并查集
58+
-------------
59+
60+
可以采用静态或初始化接口完成初始化操作。初始化时,parent 指针指向自身,rank 设置
61+
为 0。
62+
示例::
63+
64+
struct uf_node my_node = UF_INIT_NODE(my_node);
65+
66+
67+
68+
uf_node_init(&my_node);
69+
70+
查找并查集的根节点
71+
------------------
72+
73+
主要用于判断两个并查集是否属于一个集合,如果根相同,那么他们就是一个集合。在查找过程中
74+
会对路径进行压缩,提高后续查找效率。
75+
示例::
76+
77+
int connected;
78+
struct uf_node *root1 = uf_find(&node_1);
79+
struct uf_node *root2 = uf_find(&node_2);
80+
if (root1 == root2)
81+
connected = 1;
82+
else
83+
connected = 0;
84+
85+
合并两个并查集
86+
--------------
87+
88+
对于两个相交的并查集进行合并,会首先查找它们各自的根节点,然后根据根节点秩大小,将小的
89+
节点连接到大的节点下面。
90+
示例::
91+
92+
uf_union(&node_1, &node_2);

MAINTAINERS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5736,9 +5736,12 @@ S: Maintained
57365736
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
57375737
F: Documentation/admin-guide/cgroup-v1/cpusets.rst
57385738
F: include/linux/cpuset.h
5739+
F: kernel/cgroup/cpuset-internal.h
5740+
F: kernel/cgroup/cpuset-v1.c
57395741
F: kernel/cgroup/cpuset.c
57405742
F: tools/testing/selftests/cgroup/test_cpuset.c
57415743
F: tools/testing/selftests/cgroup/test_cpuset_prs.sh
5744+
F: tools/testing/selftests/cgroup/test_cpuset_v1_base.sh
57425745

57435746
CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)
57445747
M: Johannes Weiner <[email protected]>
@@ -23606,6 +23609,15 @@ F: drivers/cdrom/cdrom.c
2360623609
F: include/linux/cdrom.h
2360723610
F: include/uapi/linux/cdrom.h
2360823611

23612+
UNION-FIND
23613+
M: Xavier <[email protected]>
23614+
23615+
S: Maintained
23616+
F: Documentation/core-api/union_find.rst
23617+
F: Documentation/translations/zh_CN/core-api/union_find.rst
23618+
F: include/linux/union_find.h
23619+
F: lib/union_find.c
23620+
2360923621
UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER
2361023622
R: Alim Akhtar <[email protected]>
2361123623
R: Avri Altman <[email protected]>

include/linux/cgroup-defs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ struct cgroup_subsys_state {
210210
* fields of the containing structure.
211211
*/
212212
struct cgroup_subsys_state *parent;
213+
214+
/*
215+
* Keep track of total numbers of visible descendant CSSes.
216+
* The total number of dying CSSes is tracked in
217+
* css->cgroup->nr_dying_subsys[ssid].
218+
* Protected by cgroup_mutex.
219+
*/
220+
int nr_descendants;
213221
};
214222

215223
/*
@@ -470,6 +478,12 @@ struct cgroup {
470478
/* Private pointers for each registered subsystem */
471479
struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
472480

481+
/*
482+
* Keep track of total number of dying CSSes at and below this cgroup.
483+
* Protected by cgroup_mutex.
484+
*/
485+
int nr_dying_subsys[CGROUP_SUBSYS_COUNT];
486+
473487
struct cgroup_root *root;
474488

475489
/*

include/linux/cpuset.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,24 @@ static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
9999
extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
100100
const struct task_struct *tsk2);
101101

102+
#ifdef CONFIG_CPUSETS_V1
102103
#define cpuset_memory_pressure_bump() \
103104
do { \
104105
if (cpuset_memory_pressure_enabled) \
105106
__cpuset_memory_pressure_bump(); \
106107
} while (0)
107108
extern int cpuset_memory_pressure_enabled;
108109
extern void __cpuset_memory_pressure_bump(void);
110+
#else
111+
static inline void cpuset_memory_pressure_bump(void) { }
112+
#endif
109113

110114
extern void cpuset_task_status_allowed(struct seq_file *m,
111115
struct task_struct *task);
112116
extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
113117
struct pid *pid, struct task_struct *tsk);
114118

115119
extern int cpuset_mem_spread_node(void);
116-
extern int cpuset_slab_spread_node(void);
117120

118121
static inline int cpuset_do_page_mem_spread(void)
119122
{
@@ -246,11 +249,6 @@ static inline int cpuset_mem_spread_node(void)
246249
return 0;
247250
}
248251

249-
static inline int cpuset_slab_spread_node(void)
250-
{
251-
return 0;
252-
}
253-
254252
static inline int cpuset_do_page_mem_spread(void)
255253
{
256254
return 0;

include/linux/sched.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,6 @@ struct task_struct {
12431243
/* Sequence number to catch updates: */
12441244
seqcount_spinlock_t mems_allowed_seq;
12451245
int cpuset_mem_spread_rotor;
1246-
int cpuset_slab_spread_rotor;
12471246
#endif
12481247
#ifdef CONFIG_CGROUPS
12491248
/* Control Group info protected by css_set_lock: */

0 commit comments

Comments
 (0)