1370
/* Protected by cgroup_lock */
1371
static cpumask_var_t cpus_attach;
1373
1370
/* Called by cgroups to determine if a cpuset is usable; cgroup_mutex held */
1374
1371
static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont,
1375
struct task_struct *tsk, bool threadgroup)
1372
struct task_struct *tsk)
1378
1374
struct cpuset *cs = cgroup_cs(cont);
1380
1376
if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
1391
1387
if (tsk->flags & PF_THREAD_BOUND)
1392
1388
return -EINVAL;
1394
ret = security_task_setscheduler(tsk);
1398
struct task_struct *c;
1401
list_for_each_entry_rcu(c, &tsk->thread_group, thread_group) {
1402
ret = security_task_setscheduler(c);
1413
static void cpuset_attach_task(struct task_struct *tsk, nodemask_t *to,
1393
static int cpuset_can_attach_task(struct cgroup *cgrp, struct task_struct *task)
1395
return security_task_setscheduler(task);
1399
* Protected by cgroup_lock. The nodemasks must be stored globally because
1400
* dynamically allocating them is not allowed in pre_attach, and they must
1401
* persist among pre_attach, attach_task, and attach.
1403
static cpumask_var_t cpus_attach;
1404
static nodemask_t cpuset_attach_nodemask_from;
1405
static nodemask_t cpuset_attach_nodemask_to;
1407
/* Set-up work for before attaching each task. */
1408
static void cpuset_pre_attach(struct cgroup *cont)
1410
struct cpuset *cs = cgroup_cs(cont);
1412
if (cs == &top_cpuset)
1413
cpumask_copy(cpus_attach, cpu_possible_mask);
1415
guarantee_online_cpus(cs, cpus_attach);
1417
guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
1420
/* Per-thread attachment work. */
1421
static void cpuset_attach_task(struct cgroup *cont, struct task_struct *tsk)
1424
struct cpuset *cs = cgroup_cs(cont);
1418
1427
* can_attach beforehand should guarantee that this doesn't fail.
1419
1428
* TODO: have a better way to handle failure here
1421
1430
err = set_cpus_allowed_ptr(tsk, cpus_attach);
1422
1431
WARN_ON_ONCE(err);
1424
cpuset_change_task_nodemask(tsk, to);
1433
cpuset_change_task_nodemask(tsk, &cpuset_attach_nodemask_to);
1425
1434
cpuset_update_task_spread_flag(cs, tsk);
1429
1437
static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
1430
struct cgroup *oldcont, struct task_struct *tsk,
1438
struct cgroup *oldcont, struct task_struct *tsk)
1433
1440
struct mm_struct *mm;
1434
1441
struct cpuset *cs = cgroup_cs(cont);
1435
1442
struct cpuset *oldcs = cgroup_cs(oldcont);
1436
static nodemask_t to; /* protected by cgroup_mutex */
1438
if (cs == &top_cpuset) {
1439
cpumask_copy(cpus_attach, cpu_possible_mask);
1441
guarantee_online_cpus(cs, cpus_attach);
1443
guarantee_online_mems(cs, &to);
1445
/* do per-task migration stuff possibly for each in the threadgroup */
1446
cpuset_attach_task(tsk, &to, cs);
1448
struct task_struct *c;
1450
list_for_each_entry_rcu(c, &tsk->thread_group, thread_group) {
1451
cpuset_attach_task(c, &to, cs);
1456
/* change mm; only needs to be done once even if threadgroup */
1457
to = cs->mems_allowed;
1445
* Change mm, possibly for multiple threads in a threadgroup. This is
1446
* expensive and may sleep.
1448
cpuset_attach_nodemask_from = oldcs->mems_allowed;
1449
cpuset_attach_nodemask_to = cs->mems_allowed;
1458
1450
mm = get_task_mm(tsk);
1460
mpol_rebind_mm(mm, &to);
1452
mpol_rebind_mm(mm, &cpuset_attach_nodemask_to);
1461
1453
if (is_memory_migrate(cs))
1462
cpuset_migrate_mm(mm, &oldcs->mems_allowed, &to);
1454
cpuset_migrate_mm(mm, &cpuset_attach_nodemask_from,
1455
&cpuset_attach_nodemask_to);
1812
* post_clone() is called at the end of cgroup_clone().
1813
* 'cgroup' was just created automatically as a result of
1814
* a cgroup_clone(), and the current task is about to
1815
* be moved into 'cgroup'.
1805
* post_clone() is called during cgroup_create() when the
1806
* clone_children mount argument was specified. The cgroup
1807
* can not yet have any tasks.
1817
1809
* Currently we refuse to set up the cgroup - thereby
1818
1810
* refusing the task to be entered, and as a result refusing
1911
1903
.create = cpuset_create,
1912
1904
.destroy = cpuset_destroy,
1913
1905
.can_attach = cpuset_can_attach,
1906
.can_attach_task = cpuset_can_attach_task,
1907
.pre_attach = cpuset_pre_attach,
1908
.attach_task = cpuset_attach_task,
1914
1909
.attach = cpuset_attach,
1915
1910
.populate = cpuset_populate,
1916
1911
.post_clone = cpuset_post_clone,
2222
2217
* Like above we can temporary set any mask and rely on
2223
2218
* set_cpus_allowed_ptr() as synchronization point.
2225
cpumask_copy(&tsk->cpus_allowed, cpu_possible_mask);
2220
do_set_cpus_allowed(tsk, cpu_possible_mask);
2226
2221
cpu = cpumask_any(cpu_active_mask);