Skip to content

Commit 6aee5ae

Browse files
committed
Merge tag 'cgroup-for-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup updates from Tejun Heo: - Allow css_rstat_updated() in NMI context to enable memory accounting for allocations in NMI context. - /proc/cgroups doesn't contain useful information for cgroup2 and was updated to only show v1 controllers. This unfortunately broke something in the wild. Add an option to bring back the old behavior to ease transition. - selftest updates and other cleanups. * tag 'cgroup-for-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup: Add compatibility option for content of /proc/cgroups selftests/cgroup: fix cpu.max tests cgroup: llist: avoid memory tears for llist_node selftests: cgroup: Fix missing newline in test_zswap_writeback_one selftests: cgroup: Allow longer timeout for kmem_dead_cgroups cleanup memcg: cgroup: call css_rstat_updated irrespective of in_nmi() cgroup: remove per-cpu per-subsystem locks cgroup: make css_rstat_updated nmi safe cgroup: support to enable nmi-safe css_rstat_updated selftests: cgroup: Fix compilation on pre-cgroupns kernels selftests: cgroup: Optionally set up v1 environment selftests: cgroup: Add support for named v1 hierarchies in test_core selftests: cgroup_util: Add helpers for testing named v1 hierarchies Documentation: cgroup: add section explaining controller availability cgroup: Drop sock_cgroup_classid() dummy implementation
2 parents af5b261 + 646faf3 commit 6aee5ae

File tree

14 files changed

+266
-207
lines changed

14 files changed

+266
-207
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ both cgroups.
435435
Controlling Controllers
436436
-----------------------
437437

438+
Availablity
439+
~~~~~~~~~~~
440+
441+
A controller is available in a cgroup when it is supported by the kernel (i.e.,
442+
compiled in, not disabled and not attached to a v1 hierarchy) and listed in the
443+
"cgroup.controllers" file. Availability means the controller's interface files
444+
are exposed in the cgroup’s directory, allowing the distribution of the target
445+
resource to be observed or controlled within that cgroup.
446+
438447
Enabling and Disabling
439448
~~~~~~~~~~~~~~~~~~~~~~
440449

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@
633633
named mounts. Specifying both "all" and "named" disables
634634
all v1 hierarchies.
635635

636+
cgroup_v1_proc= [KNL] Show also missing controllers in /proc/cgroups
637+
Format: { "true" | "false" }
638+
/proc/cgroups lists only v1 controllers by default.
639+
This compatibility option enables listing also v2
640+
controllers (whose v1 code is not compiled!), so that
641+
semi-legacy software can check this file to decide
642+
about usage of v2 (sic) controllers.
643+
636644
cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
637645
Format: { "true" | "false" }
638646
Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.

include/linux/cgroup-defs.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,12 @@ struct css_rstat_cpu {
375375
* Child cgroups with stat updates on this cpu since the last read
376376
* are linked on the parent's ->updated_children through
377377
* ->updated_next. updated_children is terminated by its container css.
378-
*
379-
* In addition to being more compact, singly-linked list pointing to
380-
* the css makes it unnecessary for each per-cpu struct to point back
381-
* to the associated css.
382-
*
383-
* Protected by per-cpu css->ss->rstat_ss_cpu_lock.
384378
*/
385379
struct cgroup_subsys_state *updated_children;
386380
struct cgroup_subsys_state *updated_next; /* NULL if not on the list */
381+
382+
struct llist_node lnode; /* lockless list for update */
383+
struct cgroup_subsys_state *owner; /* back pointer */
387384
};
388385

389386
/*
@@ -821,7 +818,7 @@ struct cgroup_subsys {
821818
unsigned int depends_on;
822819

823820
spinlock_t rstat_ss_lock;
824-
raw_spinlock_t __percpu *rstat_ss_cpu_lock;
821+
struct llist_head __percpu *lhead; /* lockless update list head */
825822
};
826823

827824
extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
@@ -898,14 +895,12 @@ static inline u16 sock_cgroup_prioidx(const struct sock_cgroup_data *skcd)
898895
#endif
899896
}
900897

898+
#ifdef CONFIG_CGROUP_NET_CLASSID
901899
static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd)
902900
{
903-
#ifdef CONFIG_CGROUP_NET_CLASSID
904901
return READ_ONCE(skcd->classid);
905-
#else
906-
return 0;
907-
#endif
908902
}
903+
#endif
909904

910905
static inline void sock_cgroup_set_prioidx(struct sock_cgroup_data *skcd,
911906
u16 prioidx)
@@ -915,13 +910,13 @@ static inline void sock_cgroup_set_prioidx(struct sock_cgroup_data *skcd,
915910
#endif
916911
}
917912

913+
#ifdef CONFIG_CGROUP_NET_CLASSID
918914
static inline void sock_cgroup_set_classid(struct sock_cgroup_data *skcd,
919915
u32 classid)
920916
{
921-
#ifdef CONFIG_CGROUP_NET_CLASSID
922917
WRITE_ONCE(skcd->classid, classid);
923-
#endif
924918
}
919+
#endif
925920

926921
#else /* CONFIG_SOCK_CGROUP_DATA */
927922

include/linux/llist.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static inline void init_llist_head(struct llist_head *list)
8383
*/
8484
static inline void init_llist_node(struct llist_node *node)
8585
{
86-
node->next = node;
86+
WRITE_ONCE(node->next, node);
8787
}
8888

8989
/**
@@ -97,7 +97,7 @@ static inline void init_llist_node(struct llist_node *node)
9797
*/
9898
static inline bool llist_on_list(const struct llist_node *node)
9999
{
100-
return node->next != node;
100+
return READ_ONCE(node->next) != node;
101101
}
102102

103103
/**
@@ -220,7 +220,7 @@ static inline bool llist_empty(const struct llist_head *head)
220220

221221
static inline struct llist_node *llist_next(struct llist_node *node)
222222
{
223-
return node->next;
223+
return READ_ONCE(node->next);
224224
}
225225

226226
/**

include/trace/events/cgroup.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -257,53 +257,6 @@ DEFINE_EVENT(cgroup_rstat, cgroup_rstat_unlock,
257257
TP_ARGS(cgrp, cpu, contended)
258258
);
259259

260-
/*
261-
* Related to per CPU locks:
262-
* global rstat_base_cpu_lock for base stats
263-
* cgroup_subsys::rstat_ss_cpu_lock for subsystem stats
264-
*/
265-
DEFINE_EVENT(cgroup_rstat, cgroup_rstat_cpu_lock_contended,
266-
267-
TP_PROTO(struct cgroup *cgrp, int cpu, bool contended),
268-
269-
TP_ARGS(cgrp, cpu, contended)
270-
);
271-
272-
DEFINE_EVENT(cgroup_rstat, cgroup_rstat_cpu_lock_contended_fastpath,
273-
274-
TP_PROTO(struct cgroup *cgrp, int cpu, bool contended),
275-
276-
TP_ARGS(cgrp, cpu, contended)
277-
);
278-
279-
DEFINE_EVENT(cgroup_rstat, cgroup_rstat_cpu_locked,
280-
281-
TP_PROTO(struct cgroup *cgrp, int cpu, bool contended),
282-
283-
TP_ARGS(cgrp, cpu, contended)
284-
);
285-
286-
DEFINE_EVENT(cgroup_rstat, cgroup_rstat_cpu_locked_fastpath,
287-
288-
TP_PROTO(struct cgroup *cgrp, int cpu, bool contended),
289-
290-
TP_ARGS(cgrp, cpu, contended)
291-
);
292-
293-
DEFINE_EVENT(cgroup_rstat, cgroup_rstat_cpu_unlock,
294-
295-
TP_PROTO(struct cgroup *cgrp, int cpu, bool contended),
296-
297-
TP_ARGS(cgrp, cpu, contended)
298-
);
299-
300-
DEFINE_EVENT(cgroup_rstat, cgroup_rstat_cpu_unlock_fastpath,
301-
302-
TP_PROTO(struct cgroup *cgrp, int cpu, bool contended),
303-
304-
TP_ARGS(cgrp, cpu, contended)
305-
);
306-
307260
#endif /* _TRACE_CGROUP_H */
308261

309262
/* This part must be outside protection */

kernel/cgroup/cgroup-v1.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static u16 cgroup_no_v1_mask;
3232
/* disable named v1 mounts */
3333
static bool cgroup_no_v1_named;
3434

35+
/* Show unavailable controllers in /proc/cgroups */
36+
static bool proc_show_all;
37+
3538
/*
3639
* pidlist destructions need to be flushed on cgroup destruction. Use a
3740
* separate workqueue as flush domain.
@@ -683,10 +686,11 @@ int proc_cgroupstats_show(struct seq_file *m, void *v)
683686
*/
684687

685688
for_each_subsys(ss, i) {
686-
if (cgroup1_subsys_absent(ss))
687-
continue;
688689
cgrp_v1_visible |= ss->root != &cgrp_dfl_root;
689690

691+
if (!proc_show_all && cgroup1_subsys_absent(ss))
692+
continue;
693+
690694
seq_printf(m, "%s\t%d\t%d\t%d\n",
691695
ss->legacy_name, ss->root->hierarchy_id,
692696
atomic_read(&ss->root->nr_cgrps),
@@ -1359,3 +1363,9 @@ static int __init cgroup_no_v1(char *str)
13591363
return 1;
13601364
}
13611365
__setup("cgroup_no_v1=", cgroup_no_v1);
1366+
1367+
static int __init cgroup_v1_proc(char *str)
1368+
{
1369+
return (kstrtobool(str, &proc_show_all) == 0);
1370+
}
1371+
__setup("cgroup_v1_proc=", cgroup_v1_proc);

0 commit comments

Comments
 (0)