1015
1015
struct cpuset *cs;
1017
1017
const nodemask_t *oldmem = scan->data;
1018
NODEMASK_ALLOC(nodemask_t, newmems, GFP_KERNEL);
1018
static nodemask_t newmems; /* protected by cgroup_mutex */
1023
1020
cs = cgroup_cs(scan->cg);
1024
guarantee_online_mems(cs, newmems);
1026
cpuset_change_task_nodemask(p, newmems);
1028
NODEMASK_FREE(newmems);
1021
guarantee_online_mems(cs, &newmems);
1023
cpuset_change_task_nodemask(p, &newmems);
1030
1025
mm = get_task_mm(p);
1375
/* Protected by cgroup_lock */
1376
static cpumask_var_t cpus_attach;
1378
1370
/* Called by cgroups to determine if a cpuset is usable; cgroup_mutex held */
1379
1371
static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont,
1380
struct task_struct *tsk, bool threadgroup)
1372
struct task_struct *tsk)
1383
1374
struct cpuset *cs = cgroup_cs(cont);
1385
1376
if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
1396
1387
if (tsk->flags & PF_THREAD_BOUND)
1397
1388
return -EINVAL;
1399
ret = security_task_setscheduler(tsk);
1403
struct task_struct *c;
1406
list_for_each_entry_rcu(c, &tsk->thread_group, thread_group) {
1407
ret = security_task_setscheduler(c);
1418
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);
1423
1427
* can_attach beforehand should guarantee that this doesn't fail.
1424
1428
* TODO: have a better way to handle failure here
1426
1430
err = set_cpus_allowed_ptr(tsk, cpus_attach);
1427
1431
WARN_ON_ONCE(err);
1429
cpuset_change_task_nodemask(tsk, to);
1433
cpuset_change_task_nodemask(tsk, &cpuset_attach_nodemask_to);
1430
1434
cpuset_update_task_spread_flag(cs, tsk);
1434
1437
static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
1435
struct cgroup *oldcont, struct task_struct *tsk,
1438
struct cgroup *oldcont, struct task_struct *tsk)
1438
1440
struct mm_struct *mm;
1439
1441
struct cpuset *cs = cgroup_cs(cont);
1440
1442
struct cpuset *oldcs = cgroup_cs(oldcont);
1441
NODEMASK_ALLOC(nodemask_t, from, GFP_KERNEL);
1442
NODEMASK_ALLOC(nodemask_t, to, GFP_KERNEL);
1444
if (from == NULL || to == NULL)
1447
if (cs == &top_cpuset) {
1448
cpumask_copy(cpus_attach, cpu_possible_mask);
1450
guarantee_online_cpus(cs, cpus_attach);
1452
guarantee_online_mems(cs, to);
1454
/* do per-task migration stuff possibly for each in the threadgroup */
1455
cpuset_attach_task(tsk, to, cs);
1457
struct task_struct *c;
1459
list_for_each_entry_rcu(c, &tsk->thread_group, thread_group) {
1460
cpuset_attach_task(c, to, cs);
1465
/* change mm; only needs to be done once even if threadgroup */
1466
*from = oldcs->mems_allowed;
1467
*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;
1468
1450
mm = get_task_mm(tsk);
1470
mpol_rebind_mm(mm, to);
1452
mpol_rebind_mm(mm, &cpuset_attach_nodemask_to);
1471
1453
if (is_memory_migrate(cs))
1472
cpuset_migrate_mm(mm, from, to);
1454
cpuset_migrate_mm(mm, &cpuset_attach_nodemask_from,
1455
&cpuset_attach_nodemask_to);
1477
NODEMASK_FREE(from);
1481
1460
/* The various types of files and directories in a cpuset file system */
1610
1589
* across a page fault.
1613
static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
1592
static size_t cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
1617
1596
mutex_lock(&callback_mutex);
1618
ret = cpulist_scnprintf(page, PAGE_SIZE, cs->cpus_allowed);
1597
count = cpulist_scnprintf(page, PAGE_SIZE, cs->cpus_allowed);
1619
1598
mutex_unlock(&callback_mutex);
1624
static int cpuset_sprintf_memlist(char *page, struct cpuset *cs)
1603
static size_t cpuset_sprintf_memlist(char *page, struct cpuset *cs)
1626
NODEMASK_ALLOC(nodemask_t, mask, GFP_KERNEL);
1632
1607
mutex_lock(&callback_mutex);
1633
*mask = cs->mems_allowed;
1608
count = nodelist_scnprintf(page, PAGE_SIZE, cs->mems_allowed);
1634
1609
mutex_unlock(&callback_mutex);
1636
retval = nodelist_scnprintf(page, PAGE_SIZE, *mask);
1638
NODEMASK_FREE(mask);
1643
1614
static ssize_t cpuset_common_file_read(struct cgroup *cont,
1834
* post_clone() is called at the end of cgroup_clone().
1835
* 'cgroup' was just created automatically as a result of
1836
* a cgroup_clone(), and the current task is about to
1837
* 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.
1839
1809
* Currently we refuse to set up the cgroup - thereby
1840
1810
* refusing the task to be entered, and as a result refusing
1862
1832
cs = cgroup_cs(cgroup);
1863
1833
parent_cs = cgroup_cs(parent);
1835
mutex_lock(&callback_mutex);
1865
1836
cs->mems_allowed = parent_cs->mems_allowed;
1866
1837
cpumask_copy(cs->cpus_allowed, parent_cs->cpus_allowed);
1838
mutex_unlock(&callback_mutex);
1931
1903
.create = cpuset_create,
1932
1904
.destroy = cpuset_destroy,
1933
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,
1934
1909
.attach = cpuset_attach,
1935
1910
.populate = cpuset_populate,
1936
1911
.post_clone = cpuset_post_clone,
2066
2041
struct cpuset *cp; /* scans cpusets being updated */
2067
2042
struct cpuset *child; /* scans child cpusets of cp */
2068
2043
struct cgroup *cont;
2069
NODEMASK_ALLOC(nodemask_t, oldmems, GFP_KERNEL);
2071
if (oldmems == NULL)
2044
static nodemask_t oldmems; /* protected by cgroup_mutex */
2074
2046
list_add_tail((struct list_head *)&root->stack_list, &queue);
2086
2058
nodes_subset(cp->mems_allowed, node_states[N_HIGH_MEMORY]))
2089
*oldmems = cp->mems_allowed;
2061
oldmems = cp->mems_allowed;
2091
2063
/* Remove offline cpus and mems from this cpuset. */
2092
2064
mutex_lock(&callback_mutex);
2102
2074
remove_tasks_in_empty_cpuset(cp);
2104
2076
update_tasks_cpumask(cp, NULL);
2105
update_tasks_nodemask(cp, oldmems, NULL);
2077
update_tasks_nodemask(cp, &oldmems, NULL);
2108
NODEMASK_FREE(oldmems);
2147
2118
static int cpuset_track_online_nodes(struct notifier_block *self,
2148
2119
unsigned long action, void *arg)
2150
NODEMASK_ALLOC(nodemask_t, oldmems, GFP_KERNEL);
2152
if (oldmems == NULL)
2121
static nodemask_t oldmems; /* protected by cgroup_mutex */
2156
2124
switch (action) {
2157
2125
case MEM_ONLINE:
2158
*oldmems = top_cpuset.mems_allowed;
2126
oldmems = top_cpuset.mems_allowed;
2159
2127
mutex_lock(&callback_mutex);
2160
2128
top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY];
2161
2129
mutex_unlock(&callback_mutex);
2162
update_tasks_nodemask(&top_cpuset, oldmems, NULL);
2130
update_tasks_nodemask(&top_cpuset, &oldmems, NULL);
2164
2132
case MEM_OFFLINE:
2250
2217
* Like above we can temporary set any mask and rely on
2251
2218
* set_cpus_allowed_ptr() as synchronization point.
2253
cpumask_copy(&tsk->cpus_allowed, cpu_possible_mask);
2220
do_set_cpus_allowed(tsk, cpu_possible_mask);
2254
2221
cpu = cpumask_any(cpu_active_mask);