]> Pileus Git - ~andy/linux/blobdiff - kernel/cpuset.c
cpuset: remove unnecessary variable in cpuset_attach()
[~andy/linux] / kernel / cpuset.c
index 334d983a36b2ab108d962f3432b46464fc28593f..dbef832e5e2da16b278130738d469247911f59fa 100644 (file)
@@ -264,17 +264,6 @@ static struct cpuset top_cpuset = {
 static DEFINE_MUTEX(cpuset_mutex);
 static DEFINE_MUTEX(callback_mutex);
 
-/*
- * cpuset_buffer_lock protects both the cpuset_name and cpuset_nodelist
- * buffers.  They are statically allocated to prevent using excess stack
- * when calling cpuset_print_task_mems_allowed().
- */
-#define CPUSET_NAME_LEN                (128)
-#define        CPUSET_NODELIST_LEN     (256)
-static char cpuset_name[CPUSET_NAME_LEN];
-static char cpuset_nodelist[CPUSET_NODELIST_LEN];
-static DEFINE_SPINLOCK(cpuset_buffer_lock);
-
 /*
  * CPU / memory hotplug is handled asynchronously.
  */
@@ -315,53 +304,38 @@ static struct file_system_type cpuset_fs_type = {
 /*
  * Return in pmask the portion of a cpusets's cpus_allowed that
  * are online.  If none are online, walk up the cpuset hierarchy
- * until we find one that does have some online cpus.  If we get
- * all the way to the top and still haven't found any online cpus,
- * return cpu_online_mask.  Or if passed a NULL cs from an exit'ing
- * task, return cpu_online_mask.
+ * until we find one that does have some online cpus.  The top
+ * cpuset always has some cpus online.
  *
  * One way or another, we guarantee to return some non-empty subset
  * of cpu_online_mask.
  *
  * Call with callback_mutex held.
  */
-
 static void guarantee_online_cpus(const struct cpuset *cs,
                                  struct cpumask *pmask)
 {
-       while (cs && !cpumask_intersects(cs->cpus_allowed, cpu_online_mask))
+       while (!cpumask_intersects(cs->cpus_allowed, cpu_online_mask))
                cs = parent_cs(cs);
-       if (cs)
-               cpumask_and(pmask, cs->cpus_allowed, cpu_online_mask);
-       else
-               cpumask_copy(pmask, cpu_online_mask);
-       BUG_ON(!cpumask_intersects(pmask, cpu_online_mask));
+       cpumask_and(pmask, cs->cpus_allowed, cpu_online_mask);
 }
 
 /*
  * Return in *pmask the portion of a cpusets's mems_allowed that
  * are online, with memory.  If none are online with memory, walk
  * up the cpuset hierarchy until we find one that does have some
- * online mems.  If we get all the way to the top and still haven't
- * found any online mems, return node_states[N_MEMORY].
+ * online mems.  The top cpuset always has some mems online.
  *
  * One way or another, we guarantee to return some non-empty subset
  * of node_states[N_MEMORY].
  *
  * Call with callback_mutex held.
  */
-
 static void guarantee_online_mems(const struct cpuset *cs, nodemask_t *pmask)
 {
-       while (cs && !nodes_intersects(cs->mems_allowed,
-                                       node_states[N_MEMORY]))
+       while (!nodes_intersects(cs->mems_allowed, node_states[N_MEMORY]))
                cs = parent_cs(cs);
-       if (cs)
-               nodes_and(*pmask, cs->mems_allowed,
-                                       node_states[N_MEMORY]);
-       else
-               *pmask = node_states[N_MEMORY];
-       BUG_ON(!nodes_intersects(*pmask, node_states[N_MEMORY]));
+       nodes_and(*pmask, cs->mems_allowed, node_states[N_MEMORY]);
 }
 
 /*
@@ -780,25 +754,26 @@ static void rebuild_sched_domains_locked(void)
        lockdep_assert_held(&cpuset_mutex);
        get_online_cpus();
 
+       /*
+        * We have raced with CPU hotplug. Don't do anything to avoid
+        * passing doms with offlined cpu to partition_sched_domains().
+        * Anyways, hotplug work item will rebuild sched domains.
+        */
+       if (!cpumask_equal(top_cpuset.cpus_allowed, cpu_active_mask))
+               goto out;
+
        /* Generate domain masks and attrs */
        ndoms = generate_sched_domains(&doms, &attr);
 
        /* Have scheduler rebuild the domains */
        partition_sched_domains(ndoms, doms, attr);
-
+out:
        put_online_cpus();
 }
 #else /* !CONFIG_SMP */
 static void rebuild_sched_domains_locked(void)
 {
 }
-
-static int generate_sched_domains(cpumask_var_t **domains,
-                       struct sched_domain_attr **attributes)
-{
-       *domains = NULL;
-       return 1;
-}
 #endif /* CONFIG_SMP */
 
 void rebuild_sched_domains(void)
@@ -1388,16 +1363,16 @@ static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
 
        cgroup_taskset_for_each(task, cgrp, tset) {
                /*
-                * Kthreads bound to specific cpus cannot be moved to a new
-                * cpuset; we cannot change their cpu affinity and
-                * isolating such threads by their set of allowed nodes is
-                * unnecessary.  Thus, cpusets are not applicable for such
-                * threads.  This prevents checking for success of
-                * set_cpus_allowed_ptr() on all attached tasks before
-                * cpus_allowed may be changed.
+                * Kthreads which disallow setaffinity shouldn't be moved
+                * to a new cpuset; we don't want to change their cpu
+                * affinity and isolating such threads by their set of
+                * allowed nodes is unnecessary.  Thus, cpusets are not
+                * applicable for such threads.  This prevents checking for
+                * success of set_cpus_allowed_ptr() on all attached tasks
+                * before cpus_allowed may be changed.
                 */
                ret = -EINVAL;
-               if (task->flags & PF_THREAD_BOUND)
+               if (task->flags & PF_NO_SETAFFINITY)
                        goto out_unlock;
                ret = security_task_setscheduler(task);
                if (ret)
@@ -1432,8 +1407,7 @@ static cpumask_var_t cpus_attach;
 
 static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
 {
-       /* static bufs protected by cpuset_mutex */
-       static nodemask_t cpuset_attach_nodemask_from;
+       /* static buf protected by cpuset_mutex */
        static nodemask_t cpuset_attach_nodemask_to;
        struct mm_struct *mm;
        struct task_struct *task;
@@ -1467,13 +1441,12 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
         * Change mm, possibly for multiple threads in a threadgroup. This is
         * expensive and may sleep.
         */
-       cpuset_attach_nodemask_from = oldcs->mems_allowed;
        cpuset_attach_nodemask_to = cs->mems_allowed;
        mm = get_task_mm(leader);
        if (mm) {
                mpol_rebind_mm(mm, &cpuset_attach_nodemask_to);
                if (is_memory_migrate(cs))
-                       cpuset_migrate_mm(mm, &cpuset_attach_nodemask_from,
+                       cpuset_migrate_mm(mm, &oldcs->mems_allowed,
                                          &cpuset_attach_nodemask_to);
                mmput(mm);
        }
@@ -2005,50 +1978,6 @@ int __init cpuset_init(void)
        return 0;
 }
 
-/**
- * cpuset_do_move_task - move a given task to another cpuset
- * @tsk: pointer to task_struct the task to move
- * @scan: struct cgroup_scanner contained in its struct cpuset_hotplug_scanner
- *
- * Called by cgroup_scan_tasks() for each task in a cgroup.
- * Return nonzero to stop the walk through the tasks.
- */
-static void cpuset_do_move_task(struct task_struct *tsk,
-                               struct cgroup_scanner *scan)
-{
-       struct cgroup *new_cgroup = scan->data;
-
-       cgroup_lock();
-       cgroup_attach_task(new_cgroup, tsk);
-       cgroup_unlock();
-}
-
-/**
- * move_member_tasks_to_cpuset - move tasks from one cpuset to another
- * @from: cpuset in which the tasks currently reside
- * @to: cpuset to which the tasks will be moved
- *
- * Called with cpuset_mutex held
- * callback_mutex must not be held, as cpuset_attach() will take it.
- *
- * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
- * calling callback functions for each.
- */
-static void move_member_tasks_to_cpuset(struct cpuset *from, struct cpuset *to)
-{
-       struct cgroup_scanner scan;
-
-       scan.cg = from->css.cgroup;
-       scan.test_task = NULL; /* select all tasks in cgroup */
-       scan.process_task = cpuset_do_move_task;
-       scan.heap = NULL;
-       scan.data = to->css.cgroup;
-
-       if (cgroup_scan_tasks(&scan))
-               printk(KERN_ERR "move_member_tasks_to_cpuset: "
-                               "cgroup_scan_tasks failed\n");
-}
-
 /*
  * If CPU and/or memory hotplug handlers, below, unplug any CPUs
  * or memory nodes, we need to walk over the cpuset hierarchy,
@@ -2069,7 +1998,12 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs)
                        nodes_empty(parent->mems_allowed))
                parent = parent_cs(parent);
 
-       move_member_tasks_to_cpuset(cs, parent);
+       if (cgroup_transfer_tasks(parent->css.cgroup, cs->css.cgroup)) {
+               rcu_read_lock();
+               printk(KERN_ERR "cpuset: failed to transfer tasks out of empty cpuset %s\n",
+                      cgroup_name(cs->css.cgroup));
+               rcu_read_unlock();
+       }
 }
 
 /**
@@ -2222,17 +2156,8 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
        flush_workqueue(cpuset_propagate_hotplug_wq);
 
        /* rebuild sched domains if cpus_allowed has changed */
-       if (cpus_updated) {
-               struct sched_domain_attr *attr;
-               cpumask_var_t *doms;
-               int ndoms;
-
-               mutex_lock(&cpuset_mutex);
-               ndoms = generate_sched_domains(&doms, &attr);
-               mutex_unlock(&cpuset_mutex);
-
-               partition_sched_domains(ndoms, doms, attr);
-       }
+       if (cpus_updated)
+               rebuild_sched_domains();
 }
 
 void cpuset_update_active_cpus(bool cpu_online)
@@ -2311,8 +2236,7 @@ void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
 
        rcu_read_lock();
        cs = task_cs(tsk);
-       if (cs)
-               do_set_cpus_allowed(tsk, cs->cpus_allowed);
+       do_set_cpus_allowed(tsk, cs->cpus_allowed);
        rcu_read_unlock();
 
        /*
@@ -2594,6 +2518,8 @@ int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
        return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
 }
 
+#define CPUSET_NODELIST_LEN    (256)
+
 /**
  * cpuset_print_task_mems_allowed - prints task's cpuset and mems_allowed
  * @task: pointer to task_struct of some task.
@@ -2604,25 +2530,22 @@ int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  */
 void cpuset_print_task_mems_allowed(struct task_struct *tsk)
 {
-       struct dentry *dentry;
+        /* Statically allocated to prevent using excess stack. */
+       static char cpuset_nodelist[CPUSET_NODELIST_LEN];
+       static DEFINE_SPINLOCK(cpuset_buffer_lock);
 
-       dentry = task_cs(tsk)->css.cgroup->dentry;
-       spin_lock(&cpuset_buffer_lock);
+       struct cgroup *cgrp = task_cs(tsk)->css.cgroup;
 
-       if (!dentry) {
-               strcpy(cpuset_name, "/");
-       } else {
-               spin_lock(&dentry->d_lock);
-               strlcpy(cpuset_name, (const char *)dentry->d_name.name,
-                       CPUSET_NAME_LEN);
-               spin_unlock(&dentry->d_lock);
-       }
+       rcu_read_lock();
+       spin_lock(&cpuset_buffer_lock);
 
        nodelist_scnprintf(cpuset_nodelist, CPUSET_NODELIST_LEN,
                           tsk->mems_allowed);
        printk(KERN_INFO "%s cpuset=%s mems_allowed=%s\n",
-              tsk->comm, cpuset_name, cpuset_nodelist);
+              tsk->comm, cgroup_name(cgrp), cpuset_nodelist);
+
        spin_unlock(&cpuset_buffer_lock);
+       rcu_read_unlock();
 }
 
 /*
@@ -2668,7 +2591,7 @@ void __cpuset_memory_pressure_bump(void)
  *    and we take cpuset_mutex, keeping cpuset_attach() from changing it
  *    anyway.
  */
-static int proc_cpuset_show(struct seq_file *m, void *unused_v)
+int proc_cpuset_show(struct seq_file *m, void *unused_v)
 {
        struct pid *pid;
        struct task_struct *tsk;
@@ -2702,19 +2625,6 @@ out_free:
 out:
        return retval;
 }
-
-static int cpuset_open(struct inode *inode, struct file *file)
-{
-       struct pid *pid = PROC_I(inode)->pid;
-       return single_open(file, proc_cpuset_show, pid);
-}
-
-const struct file_operations proc_cpuset_operations = {
-       .open           = cpuset_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-};
 #endif /* CONFIG_PROC_PID_CPUSET */
 
 /* Display task mems_allowed in /proc/<pid>/status file. */