From: Peter Zijlstra <peterz@infradead.org>
To: Tejun Heo <tj@kernel.org>
Cc: Paul Turner <pjt@google.com>, Ingo Molnar <mingo@redhat.com>,
Johannes Weiner <hannes@cmpxchg.org>,
lizefan@huawei.com, cgroups <cgroups@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
kernel-team <kernel-team@fb.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy
Date: Thu, 17 Sep 2015 17:10:49 +0200 [thread overview]
Message-ID: <20150917151049.GB11639@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150917143527.GJ3604@twins.programming.kicks-ass.net>
On Thu, Sep 17, 2015 at 04:35:27PM +0200, Peter Zijlstra wrote:
> I'd be happy to fail a CPU down for user tasks where this is the last
> runnable CPU of.
A little like so. Completely untested.
---
Subject: sched: Refuse to unplug a CPU if this will violate user task affinity
Its bad policy to allow unplugging a CPU for which a user set explicit
affinity, either strictly on this CPU or in case this was the last
online CPU in its mask.
Either would end up forcing the thread on a random other CPU, violating
the sys_sched_setaffinity() constraint.
Disallow this by default; root might not be aware of all user
affinities, but can negotiate and change affinities for all tasks.
Provide a sysctl to go back to the old behaviour.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/sched/sysctl.h | 1 +
kernel/sched/core.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
kernel/sysctl.c | 9 +++++++++
3 files changed, 56 insertions(+)
diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
index c9e4731cf10b..9444b549914b 100644
--- a/include/linux/sched/sysctl.h
+++ b/include/linux/sched/sysctl.h
@@ -39,6 +39,7 @@ extern unsigned int sysctl_sched_latency;
extern unsigned int sysctl_sched_min_granularity;
extern unsigned int sysctl_sched_wakeup_granularity;
extern unsigned int sysctl_sched_child_runs_first;
+extern unsigned int sysctl_sched_strict_affinity;
enum sched_tunable_scaling {
SCHED_TUNABLESCALING_NONE,
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 6ab415aa15c4..457c8b912fc6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -284,6 +284,11 @@ __read_mostly int scheduler_running;
*/
int sysctl_sched_rt_runtime = 950000;
+/*
+ * Disallows cpu unplug if that would result in a task without runnable CPUs.
+ */
+unsigned int sysctl_sched_strict_affinity = 1;
+
/* cpus with isolated domains */
cpumask_var_t cpu_isolated_map;
@@ -5430,6 +5435,42 @@ static void set_rq_offline(struct rq *rq)
}
/*
+ * Test if there's a user task for which @cpu is the last runnable CPU
+ */
+static bool migration_possible(int cpu)
+{
+ struct task_struct *g, *p;
+ bool ret = true;
+ int next;
+
+ read_lock(&tasklist_lock);
+ for_each_process_thread(g, p) {
+ /* if its running elsewhere, this cannot be its last cpu */
+ if (task_cpu(p) != cpu)
+ continue;
+
+ /* we only care about user state */
+ if (p->flags & PF_KTHREAD)
+ continue;
+
+ next = -1;
+again:
+ next = cpumask_next_and(next, tsk_cpus_allowed(p), cpu_active_mask);
+ if (next >= nr_cpu_ids) {
+ printk(KERN_WARNING "task %s-%d refused unplug of CPU %d\n",
+ p->comm, p->pid, cpu);
+ ret = false;
+ break;
+ }
+ if (next == cpu)
+ goto again;
+ }
+ read_unlock(&tasklist_lock);
+
+ return ret;
+}
+
+/*
* migration_call - callback that gets triggered when a CPU is added.
* Here we can start up the necessary migration thread for the new CPU.
*/
@@ -5440,6 +5481,11 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
unsigned long flags;
struct rq *rq = cpu_rq(cpu);
+ if (action == CPU_DOWN_PREPARE && sysctl_sched_strict_affinity) {
+ if (!migration_possible(cpu))
+ return notifier_from_errno(-EBUSY);
+ }
+
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_UP_PREPARE:
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index e69201d8094e..9d0edcc73cc3 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -283,6 +283,15 @@ static struct ctl_table kern_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec,
},
+#ifdef CONFIG_SMP
+ {
+ .procname = "sched_strict_affinity",
+ .data = &sysctl_sched_strict_affinity,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ },
+#endif /* CONFIG_SMP */
#ifdef CONFIG_SCHED_DEBUG
{
.procname = "sched_min_granularity_ns",
next prev parent reply other threads:[~2015-09-17 15:16 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-03 22:41 [PATCHSET sched,cgroup] " Tejun Heo
2015-08-03 22:41 ` [PATCH 1/3] cgroup: define controller file conventions Tejun Heo
2015-08-04 8:42 ` Peter Zijlstra
2015-08-04 14:51 ` Tejun Heo
2015-08-04 8:48 ` Peter Zijlstra
2015-08-04 14:53 ` Tejun Heo
2015-08-04 19:31 ` [PATCH v2 " Tejun Heo
2015-08-05 0:39 ` Kamezawa Hiroyuki
2015-08-05 7:47 ` Michal Hocko
2015-08-06 2:30 ` Kamezawa Hiroyuki
2015-08-07 18:17 ` Michal Hocko
2015-08-17 22:04 ` Johannes Weiner
2015-08-17 21:34 ` Johannes Weiner
2015-08-03 22:41 ` [PATCH 2/3] sched: Misc preps for cgroup unified hierarchy interface Tejun Heo
2015-08-03 22:41 ` [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy Tejun Heo
2015-08-04 9:07 ` Peter Zijlstra
2015-08-04 15:10 ` Tejun Heo
2015-08-05 9:10 ` Peter Zijlstra
2015-08-05 14:31 ` Tejun Heo
2015-08-17 20:35 ` Tejun Heo
[not found] ` <CAPM31RJTf0v=2v90kN6-HM9xUGab_k++upO0Ym=irmfO9+BbFw@mail.gmail.com>
2015-08-18 4:03 ` Paul Turner
2015-08-18 20:31 ` Tejun Heo
2015-08-18 23:39 ` Kamezawa Hiroyuki
2015-08-19 16:23 ` Tejun Heo
2015-08-19 3:23 ` Mike Galbraith
2015-08-19 16:41 ` Tejun Heo
2015-08-20 4:00 ` Mike Galbraith
2015-08-20 7:52 ` Tejun Heo
2015-08-20 8:47 ` Mike Galbraith
2015-08-21 19:26 ` Paul Turner
2015-08-22 18:29 ` Tejun Heo
2015-08-24 15:47 ` Austin S Hemmelgarn
2015-08-24 17:04 ` Tejun Heo
2015-08-24 19:18 ` Mike Galbraith
2015-08-24 20:00 ` Austin S Hemmelgarn
2015-08-24 20:25 ` Tejun Heo
2015-08-24 21:00 ` Paul Turner
2015-08-24 21:12 ` Tejun Heo
2015-08-24 21:15 ` Paul Turner
2015-08-24 20:54 ` Paul Turner
2015-08-24 21:02 ` Tejun Heo
2015-08-24 21:10 ` Paul Turner
2015-08-24 21:17 ` Tejun Heo
2015-08-24 21:19 ` Paul Turner
2015-08-24 21:40 ` Tejun Heo
2015-08-24 22:03 ` Paul Turner
2015-08-24 22:49 ` Tejun Heo
2015-08-24 23:15 ` Paul Turner
2015-08-25 2:36 ` Kamezawa Hiroyuki
2015-08-25 21:13 ` Tejun Heo
2015-08-25 9:24 ` Ingo Molnar
2015-08-25 10:00 ` Peter Zijlstra
2015-08-25 19:18 ` Tejun Heo
2015-08-24 20:52 ` Paul Turner
2015-08-24 21:36 ` Tejun Heo
2015-08-24 21:58 ` Paul Turner
2015-08-24 22:19 ` Tejun Heo
2015-08-24 23:06 ` Paul Turner
2015-08-25 21:02 ` Tejun Heo
2015-09-02 17:03 ` Tejun Heo
2015-09-09 12:49 ` Paul Turner
2015-09-12 14:40 ` Tejun Heo
2015-09-17 14:35 ` Peter Zijlstra
2015-09-17 14:53 ` Tejun Heo
2015-09-17 15:42 ` Peter Zijlstra
2015-09-17 15:10 ` Peter Zijlstra [this message]
2015-09-17 15:52 ` Tejun Heo
2015-09-17 15:53 ` Peter Zijlstra
2015-09-17 23:29 ` Tejun Heo
2015-09-18 11:27 ` Paul Turner
2015-10-01 18:46 ` Tejun Heo
2015-10-15 11:42 ` Paul Turner
2015-10-23 22:21 ` Tejun Heo
2015-10-24 4:36 ` Mike Galbraith
2015-10-25 2:18 ` Tejun Heo
2015-10-25 3:43 ` Mike Galbraith
2015-10-27 3:16 ` Tejun Heo
2015-10-27 5:42 ` Mike Galbraith
2015-10-27 5:46 ` Tejun Heo
2015-10-27 5:56 ` Mike Galbraith
2015-10-27 6:00 ` Tejun Heo
2015-10-27 6:08 ` Mike Galbraith
2015-10-25 3:54 ` Linus Torvalds
2015-10-25 9:33 ` Ingo Molnar
2015-10-25 10:41 ` Theodore Ts'o
2015-10-25 10:47 ` Florian Weimer
2015-10-25 11:58 ` Theodore Ts'o
2015-10-25 13:17 ` Florian Weimer
2015-10-25 13:40 ` Getrandom wrapper Theodore Ts'o
2015-10-26 13:32 ` Florian Weimer
2015-10-26 14:10 ` [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy Peter Zijlstra
2015-08-04 19:32 ` [PATCH v2 " Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150917151049.GB11639@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mingo@redhat.com \
--cc=pjt@google.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®