Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e4c9a14 authored by Tejun Heo's avatar Tejun Heo
Browse files

cpuset: cleanup cpuset[_can]_attach()



cpuset_can_attach() prepare global variables cpus_attach and
cpuset_attach_nodemask_{to|from} which are used by cpuset_attach().
There is no reason to prepare in cpuset_can_attach().  The same
information can be accessed from cpuset_attach().

Move the prepartion logic from cpuset_can_attach() to cpuset_attach()
and make the global variables static ones inside cpuset_attach().

With this change, there's no reason to keep
cpuset_attach_nodemask_{from|to} global.  Move them inside
cpuset_attach().  Unfortunately, we need to keep cpus_attach global as
it can't be allocated from cpuset_attach().

v2: cpus_attach not converted to cpumask_t as per Li Zefan and Rusty
    Russell.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
parent ae8086ce
Loading
Loading
Loading
Loading
+18 −17
Original line number Original line Diff line number Diff line
@@ -1395,15 +1395,6 @@ static int fmeter_getrate(struct fmeter *fmp)
	return val;
	return val;
}
}


/*
 * Protected by cgroup_lock. The nodemasks must be stored globally because
 * dynamically allocating them is not allowed in can_attach, and they must
 * persist until attach.
 */
static cpumask_var_t cpus_attach;
static nodemask_t cpuset_attach_nodemask_from;
static nodemask_t cpuset_attach_nodemask_to;

/* Called by cgroups to determine if a cpuset is usable; cgroup_mutex held */
/* Called by cgroups to determine if a cpuset is usable; cgroup_mutex held */
static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
{
{
@@ -1430,19 +1421,21 @@ static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
			return ret;
			return ret;
	}
	}


	/* prepare for attach */
	if (cs == &top_cpuset)
		cpumask_copy(cpus_attach, cpu_possible_mask);
	else
		guarantee_online_cpus(cs, cpus_attach);

	guarantee_online_mems(cs, &cpuset_attach_nodemask_to);

	return 0;
	return 0;
}
}


/*
 * Protected by cgroup_mutex.  cpus_attach is used only by cpuset_attach()
 * but we can't allocate it dynamically there.  Define it global and
 * allocate from cpuset_init().
 */
static cpumask_var_t cpus_attach;

static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
{
{
	/* static bufs protected by cgroup_mutex */
	static nodemask_t cpuset_attach_nodemask_from;
	static nodemask_t cpuset_attach_nodemask_to;
	struct mm_struct *mm;
	struct mm_struct *mm;
	struct task_struct *task;
	struct task_struct *task;
	struct task_struct *leader = cgroup_taskset_first(tset);
	struct task_struct *leader = cgroup_taskset_first(tset);
@@ -1450,6 +1443,14 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
	struct cpuset *cs = cgroup_cs(cgrp);
	struct cpuset *cs = cgroup_cs(cgrp);
	struct cpuset *oldcs = cgroup_cs(oldcgrp);
	struct cpuset *oldcs = cgroup_cs(oldcgrp);


	/* prepare for attach */
	if (cs == &top_cpuset)
		cpumask_copy(cpus_attach, cpu_possible_mask);
	else
		guarantee_online_cpus(cs, cpus_attach);

	guarantee_online_mems(cs, &cpuset_attach_nodemask_to);

	cgroup_taskset_for_each(task, cgrp, tset) {
	cgroup_taskset_for_each(task, cgrp, tset) {
		/*
		/*
		 * can_attach beforehand should guarantee that this doesn't
		 * can_attach beforehand should guarantee that this doesn't