Re: [PATCH cgroup/for-next 1/3] cgroup: remove redundancy online_cnt

From: Chen Ridong
Date: Tue Aug 26 2025 - 20:59:23 EST




On 2025/8/26 11:40, Chen Ridong wrote:

> @@ -5949,7 +5944,7 @@ static void css_killed_work_fn(struct work_struct *work)
> css_put(css);
> /* @css can't go away while we're holding cgroup_mutex */
> css = css->parent;
> - } while (css && atomic_dec_and_test(&css->online_cnt));
> + } while (css && css_is_dying(css) && !css->nr_descendants);
>
> cgroup_unlock();
> }
> @@ -5960,7 +5955,7 @@ static void css_killed_ref_fn(struct percpu_ref *ref)
> struct cgroup_subsys_state *css =
> container_of(ref, struct cgroup_subsys_state, refcnt);
>
> - if (atomic_dec_and_test(&css->online_cnt)) {
> + if (!css->nr_descendants) {
> INIT_WORK(&css->destroy_work, css_killed_work_fn);
> queue_work(cgroup_offline_wq, &css->destroy_work);
> }

Hi Michal,

Thank you point out the data race issue, Can I modify the code just like:

@@ -5944,12 +5939,13 @@ static void css_killed_work_fn(struct work_struct *work)

cgroup_lock();

- do {
+ /* The CSS can only be taken offline when it has no living descendants. */
+ while (css && css_is_dying(css) && !css->nr_descendants) {
offline_css(css);
css_put(css);
/* @css can't go away while we're holding cgroup_mutex */
css = css->parent;
- } while (css && atomic_dec_and_test(&css->online_cnt));
+ }

cgroup_unlock();
}
@@ -5960,10 +5956,9 @@ static void css_killed_ref_fn(struct percpu_ref *ref)
struct cgroup_subsys_state *css =
container_of(ref, struct cgroup_subsys_state, refcnt);

- if (atomic_dec_and_test(&css->online_cnt)) {
- INIT_WORK(&css->destroy_work, css_killed_work_fn);
- queue_work(cgroup_offline_wq, &css->destroy_work);
- }
+ INIT_WORK(&css->destroy_work, css_killed_work_fn);
+ queue_work(cgroup_offline_wq, &css->destroy_work);
+
}

--
Best regards,
Ridong