Skip to content

Commit e0c2744

Browse files
hnaztorvalds
authored andcommitted
psi: make disabling/enabling easier for vendor kernels
Mel Gorman reports a hackbench regression with psi that would prohibit shipping the suse kernel with it default-enabled, but he'd still like users to be able to opt in at little to no cost to others. With the current combination of CONFIG_PSI and the psi_disabled bool set from the commandline, this is a challenge. Do the following things to make it easier: 1. Add a config option CONFIG_PSI_DEFAULT_DISABLED that allows distros to enable CONFIG_PSI in their kernel but leave the feature disabled unless a user requests it at boot-time. To avoid double negatives, rename psi_disabled= to psi=. 2. Make psi_disabled a static branch to eliminate any branch costs when the feature is disabled. In terms of numbers before and after this patch, Mel says: : The following is a comparision using CONFIG_PSI=n as a baseline against : your patch and a vanilla kernel : : 4.20.0-rc4 4.20.0-rc4 4.20.0-rc4 : kconfigdisable-v1r1 vanilla psidisable-v1r1 : Amean 1 1.3100 ( 0.00%) 1.3923 ( -6.28%) 1.3427 ( -2.49%) : Amean 3 3.8860 ( 0.00%) 4.1230 * -6.10%* 3.8860 ( -0.00%) : Amean 5 6.8847 ( 0.00%) 8.0390 * -16.77%* 6.7727 ( 1.63%) : Amean 7 9.9310 ( 0.00%) 10.8367 * -9.12%* 9.9910 ( -0.60%) : Amean 12 16.6577 ( 0.00%) 18.2363 * -9.48%* 17.1083 ( -2.71%) : Amean 18 26.5133 ( 0.00%) 27.8833 * -5.17%* 25.7663 ( 2.82%) : Amean 24 34.3003 ( 0.00%) 34.6830 ( -1.12%) 32.0450 ( 6.58%) : Amean 30 40.0063 ( 0.00%) 40.5800 ( -1.43%) 41.5087 ( -3.76%) : Amean 32 40.1407 ( 0.00%) 41.2273 ( -2.71%) 39.9417 ( 0.50%) : : It's showing that the vanilla kernel takes a hit (as the bisection : indicated it would) and that disabling PSI by default is reasonably : close in terms of performance for this particular workload on this : particular machine so; Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Johannes Weiner <[email protected]> Tested-by: Mel Gorman <[email protected]> Reported-by: Mel Gorman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent dbd4af5 commit e0c2744

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,10 @@
35053505
before loading.
35063506
See Documentation/blockdev/ramdisk.txt.
35073507

3508+
psi= [KNL] Enable or disable pressure stall information
3509+
tracking.
3510+
Format: <bool>
3511+
35083512
psmouse.proto= [HW,MOUSE] Highest PS2 mouse protocol extension to
35093513
probe for; one of (bare|imps|exps|lifebook|any).
35103514
psmouse.rate= [HW,MOUSE] Set desired mouse report rate, in reports

include/linux/psi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _LINUX_PSI_H
22
#define _LINUX_PSI_H
33

4+
#include <linux/jump_label.h>
45
#include <linux/psi_types.h>
56
#include <linux/sched.h>
67

@@ -9,7 +10,7 @@ struct css_set;
910

1011
#ifdef CONFIG_PSI
1112

12-
extern bool psi_disabled;
13+
extern struct static_key_false psi_disabled;
1314

1415
void psi_init(void);
1516

init/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,15 @@ config PSI
509509

510510
Say N if unsure.
511511

512+
config PSI_DEFAULT_DISABLED
513+
bool "Require boot parameter to enable pressure stall information tracking"
514+
default n
515+
depends on PSI
516+
help
517+
If set, pressure stall information tracking will be disabled
518+
per default but can be enabled through passing psi_enable=1
519+
on the kernel commandline during boot.
520+
512521
endmenu # "CPU/Task time and stats accounting"
513522

514523
config CPU_ISOLATION

kernel/sched/psi.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,18 @@
136136

137137
static int psi_bug __read_mostly;
138138

139-
bool psi_disabled __read_mostly;
140-
core_param(psi_disabled, psi_disabled, bool, 0644);
139+
DEFINE_STATIC_KEY_FALSE(psi_disabled);
140+
141+
#ifdef CONFIG_PSI_DEFAULT_DISABLED
142+
bool psi_enable;
143+
#else
144+
bool psi_enable = true;
145+
#endif
146+
static int __init setup_psi(char *str)
147+
{
148+
return kstrtobool(str, &psi_enable) == 0;
149+
}
150+
__setup("psi=", setup_psi);
141151

142152
/* Running averages - we need to be higher-res than loadavg */
143153
#define PSI_FREQ (2*HZ+1) /* 2 sec intervals */
@@ -169,8 +179,10 @@ static void group_init(struct psi_group *group)
169179

170180
void __init psi_init(void)
171181
{
172-
if (psi_disabled)
182+
if (!psi_enable) {
183+
static_branch_enable(&psi_disabled);
173184
return;
185+
}
174186

175187
psi_period = jiffies_to_nsecs(PSI_FREQ);
176188
group_init(&psi_system);
@@ -549,7 +561,7 @@ void psi_memstall_enter(unsigned long *flags)
549561
struct rq_flags rf;
550562
struct rq *rq;
551563

552-
if (psi_disabled)
564+
if (static_branch_likely(&psi_disabled))
553565
return;
554566

555567
*flags = current->flags & PF_MEMSTALL;
@@ -579,7 +591,7 @@ void psi_memstall_leave(unsigned long *flags)
579591
struct rq_flags rf;
580592
struct rq *rq;
581593

582-
if (psi_disabled)
594+
if (static_branch_likely(&psi_disabled))
583595
return;
584596

585597
if (*flags)
@@ -600,7 +612,7 @@ void psi_memstall_leave(unsigned long *flags)
600612
#ifdef CONFIG_CGROUPS
601613
int psi_cgroup_alloc(struct cgroup *cgroup)
602614
{
603-
if (psi_disabled)
615+
if (static_branch_likely(&psi_disabled))
604616
return 0;
605617

606618
cgroup->psi.pcpu = alloc_percpu(struct psi_group_cpu);
@@ -612,7 +624,7 @@ int psi_cgroup_alloc(struct cgroup *cgroup)
612624

613625
void psi_cgroup_free(struct cgroup *cgroup)
614626
{
615-
if (psi_disabled)
627+
if (static_branch_likely(&psi_disabled))
616628
return;
617629

618630
cancel_delayed_work_sync(&cgroup->psi.clock_work);
@@ -637,7 +649,7 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to)
637649
struct rq_flags rf;
638650
struct rq *rq;
639651

640-
if (psi_disabled) {
652+
if (static_branch_likely(&psi_disabled)) {
641653
/*
642654
* Lame to do this here, but the scheduler cannot be locked
643655
* from the outside, so we move cgroups from inside sched/.
@@ -673,7 +685,7 @@ int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res)
673685
{
674686
int full;
675687

676-
if (psi_disabled)
688+
if (static_branch_likely(&psi_disabled))
677689
return -EOPNOTSUPP;
678690

679691
update_stats(group);

kernel/sched/stats.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
6666
{
6767
int clear = 0, set = TSK_RUNNING;
6868

69-
if (psi_disabled)
69+
if (static_branch_likely(&psi_disabled))
7070
return;
7171

7272
if (!wakeup || p->sched_psi_wake_requeue) {
@@ -86,7 +86,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
8686
{
8787
int clear = TSK_RUNNING, set = 0;
8888

89-
if (psi_disabled)
89+
if (static_branch_likely(&psi_disabled))
9090
return;
9191

9292
if (!sleep) {
@@ -102,7 +102,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
102102

103103
static inline void psi_ttwu_dequeue(struct task_struct *p)
104104
{
105-
if (psi_disabled)
105+
if (static_branch_likely(&psi_disabled))
106106
return;
107107
/*
108108
* Is the task being migrated during a wakeup? Make sure to
@@ -128,7 +128,7 @@ static inline void psi_ttwu_dequeue(struct task_struct *p)
128128

129129
static inline void psi_task_tick(struct rq *rq)
130130
{
131-
if (psi_disabled)
131+
if (static_branch_likely(&psi_disabled))
132132
return;
133133

134134
if (unlikely(rq->curr->flags & PF_MEMSTALL))

0 commit comments

Comments
 (0)