History

cgroup: Eliminate cgrp_ancestor_storage in cgroup_root

The cgrp_ancestor_storage has two drawbacks: - it's not guaranteed that the member immediately follows struct cgrp in cgroup_root (root cgroup's ancestors[0] might thus point to a padding and not in cgrp_ancestor_storage proper), - this idiom raises warnings with -Wflex-array-member-not-at-end. Instead of relying on the auxiliary member in cgroup_root, define the 0-th level ancestor inside struct cgroup (needed for static allocation of cgrp_dfl_root), deeper cgroups would allocate flexible _low_ancestors[]. Unionized alias through ancestors[] will transparently join the two ranges. The above change would still leave the flexible array at the end of struct cgroup inside cgroup_root, so move cgrp also towards the end of cgroup_root to resolve the -Wflex-array-member-not-at-end.

Michal Koutný committed 10 months ago

Commit ef565781 parent aa7d3a52 files · +15 −12Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/cgroup-defs.h+14−11
@@ -626,7 +626,13 @@ struct cgroup { · 625 unmodified lines
626#endif626#endif
627 627
628 /* All ancestors including self */628 /* All ancestors including self */
629 struct cgroup *ancestors[];629 union {
630 DECLARE_FLEX_ARRAY(struct cgroup *, ancestors);
631 struct {
632 struct cgroup *_root_ancestor;
633 DECLARE_FLEX_ARRAY(struct cgroup *, _low_ancestors);
634 };
635 };
630};636};
631 637
632/*638/*
@@ -647,16 +653,6 @@ struct cgroup_root { · 14 unmodified lines
647 struct list_head root_list;653 struct list_head root_list;
648 struct rcu_head rcu; /* Must be near the top */654 struct rcu_head rcu; /* Must be near the top */
649 655
650 /*
651 * The root cgroup. The containing cgroup_root will be destroyed on its
652 * release. cgrp->ancestors[0] will be used overflowing into the
653 * following field. cgrp_ancestor_storage must immediately follow.
654 */
655 struct cgroup cgrp;
656
657 /* must follow cgrp for cgrp->ancestors[0], see above */
658 struct cgroup *cgrp_ancestor_storage;
659
660 /* Number of cgroups in the hierarchy, used only for /proc/cgroups */656 /* Number of cgroups in the hierarchy, used only for /proc/cgroups */
661 atomic_t nr_cgrps;657 atomic_t nr_cgrps;
662 658
@@ -668,6 +664,13 @@ struct cgroup_root { · 5 unmodified lines
668 664
669 /* The name for this hierarchy - may be empty */665 /* The name for this hierarchy - may be empty */
670 char name[MAX_CGROUP_ROOT_NAMELEN];666 char name[MAX_CGROUP_ROOT_NAMELEN];
667
668 /*
669 * The root cgroup. The containing cgroup_root will be destroyed on its
670 * release. This must be embedded last due to flexible array at the end
671 * of struct cgroup.
672 */
673 struct cgroup cgrp;
671};674};
672 675
673/*676/*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t