Skip to content

Commit 02bb586

Browse files
committed
cpuset: schedule hotplug propagation from cpuset_attach() if the cpuset is empty
cpuset is scheduled to be decoupled from cgroup_lock which will make hotplug handling race with task migration. cpus or mems will be allowed to go offline between ->can_attach() and ->attach(). If hotplug takes down all cpus or mems of a cpuset while attach is in progress, ->attach() may end up putting tasks into an empty cpuset. This patchset makes ->attach() schedule hotplug propagation if the cpuset is empty after attaching is complete. This will move the tasks to the nearest ancestor which can execute and the end result would be as if hotplug handling happened after the tasks finished attaching. cpuset_write_resmask() now also flushes cpuset_propagate_hotplug_wq to wait for propagations scheduled directly by cpuset_attach(). This currently doesn't make any functional difference as everything is protected by cgroup_mutex but enables decoupling the locking. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
1 parent 452477f commit 02bb586

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎kernel/cpuset.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ static struct workqueue_struct *cpuset_propagate_hotplug_wq;
266266

267267
static void cpuset_hotplug_workfn(struct work_struct *work);
268268
static void cpuset_propagate_hotplug_workfn(struct work_struct *work);
269+
static void schedule_cpuset_propagate_hotplug(struct cpuset *cs);
269270

270271
static DECLARE_WORK(cpuset_hotplug_work, cpuset_hotplug_workfn);
271272

@@ -1464,6 +1465,14 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
14641465
}
14651466

14661467
cs->attach_in_progress--;
1468+
1469+
/*
1470+
* We may have raced with CPU/memory hotunplug. Trigger hotplug
1471+
* propagation if @cs doesn't have any CPU or memory. It will move
1472+
* the newly added tasks to the nearest parent which can execute.
1473+
*/
1474+
if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
1475+
schedule_cpuset_propagate_hotplug(cs);
14671476
}
14681477

14691478
/* The various types of files and directories in a cpuset file system */
@@ -1569,8 +1578,13 @@ static int cpuset_write_resmask(struct cgroup *cgrp, struct cftype *cft,
15691578
* resources, wait for the previously scheduled operations before
15701579
* proceeding, so that we don't end up keep removing tasks added
15711580
* after execution capability is restored.
1581+
*
1582+
* Flushing cpuset_hotplug_work is enough to synchronize against
1583+
* hotplug hanlding; however, cpuset_attach() may schedule
1584+
* propagation work directly. Flush the workqueue too.
15721585
*/
15731586
flush_work(&cpuset_hotplug_work);
1587+
flush_workqueue(cpuset_propagate_hotplug_wq);
15741588

15751589
if (!cgroup_lock_live_group(cgrp))
15761590
return -ENODEV;

0 commit comments

Comments
 (0)