kernel/cgroup/cgroup.c | 3 --- 1 file changed, 3 deletions(-)
cgroup_migrate_finish() currently sets cset->mg_src_cgrp, cset->mg_dst_cgrp
and cset->mg_dst_cset to NULL when cleaning mgctx->preloaded_dst_csets.
These assignments are redundant for the css_sets on
mgctx->preloaded_dst_csets:
- There are only three places that modify the mg_* members of a css_set:
- cgroup_migrate_add_src(), which sets src_cset->mg_src_cgrp
- cgroup_migrate_prepare_dst(), which clears src_cset->mg_src_cgrp when
src_cset and dst_cset happen to be the same
- cgroup_migrate_finish(), which clears mg_src_cgrp for css_sets on
mgctx->preloaded_src_csets and mgctx->preloaded_dst_csets
- All three functions are invoked through the migration sequence:
cgroup_migrate_add_src() ->
cgroup_migrate_prepare_dst() ->
cgroup_migrate_add_task() ->
cgroup_migrate_execute() ->
cgroup_migrate_finish()
All migration entry points (cgroup_attach_task(),
cgroup_update_dfl_csses() and cgroup_transfer_tasks()) hold
cgroup_mutex across the whole sequence: cgroup_mutex is acquired before
cgroup_migrate_add_src() and only released after cgroup_migrate_finish()
returns. This rules out concurrent updates to the mg_* members.
- During a single migration, a given css_set cannot be on both
mgctx->preloaded_src_csets and mgctx->preloaded_dst_csets at the same
time. For css_sets on mgctx->preloaded_dst_csets, mg_src_cgrp,
mg_dst_cgrp and mg_dst_cset are never assigned and therefore remain NULL
for the entire migration.
As a result, explicitly setting these fields to NULL again in
cgroup_migrate_finish() for css_sets on mgctx->preloaded_dst_csets does not
change any observable state. Removing the redundant assignments makes the
migration state handling clearer without changing behavior.
Signed-off-by: Qingye Zhao <zhaoqingye@honor.com>
---
kernel/cgroup/cgroup.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 5f0d33b04910..6c8eff438462 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2845,9 +2845,6 @@ void cgroup_migrate_finish(struct cgroup_mgctx *mgctx)
list_for_each_entry_safe(cset, tmp_cset, &mgctx->preloaded_dst_csets,
mg_dst_preload_node) {
- cset->mg_src_cgrp = NULL;
- cset->mg_dst_cgrp = NULL;
- cset->mg_dst_cset = NULL;
list_del_init(&cset->mg_dst_preload_node);
put_css_set_locked(cset);
}
--
2.25.1
Hello Qingye. On Tue, Feb 24, 2026 at 10:36:23AM +0000, zhaoqingye <zhaoqingye@honor.com> wrote: > cgroup_migrate_finish() currently sets cset->mg_src_cgrp, cset->mg_dst_cgrp > and cset->mg_dst_cset to NULL when cleaning mgctx->preloaded_dst_csets. > > These assignments are redundant for the css_sets on > mgctx->preloaded_dst_csets: > > - There are only three places that modify the mg_* members of a css_set: > - cgroup_migrate_add_src(), which sets src_cset->mg_src_cgrp > - cgroup_migrate_prepare_dst(), which clears src_cset->mg_src_cgrp when > src_cset and dst_cset happen to be the same > - cgroup_migrate_finish(), which clears mg_src_cgrp for css_sets on > mgctx->preloaded_src_csets and mgctx->preloaded_dst_csets > > - All three functions are invoked through the migration sequence: > cgroup_migrate_add_src() -> > cgroup_migrate_prepare_dst() -> > cgroup_migrate_add_task() -> > cgroup_migrate_execute() -> > cgroup_migrate_finish() > > All migration entry points (cgroup_attach_task(), > cgroup_update_dfl_csses() and cgroup_transfer_tasks()) hold > cgroup_mutex across the whole sequence: cgroup_mutex is acquired before > cgroup_migrate_add_src() and only released after cgroup_migrate_finish() > returns. This rules out concurrent updates to the mg_* members. > > - During a single migration, a given css_set cannot be on both > mgctx->preloaded_src_csets and mgctx->preloaded_dst_csets at the same > time. For css_sets on mgctx->preloaded_dst_csets, mg_src_cgrp, > mg_dst_cgrp and mg_dst_cset are never assigned and therefore remain NULL > for the entire migration. This is impressive exercise! However, from defensive programming PoV I'd keep the cgroup_migrate_finish() as is. (Otherwise the text above would need to be added to the preloaded_src_sets processing to explain the disparity.) > As a result, explicitly setting these fields to NULL again in > cgroup_migrate_finish() for css_sets on mgctx->preloaded_dst_csets does not > change any observable state. Removing the redundant assignments makes the > migration state handling clearer without changing behavior. Despite being redundant, they pair with some WARN_ONs around and the runtime benefit here is negligible. Thanks, Michal
© 2016 - 2026 Red Hat, Inc.