Re: 20% performance drop on PostgreSQL 9.2 from kernel 3.5.3 to 3.6-rc5 on AMD chipsets - bisected

Ingo Molnar
2012-09-27T07:10:20Z

* Mike Galbraith <efault@gmx.de> wrote:

> > Do you have an easy-to-apply hack patch by chance that has
> > the effect of turning off all such preemption, which people
> > could try?
>
> They don't need any hacks, all they have to do is start
> postgreqsl SCHED_BATCH, then run pgbench the same way.
>
> I use schedctl, but in chrt speak, chrt -b 0
> /etc/init.d/postgresql start, and then the same for pgbench
> itself.

Just in case someone prefers patches to user-space approaches (I
certainly do!), here's one that turns off wakeup driven
preemption by default.

It can be turned back on via:

echo WAKEUP_PREEMPTION > /debug/sched_features

and off again via:

echo NO_WAKEUP_PREEMPTION > /debug/sched_features

(the patch is completely untested and such.)

The theory would be that this patch fixes psql performance, with
CPU selection being a measurable but second order of magnitude
effect. How well does practice match theory in this case?

Thanks,

Ingo

---------
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6b800a1..f936552 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2907,7 +2907,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
* Batch and idle tasks do not preempt non-idle tasks (their preemption
* is driven by the tick):
*/
- if (unlikely(p->policy != SCHED_NORMAL))
+ if (unlikely(p->policy != SCHED_NORMAL) || !sched_feat(WAKEUP_PREEMPTION))
return;

find_matching_se(&se, &pse);
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index eebefca..e68e69a 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -32,6 +32,11 @@ SCHED_FEAT(LAST_BUDDY, true)
SCHED_FEAT(CACHE_HOT_BUDDY, true)

/*
+ * Allow wakeup-time preemption of the current task:
+ */
+SCHED_FEAT(WAKEUP_PREEMPTION, false)
+
+/*
* Use arch dependent cpu power functions
*/
SCHED_FEAT(ARCH_POWER, true)