blob: 0ddb48d40e4da56b50a086a246c60d47acd68886 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * kernel/cpuset.c
3 *
4 * Processor and Memory placement constraints for sets of tasks.
5 *
6 * Copyright (C) 2003 BULL SA.
Paul Jackson029190c2007-10-18 23:40:20 -07007 * Copyright (C) 2004-2007 Silicon Graphics, Inc.
Paul Menage8793d852007-10-18 23:39:39 -07008 * Copyright (C) 2006 Google, Inc
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * Portions derived from Patrick Mochel's sysfs code.
11 * sysfs is Copyright (c) 2001-3 Patrick Mochel
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
Paul Jackson825a46a2006-03-24 03:16:03 -080013 * 2003-10-10 Written by Simon Derr.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * 2003-10-22 Updates by Stephen Hemminger.
Paul Jackson825a46a2006-03-24 03:16:03 -080015 * 2004 May-July Rework by Paul Jackson.
Paul Menage8793d852007-10-18 23:39:39 -070016 * 2006 Rework by Paul Menage to use generic cgroups
Max Krasnyanskycf417142008-08-11 14:33:53 -070017 * 2008 Rework of the scheduler domains and CPU hotplug handling
18 * by Max Krasnyansky
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
20 * This file is subject to the terms and conditions of the GNU General Public
21 * License. See the file COPYING in the main directory of the Linux
22 * distribution for more details.
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/cpu.h>
26#include <linux/cpumask.h>
27#include <linux/cpuset.h>
28#include <linux/err.h>
29#include <linux/errno.h>
30#include <linux/file.h>
31#include <linux/fs.h>
32#include <linux/init.h>
33#include <linux/interrupt.h>
34#include <linux/kernel.h>
35#include <linux/kmod.h>
36#include <linux/list.h>
Paul Jackson68860ec2005-10-30 15:02:36 -080037#include <linux/mempolicy.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/mm.h>
Miao Xief4818912008-11-19 15:36:30 -080039#include <linux/memory.h>
Paul Gortmaker9984de12011-05-23 14:51:41 -040040#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/mount.h>
42#include <linux/namei.h>
43#include <linux/pagemap.h>
44#include <linux/proc_fs.h>
Paul Jackson6b9c2602006-01-08 01:02:02 -080045#include <linux/rcupdate.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/sched.h>
47#include <linux/seq_file.h>
David Quigley22fb52d2006-06-23 02:04:00 -070048#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/spinlock.h>
51#include <linux/stat.h>
52#include <linux/string.h>
53#include <linux/time.h>
54#include <linux/backing-dev.h>
55#include <linux/sort.h>
56
57#include <asm/uaccess.h>
Arun Sharma600634972011-07-26 16:09:06 -070058#include <linux/atomic.h>
Ingo Molnar3d3f26a2006-03-23 03:00:18 -080059#include <linux/mutex.h>
Cliff Wickman956db3c2008-02-07 00:14:43 -080060#include <linux/workqueue.h>
61#include <linux/cgroup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Paul Jackson202f72d2006-01-08 01:01:57 -080063/*
64 * Tracks how many cpusets are currently defined in system.
65 * When there is only one cpuset (the root cpuset) we can
66 * short circuit some hooks.
67 */
Paul Jackson7edc5962006-01-08 01:02:03 -080068int number_of_cpusets __read_mostly;
Paul Jackson202f72d2006-01-08 01:01:57 -080069
Paul Menage2df167a2008-02-07 00:14:45 -080070/* Forward declare cgroup structures */
Paul Menage8793d852007-10-18 23:39:39 -070071struct cgroup_subsys cpuset_subsys;
72struct cpuset;
73
Paul Jackson3e0d98b2006-01-08 01:01:49 -080074/* See "Frequency meter" comments, below. */
75
76struct fmeter {
77 int cnt; /* unprocessed events count */
78 int val; /* most recent output value */
79 time_t time; /* clock (secs) when val computed */
80 spinlock_t lock; /* guards read or write of above */
81};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct cpuset {
Paul Menage8793d852007-10-18 23:39:39 -070084 struct cgroup_subsys_state css;
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned long flags; /* "unsigned long" so bitops work */
Li Zefan300ed6c2009-01-07 18:08:44 -080087 cpumask_var_t cpus_allowed; /* CPUs allowed to tasks in cpuset */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 nodemask_t mems_allowed; /* Memory Nodes allowed to tasks */
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 struct cpuset *parent; /* my parent */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Paul Jackson3e0d98b2006-01-08 01:01:49 -080092 struct fmeter fmeter; /* memory_pressure filter */
Paul Jackson029190c2007-10-18 23:40:20 -070093
Tejun Heo452477f2013-01-07 08:51:07 -080094 /*
95 * Tasks are being attached to this cpuset. Used to prevent
96 * zeroing cpus/mems_allowed between ->can_attach() and ->attach().
97 */
98 int attach_in_progress;
99
Paul Jackson029190c2007-10-18 23:40:20 -0700100 /* partition number for rebuild_sched_domains() */
101 int pn;
Cliff Wickman956db3c2008-02-07 00:14:43 -0800102
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900103 /* for custom sched domain */
104 int relax_domain_level;
105
Tejun Heo8d033942013-01-07 08:51:07 -0800106 struct work_struct hotplug_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Paul Menage8793d852007-10-18 23:39:39 -0700109/* Retrieve the cpuset for a cgroup */
110static inline struct cpuset *cgroup_cs(struct cgroup *cont)
111{
112 return container_of(cgroup_subsys_state(cont, cpuset_subsys_id),
113 struct cpuset, css);
114}
115
116/* Retrieve the cpuset for a task */
117static inline struct cpuset *task_cs(struct task_struct *task)
118{
119 return container_of(task_subsys_state(task, cpuset_subsys_id),
120 struct cpuset, css);
121}
Paul Menage8793d852007-10-18 23:39:39 -0700122
David Rientjesb2462722011-12-19 17:11:52 -0800123#ifdef CONFIG_NUMA
124static inline bool task_has_mempolicy(struct task_struct *task)
125{
126 return task->mempolicy;
127}
128#else
129static inline bool task_has_mempolicy(struct task_struct *task)
130{
131 return false;
132}
133#endif
134
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* bits in struct cpuset flags field */
137typedef enum {
Tejun Heoefeb77b2013-01-07 08:51:07 -0800138 CS_ONLINE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 CS_CPU_EXCLUSIVE,
140 CS_MEM_EXCLUSIVE,
Paul Menage78608362008-04-29 01:00:26 -0700141 CS_MEM_HARDWALL,
Paul Jackson45b07ef2006-01-08 01:00:56 -0800142 CS_MEMORY_MIGRATE,
Paul Jackson029190c2007-10-18 23:40:20 -0700143 CS_SCHED_LOAD_BALANCE,
Paul Jackson825a46a2006-03-24 03:16:03 -0800144 CS_SPREAD_PAGE,
145 CS_SPREAD_SLAB,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146} cpuset_flagbits_t;
147
148/* convenient tests for these bits */
Tejun Heoefeb77b2013-01-07 08:51:07 -0800149static inline bool is_cpuset_online(const struct cpuset *cs)
150{
151 return test_bit(CS_ONLINE, &cs->flags);
152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static inline int is_cpu_exclusive(const struct cpuset *cs)
155{
Paul Jackson7b5b9ef2006-03-24 03:16:00 -0800156 return test_bit(CS_CPU_EXCLUSIVE, &cs->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159static inline int is_mem_exclusive(const struct cpuset *cs)
160{
Paul Jackson7b5b9ef2006-03-24 03:16:00 -0800161 return test_bit(CS_MEM_EXCLUSIVE, &cs->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Paul Menage78608362008-04-29 01:00:26 -0700164static inline int is_mem_hardwall(const struct cpuset *cs)
165{
166 return test_bit(CS_MEM_HARDWALL, &cs->flags);
167}
168
Paul Jackson029190c2007-10-18 23:40:20 -0700169static inline int is_sched_load_balance(const struct cpuset *cs)
170{
171 return test_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
172}
173
Paul Jackson45b07ef2006-01-08 01:00:56 -0800174static inline int is_memory_migrate(const struct cpuset *cs)
175{
Paul Jackson7b5b9ef2006-03-24 03:16:00 -0800176 return test_bit(CS_MEMORY_MIGRATE, &cs->flags);
Paul Jackson45b07ef2006-01-08 01:00:56 -0800177}
178
Paul Jackson825a46a2006-03-24 03:16:03 -0800179static inline int is_spread_page(const struct cpuset *cs)
180{
181 return test_bit(CS_SPREAD_PAGE, &cs->flags);
182}
183
184static inline int is_spread_slab(const struct cpuset *cs)
185{
186 return test_bit(CS_SPREAD_SLAB, &cs->flags);
187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189static struct cpuset top_cpuset = {
Tejun Heoefeb77b2013-01-07 08:51:07 -0800190 .flags = ((1 << CS_ONLINE) | (1 << CS_CPU_EXCLUSIVE) |
191 (1 << CS_MEM_EXCLUSIVE)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
Tejun Heoae8086c2013-01-07 08:51:07 -0800194/**
195 * cpuset_for_each_child - traverse online children of a cpuset
196 * @child_cs: loop cursor pointing to the current child
197 * @pos_cgrp: used for iteration
198 * @parent_cs: target cpuset to walk children of
199 *
200 * Walk @child_cs through the online children of @parent_cs. Must be used
201 * with RCU read locked.
202 */
203#define cpuset_for_each_child(child_cs, pos_cgrp, parent_cs) \
204 cgroup_for_each_child((pos_cgrp), (parent_cs)->css.cgroup) \
205 if (is_cpuset_online(((child_cs) = cgroup_cs((pos_cgrp)))))
206
Tejun Heofc560a22013-01-07 08:51:08 -0800207/**
208 * cpuset_for_each_descendant_pre - pre-order walk of a cpuset's descendants
209 * @des_cs: loop cursor pointing to the current descendant
210 * @pos_cgrp: used for iteration
211 * @root_cs: target cpuset to walk ancestor of
212 *
213 * Walk @des_cs through the online descendants of @root_cs. Must be used
214 * with RCU read locked. The caller may modify @pos_cgrp by calling
215 * cgroup_rightmost_descendant() to skip subtree.
216 */
217#define cpuset_for_each_descendant_pre(des_cs, pos_cgrp, root_cs) \
218 cgroup_for_each_descendant_pre((pos_cgrp), (root_cs)->css.cgroup) \
219 if (is_cpuset_online(((des_cs) = cgroup_cs((pos_cgrp)))))
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
Tejun Heo5d21cc22013-01-07 08:51:08 -0800222 * There are two global mutexes guarding cpuset structures - cpuset_mutex
223 * and callback_mutex. The latter may nest inside the former. We also
224 * require taking task_lock() when dereferencing a task's cpuset pointer.
225 * See "The task_lock() exception", at the end of this comment.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800227 * A task must hold both mutexes to modify cpusets. If a task holds
228 * cpuset_mutex, then it blocks others wanting that mutex, ensuring that it
229 * is the only task able to also acquire callback_mutex and be able to
230 * modify cpusets. It can perform various checks on the cpuset structure
231 * first, knowing nothing will change. It can also allocate memory while
232 * just holding cpuset_mutex. While it is performing these checks, various
233 * callback routines can briefly acquire callback_mutex to query cpusets.
234 * Once it is ready to make the changes, it takes callback_mutex, blocking
235 * everyone else.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 *
Paul Jackson053199e2005-10-30 15:02:30 -0800237 * Calls to the kernel memory allocator can not be made while holding
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800238 * callback_mutex, as that would risk double tripping on callback_mutex
Paul Jackson053199e2005-10-30 15:02:30 -0800239 * from one of the callbacks into the cpuset code from within
240 * __alloc_pages().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 *
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800242 * If a task is only holding callback_mutex, then it has read-only
Paul Jackson053199e2005-10-30 15:02:30 -0800243 * access to cpusets.
244 *
Miao Xie58568d22009-06-16 15:31:49 -0700245 * Now, the task_struct fields mems_allowed and mempolicy may be changed
246 * by other task, we use alloc_lock in the task_struct fields to protect
247 * them.
Paul Jackson053199e2005-10-30 15:02:30 -0800248 *
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800249 * The cpuset_common_file_read() handlers only hold callback_mutex across
Paul Jackson053199e2005-10-30 15:02:30 -0800250 * small pieces of code, such as when reading out possibly multi-word
251 * cpumasks and nodemasks.
252 *
Paul Menage2df167a2008-02-07 00:14:45 -0800253 * Accessing a task's cpuset should be done in accordance with the
254 * guidelines for accessing subsystem state in kernel/cgroup.c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 */
256
Tejun Heo5d21cc22013-01-07 08:51:08 -0800257static DEFINE_MUTEX(cpuset_mutex);
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800258static DEFINE_MUTEX(callback_mutex);
Paul Jackson4247bdc2005-09-10 00:26:06 -0700259
Max Krasnyanskycf417142008-08-11 14:33:53 -0700260/*
David Rientjes75aa1992009-01-06 14:39:01 -0800261 * cpuset_buffer_lock protects both the cpuset_name and cpuset_nodelist
262 * buffers. They are statically allocated to prevent using excess stack
263 * when calling cpuset_print_task_mems_allowed().
264 */
265#define CPUSET_NAME_LEN (128)
266#define CPUSET_NODELIST_LEN (256)
267static char cpuset_name[CPUSET_NAME_LEN];
268static char cpuset_nodelist[CPUSET_NODELIST_LEN];
269static DEFINE_SPINLOCK(cpuset_buffer_lock);
270
271/*
Tejun Heo3a5a6d02013-01-07 08:51:07 -0800272 * CPU / memory hotplug is handled asynchronously.
273 */
Tejun Heo8d033942013-01-07 08:51:07 -0800274static struct workqueue_struct *cpuset_propagate_hotplug_wq;
275
Tejun Heo3a5a6d02013-01-07 08:51:07 -0800276static void cpuset_hotplug_workfn(struct work_struct *work);
Tejun Heo8d033942013-01-07 08:51:07 -0800277static void cpuset_propagate_hotplug_workfn(struct work_struct *work);
Tejun Heo02bb5862013-01-07 08:51:08 -0800278static void schedule_cpuset_propagate_hotplug(struct cpuset *cs);
Tejun Heo3a5a6d02013-01-07 08:51:07 -0800279
280static DECLARE_WORK(cpuset_hotplug_work, cpuset_hotplug_workfn);
281
282/*
Max Krasnyanskycf417142008-08-11 14:33:53 -0700283 * This is ugly, but preserves the userspace API for existing cpuset
Paul Menage8793d852007-10-18 23:39:39 -0700284 * users. If someone tries to mount the "cpuset" filesystem, we
Max Krasnyanskycf417142008-08-11 14:33:53 -0700285 * silently switch it to mount "cgroup" instead
286 */
Al Virof7e83572010-07-26 13:23:11 +0400287static struct dentry *cpuset_mount(struct file_system_type *fs_type,
288 int flags, const char *unused_dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Paul Menage8793d852007-10-18 23:39:39 -0700290 struct file_system_type *cgroup_fs = get_fs_type("cgroup");
Al Virof7e83572010-07-26 13:23:11 +0400291 struct dentry *ret = ERR_PTR(-ENODEV);
Paul Menage8793d852007-10-18 23:39:39 -0700292 if (cgroup_fs) {
293 char mountopts[] =
294 "cpuset,noprefix,"
295 "release_agent=/sbin/cpuset_release_agent";
Al Virof7e83572010-07-26 13:23:11 +0400296 ret = cgroup_fs->mount(cgroup_fs, flags,
297 unused_dev_name, mountopts);
Paul Menage8793d852007-10-18 23:39:39 -0700298 put_filesystem(cgroup_fs);
299 }
300 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
303static struct file_system_type cpuset_fs_type = {
304 .name = "cpuset",
Al Virof7e83572010-07-26 13:23:11 +0400305 .mount = cpuset_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306};
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308/*
Li Zefan300ed6c2009-01-07 18:08:44 -0800309 * Return in pmask the portion of a cpusets's cpus_allowed that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 * are online. If none are online, walk up the cpuset hierarchy
311 * until we find one that does have some online cpus. If we get
312 * all the way to the top and still haven't found any online cpus,
Rusty Russell5f054e32012-03-29 15:38:31 +1030313 * return cpu_online_mask. Or if passed a NULL cs from an exit'ing
314 * task, return cpu_online_mask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 *
316 * One way or another, we guarantee to return some non-empty subset
Rusty Russell5f054e32012-03-29 15:38:31 +1030317 * of cpu_online_mask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 *
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800319 * Call with callback_mutex held.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 */
321
Li Zefan6af866a2009-01-07 18:08:45 -0800322static void guarantee_online_cpus(const struct cpuset *cs,
323 struct cpumask *pmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Li Zefan300ed6c2009-01-07 18:08:44 -0800325 while (cs && !cpumask_intersects(cs->cpus_allowed, cpu_online_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 cs = cs->parent;
327 if (cs)
Li Zefan300ed6c2009-01-07 18:08:44 -0800328 cpumask_and(pmask, cs->cpus_allowed, cpu_online_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 else
Li Zefan300ed6c2009-01-07 18:08:44 -0800330 cpumask_copy(pmask, cpu_online_mask);
331 BUG_ON(!cpumask_intersects(pmask, cpu_online_mask));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
334/*
335 * Return in *pmask the portion of a cpusets's mems_allowed that
Christoph Lameter0e1e7c72007-10-16 01:25:38 -0700336 * are online, with memory. If none are online with memory, walk
337 * up the cpuset hierarchy until we find one that does have some
338 * online mems. If we get all the way to the top and still haven't
Lai Jiangshan38d7bee2012-12-12 13:51:24 -0800339 * found any online mems, return node_states[N_MEMORY].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 *
341 * One way or another, we guarantee to return some non-empty subset
Lai Jiangshan38d7bee2012-12-12 13:51:24 -0800342 * of node_states[N_MEMORY].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 *
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800344 * Call with callback_mutex held.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 */
346
347static void guarantee_online_mems(const struct cpuset *cs, nodemask_t *pmask)
348{
Christoph Lameter0e1e7c72007-10-16 01:25:38 -0700349 while (cs && !nodes_intersects(cs->mems_allowed,
Lai Jiangshan38d7bee2012-12-12 13:51:24 -0800350 node_states[N_MEMORY]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 cs = cs->parent;
352 if (cs)
Christoph Lameter0e1e7c72007-10-16 01:25:38 -0700353 nodes_and(*pmask, cs->mems_allowed,
Lai Jiangshan38d7bee2012-12-12 13:51:24 -0800354 node_states[N_MEMORY]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 else
Lai Jiangshan38d7bee2012-12-12 13:51:24 -0800356 *pmask = node_states[N_MEMORY];
357 BUG_ON(!nodes_intersects(*pmask, node_states[N_MEMORY]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Miao Xief3b39d42009-06-16 15:31:46 -0700360/*
361 * update task's spread flag if cpuset's page/slab spread flag is set
362 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800363 * Called with callback_mutex/cpuset_mutex held
Miao Xief3b39d42009-06-16 15:31:46 -0700364 */
365static void cpuset_update_task_spread_flag(struct cpuset *cs,
366 struct task_struct *tsk)
367{
368 if (is_spread_page(cs))
369 tsk->flags |= PF_SPREAD_PAGE;
370 else
371 tsk->flags &= ~PF_SPREAD_PAGE;
372 if (is_spread_slab(cs))
373 tsk->flags |= PF_SPREAD_SLAB;
374 else
375 tsk->flags &= ~PF_SPREAD_SLAB;
376}
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378/*
379 * is_cpuset_subset(p, q) - Is cpuset p a subset of cpuset q?
380 *
381 * One cpuset is a subset of another if all its allowed CPUs and
382 * Memory Nodes are a subset of the other, and its exclusive flags
Tejun Heo5d21cc22013-01-07 08:51:08 -0800383 * are only set if the other's are set. Call holding cpuset_mutex.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 */
385
386static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
387{
Li Zefan300ed6c2009-01-07 18:08:44 -0800388 return cpumask_subset(p->cpus_allowed, q->cpus_allowed) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 nodes_subset(p->mems_allowed, q->mems_allowed) &&
390 is_cpu_exclusive(p) <= is_cpu_exclusive(q) &&
391 is_mem_exclusive(p) <= is_mem_exclusive(q);
392}
393
Li Zefan645fcc92009-01-07 18:08:43 -0800394/**
395 * alloc_trial_cpuset - allocate a trial cpuset
396 * @cs: the cpuset that the trial cpuset duplicates
397 */
398static struct cpuset *alloc_trial_cpuset(const struct cpuset *cs)
399{
Li Zefan300ed6c2009-01-07 18:08:44 -0800400 struct cpuset *trial;
401
402 trial = kmemdup(cs, sizeof(*cs), GFP_KERNEL);
403 if (!trial)
404 return NULL;
405
406 if (!alloc_cpumask_var(&trial->cpus_allowed, GFP_KERNEL)) {
407 kfree(trial);
408 return NULL;
409 }
410 cpumask_copy(trial->cpus_allowed, cs->cpus_allowed);
411
412 return trial;
Li Zefan645fcc92009-01-07 18:08:43 -0800413}
414
415/**
416 * free_trial_cpuset - free the trial cpuset
417 * @trial: the trial cpuset to be freed
418 */
419static void free_trial_cpuset(struct cpuset *trial)
420{
Li Zefan300ed6c2009-01-07 18:08:44 -0800421 free_cpumask_var(trial->cpus_allowed);
Li Zefan645fcc92009-01-07 18:08:43 -0800422 kfree(trial);
423}
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425/*
426 * validate_change() - Used to validate that any proposed cpuset change
427 * follows the structural rules for cpusets.
428 *
429 * If we replaced the flag and mask values of the current cpuset
430 * (cur) with those values in the trial cpuset (trial), would
431 * our various subset and exclusive rules still be valid? Presumes
Tejun Heo5d21cc22013-01-07 08:51:08 -0800432 * cpuset_mutex held.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 *
434 * 'cur' is the address of an actual, in-use cpuset. Operations
435 * such as list traversal that depend on the actual address of the
436 * cpuset in the list must use cur below, not trial.
437 *
438 * 'trial' is the address of bulk structure copy of cur, with
439 * perhaps one or more of the fields cpus_allowed, mems_allowed,
440 * or flags changed to new, trial values.
441 *
442 * Return 0 if valid, -errno if not.
443 */
444
445static int validate_change(const struct cpuset *cur, const struct cpuset *trial)
446{
Paul Menage8793d852007-10-18 23:39:39 -0700447 struct cgroup *cont;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 struct cpuset *c, *par;
Tejun Heoae8086c2013-01-07 08:51:07 -0800449 int ret;
450
451 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 /* Each of our child cpusets must be a subset of us */
Tejun Heoae8086c2013-01-07 08:51:07 -0800454 ret = -EBUSY;
455 cpuset_for_each_child(c, cont, cur)
456 if (!is_cpuset_subset(c, trial))
457 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 /* Remaining checks don't apply to root cpuset */
Tejun Heoae8086c2013-01-07 08:51:07 -0800460 ret = 0;
Paul Jackson69604062006-12-06 20:36:15 -0800461 if (cur == &top_cpuset)
Tejun Heoae8086c2013-01-07 08:51:07 -0800462 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Paul Jackson69604062006-12-06 20:36:15 -0800464 par = cur->parent;
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /* We must be a subset of our parent cpuset */
Tejun Heoae8086c2013-01-07 08:51:07 -0800467 ret = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (!is_cpuset_subset(trial, par))
Tejun Heoae8086c2013-01-07 08:51:07 -0800469 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Paul Menage2df167a2008-02-07 00:14:45 -0800471 /*
472 * If either I or some sibling (!= me) is exclusive, we can't
473 * overlap
474 */
Tejun Heoae8086c2013-01-07 08:51:07 -0800475 ret = -EINVAL;
476 cpuset_for_each_child(c, cont, par) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if ((is_cpu_exclusive(trial) || is_cpu_exclusive(c)) &&
478 c != cur &&
Li Zefan300ed6c2009-01-07 18:08:44 -0800479 cpumask_intersects(trial->cpus_allowed, c->cpus_allowed))
Tejun Heoae8086c2013-01-07 08:51:07 -0800480 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if ((is_mem_exclusive(trial) || is_mem_exclusive(c)) &&
482 c != cur &&
483 nodes_intersects(trial->mems_allowed, c->mems_allowed))
Tejun Heoae8086c2013-01-07 08:51:07 -0800484 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486
Tejun Heo452477f2013-01-07 08:51:07 -0800487 /*
488 * Cpusets with tasks - existing or newly being attached - can't
489 * have empty cpus_allowed or mems_allowed.
490 */
Tejun Heoae8086c2013-01-07 08:51:07 -0800491 ret = -ENOSPC;
Tejun Heo452477f2013-01-07 08:51:07 -0800492 if ((cgroup_task_count(cur->css.cgroup) || cur->attach_in_progress) &&
Tejun Heoae8086c2013-01-07 08:51:07 -0800493 (cpumask_empty(trial->cpus_allowed) ||
494 nodes_empty(trial->mems_allowed)))
495 goto out;
Paul Jackson020958b2007-10-18 23:40:21 -0700496
Tejun Heoae8086c2013-01-07 08:51:07 -0800497 ret = 0;
498out:
499 rcu_read_unlock();
500 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Paul Menagedb7f47c2009-04-02 16:57:55 -0700503#ifdef CONFIG_SMP
Dinakar Guniguntala85d7b942005-06-25 14:57:34 -0700504/*
Max Krasnyanskycf417142008-08-11 14:33:53 -0700505 * Helper routine for generate_sched_domains().
Paul Jackson029190c2007-10-18 23:40:20 -0700506 * Do cpusets a, b have overlapping cpus_allowed masks?
507 */
Paul Jackson029190c2007-10-18 23:40:20 -0700508static int cpusets_overlap(struct cpuset *a, struct cpuset *b)
509{
Li Zefan300ed6c2009-01-07 18:08:44 -0800510 return cpumask_intersects(a->cpus_allowed, b->cpus_allowed);
Paul Jackson029190c2007-10-18 23:40:20 -0700511}
512
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900513static void
514update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c)
515{
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900516 if (dattr->relax_domain_level < c->relax_domain_level)
517 dattr->relax_domain_level = c->relax_domain_level;
518 return;
519}
520
Tejun Heofc560a22013-01-07 08:51:08 -0800521static void update_domain_attr_tree(struct sched_domain_attr *dattr,
522 struct cpuset *root_cs)
Lai Jiangshanf5393692008-07-29 22:33:22 -0700523{
Tejun Heofc560a22013-01-07 08:51:08 -0800524 struct cpuset *cp;
525 struct cgroup *pos_cgrp;
Lai Jiangshanf5393692008-07-29 22:33:22 -0700526
Tejun Heofc560a22013-01-07 08:51:08 -0800527 rcu_read_lock();
528 cpuset_for_each_descendant_pre(cp, pos_cgrp, root_cs) {
529 /* skip the whole subtree if @cp doesn't have any CPU */
530 if (cpumask_empty(cp->cpus_allowed)) {
531 pos_cgrp = cgroup_rightmost_descendant(pos_cgrp);
Lai Jiangshanf5393692008-07-29 22:33:22 -0700532 continue;
Tejun Heofc560a22013-01-07 08:51:08 -0800533 }
Lai Jiangshanf5393692008-07-29 22:33:22 -0700534
535 if (is_sched_load_balance(cp))
536 update_domain_attr(dattr, cp);
Lai Jiangshanf5393692008-07-29 22:33:22 -0700537 }
Tejun Heofc560a22013-01-07 08:51:08 -0800538 rcu_read_unlock();
Lai Jiangshanf5393692008-07-29 22:33:22 -0700539}
540
Paul Jackson029190c2007-10-18 23:40:20 -0700541/*
Max Krasnyanskycf417142008-08-11 14:33:53 -0700542 * generate_sched_domains()
Paul Jackson029190c2007-10-18 23:40:20 -0700543 *
Max Krasnyanskycf417142008-08-11 14:33:53 -0700544 * This function builds a partial partition of the systems CPUs
545 * A 'partial partition' is a set of non-overlapping subsets whose
546 * union is a subset of that set.
547 * The output of this function needs to be passed to kernel/sched.c
548 * partition_sched_domains() routine, which will rebuild the scheduler's
549 * load balancing domains (sched domains) as specified by that partial
550 * partition.
Paul Jackson029190c2007-10-18 23:40:20 -0700551 *
Li Zefan45ce80f2009-01-15 13:50:59 -0800552 * See "What is sched_load_balance" in Documentation/cgroups/cpusets.txt
Paul Jackson029190c2007-10-18 23:40:20 -0700553 * for a background explanation of this.
554 *
555 * Does not return errors, on the theory that the callers of this
556 * routine would rather not worry about failures to rebuild sched
557 * domains when operating in the severe memory shortage situations
558 * that could cause allocation failures below.
559 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800560 * Must be called with cpuset_mutex held.
Paul Jackson029190c2007-10-18 23:40:20 -0700561 *
562 * The three key local variables below are:
Li Zefanaeed6822008-07-29 22:33:24 -0700563 * q - a linked-list queue of cpuset pointers, used to implement a
Paul Jackson029190c2007-10-18 23:40:20 -0700564 * top-down scan of all cpusets. This scan loads a pointer
565 * to each cpuset marked is_sched_load_balance into the
566 * array 'csa'. For our purposes, rebuilding the schedulers
567 * sched domains, we can ignore !is_sched_load_balance cpusets.
568 * csa - (for CpuSet Array) Array of pointers to all the cpusets
569 * that need to be load balanced, for convenient iterative
570 * access by the subsequent code that finds the best partition,
571 * i.e the set of domains (subsets) of CPUs such that the
572 * cpus_allowed of every cpuset marked is_sched_load_balance
573 * is a subset of one of these domains, while there are as
574 * many such domains as possible, each as small as possible.
575 * doms - Conversion of 'csa' to an array of cpumasks, for passing to
576 * the kernel/sched.c routine partition_sched_domains() in a
577 * convenient format, that can be easily compared to the prior
578 * value to determine what partition elements (sched domains)
579 * were changed (added or removed.)
580 *
581 * Finding the best partition (set of domains):
582 * The triple nested loops below over i, j, k scan over the
583 * load balanced cpusets (using the array of cpuset pointers in
584 * csa[]) looking for pairs of cpusets that have overlapping
585 * cpus_allowed, but which don't have the same 'pn' partition
586 * number and gives them in the same partition number. It keeps
587 * looping on the 'restart' label until it can no longer find
588 * any such pairs.
589 *
590 * The union of the cpus_allowed masks from the set of
591 * all cpusets having the same 'pn' value then form the one
592 * element of the partition (one sched domain) to be passed to
593 * partition_sched_domains().
594 */
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030595static int generate_sched_domains(cpumask_var_t **domains,
Max Krasnyanskycf417142008-08-11 14:33:53 -0700596 struct sched_domain_attr **attributes)
Paul Jackson029190c2007-10-18 23:40:20 -0700597{
Paul Jackson029190c2007-10-18 23:40:20 -0700598 struct cpuset *cp; /* scans q */
599 struct cpuset **csa; /* array of all cpuset ptrs */
600 int csn; /* how many cpuset ptrs in csa so far */
601 int i, j, k; /* indices for partition finding loops */
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030602 cpumask_var_t *doms; /* resulting partition; i.e. sched domains */
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900603 struct sched_domain_attr *dattr; /* attributes for custom domains */
Ingo Molnar15837152008-11-25 10:27:49 +0100604 int ndoms = 0; /* number of sched domains in result */
Li Zefan6af866a2009-01-07 18:08:45 -0800605 int nslot; /* next empty doms[] struct cpumask slot */
Tejun Heofc560a22013-01-07 08:51:08 -0800606 struct cgroup *pos_cgrp;
Paul Jackson029190c2007-10-18 23:40:20 -0700607
Paul Jackson029190c2007-10-18 23:40:20 -0700608 doms = NULL;
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900609 dattr = NULL;
Max Krasnyanskycf417142008-08-11 14:33:53 -0700610 csa = NULL;
Paul Jackson029190c2007-10-18 23:40:20 -0700611
612 /* Special case for the 99% of systems with one, full, sched domain */
613 if (is_sched_load_balance(&top_cpuset)) {
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030614 ndoms = 1;
615 doms = alloc_sched_domains(ndoms);
Paul Jackson029190c2007-10-18 23:40:20 -0700616 if (!doms)
Max Krasnyanskycf417142008-08-11 14:33:53 -0700617 goto done;
618
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900619 dattr = kmalloc(sizeof(struct sched_domain_attr), GFP_KERNEL);
620 if (dattr) {
621 *dattr = SD_ATTR_INIT;
Li Zefan93a65572008-07-29 22:33:23 -0700622 update_domain_attr_tree(dattr, &top_cpuset);
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900623 }
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030624 cpumask_copy(doms[0], top_cpuset.cpus_allowed);
Max Krasnyanskycf417142008-08-11 14:33:53 -0700625
Max Krasnyanskycf417142008-08-11 14:33:53 -0700626 goto done;
Paul Jackson029190c2007-10-18 23:40:20 -0700627 }
628
Paul Jackson029190c2007-10-18 23:40:20 -0700629 csa = kmalloc(number_of_cpusets * sizeof(cp), GFP_KERNEL);
630 if (!csa)
631 goto done;
632 csn = 0;
633
Tejun Heofc560a22013-01-07 08:51:08 -0800634 rcu_read_lock();
635 cpuset_for_each_descendant_pre(cp, pos_cgrp, &top_cpuset) {
Lai Jiangshanf5393692008-07-29 22:33:22 -0700636 /*
Tejun Heofc560a22013-01-07 08:51:08 -0800637 * Continue traversing beyond @cp iff @cp has some CPUs and
638 * isn't load balancing. The former is obvious. The
639 * latter: All child cpusets contain a subset of the
640 * parent's cpus, so just skip them, and then we call
641 * update_domain_attr_tree() to calc relax_domain_level of
642 * the corresponding sched domain.
Lai Jiangshanf5393692008-07-29 22:33:22 -0700643 */
Tejun Heofc560a22013-01-07 08:51:08 -0800644 if (!cpumask_empty(cp->cpus_allowed) &&
645 !is_sched_load_balance(cp))
Lai Jiangshanf5393692008-07-29 22:33:22 -0700646 continue;
Lai Jiangshan489a5392008-07-25 01:47:23 -0700647
Tejun Heofc560a22013-01-07 08:51:08 -0800648 if (is_sched_load_balance(cp))
649 csa[csn++] = cp;
650
651 /* skip @cp's subtree */
652 pos_cgrp = cgroup_rightmost_descendant(pos_cgrp);
653 }
654 rcu_read_unlock();
Paul Jackson029190c2007-10-18 23:40:20 -0700655
656 for (i = 0; i < csn; i++)
657 csa[i]->pn = i;
658 ndoms = csn;
659
660restart:
661 /* Find the best partition (set of sched domains) */
662 for (i = 0; i < csn; i++) {
663 struct cpuset *a = csa[i];
664 int apn = a->pn;
665
666 for (j = 0; j < csn; j++) {
667 struct cpuset *b = csa[j];
668 int bpn = b->pn;
669
670 if (apn != bpn && cpusets_overlap(a, b)) {
671 for (k = 0; k < csn; k++) {
672 struct cpuset *c = csa[k];
673
674 if (c->pn == bpn)
675 c->pn = apn;
676 }
677 ndoms--; /* one less element */
678 goto restart;
679 }
680 }
681 }
682
Max Krasnyanskycf417142008-08-11 14:33:53 -0700683 /*
684 * Now we know how many domains to create.
685 * Convert <csn, csa> to <ndoms, doms> and populate cpu masks.
686 */
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030687 doms = alloc_sched_domains(ndoms);
Li Zefan700018e2008-11-18 14:02:03 +0800688 if (!doms)
Max Krasnyanskycf417142008-08-11 14:33:53 -0700689 goto done;
Max Krasnyanskycf417142008-08-11 14:33:53 -0700690
691 /*
692 * The rest of the code, including the scheduler, can deal with
693 * dattr==NULL case. No need to abort if alloc fails.
694 */
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +0900695 dattr = kmalloc(ndoms * sizeof(struct sched_domain_attr), GFP_KERNEL);
Paul Jackson029190c2007-10-18 23:40:20 -0700696
697 for (nslot = 0, i = 0; i < csn; i++) {
698 struct cpuset *a = csa[i];
Li Zefan6af866a2009-01-07 18:08:45 -0800699 struct cpumask *dp;
Paul Jackson029190c2007-10-18 23:40:20 -0700700 int apn = a->pn;
701
Max Krasnyanskycf417142008-08-11 14:33:53 -0700702 if (apn < 0) {
703 /* Skip completed partitions */
704 continue;
Paul Jackson029190c2007-10-18 23:40:20 -0700705 }
Max Krasnyanskycf417142008-08-11 14:33:53 -0700706
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030707 dp = doms[nslot];
Max Krasnyanskycf417142008-08-11 14:33:53 -0700708
709 if (nslot == ndoms) {
710 static int warnings = 10;
711 if (warnings) {
712 printk(KERN_WARNING
713 "rebuild_sched_domains confused:"
714 " nslot %d, ndoms %d, csn %d, i %d,"
715 " apn %d\n",
716 nslot, ndoms, csn, i, apn);
717 warnings--;
718 }
719 continue;
720 }
721
Li Zefan6af866a2009-01-07 18:08:45 -0800722 cpumask_clear(dp);
Max Krasnyanskycf417142008-08-11 14:33:53 -0700723 if (dattr)
724 *(dattr + nslot) = SD_ATTR_INIT;
725 for (j = i; j < csn; j++) {
726 struct cpuset *b = csa[j];
727
728 if (apn == b->pn) {
Li Zefan300ed6c2009-01-07 18:08:44 -0800729 cpumask_or(dp, dp, b->cpus_allowed);
Max Krasnyanskycf417142008-08-11 14:33:53 -0700730 if (dattr)
731 update_domain_attr_tree(dattr + nslot, b);
732
733 /* Done with this partition */
734 b->pn = -1;
735 }
736 }
737 nslot++;
Paul Jackson029190c2007-10-18 23:40:20 -0700738 }
739 BUG_ON(nslot != ndoms);
740
Paul Jackson029190c2007-10-18 23:40:20 -0700741done:
Paul Jackson029190c2007-10-18 23:40:20 -0700742 kfree(csa);
Max Krasnyanskycf417142008-08-11 14:33:53 -0700743
Li Zefan700018e2008-11-18 14:02:03 +0800744 /*
745 * Fallback to the default domain if kmalloc() failed.
746 * See comments in partition_sched_domains().
747 */
748 if (doms == NULL)
749 ndoms = 1;
750
Max Krasnyanskycf417142008-08-11 14:33:53 -0700751 *domains = doms;
752 *attributes = dattr;
753 return ndoms;
754}
755
756/*
757 * Rebuild scheduler domains.
758 *
Tejun Heo699140b2013-01-07 08:51:07 -0800759 * If the flag 'sched_load_balance' of any cpuset with non-empty
760 * 'cpus' changes, or if the 'cpus' allowed changes in any cpuset
761 * which has that flag enabled, or if any cpuset with a non-empty
762 * 'cpus' is removed, then call this routine to rebuild the
763 * scheduler's dynamic sched domains.
Max Krasnyanskycf417142008-08-11 14:33:53 -0700764 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800765 * Call with cpuset_mutex held. Takes get_online_cpus().
Max Krasnyanskycf417142008-08-11 14:33:53 -0700766 */
Tejun Heo699140b2013-01-07 08:51:07 -0800767static void rebuild_sched_domains_locked(void)
Max Krasnyanskycf417142008-08-11 14:33:53 -0700768{
769 struct sched_domain_attr *attr;
Rusty Russellacc3f5d2009-11-03 14:53:40 +1030770 cpumask_var_t *doms;
Max Krasnyanskycf417142008-08-11 14:33:53 -0700771 int ndoms;
772
Tejun Heo5d21cc22013-01-07 08:51:08 -0800773 lockdep_assert_held(&cpuset_mutex);
Max Krasnyanskycf417142008-08-11 14:33:53 -0700774 get_online_cpus();
775
776 /* Generate domain masks and attrs */
Max Krasnyanskycf417142008-08-11 14:33:53 -0700777 ndoms = generate_sched_domains(&doms, &attr);
Max Krasnyanskycf417142008-08-11 14:33:53 -0700778
779 /* Have scheduler rebuild the domains */
780 partition_sched_domains(ndoms, doms, attr);
781
782 put_online_cpus();
783}
Paul Menagedb7f47c2009-04-02 16:57:55 -0700784#else /* !CONFIG_SMP */
Tejun Heo699140b2013-01-07 08:51:07 -0800785static void rebuild_sched_domains_locked(void)
Paul Menagedb7f47c2009-04-02 16:57:55 -0700786{
787}
788
Geert Uytterhoevene1b80902009-12-06 20:41:16 +0100789static int generate_sched_domains(cpumask_var_t **domains,
Paul Menagedb7f47c2009-04-02 16:57:55 -0700790 struct sched_domain_attr **attributes)
791{
792 *domains = NULL;
793 return 1;
794}
795#endif /* CONFIG_SMP */
Max Krasnyanskycf417142008-08-11 14:33:53 -0700796
Max Krasnyanskycf417142008-08-11 14:33:53 -0700797void rebuild_sched_domains(void)
798{
Tejun Heo5d21cc22013-01-07 08:51:08 -0800799 mutex_lock(&cpuset_mutex);
Tejun Heo699140b2013-01-07 08:51:07 -0800800 rebuild_sched_domains_locked();
Tejun Heo5d21cc22013-01-07 08:51:08 -0800801 mutex_unlock(&cpuset_mutex);
Paul Jackson029190c2007-10-18 23:40:20 -0700802}
803
Cliff Wickman58f47902008-02-07 00:14:44 -0800804/**
805 * cpuset_test_cpumask - test a task's cpus_allowed versus its cpuset's
806 * @tsk: task to test
807 * @scan: struct cgroup_scanner contained in its struct cpuset_hotplug_scanner
808 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800809 * Call with cpuset_mutex held. May take callback_mutex during call.
Cliff Wickman58f47902008-02-07 00:14:44 -0800810 * Called for each task in a cgroup by cgroup_scan_tasks().
811 * Return nonzero if this tasks's cpus_allowed mask should be changed (in other
812 * words, if its mask is not equal to its cpuset's mask).
Paul Jackson053199e2005-10-30 15:02:30 -0800813 */
Adrian Bunk9e0c9142008-04-29 01:00:25 -0700814static int cpuset_test_cpumask(struct task_struct *tsk,
815 struct cgroup_scanner *scan)
Cliff Wickman58f47902008-02-07 00:14:44 -0800816{
Li Zefan300ed6c2009-01-07 18:08:44 -0800817 return !cpumask_equal(&tsk->cpus_allowed,
Cliff Wickman58f47902008-02-07 00:14:44 -0800818 (cgroup_cs(scan->cg))->cpus_allowed);
819}
Paul Jackson053199e2005-10-30 15:02:30 -0800820
Cliff Wickman58f47902008-02-07 00:14:44 -0800821/**
822 * cpuset_change_cpumask - make a task's cpus_allowed the same as its cpuset's
823 * @tsk: task to test
824 * @scan: struct cgroup_scanner containing the cgroup of the task
825 *
826 * Called by cgroup_scan_tasks() for each task in a cgroup whose
827 * cpus_allowed mask needs to be changed.
828 *
829 * We don't need to re-check for the cgroup/cpuset membership, since we're
Tejun Heo5d21cc22013-01-07 08:51:08 -0800830 * holding cpuset_mutex at this point.
Cliff Wickman58f47902008-02-07 00:14:44 -0800831 */
Adrian Bunk9e0c9142008-04-29 01:00:25 -0700832static void cpuset_change_cpumask(struct task_struct *tsk,
833 struct cgroup_scanner *scan)
Cliff Wickman58f47902008-02-07 00:14:44 -0800834{
Li Zefan300ed6c2009-01-07 18:08:44 -0800835 set_cpus_allowed_ptr(tsk, ((cgroup_cs(scan->cg))->cpus_allowed));
Cliff Wickman58f47902008-02-07 00:14:44 -0800836}
837
838/**
Miao Xie0b2f6302008-07-25 01:47:21 -0700839 * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
840 * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
Li Zefan4e743392008-09-13 02:33:08 -0700841 * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
Miao Xie0b2f6302008-07-25 01:47:21 -0700842 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800843 * Called with cpuset_mutex held
Miao Xie0b2f6302008-07-25 01:47:21 -0700844 *
845 * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
846 * calling callback functions for each.
847 *
Li Zefan4e743392008-09-13 02:33:08 -0700848 * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
849 * if @heap != NULL.
Miao Xie0b2f6302008-07-25 01:47:21 -0700850 */
Li Zefan4e743392008-09-13 02:33:08 -0700851static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
Miao Xie0b2f6302008-07-25 01:47:21 -0700852{
853 struct cgroup_scanner scan;
Miao Xie0b2f6302008-07-25 01:47:21 -0700854
855 scan.cg = cs->css.cgroup;
856 scan.test_task = cpuset_test_cpumask;
857 scan.process_task = cpuset_change_cpumask;
Li Zefan4e743392008-09-13 02:33:08 -0700858 scan.heap = heap;
859 cgroup_scan_tasks(&scan);
Miao Xie0b2f6302008-07-25 01:47:21 -0700860}
861
862/**
Cliff Wickman58f47902008-02-07 00:14:44 -0800863 * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
864 * @cs: the cpuset to consider
865 * @buf: buffer of cpu numbers written to this cpuset
866 */
Li Zefan645fcc92009-01-07 18:08:43 -0800867static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
868 const char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
Li Zefan4e743392008-09-13 02:33:08 -0700870 struct ptr_heap heap;
Cliff Wickman58f47902008-02-07 00:14:44 -0800871 int retval;
872 int is_load_balanced;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Rusty Russell5f054e32012-03-29 15:38:31 +1030874 /* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */
Paul Jackson4c4d50f2006-08-27 01:23:51 -0700875 if (cs == &top_cpuset)
876 return -EACCES;
877
David Rientjes6f7f02e2007-05-08 00:31:43 -0700878 /*
Paul Jacksonc8d9c902008-02-07 00:14:46 -0800879 * An empty cpus_allowed is ok only if the cpuset has no tasks.
Paul Jackson020958b2007-10-18 23:40:21 -0700880 * Since cpulist_parse() fails on an empty mask, we special case
881 * that parsing. The validate_change() call ensures that cpusets
882 * with tasks have cpus.
David Rientjes6f7f02e2007-05-08 00:31:43 -0700883 */
Paul Jackson020958b2007-10-18 23:40:21 -0700884 if (!*buf) {
Li Zefan300ed6c2009-01-07 18:08:44 -0800885 cpumask_clear(trialcs->cpus_allowed);
David Rientjes6f7f02e2007-05-08 00:31:43 -0700886 } else {
Li Zefan300ed6c2009-01-07 18:08:44 -0800887 retval = cpulist_parse(buf, trialcs->cpus_allowed);
David Rientjes6f7f02e2007-05-08 00:31:43 -0700888 if (retval < 0)
889 return retval;
Lai Jiangshan37340742008-06-05 22:46:32 -0700890
Peter Zijlstra6ad4c182009-11-25 13:31:39 +0100891 if (!cpumask_subset(trialcs->cpus_allowed, cpu_active_mask))
Lai Jiangshan37340742008-06-05 22:46:32 -0700892 return -EINVAL;
David Rientjes6f7f02e2007-05-08 00:31:43 -0700893 }
Li Zefan645fcc92009-01-07 18:08:43 -0800894 retval = validate_change(cs, trialcs);
Dinakar Guniguntala85d7b942005-06-25 14:57:34 -0700895 if (retval < 0)
896 return retval;
Paul Jackson029190c2007-10-18 23:40:20 -0700897
Paul Menage8707d8b2007-10-18 23:40:22 -0700898 /* Nothing to do if the cpus didn't change */
Li Zefan300ed6c2009-01-07 18:08:44 -0800899 if (cpumask_equal(cs->cpus_allowed, trialcs->cpus_allowed))
Paul Menage8707d8b2007-10-18 23:40:22 -0700900 return 0;
Cliff Wickman58f47902008-02-07 00:14:44 -0800901
Li Zefan4e743392008-09-13 02:33:08 -0700902 retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
903 if (retval)
904 return retval;
905
Li Zefan645fcc92009-01-07 18:08:43 -0800906 is_load_balanced = is_sched_load_balance(trialcs);
Paul Jackson029190c2007-10-18 23:40:20 -0700907
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800908 mutex_lock(&callback_mutex);
Li Zefan300ed6c2009-01-07 18:08:44 -0800909 cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed);
Ingo Molnar3d3f26a2006-03-23 03:00:18 -0800910 mutex_unlock(&callback_mutex);
Paul Jackson029190c2007-10-18 23:40:20 -0700911
Paul Menage8707d8b2007-10-18 23:40:22 -0700912 /*
913 * Scan tasks in the cpuset, and update the cpumasks of any
Cliff Wickman58f47902008-02-07 00:14:44 -0800914 * that need an update.
Paul Menage8707d8b2007-10-18 23:40:22 -0700915 */
Li Zefan4e743392008-09-13 02:33:08 -0700916 update_tasks_cpumask(cs, &heap);
917
918 heap_free(&heap);
Cliff Wickman58f47902008-02-07 00:14:44 -0800919
Paul Menage8707d8b2007-10-18 23:40:22 -0700920 if (is_load_balanced)
Tejun Heo699140b2013-01-07 08:51:07 -0800921 rebuild_sched_domains_locked();
Dinakar Guniguntala85d7b942005-06-25 14:57:34 -0700922 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924
Paul Jackson053199e2005-10-30 15:02:30 -0800925/*
Paul Jacksone4e364e2006-03-31 02:30:52 -0800926 * cpuset_migrate_mm
927 *
928 * Migrate memory region from one set of nodes to another.
929 *
930 * Temporarilly set tasks mems_allowed to target nodes of migration,
931 * so that the migration code can allocate pages on these nodes.
932 *
Tejun Heo5d21cc22013-01-07 08:51:08 -0800933 * Call holding cpuset_mutex, so current's cpuset won't change
Paul Jacksonc8d9c902008-02-07 00:14:46 -0800934 * during this call, as manage_mutex holds off any cpuset_attach()
Paul Jacksone4e364e2006-03-31 02:30:52 -0800935 * calls. Therefore we don't need to take task_lock around the
936 * call to guarantee_online_mems(), as we know no one is changing
Paul Menage2df167a2008-02-07 00:14:45 -0800937 * our task's cpuset.
Paul Jacksone4e364e2006-03-31 02:30:52 -0800938 *
Paul Jacksone4e364e2006-03-31 02:30:52 -0800939 * While the mm_struct we are migrating is typically from some
940 * other task, the task_struct mems_allowed that we are hacking
941 * is for our current task, which must allocate new pages for that
942 * migrating memory region.
Paul Jacksone4e364e2006-03-31 02:30:52 -0800943 */
944
945static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
946 const nodemask_t *to)
947{
948 struct task_struct *tsk = current;
949
Paul Jacksone4e364e2006-03-31 02:30:52 -0800950 tsk->mems_allowed = *to;
Paul Jacksone4e364e2006-03-31 02:30:52 -0800951
952 do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL);
953
Paul Menage8793d852007-10-18 23:39:39 -0700954 guarantee_online_mems(task_cs(tsk),&tsk->mems_allowed);
Paul Jacksone4e364e2006-03-31 02:30:52 -0800955}
956
Li Zefan3b6766f2009-04-02 16:57:51 -0700957/*
Miao Xie58568d22009-06-16 15:31:49 -0700958 * cpuset_change_task_nodemask - change task's mems_allowed and mempolicy
959 * @tsk: the task to change
960 * @newmems: new nodes that the task will be set
961 *
962 * In order to avoid seeing no nodes if the old and new nodes are disjoint,
963 * we structure updates as setting all new allowed nodes, then clearing newly
964 * disallowed ones.
Miao Xie58568d22009-06-16 15:31:49 -0700965 */
966static void cpuset_change_task_nodemask(struct task_struct *tsk,
967 nodemask_t *newmems)
968{
David Rientjesb2462722011-12-19 17:11:52 -0800969 bool need_loop;
David Rientjes89e8a242011-11-02 13:38:39 -0700970
Miao Xiec0ff7452010-05-24 14:32:08 -0700971 /*
972 * Allow tasks that have access to memory reserves because they have
973 * been OOM killed to get memory anywhere.
974 */
975 if (unlikely(test_thread_flag(TIF_MEMDIE)))
976 return;
977 if (current->flags & PF_EXITING) /* Let dying task have memory */
978 return;
979
980 task_lock(tsk);
David Rientjesb2462722011-12-19 17:11:52 -0800981 /*
982 * Determine if a loop is necessary if another thread is doing
983 * get_mems_allowed(). If at least one node remains unchanged and
984 * tsk does not have a mempolicy, then an empty nodemask will not be
985 * possible when mems_allowed is larger than a word.
986 */
987 need_loop = task_has_mempolicy(tsk) ||
988 !nodes_intersects(*newmems, tsk->mems_allowed);
Mel Gormancc9a6c82012-03-21 16:34:11 -0700989
990 if (need_loop)
991 write_seqcount_begin(&tsk->mems_allowed_seq);
992
Miao Xie58568d22009-06-16 15:31:49 -0700993 nodes_or(tsk->mems_allowed, tsk->mems_allowed, *newmems);
Miao Xiec0ff7452010-05-24 14:32:08 -0700994 mpol_rebind_task(tsk, newmems, MPOL_REBIND_STEP1);
995
Miao Xiec0ff7452010-05-24 14:32:08 -0700996 mpol_rebind_task(tsk, newmems, MPOL_REBIND_STEP2);
Miao Xie58568d22009-06-16 15:31:49 -0700997 tsk->mems_allowed = *newmems;
Mel Gormancc9a6c82012-03-21 16:34:11 -0700998
999 if (need_loop)
1000 write_seqcount_end(&tsk->mems_allowed_seq);
1001
Miao Xiec0ff7452010-05-24 14:32:08 -07001002 task_unlock(tsk);
Miao Xie58568d22009-06-16 15:31:49 -07001003}
1004
1005/*
1006 * Update task's mems_allowed and rebind its mempolicy and vmas' mempolicy
1007 * of it to cpuset's new mems_allowed, and migrate pages to new nodes if
Tejun Heo5d21cc22013-01-07 08:51:08 -08001008 * memory_migrate flag is set. Called with cpuset_mutex held.
Li Zefan3b6766f2009-04-02 16:57:51 -07001009 */
1010static void cpuset_change_nodemask(struct task_struct *p,
1011 struct cgroup_scanner *scan)
1012{
1013 struct mm_struct *mm;
1014 struct cpuset *cs;
1015 int migrate;
1016 const nodemask_t *oldmem = scan->data;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001017 static nodemask_t newmems; /* protected by cpuset_mutex */
Miao Xie58568d22009-06-16 15:31:49 -07001018
1019 cs = cgroup_cs(scan->cg);
Li Zefanee24d372011-03-23 16:42:47 -07001020 guarantee_online_mems(cs, &newmems);
Miao Xie58568d22009-06-16 15:31:49 -07001021
Li Zefanee24d372011-03-23 16:42:47 -07001022 cpuset_change_task_nodemask(p, &newmems);
Miao Xie53feb292010-03-23 13:35:35 -07001023
Li Zefan3b6766f2009-04-02 16:57:51 -07001024 mm = get_task_mm(p);
1025 if (!mm)
1026 return;
1027
Li Zefan3b6766f2009-04-02 16:57:51 -07001028 migrate = is_memory_migrate(cs);
1029
1030 mpol_rebind_mm(mm, &cs->mems_allowed);
1031 if (migrate)
1032 cpuset_migrate_mm(mm, oldmem, &cs->mems_allowed);
1033 mmput(mm);
1034}
1035
Paul Menage8793d852007-10-18 23:39:39 -07001036static void *cpuset_being_rebound;
1037
Miao Xie0b2f6302008-07-25 01:47:21 -07001038/**
1039 * update_tasks_nodemask - Update the nodemasks of tasks in the cpuset.
1040 * @cs: the cpuset in which each task's mems_allowed mask needs to be changed
1041 * @oldmem: old mems_allowed of cpuset cs
Li Zefan010cfac2009-04-02 16:57:52 -07001042 * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
Miao Xie0b2f6302008-07-25 01:47:21 -07001043 *
Tejun Heo5d21cc22013-01-07 08:51:08 -08001044 * Called with cpuset_mutex held
Li Zefan010cfac2009-04-02 16:57:52 -07001045 * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
1046 * if @heap != NULL.
Miao Xie0b2f6302008-07-25 01:47:21 -07001047 */
Li Zefan010cfac2009-04-02 16:57:52 -07001048static void update_tasks_nodemask(struct cpuset *cs, const nodemask_t *oldmem,
1049 struct ptr_heap *heap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Li Zefan3b6766f2009-04-02 16:57:51 -07001051 struct cgroup_scanner scan;
Paul Jackson59dac162006-01-08 01:01:52 -08001052
Lee Schermerhorn846a16b2008-04-28 02:13:09 -07001053 cpuset_being_rebound = cs; /* causes mpol_dup() rebind */
Paul Jackson42253992006-01-08 01:01:59 -08001054
Li Zefan3b6766f2009-04-02 16:57:51 -07001055 scan.cg = cs->css.cgroup;
1056 scan.test_task = NULL;
1057 scan.process_task = cpuset_change_nodemask;
Li Zefan010cfac2009-04-02 16:57:52 -07001058 scan.heap = heap;
Li Zefan3b6766f2009-04-02 16:57:51 -07001059 scan.data = (nodemask_t *)oldmem;
Paul Jackson42253992006-01-08 01:01:59 -08001060
1061 /*
Li Zefan3b6766f2009-04-02 16:57:51 -07001062 * The mpol_rebind_mm() call takes mmap_sem, which we couldn't
1063 * take while holding tasklist_lock. Forks can happen - the
1064 * mpol_dup() cpuset_being_rebound check will catch such forks,
1065 * and rebind their vma mempolicies too. Because we still hold
Tejun Heo5d21cc22013-01-07 08:51:08 -08001066 * the global cpuset_mutex, we know that no other rebind effort
Li Zefan3b6766f2009-04-02 16:57:51 -07001067 * will be contending for the global variable cpuset_being_rebound.
Paul Jackson42253992006-01-08 01:01:59 -08001068 * It's ok if we rebind the same mm twice; mpol_rebind_mm()
Paul Jackson04c19fa2006-01-08 01:02:00 -08001069 * is idempotent. Also migrate pages in each mm to new nodes.
Paul Jackson42253992006-01-08 01:01:59 -08001070 */
Li Zefan010cfac2009-04-02 16:57:52 -07001071 cgroup_scan_tasks(&scan);
Paul Jackson42253992006-01-08 01:01:59 -08001072
Paul Menage2df167a2008-02-07 00:14:45 -08001073 /* We're done rebinding vmas to this cpuset's new mems_allowed. */
Paul Menage8793d852007-10-18 23:39:39 -07001074 cpuset_being_rebound = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
Miao Xie0b2f6302008-07-25 01:47:21 -07001077/*
1078 * Handle user request to change the 'mems' memory placement
1079 * of a cpuset. Needs to validate the request, update the
Miao Xie58568d22009-06-16 15:31:49 -07001080 * cpusets mems_allowed, and for each task in the cpuset,
1081 * update mems_allowed and rebind task's mempolicy and any vma
1082 * mempolicies and if the cpuset is marked 'memory_migrate',
1083 * migrate the tasks pages to the new memory.
Miao Xie0b2f6302008-07-25 01:47:21 -07001084 *
Tejun Heo5d21cc22013-01-07 08:51:08 -08001085 * Call with cpuset_mutex held. May take callback_mutex during call.
Miao Xie0b2f6302008-07-25 01:47:21 -07001086 * Will take tasklist_lock, scan tasklist for tasks in cpuset cs,
1087 * lock each such tasks mm->mmap_sem, scan its vma's and rebind
1088 * their mempolicies to the cpusets new mems_allowed.
1089 */
Li Zefan645fcc92009-01-07 18:08:43 -08001090static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
1091 const char *buf)
Miao Xie0b2f6302008-07-25 01:47:21 -07001092{
Miao Xie53feb292010-03-23 13:35:35 -07001093 NODEMASK_ALLOC(nodemask_t, oldmem, GFP_KERNEL);
Miao Xie0b2f6302008-07-25 01:47:21 -07001094 int retval;
Li Zefan010cfac2009-04-02 16:57:52 -07001095 struct ptr_heap heap;
Miao Xie0b2f6302008-07-25 01:47:21 -07001096
Miao Xie53feb292010-03-23 13:35:35 -07001097 if (!oldmem)
1098 return -ENOMEM;
1099
Miao Xie0b2f6302008-07-25 01:47:21 -07001100 /*
Lai Jiangshan38d7bee2012-12-12 13:51:24 -08001101 * top_cpuset.mems_allowed tracks node_stats[N_MEMORY];
Miao Xie0b2f6302008-07-25 01:47:21 -07001102 * it's read-only
1103 */
Miao Xie53feb292010-03-23 13:35:35 -07001104 if (cs == &top_cpuset) {
1105 retval = -EACCES;
1106 goto done;
1107 }
Miao Xie0b2f6302008-07-25 01:47:21 -07001108
Miao Xie0b2f6302008-07-25 01:47:21 -07001109 /*
1110 * An empty mems_allowed is ok iff there are no tasks in the cpuset.
1111 * Since nodelist_parse() fails on an empty mask, we special case
1112 * that parsing. The validate_change() call ensures that cpusets
1113 * with tasks have memory.
1114 */
1115 if (!*buf) {
Li Zefan645fcc92009-01-07 18:08:43 -08001116 nodes_clear(trialcs->mems_allowed);
Miao Xie0b2f6302008-07-25 01:47:21 -07001117 } else {
Li Zefan645fcc92009-01-07 18:08:43 -08001118 retval = nodelist_parse(buf, trialcs->mems_allowed);
Miao Xie0b2f6302008-07-25 01:47:21 -07001119 if (retval < 0)
1120 goto done;
1121
Li Zefan645fcc92009-01-07 18:08:43 -08001122 if (!nodes_subset(trialcs->mems_allowed,
Lai Jiangshan38d7bee2012-12-12 13:51:24 -08001123 node_states[N_MEMORY])) {
Miao Xie53feb292010-03-23 13:35:35 -07001124 retval = -EINVAL;
1125 goto done;
1126 }
Miao Xie0b2f6302008-07-25 01:47:21 -07001127 }
Miao Xie53feb292010-03-23 13:35:35 -07001128 *oldmem = cs->mems_allowed;
1129 if (nodes_equal(*oldmem, trialcs->mems_allowed)) {
Miao Xie0b2f6302008-07-25 01:47:21 -07001130 retval = 0; /* Too easy - nothing to do */
1131 goto done;
1132 }
Li Zefan645fcc92009-01-07 18:08:43 -08001133 retval = validate_change(cs, trialcs);
Miao Xie0b2f6302008-07-25 01:47:21 -07001134 if (retval < 0)
1135 goto done;
1136
Li Zefan010cfac2009-04-02 16:57:52 -07001137 retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
1138 if (retval < 0)
1139 goto done;
1140
Miao Xie0b2f6302008-07-25 01:47:21 -07001141 mutex_lock(&callback_mutex);
Li Zefan645fcc92009-01-07 18:08:43 -08001142 cs->mems_allowed = trialcs->mems_allowed;
Miao Xie0b2f6302008-07-25 01:47:21 -07001143 mutex_unlock(&callback_mutex);
1144
Miao Xie53feb292010-03-23 13:35:35 -07001145 update_tasks_nodemask(cs, oldmem, &heap);
Li Zefan010cfac2009-04-02 16:57:52 -07001146
1147 heap_free(&heap);
Miao Xie0b2f6302008-07-25 01:47:21 -07001148done:
Miao Xie53feb292010-03-23 13:35:35 -07001149 NODEMASK_FREE(oldmem);
Miao Xie0b2f6302008-07-25 01:47:21 -07001150 return retval;
1151}
1152
Paul Menage8793d852007-10-18 23:39:39 -07001153int current_cpuset_is_being_rebound(void)
1154{
1155 return task_cs(current) == cpuset_being_rebound;
1156}
1157
Paul Menage5be7a472008-05-06 20:42:41 -07001158static int update_relax_domain_level(struct cpuset *cs, s64 val)
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001159{
Paul Menagedb7f47c2009-04-02 16:57:55 -07001160#ifdef CONFIG_SMP
Peter Zijlstra60495e72011-04-07 14:10:04 +02001161 if (val < -1 || val >= sched_domain_level_max)
Li Zefan30e0e172008-05-13 10:27:17 +08001162 return -EINVAL;
Paul Menagedb7f47c2009-04-02 16:57:55 -07001163#endif
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001164
1165 if (val != cs->relax_domain_level) {
1166 cs->relax_domain_level = val;
Li Zefan300ed6c2009-01-07 18:08:44 -08001167 if (!cpumask_empty(cs->cpus_allowed) &&
1168 is_sched_load_balance(cs))
Tejun Heo699140b2013-01-07 08:51:07 -08001169 rebuild_sched_domains_locked();
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001170 }
1171
1172 return 0;
1173}
1174
Paul Jackson3e0d98b2006-01-08 01:01:49 -08001175/*
Miao Xie950592f2009-06-16 15:31:47 -07001176 * cpuset_change_flag - make a task's spread flags the same as its cpuset's
1177 * @tsk: task to be updated
1178 * @scan: struct cgroup_scanner containing the cgroup of the task
1179 *
1180 * Called by cgroup_scan_tasks() for each task in a cgroup.
1181 *
1182 * We don't need to re-check for the cgroup/cpuset membership, since we're
Tejun Heo5d21cc22013-01-07 08:51:08 -08001183 * holding cpuset_mutex at this point.
Miao Xie950592f2009-06-16 15:31:47 -07001184 */
1185static void cpuset_change_flag(struct task_struct *tsk,
1186 struct cgroup_scanner *scan)
1187{
1188 cpuset_update_task_spread_flag(cgroup_cs(scan->cg), tsk);
1189}
1190
1191/*
1192 * update_tasks_flags - update the spread flags of tasks in the cpuset.
1193 * @cs: the cpuset in which each task's spread flags needs to be changed
1194 * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
1195 *
Tejun Heo5d21cc22013-01-07 08:51:08 -08001196 * Called with cpuset_mutex held
Miao Xie950592f2009-06-16 15:31:47 -07001197 *
1198 * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
1199 * calling callback functions for each.
1200 *
1201 * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
1202 * if @heap != NULL.
1203 */
1204static void update_tasks_flags(struct cpuset *cs, struct ptr_heap *heap)
1205{
1206 struct cgroup_scanner scan;
1207
1208 scan.cg = cs->css.cgroup;
1209 scan.test_task = NULL;
1210 scan.process_task = cpuset_change_flag;
1211 scan.heap = heap;
1212 cgroup_scan_tasks(&scan);
1213}
1214
1215/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 * update_flag - read a 0 or a 1 in a file and update associated flag
Paul Menage78608362008-04-29 01:00:26 -07001217 * bit: the bit to update (see cpuset_flagbits_t)
1218 * cs: the cpuset to update
1219 * turning_on: whether the flag is being set or cleared
Paul Jackson053199e2005-10-30 15:02:30 -08001220 *
Tejun Heo5d21cc22013-01-07 08:51:08 -08001221 * Call with cpuset_mutex held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 */
1223
Paul Menage700fe1a2008-04-29 01:00:00 -07001224static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
1225 int turning_on)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Li Zefan645fcc92009-01-07 18:08:43 -08001227 struct cpuset *trialcs;
Rakib Mullick40b6a762008-10-18 20:28:18 -07001228 int balance_flag_changed;
Miao Xie950592f2009-06-16 15:31:47 -07001229 int spread_flag_changed;
1230 struct ptr_heap heap;
1231 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Li Zefan645fcc92009-01-07 18:08:43 -08001233 trialcs = alloc_trial_cpuset(cs);
1234 if (!trialcs)
1235 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Li Zefan645fcc92009-01-07 18:08:43 -08001237 if (turning_on)
1238 set_bit(bit, &trialcs->flags);
1239 else
1240 clear_bit(bit, &trialcs->flags);
1241
1242 err = validate_change(cs, trialcs);
Dinakar Guniguntala85d7b942005-06-25 14:57:34 -07001243 if (err < 0)
Li Zefan645fcc92009-01-07 18:08:43 -08001244 goto out;
Paul Jackson029190c2007-10-18 23:40:20 -07001245
Miao Xie950592f2009-06-16 15:31:47 -07001246 err = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
1247 if (err < 0)
1248 goto out;
1249
Paul Jackson029190c2007-10-18 23:40:20 -07001250 balance_flag_changed = (is_sched_load_balance(cs) !=
Li Zefan645fcc92009-01-07 18:08:43 -08001251 is_sched_load_balance(trialcs));
Paul Jackson029190c2007-10-18 23:40:20 -07001252
Miao Xie950592f2009-06-16 15:31:47 -07001253 spread_flag_changed = ((is_spread_slab(cs) != is_spread_slab(trialcs))
1254 || (is_spread_page(cs) != is_spread_page(trialcs)));
1255
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08001256 mutex_lock(&callback_mutex);
Li Zefan645fcc92009-01-07 18:08:43 -08001257 cs->flags = trialcs->flags;
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08001258 mutex_unlock(&callback_mutex);
Dinakar Guniguntala85d7b942005-06-25 14:57:34 -07001259
Li Zefan300ed6c2009-01-07 18:08:44 -08001260 if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed)
Tejun Heo699140b2013-01-07 08:51:07 -08001261 rebuild_sched_domains_locked();
Paul Jackson029190c2007-10-18 23:40:20 -07001262
Miao Xie950592f2009-06-16 15:31:47 -07001263 if (spread_flag_changed)
1264 update_tasks_flags(cs, &heap);
1265 heap_free(&heap);
Li Zefan645fcc92009-01-07 18:08:43 -08001266out:
1267 free_trial_cpuset(trialcs);
1268 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Paul Jackson053199e2005-10-30 15:02:30 -08001271/*
Adrian Bunk80f72282006-06-30 18:27:16 +02001272 * Frequency meter - How fast is some event occurring?
Paul Jackson3e0d98b2006-01-08 01:01:49 -08001273 *
1274 * These routines manage a digitally filtered, constant time based,
1275 * event frequency meter. There are four routines:
1276 * fmeter_init() - initialize a frequency meter.
1277 * fmeter_markevent() - called each time the event happens.
1278 * fmeter_getrate() - returns the recent rate of such events.
1279 * fmeter_update() - internal routine used to update fmeter.
1280 *
1281 * A common data structure is passed to each of these routines,
1282 * which is used to keep track of the state required to manage the
1283 * frequency meter and its digital filter.
1284 *
1285 * The filter works on the number of events marked per unit time.
1286 * The filter is single-pole low-pass recursive (IIR). The time unit
1287 * is 1 second. Arithmetic is done using 32-bit integers scaled to
1288 * simulate 3 decimal digits of precision (multiplied by 1000).
1289 *
1290 * With an FM_COEF of 933, and a time base of 1 second, the filter
1291 * has a half-life of 10 seconds, meaning that if the events quit
1292 * happening, then the rate returned from the fmeter_getrate()
1293 * will be cut in half each 10 seconds, until it converges to zero.
1294 *
1295 * It is not worth doing a real infinitely recursive filter. If more
1296 * than FM_MAXTICKS ticks have elapsed since the last filter event,
1297 * just compute FM_MAXTICKS ticks worth, by which point the level
1298 * will be stable.
1299 *
1300 * Limit the count of unprocessed events to FM_MAXCNT, so as to avoid
1301 * arithmetic overflow in the fmeter_update() routine.
1302 *
1303 * Given the simple 32 bit integer arithmetic used, this meter works
1304 * best for reporting rates between one per millisecond (msec) and
1305 * one per 32 (approx) seconds. At constant rates faster than one
1306 * per msec it maxes out at values just under 1,000,000. At constant
1307 * rates between one per msec, and one per second it will stabilize
1308 * to a value N*1000, where N is the rate of events per second.
1309 * At constant rates between one per second and one per 32 seconds,
1310 * it will be choppy, moving up on the seconds that have an event,
1311 * and then decaying until the next event. At rates slower than
1312 * about one in 32 seconds, it decays all the way back to zero between
1313 * each event.
1314 */
1315
1316#define FM_COEF 933 /* coefficient for half-life of 10 secs */
1317#define FM_MAXTICKS ((time_t)99) /* useless computing more ticks than this */
1318#define FM_MAXCNT 1000000 /* limit cnt to avoid overflow */
1319#define FM_SCALE 1000 /* faux fixed point scale */
1320
1321/* Initialize a frequency meter */
1322static void fmeter_init(struct fmeter *fmp)
1323{
1324 fmp->cnt = 0;
1325 fmp->val = 0;
1326 fmp->time = 0;
1327 spin_lock_init(&fmp->lock);
1328}
1329
1330/* Internal meter update - process cnt events and update value */
1331static void fmeter_update(struct fmeter *fmp)
1332{
1333 time_t now = get_seconds();
1334 time_t ticks = now - fmp->time;
1335
1336 if (ticks == 0)
1337 return;
1338
1339 ticks = min(FM_MAXTICKS, ticks);
1340 while (ticks-- > 0)
1341 fmp->val = (FM_COEF * fmp->val) / FM_SCALE;
1342 fmp->time = now;
1343
1344 fmp->val += ((FM_SCALE - FM_COEF) * fmp->cnt) / FM_SCALE;
1345 fmp->cnt = 0;
1346}
1347
1348/* Process any previous ticks, then bump cnt by one (times scale). */
1349static void fmeter_markevent(struct fmeter *fmp)
1350{
1351 spin_lock(&fmp->lock);
1352 fmeter_update(fmp);
1353 fmp->cnt = min(FM_MAXCNT, fmp->cnt + FM_SCALE);
1354 spin_unlock(&fmp->lock);
1355}
1356
1357/* Process any previous ticks, then return current value. */
1358static int fmeter_getrate(struct fmeter *fmp)
1359{
1360 int val;
1361
1362 spin_lock(&fmp->lock);
1363 fmeter_update(fmp);
1364 val = fmp->val;
1365 spin_unlock(&fmp->lock);
1366 return val;
1367}
1368
Tejun Heo5d21cc22013-01-07 08:51:08 -08001369/* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
Li Zefan761b3ef52012-01-31 13:47:36 +08001370static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
Ben Blumf780bdb2011-05-26 16:25:19 -07001371{
Tejun Heo2f7ee562011-12-12 18:12:21 -08001372 struct cpuset *cs = cgroup_cs(cgrp);
Tejun Heobb9d97b2011-12-12 18:12:21 -08001373 struct task_struct *task;
1374 int ret;
Ben Blumf780bdb2011-05-26 16:25:19 -07001375
Tejun Heo5d21cc22013-01-07 08:51:08 -08001376 mutex_lock(&cpuset_mutex);
1377
1378 ret = -ENOSPC;
Ben Blumbe367d02009-09-23 15:56:31 -07001379 if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
Tejun Heo5d21cc22013-01-07 08:51:08 -08001380 goto out_unlock;
Ben Blumbe367d02009-09-23 15:56:31 -07001381
Tejun Heobb9d97b2011-12-12 18:12:21 -08001382 cgroup_taskset_for_each(task, cgrp, tset) {
1383 /*
1384 * Kthreads bound to specific cpus cannot be moved to a new
1385 * cpuset; we cannot change their cpu affinity and
1386 * isolating such threads by their set of allowed nodes is
1387 * unnecessary. Thus, cpusets are not applicable for such
1388 * threads. This prevents checking for success of
1389 * set_cpus_allowed_ptr() on all attached tasks before
1390 * cpus_allowed may be changed.
1391 */
Tejun Heo5d21cc22013-01-07 08:51:08 -08001392 ret = -EINVAL;
Tejun Heobb9d97b2011-12-12 18:12:21 -08001393 if (task->flags & PF_THREAD_BOUND)
Tejun Heo5d21cc22013-01-07 08:51:08 -08001394 goto out_unlock;
1395 ret = security_task_setscheduler(task);
1396 if (ret)
1397 goto out_unlock;
Tejun Heobb9d97b2011-12-12 18:12:21 -08001398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Tejun Heo452477f2013-01-07 08:51:07 -08001400 /*
1401 * Mark attach is in progress. This makes validate_change() fail
1402 * changes which zero cpus/mems_allowed.
1403 */
1404 cs->attach_in_progress++;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001405 ret = 0;
1406out_unlock:
1407 mutex_unlock(&cpuset_mutex);
1408 return ret;
Tejun Heo4e4c9a12013-01-07 08:51:07 -08001409}
1410
Tejun Heo452477f2013-01-07 08:51:07 -08001411static void cpuset_cancel_attach(struct cgroup *cgrp,
1412 struct cgroup_taskset *tset)
1413{
Tejun Heo5d21cc22013-01-07 08:51:08 -08001414 mutex_lock(&cpuset_mutex);
Tejun Heo452477f2013-01-07 08:51:07 -08001415 cgroup_cs(cgrp)->attach_in_progress--;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001416 mutex_unlock(&cpuset_mutex);
Tejun Heo452477f2013-01-07 08:51:07 -08001417}
1418
Tejun Heo4e4c9a12013-01-07 08:51:07 -08001419/*
Tejun Heo5d21cc22013-01-07 08:51:08 -08001420 * Protected by cpuset_mutex. cpus_attach is used only by cpuset_attach()
Tejun Heo4e4c9a12013-01-07 08:51:07 -08001421 * but we can't allocate it dynamically there. Define it global and
1422 * allocate from cpuset_init().
1423 */
1424static cpumask_var_t cpus_attach;
1425
1426static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
1427{
Tejun Heo5d21cc22013-01-07 08:51:08 -08001428 /* static bufs protected by cpuset_mutex */
Tejun Heo4e4c9a12013-01-07 08:51:07 -08001429 static nodemask_t cpuset_attach_nodemask_from;
1430 static nodemask_t cpuset_attach_nodemask_to;
1431 struct mm_struct *mm;
1432 struct task_struct *task;
1433 struct task_struct *leader = cgroup_taskset_first(tset);
1434 struct cgroup *oldcgrp = cgroup_taskset_cur_cgroup(tset);
1435 struct cpuset *cs = cgroup_cs(cgrp);
1436 struct cpuset *oldcs = cgroup_cs(oldcgrp);
1437
Tejun Heo5d21cc22013-01-07 08:51:08 -08001438 mutex_lock(&cpuset_mutex);
1439
Tejun Heo94196f52011-12-12 18:12:22 -08001440 /* prepare for attach */
Ben Blumf780bdb2011-05-26 16:25:19 -07001441 if (cs == &top_cpuset)
1442 cpumask_copy(cpus_attach, cpu_possible_mask);
1443 else
1444 guarantee_online_cpus(cs, cpus_attach);
1445
1446 guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
Tejun Heo94196f52011-12-12 18:12:22 -08001447
Tejun Heobb9d97b2011-12-12 18:12:21 -08001448 cgroup_taskset_for_each(task, cgrp, tset) {
1449 /*
1450 * can_attach beforehand should guarantee that this doesn't
1451 * fail. TODO: have a better way to handle failure here
1452 */
1453 WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach));
1454
1455 cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to);
1456 cpuset_update_task_spread_flag(cs, task);
1457 }
David Quigley22fb52d2006-06-23 02:04:00 -07001458
Ben Blumf780bdb2011-05-26 16:25:19 -07001459 /*
1460 * Change mm, possibly for multiple threads in a threadgroup. This is
1461 * expensive and may sleep.
1462 */
1463 cpuset_attach_nodemask_from = oldcs->mems_allowed;
1464 cpuset_attach_nodemask_to = cs->mems_allowed;
Tejun Heobb9d97b2011-12-12 18:12:21 -08001465 mm = get_task_mm(leader);
Paul Jackson42253992006-01-08 01:01:59 -08001466 if (mm) {
Ben Blumf780bdb2011-05-26 16:25:19 -07001467 mpol_rebind_mm(mm, &cpuset_attach_nodemask_to);
Paul Jackson2741a552006-03-31 02:30:51 -08001468 if (is_memory_migrate(cs))
Ben Blumf780bdb2011-05-26 16:25:19 -07001469 cpuset_migrate_mm(mm, &cpuset_attach_nodemask_from,
1470 &cpuset_attach_nodemask_to);
Paul Jackson42253992006-01-08 01:01:59 -08001471 mmput(mm);
1472 }
Tejun Heo452477f2013-01-07 08:51:07 -08001473
1474 cs->attach_in_progress--;
Tejun Heo02bb5862013-01-07 08:51:08 -08001475
1476 /*
1477 * We may have raced with CPU/memory hotunplug. Trigger hotplug
1478 * propagation if @cs doesn't have any CPU or memory. It will move
1479 * the newly added tasks to the nearest parent which can execute.
1480 */
1481 if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
1482 schedule_cpuset_propagate_hotplug(cs);
Tejun Heo5d21cc22013-01-07 08:51:08 -08001483
1484 mutex_unlock(&cpuset_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485}
1486
1487/* The various types of files and directories in a cpuset file system */
1488
1489typedef enum {
Paul Jackson45b07ef2006-01-08 01:00:56 -08001490 FILE_MEMORY_MIGRATE,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 FILE_CPULIST,
1492 FILE_MEMLIST,
1493 FILE_CPU_EXCLUSIVE,
1494 FILE_MEM_EXCLUSIVE,
Paul Menage78608362008-04-29 01:00:26 -07001495 FILE_MEM_HARDWALL,
Paul Jackson029190c2007-10-18 23:40:20 -07001496 FILE_SCHED_LOAD_BALANCE,
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001497 FILE_SCHED_RELAX_DOMAIN_LEVEL,
Paul Jackson3e0d98b2006-01-08 01:01:49 -08001498 FILE_MEMORY_PRESSURE_ENABLED,
1499 FILE_MEMORY_PRESSURE,
Paul Jackson825a46a2006-03-24 03:16:03 -08001500 FILE_SPREAD_PAGE,
1501 FILE_SPREAD_SLAB,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502} cpuset_filetype_t;
1503
Paul Menage700fe1a2008-04-29 01:00:00 -07001504static int cpuset_write_u64(struct cgroup *cgrp, struct cftype *cft, u64 val)
1505{
Paul Menage700fe1a2008-04-29 01:00:00 -07001506 struct cpuset *cs = cgroup_cs(cgrp);
1507 cpuset_filetype_t type = cft->private;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001508 int retval = -ENODEV;
Paul Menage700fe1a2008-04-29 01:00:00 -07001509
Tejun Heo5d21cc22013-01-07 08:51:08 -08001510 mutex_lock(&cpuset_mutex);
1511 if (!is_cpuset_online(cs))
1512 goto out_unlock;
Paul Menage700fe1a2008-04-29 01:00:00 -07001513
1514 switch (type) {
1515 case FILE_CPU_EXCLUSIVE:
1516 retval = update_flag(CS_CPU_EXCLUSIVE, cs, val);
1517 break;
1518 case FILE_MEM_EXCLUSIVE:
1519 retval = update_flag(CS_MEM_EXCLUSIVE, cs, val);
1520 break;
Paul Menage78608362008-04-29 01:00:26 -07001521 case FILE_MEM_HARDWALL:
1522 retval = update_flag(CS_MEM_HARDWALL, cs, val);
1523 break;
Paul Menage700fe1a2008-04-29 01:00:00 -07001524 case FILE_SCHED_LOAD_BALANCE:
1525 retval = update_flag(CS_SCHED_LOAD_BALANCE, cs, val);
1526 break;
1527 case FILE_MEMORY_MIGRATE:
1528 retval = update_flag(CS_MEMORY_MIGRATE, cs, val);
1529 break;
1530 case FILE_MEMORY_PRESSURE_ENABLED:
1531 cpuset_memory_pressure_enabled = !!val;
1532 break;
1533 case FILE_MEMORY_PRESSURE:
1534 retval = -EACCES;
1535 break;
1536 case FILE_SPREAD_PAGE:
1537 retval = update_flag(CS_SPREAD_PAGE, cs, val);
Paul Menage700fe1a2008-04-29 01:00:00 -07001538 break;
1539 case FILE_SPREAD_SLAB:
1540 retval = update_flag(CS_SPREAD_SLAB, cs, val);
Paul Menage700fe1a2008-04-29 01:00:00 -07001541 break;
1542 default:
1543 retval = -EINVAL;
1544 break;
1545 }
Tejun Heo5d21cc22013-01-07 08:51:08 -08001546out_unlock:
1547 mutex_unlock(&cpuset_mutex);
Paul Menage700fe1a2008-04-29 01:00:00 -07001548 return retval;
1549}
1550
Paul Menage5be7a472008-05-06 20:42:41 -07001551static int cpuset_write_s64(struct cgroup *cgrp, struct cftype *cft, s64 val)
1552{
Paul Menage5be7a472008-05-06 20:42:41 -07001553 struct cpuset *cs = cgroup_cs(cgrp);
1554 cpuset_filetype_t type = cft->private;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001555 int retval = -ENODEV;
Paul Menage5be7a472008-05-06 20:42:41 -07001556
Tejun Heo5d21cc22013-01-07 08:51:08 -08001557 mutex_lock(&cpuset_mutex);
1558 if (!is_cpuset_online(cs))
1559 goto out_unlock;
Paul Menagee3712392008-07-25 01:47:02 -07001560
Paul Menage5be7a472008-05-06 20:42:41 -07001561 switch (type) {
1562 case FILE_SCHED_RELAX_DOMAIN_LEVEL:
1563 retval = update_relax_domain_level(cs, val);
1564 break;
1565 default:
1566 retval = -EINVAL;
1567 break;
1568 }
Tejun Heo5d21cc22013-01-07 08:51:08 -08001569out_unlock:
1570 mutex_unlock(&cpuset_mutex);
Paul Menage5be7a472008-05-06 20:42:41 -07001571 return retval;
1572}
1573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574/*
Paul Menagee3712392008-07-25 01:47:02 -07001575 * Common handling for a write to a "cpus" or "mems" file.
1576 */
1577static int cpuset_write_resmask(struct cgroup *cgrp, struct cftype *cft,
1578 const char *buf)
1579{
Li Zefan645fcc92009-01-07 18:08:43 -08001580 struct cpuset *cs = cgroup_cs(cgrp);
1581 struct cpuset *trialcs;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001582 int retval = -ENODEV;
Paul Menagee3712392008-07-25 01:47:02 -07001583
Tejun Heo3a5a6d02013-01-07 08:51:07 -08001584 /*
1585 * CPU or memory hotunplug may leave @cs w/o any execution
1586 * resources, in which case the hotplug code asynchronously updates
1587 * configuration and transfers all tasks to the nearest ancestor
1588 * which can execute.
1589 *
1590 * As writes to "cpus" or "mems" may restore @cs's execution
1591 * resources, wait for the previously scheduled operations before
1592 * proceeding, so that we don't end up keep removing tasks added
1593 * after execution capability is restored.
Tejun Heo02bb5862013-01-07 08:51:08 -08001594 *
1595 * Flushing cpuset_hotplug_work is enough to synchronize against
1596 * hotplug hanlding; however, cpuset_attach() may schedule
1597 * propagation work directly. Flush the workqueue too.
Tejun Heo3a5a6d02013-01-07 08:51:07 -08001598 */
1599 flush_work(&cpuset_hotplug_work);
Tejun Heo02bb5862013-01-07 08:51:08 -08001600 flush_workqueue(cpuset_propagate_hotplug_wq);
Tejun Heo3a5a6d02013-01-07 08:51:07 -08001601
Tejun Heo5d21cc22013-01-07 08:51:08 -08001602 mutex_lock(&cpuset_mutex);
1603 if (!is_cpuset_online(cs))
1604 goto out_unlock;
Paul Menagee3712392008-07-25 01:47:02 -07001605
Li Zefan645fcc92009-01-07 18:08:43 -08001606 trialcs = alloc_trial_cpuset(cs);
Li Zefanb75f38d2011-03-04 17:36:21 -08001607 if (!trialcs) {
1608 retval = -ENOMEM;
Tejun Heo5d21cc22013-01-07 08:51:08 -08001609 goto out_unlock;
Li Zefanb75f38d2011-03-04 17:36:21 -08001610 }
Li Zefan645fcc92009-01-07 18:08:43 -08001611
Paul Menagee3712392008-07-25 01:47:02 -07001612 switch (cft->private) {
1613 case FILE_CPULIST:
Li Zefan645fcc92009-01-07 18:08:43 -08001614 retval = update_cpumask(cs, trialcs, buf);
Paul Menagee3712392008-07-25 01:47:02 -07001615 break;
1616 case FILE_MEMLIST:
Li Zefan645fcc92009-01-07 18:08:43 -08001617 retval = update_nodemask(cs, trialcs, buf);
Paul Menagee3712392008-07-25 01:47:02 -07001618 break;
1619 default:
1620 retval = -EINVAL;
1621 break;
1622 }
Li Zefan645fcc92009-01-07 18:08:43 -08001623
1624 free_trial_cpuset(trialcs);
Tejun Heo5d21cc22013-01-07 08:51:08 -08001625out_unlock:
1626 mutex_unlock(&cpuset_mutex);
Paul Menagee3712392008-07-25 01:47:02 -07001627 return retval;
1628}
1629
1630/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 * These ascii lists should be read in a single call, by using a user
1632 * buffer large enough to hold the entire map. If read in smaller
1633 * chunks, there is no guarantee of atomicity. Since the display format
1634 * used, list of ranges of sequential numbers, is variable length,
1635 * and since these maps can change value dynamically, one could read
1636 * gibberish by doing partial reads while a list was changing.
1637 * A single large read to a buffer that crosses a page boundary is
1638 * ok, because the result being copied to user land is not recomputed
1639 * across a page fault.
1640 */
1641
Li Zefan9303e0c2011-03-23 16:42:45 -07001642static size_t cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Li Zefan9303e0c2011-03-23 16:42:45 -07001644 size_t count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08001646 mutex_lock(&callback_mutex);
Li Zefan9303e0c2011-03-23 16:42:45 -07001647 count = cpulist_scnprintf(page, PAGE_SIZE, cs->cpus_allowed);
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08001648 mutex_unlock(&callback_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Li Zefan9303e0c2011-03-23 16:42:45 -07001650 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Li Zefan9303e0c2011-03-23 16:42:45 -07001653static size_t cpuset_sprintf_memlist(char *page, struct cpuset *cs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
Li Zefan9303e0c2011-03-23 16:42:45 -07001655 size_t count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08001657 mutex_lock(&callback_mutex);
Li Zefan9303e0c2011-03-23 16:42:45 -07001658 count = nodelist_scnprintf(page, PAGE_SIZE, cs->mems_allowed);
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08001659 mutex_unlock(&callback_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Li Zefan9303e0c2011-03-23 16:42:45 -07001661 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
1663
Paul Menage8793d852007-10-18 23:39:39 -07001664static ssize_t cpuset_common_file_read(struct cgroup *cont,
1665 struct cftype *cft,
1666 struct file *file,
1667 char __user *buf,
1668 size_t nbytes, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
Paul Menage8793d852007-10-18 23:39:39 -07001670 struct cpuset *cs = cgroup_cs(cont);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 cpuset_filetype_t type = cft->private;
1672 char *page;
1673 ssize_t retval = 0;
1674 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Mel Gormane12ba742007-10-16 01:25:52 -07001676 if (!(page = (char *)__get_free_page(GFP_TEMPORARY)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 return -ENOMEM;
1678
1679 s = page;
1680
1681 switch (type) {
1682 case FILE_CPULIST:
1683 s += cpuset_sprintf_cpulist(s, cs);
1684 break;
1685 case FILE_MEMLIST:
1686 s += cpuset_sprintf_memlist(s, cs);
1687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 default:
1689 retval = -EINVAL;
1690 goto out;
1691 }
1692 *s++ = '\n';
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Al Viroeacaa1f2005-09-30 03:26:43 +01001694 retval = simple_read_from_buffer(buf, nbytes, ppos, page, s - page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695out:
1696 free_page((unsigned long)page);
1697 return retval;
1698}
1699
Paul Menage700fe1a2008-04-29 01:00:00 -07001700static u64 cpuset_read_u64(struct cgroup *cont, struct cftype *cft)
1701{
1702 struct cpuset *cs = cgroup_cs(cont);
1703 cpuset_filetype_t type = cft->private;
1704 switch (type) {
1705 case FILE_CPU_EXCLUSIVE:
1706 return is_cpu_exclusive(cs);
1707 case FILE_MEM_EXCLUSIVE:
1708 return is_mem_exclusive(cs);
Paul Menage78608362008-04-29 01:00:26 -07001709 case FILE_MEM_HARDWALL:
1710 return is_mem_hardwall(cs);
Paul Menage700fe1a2008-04-29 01:00:00 -07001711 case FILE_SCHED_LOAD_BALANCE:
1712 return is_sched_load_balance(cs);
1713 case FILE_MEMORY_MIGRATE:
1714 return is_memory_migrate(cs);
1715 case FILE_MEMORY_PRESSURE_ENABLED:
1716 return cpuset_memory_pressure_enabled;
1717 case FILE_MEMORY_PRESSURE:
1718 return fmeter_getrate(&cs->fmeter);
1719 case FILE_SPREAD_PAGE:
1720 return is_spread_page(cs);
1721 case FILE_SPREAD_SLAB:
1722 return is_spread_slab(cs);
1723 default:
1724 BUG();
1725 }
Max Krasnyanskycf417142008-08-11 14:33:53 -07001726
1727 /* Unreachable but makes gcc happy */
1728 return 0;
Paul Menage700fe1a2008-04-29 01:00:00 -07001729}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Paul Menage5be7a472008-05-06 20:42:41 -07001731static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft)
1732{
1733 struct cpuset *cs = cgroup_cs(cont);
1734 cpuset_filetype_t type = cft->private;
1735 switch (type) {
1736 case FILE_SCHED_RELAX_DOMAIN_LEVEL:
1737 return cs->relax_domain_level;
1738 default:
1739 BUG();
1740 }
Max Krasnyanskycf417142008-08-11 14:33:53 -07001741
1742 /* Unrechable but makes gcc happy */
1743 return 0;
Paul Menage5be7a472008-05-06 20:42:41 -07001744}
1745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747/*
1748 * for the common functions, 'private' gives the type of file
1749 */
1750
Paul Menageaddf2c72008-04-29 01:00:26 -07001751static struct cftype files[] = {
1752 {
1753 .name = "cpus",
1754 .read = cpuset_common_file_read,
Paul Menagee3712392008-07-25 01:47:02 -07001755 .write_string = cpuset_write_resmask,
1756 .max_write_len = (100U + 6 * NR_CPUS),
Paul Menageaddf2c72008-04-29 01:00:26 -07001757 .private = FILE_CPULIST,
1758 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Paul Menageaddf2c72008-04-29 01:00:26 -07001760 {
1761 .name = "mems",
1762 .read = cpuset_common_file_read,
Paul Menagee3712392008-07-25 01:47:02 -07001763 .write_string = cpuset_write_resmask,
1764 .max_write_len = (100U + 6 * MAX_NUMNODES),
Paul Menageaddf2c72008-04-29 01:00:26 -07001765 .private = FILE_MEMLIST,
1766 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
Paul Menageaddf2c72008-04-29 01:00:26 -07001768 {
1769 .name = "cpu_exclusive",
1770 .read_u64 = cpuset_read_u64,
1771 .write_u64 = cpuset_write_u64,
1772 .private = FILE_CPU_EXCLUSIVE,
1773 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Paul Menageaddf2c72008-04-29 01:00:26 -07001775 {
1776 .name = "mem_exclusive",
1777 .read_u64 = cpuset_read_u64,
1778 .write_u64 = cpuset_write_u64,
1779 .private = FILE_MEM_EXCLUSIVE,
1780 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Paul Menageaddf2c72008-04-29 01:00:26 -07001782 {
Paul Menage78608362008-04-29 01:00:26 -07001783 .name = "mem_hardwall",
1784 .read_u64 = cpuset_read_u64,
1785 .write_u64 = cpuset_write_u64,
1786 .private = FILE_MEM_HARDWALL,
1787 },
1788
1789 {
Paul Menageaddf2c72008-04-29 01:00:26 -07001790 .name = "sched_load_balance",
1791 .read_u64 = cpuset_read_u64,
1792 .write_u64 = cpuset_write_u64,
1793 .private = FILE_SCHED_LOAD_BALANCE,
1794 },
Paul Jackson029190c2007-10-18 23:40:20 -07001795
Paul Menageaddf2c72008-04-29 01:00:26 -07001796 {
1797 .name = "sched_relax_domain_level",
Paul Menage5be7a472008-05-06 20:42:41 -07001798 .read_s64 = cpuset_read_s64,
1799 .write_s64 = cpuset_write_s64,
Paul Menageaddf2c72008-04-29 01:00:26 -07001800 .private = FILE_SCHED_RELAX_DOMAIN_LEVEL,
1801 },
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001802
Paul Menageaddf2c72008-04-29 01:00:26 -07001803 {
1804 .name = "memory_migrate",
1805 .read_u64 = cpuset_read_u64,
1806 .write_u64 = cpuset_write_u64,
1807 .private = FILE_MEMORY_MIGRATE,
1808 },
1809
1810 {
1811 .name = "memory_pressure",
1812 .read_u64 = cpuset_read_u64,
1813 .write_u64 = cpuset_write_u64,
1814 .private = FILE_MEMORY_PRESSURE,
Li Zefan099fca32009-04-02 16:57:29 -07001815 .mode = S_IRUGO,
Paul Menageaddf2c72008-04-29 01:00:26 -07001816 },
1817
1818 {
1819 .name = "memory_spread_page",
1820 .read_u64 = cpuset_read_u64,
1821 .write_u64 = cpuset_write_u64,
1822 .private = FILE_SPREAD_PAGE,
1823 },
1824
1825 {
1826 .name = "memory_spread_slab",
1827 .read_u64 = cpuset_read_u64,
1828 .write_u64 = cpuset_write_u64,
1829 .private = FILE_SPREAD_SLAB,
1830 },
Tejun Heo4baf6e32012-04-01 12:09:55 -07001831
1832 {
1833 .name = "memory_pressure_enabled",
1834 .flags = CFTYPE_ONLY_ON_ROOT,
1835 .read_u64 = cpuset_read_u64,
1836 .write_u64 = cpuset_write_u64,
1837 .private = FILE_MEMORY_PRESSURE_ENABLED,
1838 },
1839
1840 { } /* terminate */
Paul Jackson45b07ef2006-01-08 01:00:56 -08001841};
1842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843/*
Tejun Heo92fb9742012-11-19 08:13:38 -08001844 * cpuset_css_alloc - allocate a cpuset css
Paul Menage2df167a2008-02-07 00:14:45 -08001845 * cont: control group that the new cpuset will be part of
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 */
1847
Tejun Heo92fb9742012-11-19 08:13:38 -08001848static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
Tejun Heoc8f699b2013-01-07 08:51:07 -08001850 struct cpuset *cs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Tejun Heoc8f699b2013-01-07 08:51:07 -08001852 if (!cont->parent)
Paul Menage8793d852007-10-18 23:39:39 -07001853 return &top_cpuset.css;
Tejun Heo033fa1c2012-11-19 08:13:39 -08001854
Tejun Heoc8f699b2013-01-07 08:51:07 -08001855 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 if (!cs)
Paul Menage8793d852007-10-18 23:39:39 -07001857 return ERR_PTR(-ENOMEM);
Li Zefan300ed6c2009-01-07 18:08:44 -08001858 if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL)) {
1859 kfree(cs);
1860 return ERR_PTR(-ENOMEM);
1861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
Paul Jackson029190c2007-10-18 23:40:20 -07001863 set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
Li Zefan300ed6c2009-01-07 18:08:44 -08001864 cpumask_clear(cs->cpus_allowed);
Mike Travisf9a86fc2008-04-04 18:11:07 -07001865 nodes_clear(cs->mems_allowed);
Paul Jackson3e0d98b2006-01-08 01:01:49 -08001866 fmeter_init(&cs->fmeter);
Tejun Heo8d033942013-01-07 08:51:07 -08001867 INIT_WORK(&cs->hotplug_work, cpuset_propagate_hotplug_workfn);
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001868 cs->relax_domain_level = -1;
Tejun Heoc8f699b2013-01-07 08:51:07 -08001869 cs->parent = cgroup_cs(cont->parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Tejun Heoc8f699b2013-01-07 08:51:07 -08001871 return &cs->css;
1872}
1873
1874static int cpuset_css_online(struct cgroup *cgrp)
1875{
1876 struct cpuset *cs = cgroup_cs(cgrp);
1877 struct cpuset *parent = cs->parent;
Tejun Heoae8086c2013-01-07 08:51:07 -08001878 struct cpuset *tmp_cs;
1879 struct cgroup *pos_cg;
Tejun Heoc8f699b2013-01-07 08:51:07 -08001880
1881 if (!parent)
1882 return 0;
1883
Tejun Heo5d21cc22013-01-07 08:51:08 -08001884 mutex_lock(&cpuset_mutex);
1885
Tejun Heoefeb77b2013-01-07 08:51:07 -08001886 set_bit(CS_ONLINE, &cs->flags);
Tejun Heoc8f699b2013-01-07 08:51:07 -08001887 if (is_spread_page(parent))
1888 set_bit(CS_SPREAD_PAGE, &cs->flags);
1889 if (is_spread_slab(parent))
1890 set_bit(CS_SPREAD_SLAB, &cs->flags);
1891
Paul Jackson202f72d2006-01-08 01:01:57 -08001892 number_of_cpusets++;
Tejun Heo033fa1c2012-11-19 08:13:39 -08001893
Tejun Heoc8f699b2013-01-07 08:51:07 -08001894 if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags))
Tejun Heo5d21cc22013-01-07 08:51:08 -08001895 goto out_unlock;
Tejun Heo033fa1c2012-11-19 08:13:39 -08001896
1897 /*
1898 * Clone @parent's configuration if CGRP_CPUSET_CLONE_CHILDREN is
1899 * set. This flag handling is implemented in cgroup core for
1900 * histrical reasons - the flag may be specified during mount.
1901 *
1902 * Currently, if any sibling cpusets have exclusive cpus or mem, we
1903 * refuse to clone the configuration - thereby refusing the task to
1904 * be entered, and as a result refusing the sys_unshare() or
1905 * clone() which initiated it. If this becomes a problem for some
1906 * users who wish to allow that scenario, then this could be
1907 * changed to grant parent->cpus_allowed-sibling_cpus_exclusive
1908 * (and likewise for mems) to the new cgroup.
1909 */
Tejun Heoae8086c2013-01-07 08:51:07 -08001910 rcu_read_lock();
1911 cpuset_for_each_child(tmp_cs, pos_cg, parent) {
1912 if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs)) {
1913 rcu_read_unlock();
Tejun Heo5d21cc22013-01-07 08:51:08 -08001914 goto out_unlock;
Tejun Heoae8086c2013-01-07 08:51:07 -08001915 }
Tejun Heo033fa1c2012-11-19 08:13:39 -08001916 }
Tejun Heoae8086c2013-01-07 08:51:07 -08001917 rcu_read_unlock();
Tejun Heo033fa1c2012-11-19 08:13:39 -08001918
1919 mutex_lock(&callback_mutex);
1920 cs->mems_allowed = parent->mems_allowed;
1921 cpumask_copy(cs->cpus_allowed, parent->cpus_allowed);
1922 mutex_unlock(&callback_mutex);
Tejun Heo5d21cc22013-01-07 08:51:08 -08001923out_unlock:
1924 mutex_unlock(&cpuset_mutex);
Tejun Heoc8f699b2013-01-07 08:51:07 -08001925 return 0;
1926}
1927
1928static void cpuset_css_offline(struct cgroup *cgrp)
1929{
1930 struct cpuset *cs = cgroup_cs(cgrp);
1931
Tejun Heo5d21cc22013-01-07 08:51:08 -08001932 mutex_lock(&cpuset_mutex);
Tejun Heoc8f699b2013-01-07 08:51:07 -08001933
1934 if (is_sched_load_balance(cs))
1935 update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
1936
1937 number_of_cpusets--;
Tejun Heoefeb77b2013-01-07 08:51:07 -08001938 clear_bit(CS_ONLINE, &cs->flags);
Tejun Heoc8f699b2013-01-07 08:51:07 -08001939
Tejun Heo5d21cc22013-01-07 08:51:08 -08001940 mutex_unlock(&cpuset_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
Paul Jackson029190c2007-10-18 23:40:20 -07001943/*
Paul Jackson029190c2007-10-18 23:40:20 -07001944 * If the cpuset being removed has its flag 'sched_load_balance'
1945 * enabled, then simulate turning sched_load_balance off, which
Tejun Heo699140b2013-01-07 08:51:07 -08001946 * will call rebuild_sched_domains_locked().
Paul Jackson029190c2007-10-18 23:40:20 -07001947 */
1948
Tejun Heo92fb9742012-11-19 08:13:38 -08001949static void cpuset_css_free(struct cgroup *cont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
Paul Menage8793d852007-10-18 23:39:39 -07001951 struct cpuset *cs = cgroup_cs(cont);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Li Zefan300ed6c2009-01-07 18:08:44 -08001953 free_cpumask_var(cs->cpus_allowed);
Paul Menage8793d852007-10-18 23:39:39 -07001954 kfree(cs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}
1956
Paul Menage8793d852007-10-18 23:39:39 -07001957struct cgroup_subsys cpuset_subsys = {
1958 .name = "cpuset",
Tejun Heo92fb9742012-11-19 08:13:38 -08001959 .css_alloc = cpuset_css_alloc,
Tejun Heoc8f699b2013-01-07 08:51:07 -08001960 .css_online = cpuset_css_online,
1961 .css_offline = cpuset_css_offline,
Tejun Heo92fb9742012-11-19 08:13:38 -08001962 .css_free = cpuset_css_free,
Paul Menage8793d852007-10-18 23:39:39 -07001963 .can_attach = cpuset_can_attach,
Tejun Heo452477f2013-01-07 08:51:07 -08001964 .cancel_attach = cpuset_cancel_attach,
Paul Menage8793d852007-10-18 23:39:39 -07001965 .attach = cpuset_attach,
Paul Menage8793d852007-10-18 23:39:39 -07001966 .subsys_id = cpuset_subsys_id,
Tejun Heo4baf6e32012-04-01 12:09:55 -07001967 .base_cftypes = files,
Paul Menage8793d852007-10-18 23:39:39 -07001968 .early_init = 1,
1969};
1970
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971/**
1972 * cpuset_init - initialize cpusets at system boot
1973 *
1974 * Description: Initialize top_cpuset and the cpuset internal file system,
1975 **/
1976
1977int __init cpuset_init(void)
1978{
Paul Menage8793d852007-10-18 23:39:39 -07001979 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
Miao Xie58568d22009-06-16 15:31:49 -07001981 if (!alloc_cpumask_var(&top_cpuset.cpus_allowed, GFP_KERNEL))
1982 BUG();
1983
Li Zefan300ed6c2009-01-07 18:08:44 -08001984 cpumask_setall(top_cpuset.cpus_allowed);
Mike Travisf9a86fc2008-04-04 18:11:07 -07001985 nodes_setall(top_cpuset.mems_allowed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Paul Jackson3e0d98b2006-01-08 01:01:49 -08001987 fmeter_init(&top_cpuset.fmeter);
Paul Jackson029190c2007-10-18 23:40:20 -07001988 set_bit(CS_SCHED_LOAD_BALANCE, &top_cpuset.flags);
Hidetoshi Seto1d3504f2008-04-15 14:04:23 +09001989 top_cpuset.relax_domain_level = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 err = register_filesystem(&cpuset_fs_type);
1992 if (err < 0)
Paul Menage8793d852007-10-18 23:39:39 -07001993 return err;
1994
Li Zefan2341d1b2009-01-07 18:08:42 -08001995 if (!alloc_cpumask_var(&cpus_attach, GFP_KERNEL))
1996 BUG();
1997
Paul Jackson202f72d2006-01-08 01:01:57 -08001998 number_of_cpusets = 1;
Paul Menage8793d852007-10-18 23:39:39 -07001999 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000}
2001
Cliff Wickman956db3c2008-02-07 00:14:43 -08002002/**
2003 * cpuset_do_move_task - move a given task to another cpuset
2004 * @tsk: pointer to task_struct the task to move
2005 * @scan: struct cgroup_scanner contained in its struct cpuset_hotplug_scanner
2006 *
2007 * Called by cgroup_scan_tasks() for each task in a cgroup.
2008 * Return nonzero to stop the walk through the tasks.
2009 */
Adrian Bunk9e0c9142008-04-29 01:00:25 -07002010static void cpuset_do_move_task(struct task_struct *tsk,
2011 struct cgroup_scanner *scan)
Cliff Wickman956db3c2008-02-07 00:14:43 -08002012{
Li Zefan7f81b1a2009-04-02 16:57:53 -07002013 struct cgroup *new_cgroup = scan->data;
Cliff Wickman956db3c2008-02-07 00:14:43 -08002014
Tejun Heo5d21cc22013-01-07 08:51:08 -08002015 cgroup_lock();
Li Zefan7f81b1a2009-04-02 16:57:53 -07002016 cgroup_attach_task(new_cgroup, tsk);
Tejun Heo5d21cc22013-01-07 08:51:08 -08002017 cgroup_unlock();
Cliff Wickman956db3c2008-02-07 00:14:43 -08002018}
2019
2020/**
2021 * move_member_tasks_to_cpuset - move tasks from one cpuset to another
2022 * @from: cpuset in which the tasks currently reside
2023 * @to: cpuset to which the tasks will be moved
2024 *
Tejun Heo5d21cc22013-01-07 08:51:08 -08002025 * Called with cpuset_mutex held
Paul Jacksonc8d9c902008-02-07 00:14:46 -08002026 * callback_mutex must not be held, as cpuset_attach() will take it.
Cliff Wickman956db3c2008-02-07 00:14:43 -08002027 *
2028 * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
2029 * calling callback functions for each.
2030 */
2031static void move_member_tasks_to_cpuset(struct cpuset *from, struct cpuset *to)
2032{
Li Zefan7f81b1a2009-04-02 16:57:53 -07002033 struct cgroup_scanner scan;
Cliff Wickman956db3c2008-02-07 00:14:43 -08002034
Li Zefan7f81b1a2009-04-02 16:57:53 -07002035 scan.cg = from->css.cgroup;
2036 scan.test_task = NULL; /* select all tasks in cgroup */
2037 scan.process_task = cpuset_do_move_task;
2038 scan.heap = NULL;
2039 scan.data = to->css.cgroup;
Cliff Wickman956db3c2008-02-07 00:14:43 -08002040
Li Zefan7f81b1a2009-04-02 16:57:53 -07002041 if (cgroup_scan_tasks(&scan))
Cliff Wickman956db3c2008-02-07 00:14:43 -08002042 printk(KERN_ERR "move_member_tasks_to_cpuset: "
2043 "cgroup_scan_tasks failed\n");
2044}
2045
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002046/*
Max Krasnyanskycf417142008-08-11 14:33:53 -07002047 * If CPU and/or memory hotplug handlers, below, unplug any CPUs
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002048 * or memory nodes, we need to walk over the cpuset hierarchy,
2049 * removing that CPU or node from all cpusets. If this removes the
Cliff Wickman956db3c2008-02-07 00:14:43 -08002050 * last CPU or node from a cpuset, then move the tasks in the empty
2051 * cpuset to its next-highest non-empty parent.
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002052 */
Cliff Wickman956db3c2008-02-07 00:14:43 -08002053static void remove_tasks_in_empty_cpuset(struct cpuset *cs)
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002054{
Cliff Wickman956db3c2008-02-07 00:14:43 -08002055 struct cpuset *parent;
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002056
Paul Jacksonc8d9c902008-02-07 00:14:46 -08002057 /*
Cliff Wickman956db3c2008-02-07 00:14:43 -08002058 * Find its next-highest non-empty parent, (top cpuset
2059 * has online cpus, so can't be empty).
2060 */
2061 parent = cs->parent;
Li Zefan300ed6c2009-01-07 18:08:44 -08002062 while (cpumask_empty(parent->cpus_allowed) ||
Paul Jacksonb4501292008-02-07 00:14:47 -08002063 nodes_empty(parent->mems_allowed))
Cliff Wickman956db3c2008-02-07 00:14:43 -08002064 parent = parent->parent;
Cliff Wickman956db3c2008-02-07 00:14:43 -08002065
2066 move_member_tasks_to_cpuset(cs, parent);
2067}
2068
Tejun Heodeb7aa32013-01-07 08:51:07 -08002069/**
Tejun Heo8d033942013-01-07 08:51:07 -08002070 * cpuset_propagate_hotplug_workfn - propagate CPU/memory hotplug to a cpuset
Tejun Heodeb7aa32013-01-07 08:51:07 -08002071 * @cs: cpuset in interest
Cliff Wickman956db3c2008-02-07 00:14:43 -08002072 *
Tejun Heodeb7aa32013-01-07 08:51:07 -08002073 * Compare @cs's cpu and mem masks against top_cpuset and if some have gone
2074 * offline, update @cs accordingly. If @cs ends up with no CPU or memory,
2075 * all its tasks are moved to the nearest ancestor with both resources.
Cliff Wickman956db3c2008-02-07 00:14:43 -08002076 */
Tejun Heo8d033942013-01-07 08:51:07 -08002077static void cpuset_propagate_hotplug_workfn(struct work_struct *work)
Cliff Wickman956db3c2008-02-07 00:14:43 -08002078{
Tejun Heodeb7aa32013-01-07 08:51:07 -08002079 static cpumask_t off_cpus;
2080 static nodemask_t off_mems, tmp_mems;
Tejun Heo8d033942013-01-07 08:51:07 -08002081 struct cpuset *cs = container_of(work, struct cpuset, hotplug_work);
Tejun Heo5d21cc22013-01-07 08:51:08 -08002082 bool is_empty;
Cliff Wickman956db3c2008-02-07 00:14:43 -08002083
Tejun Heo5d21cc22013-01-07 08:51:08 -08002084 mutex_lock(&cpuset_mutex);
Cliff Wickman956db3c2008-02-07 00:14:43 -08002085
Tejun Heodeb7aa32013-01-07 08:51:07 -08002086 cpumask_andnot(&off_cpus, cs->cpus_allowed, top_cpuset.cpus_allowed);
2087 nodes_andnot(off_mems, cs->mems_allowed, top_cpuset.mems_allowed);
Paul Jacksonb4501292008-02-07 00:14:47 -08002088
Tejun Heodeb7aa32013-01-07 08:51:07 -08002089 /* remove offline cpus from @cs */
2090 if (!cpumask_empty(&off_cpus)) {
2091 mutex_lock(&callback_mutex);
2092 cpumask_andnot(cs->cpus_allowed, cs->cpus_allowed, &off_cpus);
2093 mutex_unlock(&callback_mutex);
2094 update_tasks_cpumask(cs, NULL);
2095 }
Paul Jacksonb4501292008-02-07 00:14:47 -08002096
Tejun Heodeb7aa32013-01-07 08:51:07 -08002097 /* remove offline mems from @cs */
2098 if (!nodes_empty(off_mems)) {
2099 tmp_mems = cs->mems_allowed;
2100 mutex_lock(&callback_mutex);
2101 nodes_andnot(cs->mems_allowed, cs->mems_allowed, off_mems);
2102 mutex_unlock(&callback_mutex);
2103 update_tasks_nodemask(cs, &tmp_mems, NULL);
2104 }
Miao Xief9b4fb82008-07-25 01:47:22 -07002105
Tejun Heo5d21cc22013-01-07 08:51:08 -08002106 is_empty = cpumask_empty(cs->cpus_allowed) ||
2107 nodes_empty(cs->mems_allowed);
Tejun Heo8d033942013-01-07 08:51:07 -08002108
Tejun Heo5d21cc22013-01-07 08:51:08 -08002109 mutex_unlock(&cpuset_mutex);
2110
2111 /*
2112 * If @cs became empty, move tasks to the nearest ancestor with
2113 * execution resources. This is full cgroup operation which will
2114 * also call back into cpuset. Should be done outside any lock.
2115 */
2116 if (is_empty)
2117 remove_tasks_in_empty_cpuset(cs);
Tejun Heo8d033942013-01-07 08:51:07 -08002118
2119 /* the following may free @cs, should be the last operation */
2120 css_put(&cs->css);
2121}
2122
2123/**
2124 * schedule_cpuset_propagate_hotplug - schedule hotplug propagation to a cpuset
2125 * @cs: cpuset of interest
2126 *
2127 * Schedule cpuset_propagate_hotplug_workfn() which will update CPU and
2128 * memory masks according to top_cpuset.
2129 */
2130static void schedule_cpuset_propagate_hotplug(struct cpuset *cs)
2131{
2132 /*
2133 * Pin @cs. The refcnt will be released when the work item
2134 * finishes executing.
2135 */
2136 if (!css_tryget(&cs->css))
2137 return;
2138
2139 /*
2140 * Queue @cs->hotplug_work. If already pending, lose the css ref.
2141 * cpuset_propagate_hotplug_wq is ordered and propagation will
2142 * happen in the order this function is called.
2143 */
2144 if (!queue_work(cpuset_propagate_hotplug_wq, &cs->hotplug_work))
2145 css_put(&cs->css);
Tejun Heodeb7aa32013-01-07 08:51:07 -08002146}
Srivatsa S. Bhat7ddf96b2012-05-24 19:46:55 +05302147
Tejun Heodeb7aa32013-01-07 08:51:07 -08002148/**
Tejun Heo3a5a6d02013-01-07 08:51:07 -08002149 * cpuset_hotplug_workfn - handle CPU/memory hotunplug for a cpuset
Tejun Heodeb7aa32013-01-07 08:51:07 -08002150 *
2151 * This function is called after either CPU or memory configuration has
2152 * changed and updates cpuset accordingly. The top_cpuset is always
2153 * synchronized to cpu_active_mask and N_MEMORY, which is necessary in
2154 * order to make cpusets transparent (of no affect) on systems that are
2155 * actively using CPU hotplug but making no active use of cpusets.
2156 *
2157 * Non-root cpusets are only affected by offlining. If any CPUs or memory
2158 * nodes have been taken down, cpuset_propagate_hotplug() is invoked on all
2159 * descendants.
2160 *
2161 * Note that CPU offlining during suspend is ignored. We don't modify
2162 * cpusets across suspend/resume cycles at all.
2163 */
Tejun Heo3a5a6d02013-01-07 08:51:07 -08002164static void cpuset_hotplug_workfn(struct work_struct *work)
Tejun Heodeb7aa32013-01-07 08:51:07 -08002165{
2166 static cpumask_t new_cpus, tmp_cpus;
2167 static nodemask_t new_mems, tmp_mems;
2168 bool cpus_updated, mems_updated;
2169 bool cpus_offlined, mems_offlined;
Srivatsa S. Bhat7ddf96b2012-05-24 19:46:55 +05302170
Tejun Heo5d21cc22013-01-07 08:51:08 -08002171 mutex_lock(&cpuset_mutex);
Srivatsa S. Bhat7ddf96b2012-05-24 19:46:55 +05302172
Tejun Heodeb7aa32013-01-07 08:51:07 -08002173 /* fetch the available cpus/mems and find out which changed how */
2174 cpumask_copy(&new_cpus, cpu_active_mask);
2175 new_mems = node_states[N_MEMORY];
Srivatsa S. Bhat7ddf96b2012-05-24 19:46:55 +05302176
Tejun Heodeb7aa32013-01-07 08:51:07 -08002177 cpus_updated = !cpumask_equal(top_cpuset.cpus_allowed, &new_cpus);
2178 cpus_offlined = cpumask_andnot(&tmp_cpus, top_cpuset.cpus_allowed,
2179 &new_cpus);
Paul Jacksonb4501292008-02-07 00:14:47 -08002180
Tejun Heodeb7aa32013-01-07 08:51:07 -08002181 mems_updated = !nodes_equal(top_cpuset.mems_allowed, new_mems);
2182 nodes_andnot(tmp_mems, top_cpuset.mems_allowed, new_mems);
2183 mems_offlined = !nodes_empty(tmp_mems);
2184
2185 /* synchronize cpus_allowed to cpu_active_mask */
2186 if (cpus_updated) {
2187 mutex_lock(&callback_mutex);
2188 cpumask_copy(top_cpuset.cpus_allowed, &new_cpus);
2189 mutex_unlock(&callback_mutex);
2190 /* we don't mess with cpumasks of tasks in top_cpuset */
2191 }
2192
2193 /* synchronize mems_allowed to N_MEMORY */
2194 if (mems_updated) {
2195 tmp_mems = top_cpuset.mems_allowed;
2196 mutex_lock(&callback_mutex);
2197 top_cpuset.mems_allowed = new_mems;
2198 mutex_unlock(&callback_mutex);
2199 update_tasks_nodemask(&top_cpuset, &tmp_mems, NULL);
2200 }
2201
2202 /* if cpus or mems went down, we need to propagate to descendants */
2203 if (cpus_offlined || mems_offlined) {
2204 struct cpuset *cs;
Tejun Heofc560a22013-01-07 08:51:08 -08002205 struct cgroup *pos_cgrp;
Tejun Heodeb7aa32013-01-07 08:51:07 -08002206
Tejun Heofc560a22013-01-07 08:51:08 -08002207 rcu_read_lock();
2208 cpuset_for_each_descendant_pre(cs, pos_cgrp, &top_cpuset)
2209 schedule_cpuset_propagate_hotplug(cs);
2210 rcu_read_unlock();
Tejun Heodeb7aa32013-01-07 08:51:07 -08002211 }
2212
Tejun Heo5d21cc22013-01-07 08:51:08 -08002213 mutex_unlock(&cpuset_mutex);
Tejun Heodeb7aa32013-01-07 08:51:07 -08002214
Tejun Heo8d033942013-01-07 08:51:07 -08002215 /* wait for propagations to finish */
2216 flush_workqueue(cpuset_propagate_hotplug_wq);
2217
Tejun Heodeb7aa32013-01-07 08:51:07 -08002218 /* rebuild sched domains if cpus_allowed has changed */
2219 if (cpus_updated) {
2220 struct sched_domain_attr *attr;
2221 cpumask_var_t *doms;
2222 int ndoms;
2223
Tejun Heo5d21cc22013-01-07 08:51:08 -08002224 mutex_lock(&cpuset_mutex);
Tejun Heodeb7aa32013-01-07 08:51:07 -08002225 ndoms = generate_sched_domains(&doms, &attr);
Tejun Heo5d21cc22013-01-07 08:51:08 -08002226 mutex_unlock(&cpuset_mutex);
Tejun Heodeb7aa32013-01-07 08:51:07 -08002227
2228 partition_sched_domains(ndoms, doms, attr);
Cliff Wickman956db3c2008-02-07 00:14:43 -08002229 }
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002230}
2231
Srivatsa S. Bhat7ddf96b2012-05-24 19:46:55 +05302232void cpuset_update_active_cpus(bool cpu_online)
Paul Jackson4c4d50f2006-08-27 01:23:51 -07002233{
Tejun Heo3a5a6d02013-01-07 08:51:07 -08002234 /*
2235 * We're inside cpu hotplug critical region which usually nests
2236 * inside cgroup synchronization. Bounce actual hotplug processing
2237 * to a work item to avoid reverse locking order.
2238 *
2239 * We still need to do partition_sched_domains() synchronously;
2240 * otherwise, the scheduler will get confused and put tasks to the
2241 * dead CPU. Fall back to the default single domain.
2242 * cpuset_hotplug_workfn() will rebuild it as necessary.
2243 */
2244 partition_sched_domains(1, NULL, NULL);
2245 schedule_work(&cpuset_hotplug_work);
Paul Jackson4c4d50f2006-08-27 01:23:51 -07002246}
Paul Jackson4c4d50f2006-08-27 01:23:51 -07002247
Paul Jacksonb1aac8b2006-09-29 02:01:17 -07002248#ifdef CONFIG_MEMORY_HOTPLUG
Paul Jackson38837fc2006-09-29 02:01:16 -07002249/*
Lai Jiangshan38d7bee2012-12-12 13:51:24 -08002250 * Keep top_cpuset.mems_allowed tracking node_states[N_MEMORY].
2251 * Call this routine anytime after node_states[N_MEMORY] changes.
Srivatsa S. Bhata1cd2b12012-05-24 19:47:03 +05302252 * See cpuset_update_active_cpus() for CPU hotplug handling.
Paul Jackson38837fc2006-09-29 02:01:16 -07002253 */
Miao Xief4818912008-11-19 15:36:30 -08002254static int cpuset_track_online_nodes(struct notifier_block *self,
2255 unsigned long action, void *arg)
Paul Jackson38837fc2006-09-29 02:01:16 -07002256{
Tejun Heo3a5a6d02013-01-07 08:51:07 -08002257 schedule_work(&cpuset_hotplug_work);
Miao Xief4818912008-11-19 15:36:30 -08002258 return NOTIFY_OK;
Paul Jackson38837fc2006-09-29 02:01:16 -07002259}
2260#endif
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262/**
2263 * cpuset_init_smp - initialize cpus_allowed
2264 *
2265 * Description: Finish top cpuset after cpu, node maps are initialized
2266 **/
2267
2268void __init cpuset_init_smp(void)
2269{
Peter Zijlstra6ad4c182009-11-25 13:31:39 +01002270 cpumask_copy(top_cpuset.cpus_allowed, cpu_active_mask);
Lai Jiangshan38d7bee2012-12-12 13:51:24 -08002271 top_cpuset.mems_allowed = node_states[N_MEMORY];
Paul Jackson4c4d50f2006-08-27 01:23:51 -07002272
Miao Xief4818912008-11-19 15:36:30 -08002273 hotplug_memory_notifier(cpuset_track_online_nodes, 10);
Tejun Heo8d033942013-01-07 08:51:07 -08002274
2275 cpuset_propagate_hotplug_wq =
2276 alloc_ordered_workqueue("cpuset_hotplug", 0);
2277 BUG_ON(!cpuset_propagate_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278}
2279
2280/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset.
2282 * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed.
Li Zefan6af866a2009-01-07 18:08:45 -08002283 * @pmask: pointer to struct cpumask variable to receive cpus_allowed set.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 *
Li Zefan300ed6c2009-01-07 18:08:44 -08002285 * Description: Returns the cpumask_var_t cpus_allowed of the cpuset
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 * attached to the specified @tsk. Guaranteed to return some non-empty
Rusty Russell5f054e32012-03-29 15:38:31 +10302287 * subset of cpu_online_mask, even if this means going outside the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 * tasks cpuset.
2289 **/
2290
Li Zefan6af866a2009-01-07 18:08:45 -08002291void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08002293 mutex_lock(&callback_mutex);
Paul Jackson909d75a2006-01-08 01:01:55 -08002294 task_lock(tsk);
Mike Travisf9a86fc2008-04-04 18:11:07 -07002295 guarantee_online_cpus(task_cs(tsk), pmask);
Paul Jackson909d75a2006-01-08 01:01:55 -08002296 task_unlock(tsk);
Oleg Nesterov897f0b32010-03-15 10:10:03 +01002297 mutex_unlock(&callback_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
Peter Zijlstra2baab4e2012-03-20 15:57:01 +01002300void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
Oleg Nesterov9084bb82010-03-15 10:10:27 +01002301{
2302 const struct cpuset *cs;
Oleg Nesterov9084bb82010-03-15 10:10:27 +01002303
2304 rcu_read_lock();
2305 cs = task_cs(tsk);
2306 if (cs)
KOSAKI Motohiro1e1b6c52011-05-19 15:08:58 +09002307 do_set_cpus_allowed(tsk, cs->cpus_allowed);
Oleg Nesterov9084bb82010-03-15 10:10:27 +01002308 rcu_read_unlock();
2309
2310 /*
2311 * We own tsk->cpus_allowed, nobody can change it under us.
2312 *
2313 * But we used cs && cs->cpus_allowed lockless and thus can
2314 * race with cgroup_attach_task() or update_cpumask() and get
2315 * the wrong tsk->cpus_allowed. However, both cases imply the
2316 * subsequent cpuset_change_cpumask()->set_cpus_allowed_ptr()
2317 * which takes task_rq_lock().
2318 *
2319 * If we are called after it dropped the lock we must see all
2320 * changes in tsk_cs()->cpus_allowed. Otherwise we can temporary
2321 * set any mask even if it is not right from task_cs() pov,
2322 * the pending set_cpus_allowed_ptr() will fix things.
Peter Zijlstra2baab4e2012-03-20 15:57:01 +01002323 *
2324 * select_fallback_rq() will fix things ups and set cpu_possible_mask
2325 * if required.
Oleg Nesterov9084bb82010-03-15 10:10:27 +01002326 */
Oleg Nesterov9084bb82010-03-15 10:10:27 +01002327}
2328
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329void cpuset_init_current_mems_allowed(void)
2330{
Mike Travisf9a86fc2008-04-04 18:11:07 -07002331 nodes_setall(current->mems_allowed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
Randy Dunlapd9fd8a62005-07-27 11:45:11 -07002334/**
Paul Jackson909d75a2006-01-08 01:01:55 -08002335 * cpuset_mems_allowed - return mems_allowed mask from a tasks cpuset.
2336 * @tsk: pointer to task_struct from which to obtain cpuset->mems_allowed.
2337 *
2338 * Description: Returns the nodemask_t mems_allowed of the cpuset
2339 * attached to the specified @tsk. Guaranteed to return some non-empty
Lai Jiangshan38d7bee2012-12-12 13:51:24 -08002340 * subset of node_states[N_MEMORY], even if this means going outside the
Paul Jackson909d75a2006-01-08 01:01:55 -08002341 * tasks cpuset.
2342 **/
2343
2344nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
2345{
2346 nodemask_t mask;
2347
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08002348 mutex_lock(&callback_mutex);
Paul Jackson909d75a2006-01-08 01:01:55 -08002349 task_lock(tsk);
Paul Menage8793d852007-10-18 23:39:39 -07002350 guarantee_online_mems(task_cs(tsk), &mask);
Paul Jackson909d75a2006-01-08 01:01:55 -08002351 task_unlock(tsk);
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08002352 mutex_unlock(&callback_mutex);
Paul Jackson909d75a2006-01-08 01:01:55 -08002353
2354 return mask;
2355}
2356
2357/**
Mel Gorman19770b32008-04-28 02:12:18 -07002358 * cpuset_nodemask_valid_mems_allowed - check nodemask vs. curremt mems_allowed
2359 * @nodemask: the nodemask to be checked
Randy Dunlapd9fd8a62005-07-27 11:45:11 -07002360 *
Mel Gorman19770b32008-04-28 02:12:18 -07002361 * Are any of the nodes in the nodemask allowed in current->mems_allowed?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 */
Mel Gorman19770b32008-04-28 02:12:18 -07002363int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
Mel Gorman19770b32008-04-28 02:12:18 -07002365 return nodes_intersects(*nodemask, current->mems_allowed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
Paul Jackson9bf22292005-09-06 15:18:12 -07002368/*
Paul Menage78608362008-04-29 01:00:26 -07002369 * nearest_hardwall_ancestor() - Returns the nearest mem_exclusive or
2370 * mem_hardwall ancestor to the specified cpuset. Call holding
2371 * callback_mutex. If no ancestor is mem_exclusive or mem_hardwall
2372 * (an unusual configuration), then returns the root cpuset.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 */
Paul Menage78608362008-04-29 01:00:26 -07002374static const struct cpuset *nearest_hardwall_ancestor(const struct cpuset *cs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
Paul Menage78608362008-04-29 01:00:26 -07002376 while (!(is_mem_exclusive(cs) || is_mem_hardwall(cs)) && cs->parent)
Paul Jackson9bf22292005-09-06 15:18:12 -07002377 cs = cs->parent;
2378 return cs;
2379}
2380
2381/**
David Rientjesa1bc5a42009-04-02 16:57:54 -07002382 * cpuset_node_allowed_softwall - Can we allocate on a memory node?
2383 * @node: is this an allowed node?
Paul Jackson02a0e532006-12-13 00:34:25 -08002384 * @gfp_mask: memory allocation flags
Paul Jackson9bf22292005-09-06 15:18:12 -07002385 *
David Rientjesa1bc5a42009-04-02 16:57:54 -07002386 * If we're in interrupt, yes, we can always allocate. If __GFP_THISNODE is
2387 * set, yes, we can always allocate. If node is in our task's mems_allowed,
2388 * yes. If it's not a __GFP_HARDWALL request and this node is in the nearest
2389 * hardwalled cpuset ancestor to this task's cpuset, yes. If the task has been
2390 * OOM killed and has access to memory reserves as specified by the TIF_MEMDIE
2391 * flag, yes.
Paul Jackson9bf22292005-09-06 15:18:12 -07002392 * Otherwise, no.
2393 *
David Rientjesa1bc5a42009-04-02 16:57:54 -07002394 * If __GFP_HARDWALL is set, cpuset_node_allowed_softwall() reduces to
2395 * cpuset_node_allowed_hardwall(). Otherwise, cpuset_node_allowed_softwall()
2396 * might sleep, and might allow a node from an enclosing cpuset.
Paul Jackson02a0e532006-12-13 00:34:25 -08002397 *
David Rientjesa1bc5a42009-04-02 16:57:54 -07002398 * cpuset_node_allowed_hardwall() only handles the simpler case of hardwall
2399 * cpusets, and never sleeps.
Paul Jackson02a0e532006-12-13 00:34:25 -08002400 *
2401 * The __GFP_THISNODE placement logic is really handled elsewhere,
2402 * by forcibly using a zonelist starting at a specified node, and by
2403 * (in get_page_from_freelist()) refusing to consider the zones for
2404 * any node on the zonelist except the first. By the time any such
2405 * calls get to this routine, we should just shut up and say 'yes'.
2406 *
Paul Jackson9bf22292005-09-06 15:18:12 -07002407 * GFP_USER allocations are marked with the __GFP_HARDWALL bit,
David Rientjesc596d9f2007-05-06 14:49:32 -07002408 * and do not allow allocations outside the current tasks cpuset
2409 * unless the task has been OOM killed as is marked TIF_MEMDIE.
Paul Jackson9bf22292005-09-06 15:18:12 -07002410 * GFP_KERNEL allocations are not so marked, so can escape to the
Paul Menage78608362008-04-29 01:00:26 -07002411 * nearest enclosing hardwalled ancestor cpuset.
Paul Jackson9bf22292005-09-06 15:18:12 -07002412 *
Paul Jackson02a0e532006-12-13 00:34:25 -08002413 * Scanning up parent cpusets requires callback_mutex. The
2414 * __alloc_pages() routine only calls here with __GFP_HARDWALL bit
2415 * _not_ set if it's a GFP_KERNEL allocation, and all nodes in the
2416 * current tasks mems_allowed came up empty on the first pass over
2417 * the zonelist. So only GFP_KERNEL allocations, if all nodes in the
2418 * cpuset are short of memory, might require taking the callback_mutex
2419 * mutex.
Paul Jackson9bf22292005-09-06 15:18:12 -07002420 *
Paul Jackson36be57f2006-05-20 15:00:10 -07002421 * The first call here from mm/page_alloc:get_page_from_freelist()
Paul Jackson02a0e532006-12-13 00:34:25 -08002422 * has __GFP_HARDWALL set in gfp_mask, enforcing hardwall cpusets,
2423 * so no allocation on a node outside the cpuset is allowed (unless
2424 * in interrupt, of course).
Paul Jackson9bf22292005-09-06 15:18:12 -07002425 *
Paul Jackson36be57f2006-05-20 15:00:10 -07002426 * The second pass through get_page_from_freelist() doesn't even call
2427 * here for GFP_ATOMIC calls. For those calls, the __alloc_pages()
2428 * variable 'wait' is not set, and the bit ALLOC_CPUSET is not set
2429 * in alloc_flags. That logic and the checks below have the combined
2430 * affect that:
Paul Jackson9bf22292005-09-06 15:18:12 -07002431 * in_interrupt - any node ok (current task context irrelevant)
2432 * GFP_ATOMIC - any node ok
David Rientjesc596d9f2007-05-06 14:49:32 -07002433 * TIF_MEMDIE - any node ok
Paul Menage78608362008-04-29 01:00:26 -07002434 * GFP_KERNEL - any node in enclosing hardwalled cpuset ok
Paul Jackson9bf22292005-09-06 15:18:12 -07002435 * GFP_USER - only nodes in current tasks mems allowed ok.
Paul Jackson36be57f2006-05-20 15:00:10 -07002436 *
2437 * Rule:
David Rientjesa1bc5a42009-04-02 16:57:54 -07002438 * Don't call cpuset_node_allowed_softwall if you can't sleep, unless you
Paul Jackson36be57f2006-05-20 15:00:10 -07002439 * pass in the __GFP_HARDWALL flag set in gfp_flag, which disables
2440 * the code that might scan up ancestor cpusets and sleep.
Paul Jackson02a0e532006-12-13 00:34:25 -08002441 */
David Rientjesa1bc5a42009-04-02 16:57:54 -07002442int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
Paul Jackson9bf22292005-09-06 15:18:12 -07002443{
Paul Jackson9bf22292005-09-06 15:18:12 -07002444 const struct cpuset *cs; /* current cpuset ancestors */
Paul Jackson29afd492006-03-24 03:16:12 -08002445 int allowed; /* is allocation in zone z allowed? */
Paul Jackson9bf22292005-09-06 15:18:12 -07002446
Christoph Lameter9b819d22006-09-25 23:31:40 -07002447 if (in_interrupt() || (gfp_mask & __GFP_THISNODE))
Paul Jackson9bf22292005-09-06 15:18:12 -07002448 return 1;
Paul Jackson92d1dbd2006-05-20 15:00:11 -07002449 might_sleep_if(!(gfp_mask & __GFP_HARDWALL));
Paul Jackson9bf22292005-09-06 15:18:12 -07002450 if (node_isset(node, current->mems_allowed))
2451 return 1;
David Rientjesc596d9f2007-05-06 14:49:32 -07002452 /*
2453 * Allow tasks that have access to memory reserves because they have
2454 * been OOM killed to get memory anywhere.
2455 */
2456 if (unlikely(test_thread_flag(TIF_MEMDIE)))
2457 return 1;
Paul Jackson9bf22292005-09-06 15:18:12 -07002458 if (gfp_mask & __GFP_HARDWALL) /* If hardwall request, stop here */
2459 return 0;
2460
Bob Picco5563e772005-11-13 16:06:35 -08002461 if (current->flags & PF_EXITING) /* Let dying task have memory */
2462 return 1;
2463
Paul Jackson9bf22292005-09-06 15:18:12 -07002464 /* Not hardwall and node outside mems_allowed: scan up cpusets */
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08002465 mutex_lock(&callback_mutex);
Paul Jackson053199e2005-10-30 15:02:30 -08002466
Paul Jackson053199e2005-10-30 15:02:30 -08002467 task_lock(current);
Paul Menage78608362008-04-29 01:00:26 -07002468 cs = nearest_hardwall_ancestor(task_cs(current));
Paul Jackson053199e2005-10-30 15:02:30 -08002469 task_unlock(current);
2470
Paul Jackson9bf22292005-09-06 15:18:12 -07002471 allowed = node_isset(node, cs->mems_allowed);
Ingo Molnar3d3f26a2006-03-23 03:00:18 -08002472 mutex_unlock(&callback_mutex);
Paul Jackson9bf22292005-09-06 15:18:12 -07002473 return allowed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
2475
Paul Jackson02a0e532006-12-13 00:34:25 -08002476/*
David Rientjesa1bc5a42009-04-02 16:57:54 -07002477 * cpuset_node_allowed_hardwall - Can we allocate on a memory node?
2478 * @node: is this an allowed node?
Paul Jackson02a0e532006-12-13 00:34:25 -08002479 * @gfp_mask: memory allocation flags
2480 *
David Rientjesa1bc5a42009-04-02 16:57:54 -07002481 * If we're in interrupt, yes, we can always allocate. If __GFP_THISNODE is
2482 * set, yes, we can always allocate. If node is in our task's mems_allowed,
2483 * yes. If the task has been OOM killed and has access to memory reserves as
2484 * specified by the TIF_MEMDIE flag, yes.
2485 * Otherwise, no.
Paul Jackson02a0e532006-12-13 00:34:25 -08002486 *
2487 * The __GFP_THISNODE placement logic is really handled elsewhere,
2488 * by forcibly using a zonelist starting at a specified node, and by
2489 * (in get_page_from_freelist()) refusing to consider the zones for
2490 * any node on the zonelist except the first. By the time any such
2491 * calls get to this routine, we should just shut up and say 'yes'.
2492 *
David Rientjesa1bc5a42009-04-02 16:57:54 -07002493 * Unlike the cpuset_node_allowed_softwall() variant, above,
2494 * this variant requires that the node be in the current task's
Paul Jackson02a0e532006-12-13 00:34:25 -08002495 * mems_allowed or that we're in interrupt. It does not scan up the
2496 * cpuset hierarchy for the nearest enclosing mem_exclusive cpuset.
2497 * It never sleeps.
2498 */
David Rientjesa1bc5a42009-04-02 16:57:54 -07002499int __cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
Paul Jackson02a0e532006-12-13 00:34:25 -08002500{
Paul Jackson02a0e532006-12-13 00:34:25 -08002501 if (in_interrupt() || (gfp_mask & __GFP_THISNODE))
2502 return 1;
Paul Jackson02a0e532006-12-13 00:34:25 -08002503 if (node_isset(node, current->mems_allowed))
2504 return 1;
Daniel Walkerdedf8b72007-10-18 03:06:04 -07002505 /*
2506 * Allow tasks that have access to memory reserves because they have
2507 * been OOM killed to get memory anywhere.
2508 */
2509 if (unlikely(test_thread_flag(TIF_MEMDIE)))
2510 return 1;
Paul Jackson02a0e532006-12-13 00:34:25 -08002511 return 0;
2512}
2513
Paul Jacksonef08e3b2005-09-06 15:18:13 -07002514/**
Jack Steiner6adef3e2010-05-26 14:42:49 -07002515 * cpuset_mem_spread_node() - On which node to begin search for a file page
2516 * cpuset_slab_spread_node() - On which node to begin search for a slab page
Paul Jackson825a46a2006-03-24 03:16:03 -08002517 *
2518 * If a task is marked PF_SPREAD_PAGE or PF_SPREAD_SLAB (as for
2519 * tasks in a cpuset with is_spread_page or is_spread_slab set),
2520 * and if the memory allocation used cpuset_mem_spread_node()
2521 * to determine on which node to start looking, as it will for
2522 * certain page cache or slab cache pages such as used for file
2523 * system buffers and inode caches, then instead of starting on the
2524 * local node to look for a free page, rather spread the starting
2525 * node around the tasks mems_allowed nodes.
2526 *
2527 * We don't have to worry about the returned node being offline
2528 * because "it can't happen", and even if it did, it would be ok.
2529 *
2530 * The routines calling guarantee_online_mems() are careful to
2531 * only set nodes in task->mems_allowed that are online. So it
2532 * should not be possible for the following code to return an
2533 * offline node. But if it did, that would be ok, as this routine
2534 * is not returning the node where the allocation must be, only
2535 * the node where the search should start. The zonelist passed to
2536 * __alloc_pages() will include all nodes. If the slab allocator
2537 * is passed an offline node, it will fall back to the local node.
2538 * See kmem_cache_alloc_node().
2539 */
2540
Jack Steiner6adef3e2010-05-26 14:42:49 -07002541static int cpuset_spread_node(int *rotor)
Paul Jackson825a46a2006-03-24 03:16:03 -08002542{
2543 int node;
2544
Jack Steiner6adef3e2010-05-26 14:42:49 -07002545 node = next_node(*rotor, current->mems_allowed);
Paul Jackson825a46a2006-03-24 03:16:03 -08002546 if (node == MAX_NUMNODES)
2547 node = first_node(current->mems_allowed);
Jack Steiner6adef3e2010-05-26 14:42:49 -07002548 *rotor = node;
Paul Jackson825a46a2006-03-24 03:16:03 -08002549 return node;
2550}
Jack Steiner6adef3e2010-05-26 14:42:49 -07002551
2552int cpuset_mem_spread_node(void)
2553{
Michal Hocko778d3b02011-07-26 16:08:30 -07002554 if (current->cpuset_mem_spread_rotor == NUMA_NO_NODE)
2555 current->cpuset_mem_spread_rotor =
2556 node_random(&current->mems_allowed);
2557
Jack Steiner6adef3e2010-05-26 14:42:49 -07002558 return cpuset_spread_node(&current->cpuset_mem_spread_rotor);
2559}
2560
2561int cpuset_slab_spread_node(void)
2562{
Michal Hocko778d3b02011-07-26 16:08:30 -07002563 if (current->cpuset_slab_spread_rotor == NUMA_NO_NODE)
2564 current->cpuset_slab_spread_rotor =
2565 node_random(&current->mems_allowed);
2566
Jack Steiner6adef3e2010-05-26 14:42:49 -07002567 return cpuset_spread_node(&current->cpuset_slab_spread_rotor);
2568}
2569
Paul Jackson825a46a2006-03-24 03:16:03 -08002570EXPORT_SYMBOL_GPL(cpuset_mem_spread_node);
2571
2572/**
David Rientjesbbe373f2007-10-16 23:25:58 -07002573 * cpuset_mems_allowed_intersects - Does @tsk1's mems_allowed intersect @tsk2's?
2574 * @tsk1: pointer to task_struct of some task.
2575 * @tsk2: pointer to task_struct of some other task.
Paul Jacksonef08e3b2005-09-06 15:18:13 -07002576 *
David Rientjesbbe373f2007-10-16 23:25:58 -07002577 * Description: Return true if @tsk1's mems_allowed intersects the
2578 * mems_allowed of @tsk2. Used by the OOM killer to determine if
2579 * one of the task's memory usage might impact the memory available
2580 * to the other.
Paul Jacksonef08e3b2005-09-06 15:18:13 -07002581 **/
2582
David Rientjesbbe373f2007-10-16 23:25:58 -07002583int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
2584 const struct task_struct *tsk2)
Paul Jacksonef08e3b2005-09-06 15:18:13 -07002585{
David Rientjesbbe373f2007-10-16 23:25:58 -07002586 return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
Paul Jacksonef08e3b2005-09-06 15:18:13 -07002587}
2588
David Rientjes75aa1992009-01-06 14:39:01 -08002589/**
2590 * cpuset_print_task_mems_allowed - prints task's cpuset and mems_allowed
2591 * @task: pointer to task_struct of some task.
2592 *
2593 * Description: Prints @task's name, cpuset name, and cached copy of its
2594 * mems_allowed to the kernel log. Must hold task_lock(task) to allow
2595 * dereferencing task_cs(task).
2596 */
2597void cpuset_print_task_mems_allowed(struct task_struct *tsk)
2598{
2599 struct dentry *dentry;
2600
2601 dentry = task_cs(tsk)->css.cgroup->dentry;
2602 spin_lock(&cpuset_buffer_lock);
2603 snprintf(cpuset_name, CPUSET_NAME_LEN,
2604 dentry ? (const char *)dentry->d_name.name : "/");
2605 nodelist_scnprintf(cpuset_nodelist, CPUSET_NODELIST_LEN,
2606 tsk->mems_allowed);
2607 printk(KERN_INFO "%s cpuset=%s mems_allowed=%s\n",
2608 tsk->comm, cpuset_name, cpuset_nodelist);
2609 spin_unlock(&cpuset_buffer_lock);
2610}
2611
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612/*
Paul Jackson3e0d98b2006-01-08 01:01:49 -08002613 * Collection of memory_pressure is suppressed unless
2614 * this flag is enabled by writing "1" to the special
2615 * cpuset file 'memory_pressure_enabled' in the root cpuset.
2616 */
2617
Paul Jacksonc5b2aff82006-01-08 01:01:51 -08002618int cpuset_memory_pressure_enabled __read_mostly;
Paul Jackson3e0d98b2006-01-08 01:01:49 -08002619
2620/**
2621 * cpuset_memory_pressure_bump - keep stats of per-cpuset reclaims.
2622 *
2623 * Keep a running average of the rate of synchronous (direct)
2624 * page reclaim efforts initiated by tasks in each cpuset.
2625 *
2626 * This represents the rate at which some task in the cpuset
2627 * ran low on memory on all nodes it was allowed to use, and
2628 * had to enter the kernels page reclaim code in an effort to
2629 * create more free memory by tossing clean pages or swapping
2630 * or writing dirty pages.
2631 *
2632 * Display to user space in the per-cpuset read-only file
2633 * "memory_pressure". Value displayed is an integer
2634 * representing the recent rate of entry into the synchronous
2635 * (direct) page reclaim by any task attached to the cpuset.
2636 **/
2637
2638void __cpuset_memory_pressure_bump(void)
2639{
Paul Jackson3e0d98b2006-01-08 01:01:49 -08002640 task_lock(current);
Paul Menage8793d852007-10-18 23:39:39 -07002641 fmeter_markevent(&task_cs(current)->fmeter);
Paul Jackson3e0d98b2006-01-08 01:01:49 -08002642 task_unlock(current);
2643}
2644
Paul Menage8793d852007-10-18 23:39:39 -07002645#ifdef CONFIG_PROC_PID_CPUSET
Paul Jackson3e0d98b2006-01-08 01:01:49 -08002646/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 * proc_cpuset_show()
2648 * - Print tasks cpuset path into seq_file.
2649 * - Used for /proc/<pid>/cpuset.
Paul Jackson053199e2005-10-30 15:02:30 -08002650 * - No need to task_lock(tsk) on this tsk->cpuset reference, as it
2651 * doesn't really matter if tsk->cpuset changes after we read it,
Tejun Heo5d21cc22013-01-07 08:51:08 -08002652 * and we take cpuset_mutex, keeping cpuset_attach() from changing it
Paul Menage2df167a2008-02-07 00:14:45 -08002653 * anyway.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 */
Paul Jackson029190c2007-10-18 23:40:20 -07002655static int proc_cpuset_show(struct seq_file *m, void *unused_v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656{
Eric W. Biederman13b41b02006-06-26 00:25:56 -07002657 struct pid *pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 struct task_struct *tsk;
2659 char *buf;
Paul Menage8793d852007-10-18 23:39:39 -07002660 struct cgroup_subsys_state *css;
Eric W. Biederman99f89552006-06-26 00:25:55 -07002661 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Eric W. Biederman99f89552006-06-26 00:25:55 -07002663 retval = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2665 if (!buf)
Eric W. Biederman99f89552006-06-26 00:25:55 -07002666 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
Eric W. Biederman99f89552006-06-26 00:25:55 -07002668 retval = -ESRCH;
Eric W. Biederman13b41b02006-06-26 00:25:56 -07002669 pid = m->private;
2670 tsk = get_pid_task(pid, PIDTYPE_PID);
Eric W. Biederman99f89552006-06-26 00:25:55 -07002671 if (!tsk)
2672 goto out_free;
2673
2674 retval = -EINVAL;
Tejun Heo5d21cc22013-01-07 08:51:08 -08002675 mutex_lock(&cpuset_mutex);
Paul Menage8793d852007-10-18 23:39:39 -07002676 css = task_subsys_state(tsk, cpuset_subsys_id);
2677 retval = cgroup_path(css->cgroup, buf, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 if (retval < 0)
Eric W. Biederman99f89552006-06-26 00:25:55 -07002679 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 seq_puts(m, buf);
2681 seq_putc(m, '\n');
Eric W. Biederman99f89552006-06-26 00:25:55 -07002682out_unlock:
Tejun Heo5d21cc22013-01-07 08:51:08 -08002683 mutex_unlock(&cpuset_mutex);
Eric W. Biederman99f89552006-06-26 00:25:55 -07002684 put_task_struct(tsk);
2685out_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 kfree(buf);
Eric W. Biederman99f89552006-06-26 00:25:55 -07002687out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 return retval;
2689}
2690
2691static int cpuset_open(struct inode *inode, struct file *file)
2692{
Eric W. Biederman13b41b02006-06-26 00:25:56 -07002693 struct pid *pid = PROC_I(inode)->pid;
2694 return single_open(file, proc_cpuset_show, pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695}
2696
Arjan van de Ven9a321442007-02-12 00:55:35 -08002697const struct file_operations proc_cpuset_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 .open = cpuset_open,
2699 .read = seq_read,
2700 .llseek = seq_lseek,
2701 .release = single_release,
2702};
Paul Menage8793d852007-10-18 23:39:39 -07002703#endif /* CONFIG_PROC_PID_CPUSET */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
Heiko Carstensd01d4822009-09-21 11:06:27 +02002705/* Display task mems_allowed in /proc/<pid>/status file. */
Eric W. Biedermandf5f8312008-02-08 04:18:33 -08002706void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707{
Eric W. Biedermandf5f8312008-02-08 04:18:33 -08002708 seq_printf(m, "Mems_allowed:\t");
Lai Jiangshan30e8e132008-10-18 20:28:20 -07002709 seq_nodemask(m, &task->mems_allowed);
Eric W. Biedermandf5f8312008-02-08 04:18:33 -08002710 seq_printf(m, "\n");
Mike Travis39106dc2008-04-08 11:43:03 -07002711 seq_printf(m, "Mems_allowed_list:\t");
Lai Jiangshan30e8e132008-10-18 20:28:20 -07002712 seq_nodemask_list(m, &task->mems_allowed);
Mike Travis39106dc2008-04-08 11:43:03 -07002713 seq_printf(m, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714}