PSI feature for 4.14
cover PSI feature for 4.14
Hi Folks,
This is a backport for PSI feature from:
http://git.cmpxchg.org/cgit.cgi/linux-psi.git/log/?h=psi-4.17
The patches are included since 4.20.
We're run LTP tests and stress test with these patches on 4.14.93, no problem found.
I send them out for review, also maybe there are other guys are intereseted.
I kept the conflict note in commit message, so it's easier to review.
Regards,
Jack
Johannes Weiner (10):
mm: workingset: don't drop refault information prematurely
mm: workingset: tell cache transitions from workingset thrashing
delayacct: track delays from thrashing cache pages
sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD
sched: loadavg: make calc_load_n() public
sched: sched.h: make rq locking and clock functions available in
stats.h
sched: introduce this_rq_lock_irq()
psi: pressure stall information for CPU, memory, and IO
psi: cgroup support
psi: make disabling/enabling easier for vendor kernels
Olof Johansson (1):
kernel/sched/psi.c: simplify cgroup_move_task()
Documentation/accounting/psi.txt | 73 ++ .../admin-guide/kernel-parameters.txt | 4 + Documentation/cgroup-v2.txt | 17 + .../platforms/cell/cpufreq_spudemand.c | 2 +- arch/powerpc/platforms/cell/spufs/sched.c | 9 +- arch/s390/appldata/appldata_os.c | 4 - drivers/cpuidle/governors/menu.c | 4 - fs/proc/loadavg.c | 3 - include/linux/cgroup-defs.h | 4 + include/linux/cgroup.h | 15 + include/linux/delayacct.h | 23 + include/linux/mmzone.h | 1 + include/linux/page-flags.h | 5 +- include/linux/psi.h | 54 ++ include/linux/psi_types.h | 92 +++ include/linux/sched.h | 10 + include/linux/sched/loadavg.h | 24 +- include/linux/swap.h | 2 +- include/trace/events/mmflags.h | 1 + include/uapi/linux/taskstats.h | 6 +- init/Kconfig | 28 + kernel/cgroup/cgroup.c | 44 +- kernel/debug/kdb/kdb_main.c | 7 +- kernel/delayacct.c | 15 + kernel/fork.c | 4 + kernel/sched/Makefile | 1 + kernel/sched/core.c | 16 +- kernel/sched/loadavg.c | 139 ++-- kernel/sched/psi.c | 772 ++++++++++++++++++ kernel/sched/sched.h | 175 ++-- kernel/sched/stats.h | 86 ++ mm/compaction.c | 5 + mm/filemap.c | 27 +- mm/huge_memory.c | 1 + mm/migrate.c | 2 + mm/page_alloc.c | 9 + mm/swap_state.c | 1 + mm/vmscan.c | 12 + mm/vmstat.c | 1 + mm/workingset.c | 117 ++- tools/accounting/getdelays.c | 8 +- 41 files changed, 1580 insertions(+), 243 deletions(-) create mode 100644 Documentation/accounting/psi.txt create mode 100644 include/linux/psi.h create mode 100644 include/linux/psi_types.h create mode 100644 kernel/sched/psi.c
Signature · 1 line
2.17.1
PATCH 2/11 mm: workingset: tell cache transitions from workingset thrashing
From: Johannes Weiner <[email protected]>
Refaults happen during transitions between workingsets as well as in-place thrashing. Knowing the difference between the two has a range of applications, including measuring the impact of memory shortage on the system performance, as well as the ability to smarter balance pressure between the filesystem cache and the swap-backed workingset.
During workingset transitions, inactive cache refaults and pushes out established active cache. When that active cache isn't stale, however, and also ends up refaulting, that's bonafide thrashing.
Introduce a new page flag that tells on eviction whether the page has been active or not in its lifetime. This bit is then stored in the shadow entry, to classify refaults as transitioning or thrashing.
How many page->flags does this leave us with on 32-bit?
20 bits are always page flags
21 if you have an MMU
23 with the zone bits for DMA, Normal, HighMem, Movable
29 with the sparsemem section bits
30 if PAE is enabled
31 with this patch.
So on 32-bit PAE, that leaves 1 bit for distinguishing two NUMA nodes. If that's not enough, the system can switch to discontigmem and re-gain the 6 or 7 sparsemem section bits.
--- include/linux/mmzone.h | 1 + include/linux/page-flags.h | 5 +- include/linux/swap.h | 2 +- include/trace/events/mmflags.h | 1 + mm/filemap.c | 9 ++-- mm/huge_memory.c | 1 + mm/migrate.c | 2 + mm/swap_state.c | 1 + mm/vmscan.c | 1 + mm/vmstat.c | 1 + mm/workingset.c | 95 ++++++++++++++++++++++------------ 11 files changed, 77 insertions(+), 42 deletions(-)
include/linux/mmzone.h +1 -0
@@ -163,6 +163,7 @@ enum node_stat_item {NR_ISOLATED_FILE ,/* Temporary isolated pages from file lru */ WORKINGSET_REFAULT ,WORKINGSET_ACTIVATE , +WORKINGSET_RESTORE ,WORKINGSET_NODERECLAIM ,NR_ANON_MAPPED ,/* Mapped anonymous pages */ NR_FILE_MAPPED, /* pagecache pages mapped into pagetables.
include/linux/page-flags.h +4 -1
@@ -74,13 +74,14 @@*/ enum pageflags { PG_locked,/* Page is locked. Don't touch. */ - PG_error, PG_referenced, PG_uptodate, PG_dirty, PG_lru, PG_active, + PG_workingset, PG_waiters,/* Page has waiters, check its waitqueue. Must be bit #7 and in the same byte as "PG_locked" */ + PG_error, PG_slab, PG_owner_priv_1,/* Owner use. If pagecache, fs may use*/ PG_arch_1,
@@ -273,6 +274,8 @@ PAGEFLAG(Dirty, dirty, PF_HEAD) TESTSCFLAG(Dirty, dirty, PF_HEAD) PAGEFLAG(LRU, lru, PF_HEAD) __CLEARPAGEFLAG(LRU, lru, PF_HEAD) PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD) TESTCLEARFLAG(Active, active, PF_HEAD) +PAGEFLAG(Workingset, workingset, PF_HEAD) + TESTCLEARFLAG(Workingset, workingset, PF_HEAD) __PAGEFLAG(Slab, slab, PF_NO_TAIL) __PAGEFLAG(SlobFree, slob_free, PF_NO_TAIL)PAGEFLAG (Checked, checked,PF_NO_COMPOUND )/* Used by some filesystems */
include/linux/swap.h +1 -1
@@ -304,7 +304,7 @@ struct vma_swap_readahead {/* linux/mm/workingset.c */ void *workingset_eviction (struct address_space *mapping,struct page *page); -bool workingset_refault (void *shadow); +void workingset_refault (struct page *page,void *shadow);void workingset_activation (struct page *page);void workingset_update_node (struct radix_tree_node *node,void *private);
include/trace/events/mmflags.h +1 -0
@@ -89,6 +89,7 @@ {1UL << PG_dirty, "dirty" }, \ {1UL << PG_lru, "lru" }, \ {1UL << PG_active, "active" }, \ + {1UL << PG_workingset, "workingset" }, \ {1UL << PG_slab, "slab" }, \ {1UL << PG_owner_priv_1, "owner_priv_1" }, \ {1UL << PG_arch_1, "arch_1" }, \
mm/filemap.c +3 -6
@@ -817,12 +817,9 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping,* data from the working set, only to cache data that will * get overwritten with something else, is a waste of memory. */ -if (!(gfp_mask & __GFP_WRITE) && - shadow &&workingset_refault (shadow)) { -SetPageActive (page); -workingset_activation (page); - }else -ClearPageActive (page); +WARN_ON_ONCE (PageActive (page)); +if (!(gfp_mask & __GFP_WRITE) && shadow) +workingset_refault (page, shadow);lru_cache_add (page); }return ret;
mm/huge_memory.c +1 -0
@@ -2327,6 +2327,7 @@ static void __split_huge_page_tail(struct page *head, int tail, (1L << PG_mlocked) | (1L << PG_uptodate) | (1L << PG_active) | + (1L << PG_workingset) | (1L << PG_locked) | (1L << PG_unevictable) | (1L << PG_dirty)));
mm/migrate.c +2 -0
@@ -673,6 +673,8 @@ void migrate_page_states(struct page *newpage, struct page *page)SetPageActive (newpage); }else if (TestClearPageUnevictable (page))SetPageUnevictable (newpage); +if (PageWorkingset (page)) +SetPageWorkingset (newpage);if (PageChecked (page))SetPageChecked (newpage);if (PageMappedToDisk (page))
mm/swap_state.c +1 -0
@@ -435,6 +435,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,/* * Initiate read into locked page and return. */ +SetPageWorkingset (new_page);lru_cache_add_anon (new_page); *new_page_allocated = true;return new_page;
mm/vmscan.c +1 -0
@@ -2056,6 +2056,7 @@ static void shrink_active_list(unsigned long nr_to_scan, }ClearPageActive (page);/* we are de-activating */ +SetPageWorkingset (page);list_add (&page->lru, &l_inactive); }
mm/vmstat.c +1 -0
@@ -1074,6 +1074,7 @@ const char * const vmstat_text[] = {"nr_isolated_file" ,"workingset_refault" ,"workingset_activate" , +"workingset_restore" ,"workingset_nodereclaim" ,"nr_anon_pages" , "nr_mapped",
mm/workingset.c +61 -34
196 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 1/11 mm: workingset: don't drop refault information prematurely
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
Patch series "psi: pressure stall information for CPU, memory, and IO", v4.
Overview
PSI reports the overall wallclock time in which the tasks in a system (or cgroup) wait for (contended) hardware resources.
This helps users understand the resource pressure their workloads are under, which allows them to rootcause and fix throughput and latency problems caused by overcommitting, underprovisioning, suboptimal job placement in a grid; as well as anticipate major disruptions like OOM.
Real-world applications
We're using the data collected by PSI (and its previous incarnation, memdelay) quite extensively at Facebook, and with several success stories.
One usecase is avoiding OOM hangs/livelocks. The reason these happen is because the OOM killer is triggered by reclaim not being able to free pages, but with fast flash devices there is *always* some clean and uptodate cache to reclaim; the OOM killer never kicks in, even as tasks spend 90% of the time thrashing the cache pages of their own executables. There is no situation where this ever makes sense in practice. We wrote a <100 line POC python script to monitor memory pressure and kill stuff way before such pathological thrashing leads to full system losses that would require forcible hard resets.
We've since extended and deployed this code into other places to guarantee latency and throughput SLAs, since they're usually violated way before the kernel OOM killer would ever kick in.
It is available here: https://github.com/facebookincubator/oomd
Eventually we probably want to trigger the in-kernel OOM killer based on extreme sustained pressure as well, so that Linux can avoid memory livelocks - which technically aren't deadlocks, but to the user indistinguishable from them - out of the box. We'd continue using OOMD as the first line of defense to ensure workload health and implement complex kill policies that are beyond the scope of the kernel.
We also use PSI memory pressure for loadshedding. Our batch job infrastructure used to use heuristics based on various VM stats to anticipate OOM situations, with lackluster success. We switched it to PSI and managed to anticipate and avoid OOM kills and lockups fairly reliably. The reduction of OOM outages in the worker pool raised the pool's aggregate productivity, and we were able to switch that service to smaller machines.
Lastly, we use cgroups to isolate a machine's main workload from maintenance crap like package upgrades, logging, configuration, as well as to prevent multiple workloads on a machine from stepping on each others' toes. We were not able to configure this properly without the pressure metrics; we would see latency or bandwidth drops, but it would often be hard to impossible to rootcause it post-mortem.
We now log and graph pressure for the containers in our fleet and can trivially link latency spikes and throughput drops to shortages of specific resources after the fact, and fix the job config/scheduling.
PSI has also received testing, feedback, and feature requests from Android and EndlessOS for the purpose of low-latency OOM killing, to intervene in pressure situations before the UI starts hanging.
How do you use this feature?
A kernel with CONFIG_PSI=y will create a /proc/pressure directory with 3
files: cpu, memory, and io. If using cgroup2, cgroups will also have cpu.pressure, memory.pressure and io.pressure files, which simply aggregate task stalls at the cgroup level instead of system-wide.
The cpu file contains one line:
some avg10=2.04 avg60=0.75 avg300=0.40 total=157656722
The averages give the percentage of walltime in which one or more tasks are delayed on the runqueue while another task has the CPU. They're recent averages over 10s, 1m, 5m windows, so you can tell short term trends from long term ones, similarly to the load average.
The total= value gives the absolute stall time in microseconds. This allows detecting latency spikes that might be too short to sway the running averages. It also allows custom time averaging in case the 10s/1m/5m windows aren't adequate for the usecase (or are too coarse with future hardware).
What to make of this "some" metric? If CPU utilization is at 100% and CPU pressure is 0, it means the system is perfectly utilized, with one runnable thread per CPU and nobody waiting. At two or more runnable tasks per CPU, the system is 100% overcommitted and the pressure average will indicate as much. From a utilization perspective this is a great state of
course: no CPU cycles are being wasted, even when 50% of the threads were to go idle (as most workloads do vary). From the perspective of the individual job it's not great, however, and they would do better with more resources. Depending on what your priority and options are, raised "some" numbers may or may not require action.
The memory file contains two lines:
some avg10=70.24 avg60=68.52 avg300=69.91 total=3559632828 full avg10=57.59 avg60=58.06 avg300=60.38 total=3300487258
The some line is the same as for cpu, the time in which at least one task is stalled on the resource. In the case of memory, this includes waiting on swap-in, page cache refaults and page reclaim.
The full line, however, indicates time in which *nobody* is using the CPU productively due to pressure: all non-idle tasks are waiting for memory in one form or another. Significant time spent in there is a good trigger for killing things, moving jobs to other machines, or dropping incoming requests, since neither the jobs nor the machine overall are making too much headway.
The io file is similar to memory. Because the block layer doesn't have a concept of hardware contention right now (how much longer is my IO request taking due to other tasks?), it reports CPU potential lost on all IO delays, not just the potential lost due to competition.
FAQ
Q: How is PSI's CPU component different from the load average?
A: There are several quirks in the load average that make it hard to
impossible to tell how overcommitted the CPU really is.
1. The load average is reported as a raw number of active tasks. You need to know how many CPUs there are in the system, how many CPUs the workload is allowed to use, then think about what the proportion between load and the number of CPUs mean for the tasks trying to run.
PSI reports the percentage of wallclock time in which tasks are waiting for a CPU to run on. It doesn't matter how many CPUs are present or usable. The number always tells the quality of life of tasks in the system or in a particular cgroup.
2. The shortest averaging window is 1m, which is extremely coarse, and it's sampled in 5s intervals. A *lot* can happen on a CPU in 5 seconds. This *may* be able to identify persistent long-term trends and very clear and obvious overloads, but it's unusable for latency spikes and more subtle overutilization.
PSI's shortest window is 10s. It also exports the cumulative stall times (in microseconds) of synchronously recorded events.
3. On Linux, the load average for historical reasons includes all TASK_UNINTERRUPTIBLE tasks. This gives a broader sense of how busy the system is, but on the flipside it doesn't distinguish whether tasks are likely to contend over the CPU or IO - which obviously requires very different interventions from a sys admin or a job scheduler.
PSI reports independent metrics for CPU and IO. You can tell which resource is making the tasks wait, but in conjunction still see how overloaded the system is overall.
Q: What's the cost / performance impact of this feature?
A: PSI's primary cost is in the scheduler, in particular task wakeups
and sleeps.
I benchmarked this code using Facebook's two most scheduling sensitive workloads: memcache and webserver. They handle a ton of small requests - lots of wakeups and sleeps with little actual work in between - so they tend to be canaries for scheduler regressions.
In the tests, the boxes were handling live traffic over the course of several hours. Half the machines, the control, ran with CONFIG_PSI=n.
For memcache I used eight machines total. They're 2-socket, 14 core, 56 thread boxes. The test runs for half the test period, flips the test and control kernels on the hardware to rule out HW factors, DC location etc., then runs the other half of the test.
For the webservers, I used 32 machines total. They're single socket, 16 core, 32 thread machines.
During the memcache test, CPU load was nopsi=78.05% psi=78.98% in the first half and nopsi=77.52% psi=78.25%, so PSI added between 0.7 and 0.9 percentage points to the CPU load, a difference of about 1%.
UPDATE: I re-ran this test with the v3 version of this patch set and the CPU utilization was equivalent between test and control.
UPDATE: v4 is on par with v3.
As far as end-to-end request latency from the client perspective goes, we don't sample those finely enough to capture the requests going to those particular machines during the test, but we know the p50 turnaround time in this workload is 54us, and perf bench sched pipe on those machines show nopsi=5.232666 us/op and psi=5.587347 us/op, so this doesn't add much here either.
The profile for the pipe benchmark shows:
0.87% sched-pipe [kernel.vmlinux] [k] psi_group_change
0.83% perf.real [kernel.vmlinux] [k] psi_group_change
0.82% perf.real [kernel.vmlinux] [k] psi_task_change
0.58% sched-pipe [kernel.vmlinux] [k] psi_task_changeThe webserver load is running inside 4 nested cgroup levels. The CPU load with both nopsi and psi kernels was indistinguishable at 81%.
For comparison, we had to disable the cgroup cpu controller on the webservers because it added 4 percentage points to the CPU% during this same exact test.
Versions of this accounting code now run on 80% of our fleet. None of our workloads have reported regressions during the rollout.
Daniel Drake said:
: I just retested the latest version at
: http://git.cmpxchg.org/cgit.cgi/linux-psi.git (Linux 4.18) and the results : are great.
:
: Test setup:
: Endless OS
: GeminiLake N4200 low end laptop
: 2GB RAM
: swap (and zram swap) disabled
:
: Baseline test: open a handful of large-ish apps and several website : tabs in Google Chrome.
:
: Results: after a couple of minutes, system is excessively thrashing, mouse : cursor can barely be moved, UI is not responding to mouse clicks, so it's : impractical to recover from this situation as an ordinary user :
: Add my simple killer:
: https://gist.github.com/dsd/a8988bf0b81a6163475988120fe8d9cd
:
: Results: when the thrashing causes the UI to become sluggish, the killer : steps in and kills something (usually a chrome tab), and the system : remains usable. I repeatedly opened more apps and more websites over a 15 : minute period but I wasn't able to get the system to a point of UI : unresponsiveness.
Suren said:
: Backported to 4.9 and retested on ARMv8 8 code system running Android. : Signals behave as expected reacting to memory pressure, no jumps in : "total" counters that would indicate an overflow/underflow issues. Nicely : done!
This patch (of 9):
If we keep just enough refault information to match the *current* page cache during reclaim time, we could lose a lot of events when there is only a temporary spike in non-cache memory consumption that pushes out all the cache. Once cache comes back, we won't see those refaults. They might not be actionable for LRU aging, but we want to know about them for measuring memory pressure.
--- mm/workingset.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
mm/workingset.c +14 -8
@@ -370,7 +370,7 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, {unsigned long max_nodes;unsigned long nodes; -unsigned long cache; +unsigned long pages;/* list_lru lock nests inside IRQ-safe mapping->tree_lock */ local_irq_disable ();
@@ -399,14 +399,20 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker,* * PAGE_SIZE / radix_tree_nodes / node_entries * 8 / PAGE_SIZE */ +#ifdef CONFIG_MEMCG if (sc->memcg) { - cache =mem_cgroup_node_nr_lru_pages (sc->memcg, sc->nid, -LRU_ALL_FILE ); - }else { - cache =node_page_state (NODE_DATA (sc->nid),NR_ACTIVE_FILE ) + -node_page_state (NODE_DATA (sc->nid),NR_INACTIVE_FILE ); - } - max_nodes = cache >> (RADIX_TREE_MAP_SHIFT -3 ); +struct lruvec *lruvec; + + pages =mem_cgroup_node_nr_lru_pages (sc->memcg, sc->nid, +LRU_ALL ); + lruvec =mem_cgroup_lruvec (NODE_DATA (sc->nid), sc->memcg); + pages +=lruvec_page_state (lruvec,NR_SLAB_RECLAIMABLE ); + pages +=lruvec_page_state (lruvec,NR_SLAB_UNRECLAIMABLE ); + } else +#endif + pages =node_present_pages (sc->nid); + + max_nodes = pages >> (RADIX_TREE_MAP_SHIFT -3 );if (nodes <= max_nodes)return 0 ;
Signature · 1 line
2.17.1
PATCH 3/11 delayacct: track delays from thrashing cache pages
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
Delay accounting already measures the time a task spends in direct reclaim and waiting for swapin, but in low memory situations tasks spend can spend a significant amount of their time waiting on thrashing page cache. This isn't tracked right now.
To know the full impact of memory contention on an individual task, measure the delay when waiting for a recently evicted active cache page to read back into memory.
Also update tools/accounting/getdelays.c:
[hannes@computer accounting]$ sudo ./getdelays -d -p 1 print delayacct stats ON
PID 1
CPU count real total virtual total delay total delay average
50318 745000000 847346785 400533713 0.008ms
IO count delay total delay average
435 122601218 0ms
SWAP count delay total delay average
0 0 0ms
RECLAIM count delay total delay average
0 0 0ms
THRASHING count delay total delay average
19 12621439 0ms
Conflicts:
kernel/delayacct.c
--- include/linux/delayacct.h | 23 +++++++++++++++++++++++ include/uapi/linux/taskstats.h | 6 +++++- kernel/delayacct.c | 15 +++++++++++++++ mm/filemap.c | 11 +++++++++++ tools/accounting/getdelays.c | 8 +++++++- 5 files changed, 61 insertions(+), 2 deletions(-)
include/linux/delayacct.h +23 -0
@@ -57,7 +57,12 @@ struct task_delay_info {u64 freepages_start;u64 freepages_delay;/* wait for memory reclaim */ + +u64 thrashing_start; +u64 thrashing_delay;/* wait for thrashing page */ +u32 freepages_count;/* total count of memory reclaim */ + u32 thrashing_count; /* total count of thrash waits */ };#endif
@@ -76,6 +81,8 @@ extern int __delayacct_add_tsk(struct taskstats *, struct task_struct *);extern __u64 __delayacct_blkio_ticks (struct task_struct *);extern void __delayacct_freepages_start (void );extern void __delayacct_freepages_end (void ); +extern void __delayacct_thrashing_start (void ); +extern void __delayacct_thrashing_end (void );static inline int delayacct_is_task_waiting_on_io (struct task_struct *p) {
@@ -156,6 +163,18 @@ static inline void delayacct_freepages_end(void) __delayacct_freepages_end(); } +static inline void delayacct_thrashing_start (void ) +{ +if (current->delays) +__delayacct_thrashing_start (); +} + +static inline void delayacct_thrashing_end (void ) +{ +if (current->delays) +__delayacct_thrashing_end (); +} +#else static inline void delayacct_set_flag (int flag) {}
@@ -182,6 +201,10 @@ static inline void delayacct_freepages_start(void) {}static inline void delayacct_freepages_end (void ) {} +static inline void delayacct_thrashing_start (void ) +{} +static inline void delayacct_thrashing_end (void ) +{}#endif /* CONFIG_TASK_DELAY_ACCT */
include/uapi/linux/taskstats.h +5 -1
@@ -34,7 +34,7 @@*/ -#define TASKSTATS_VERSION 8 +#define TASKSTATS_VERSION 9#define TS_COMM_LEN 32/* should be >= TASK_COMM_LEN * in linux/sched.h */
@@ -164,6 +164,10 @@ struct taskstats {/* Delay waiting for memory reclaim */ __u64 freepages_count;__u64 freepages_delay_total; + +/* Delay waiting for thrashing page */ +__u64 thrashing_count; +__u64 thrashing_delay_total; };
kernel/delayacct.c +15 -0
@@ -135,9 +135,12 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk) d->swapin_delay_total = (tmp < d->swapin_delay_total) ?0 : tmp; tmp = d->freepages_delay_total + tsk->delays->freepages_delay; d->freepages_delay_total = (tmp < d->freepages_delay_total) ?0 : tmp; + tmp = d->thrashing_delay_total + tsk->delays->thrashing_delay; + d->thrashing_delay_total = (tmp < d->thrashing_delay_total) ?0 : tmp; d->blkio_count += tsk->delays->blkio_count; d->swapin_count += tsk->delays->swapin_count; d->freepages_count += tsk->delays->freepages_count; + d->thrashing_count += tsk->delays->thrashing_count;raw_spin_unlock_irqrestore (&tsk->delays->lock, flags);return 0 ;
@@ -169,3 +172,15 @@ void __delayacct_freepages_end(void) ¤t->delays->freepages_count); } +void __delayacct_thrashing_start (void ) +{ + current->delays->thrashing_start =ktime_get_ns (); +} + +void __delayacct_thrashing_end (void ) +{ +delayacct_end (¤t->delays->lock, + ¤t->delays->thrashing_start, + ¤t->delays->thrashing_delay, + ¤t->delays->thrashing_count); +}
mm/filemap.c +11 -0
@@ -36,6 +36,7 @@#include <linux/memcontrol.h> #include <linux/cleancache.h> #include <linux/rmap.h> +#include <linux/delayacct.h> #include "internal.h" #define CREATE_TRACE_POINTS
@@ -975,8 +976,15 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q, {struct wait_page_queue wait_page;wait_queue_entry_t *wait = &wait_page.wait; +bool thrashing = false;int ret =0 ; +if (bit_nr == PG_locked && !PageSwapBacked (page) && + !PageUptodate (page) &&PageWorkingset (page)) { +delayacct_thrashing_start (); + thrashing = true; + } +init_wait (wait); wait->flags = lock ?WQ_FLAG_EXCLUSIVE :0 ; wait->func = wake_page_function;
@@ -1015,6 +1023,9 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,finish_wait (q, wait); +if (thrashing) +delayacct_thrashing_end (); +/* * A signal could leave PageWaiters set. Clearing it here if * !waitqueue_active would be possible (by open-coding finish_wait),
tools/accounting/getdelays.c +7 -1
@@ -203,6 +203,8 @@ static void print_delayacct(struct taskstats *t)"SWAP %15s%15s%15s\n" " %15llu%15llu%15llums\n" "RECLAIM %12s%15s%15s\n" +" %15llu%15llu%15llums\n" +"THRASHING%12s%15s%15s\n" " %15llu%15llu%15llums\n" ,"count" ,"real total" ,"virtual total" , "delay total", "delay average",
@@ -222,7 +224,11 @@ static void print_delayacct(struct taskstats *t)"count" ,"delay total" ,"delay average" , (unsigned long long )t->freepages_count, (unsigned long long )t->freepages_delay_total, - average_ms(t->freepages_delay_total, t->freepages_count)); +average_ms (t->freepages_delay_total, t->freepages_count), +"count" ,"delay total" ,"delay average" , + (unsigned long long )t->thrashing_count, + (unsigned long long )t->thrashing_delay_total, + average_ms(t->thrashing_delay_total, t->thrashing_count)); }static void task_context_switch_counts (struct taskstats *t)
Signature · 1 line
2.17.1
PATCH 4/11 sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
There are several definitions of those functions/macros in places that mess with fixed-point load averages. Provide an official version.
--- .../platforms/cell/cpufreq_spudemand.c | 2 +- arch/powerpc/platforms/cell/spufs/sched.c | 9 +++----- arch/s390/appldata/appldata_os.c | 4 ---- drivers/cpuidle/governors/menu.c | 4 ---- fs/proc/loadavg.c | 3 --- include/linux/sched/loadavg.h | 21 +++++++++++++++---- kernel/debug/kdb/kdb_main.c | 7 +------ kernel/sched/loadavg.c | 15 ------------- 8 files changed, 22 insertions(+), 43 deletions(-)
arch/powerpc/platforms/cell/cpufreq_spudemand.c +1 -1
@@ -49,7 +49,7 @@ static int calc_freq(struct spu_gov_info_struct *info) cpu = info->policy->cpu; busy_spus =atomic_read (&cbe_spu_info[cpu_to_node (cpu)].busy_spus); -CALC_LOAD (info->busy_spus,EXP , busy_spus *FIXED_1 ); + info->busy_spus =calc_load (info->busy_spus,EXP , busy_spus *FIXED_1 );pr_debug ("cpu %d: busy_spus=%d, info->busy_spus=%ld\n" , cpu, busy_spus, info->busy_spus);
arch/powerpc/platforms/cell/spufs/sched.c +3 -6
@@ -987,9 +987,9 @@ static void spu_calc_load(void)unsigned long active_tasks;/* fixed-point */ active_tasks =count_active_contexts () *FIXED_1 ; -CALC_LOAD (spu_avenrun[0 ],EXP_1 , active_tasks); -CALC_LOAD (spu_avenrun[1 ],EXP_5 , active_tasks); -CALC_LOAD (spu_avenrun[2 ],EXP_15 , active_tasks); + spu_avenrun[0 ] =calc_load (spu_avenrun[0 ],EXP_1 , active_tasks); + spu_avenrun[1 ] =calc_load (spu_avenrun[1 ],EXP_5 , active_tasks); + spu_avenrun[2 ] =calc_load (spu_avenrun[2 ],EXP_15 , active_tasks); }static void spusched_wake (unsigned long data)
@@ -1071,9 +1071,6 @@ void spuctx_switch_state(struct spu_context *ctx, } } -#define LOAD_INT (x) ((x) >> FSHIFT) -#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100) -static int show_spu_loadavg (struct seq_file *s,void *private) {int a, b, c;
arch/s390/appldata/appldata_os.c +0 -4
@@ -24,10 +24,6 @@#include "appldata.h" - -#define LOAD_INT (x) ((x) >> FSHIFT) -#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100) -/* * OS data *
drivers/cpuidle/governors/menu.c +0 -4
@@ -132,10 +132,6 @@ struct menu_device {int interval_ptr; }; - -#define LOAD_INT (x) ((x) >> FSHIFT) -#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100) -static inline int get_loadavg (unsigned long load) {return LOAD_INT (load) *10 +LOAD_FRAC (load) /10 ;
fs/proc/loadavg.c +0 -3
@@ -10,9 +10,6 @@#include <linux/seqlock.h> #include <linux/time.h> -#define LOAD_INT (x) ((x) >> FSHIFT) -#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100) -static int loadavg_proc_show (struct seq_file *m,void *v) {unsigned long avnrun[3 ];
include/linux/sched/loadavg.h +17 -4
@@ -22,10 +22,23 @@ extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);#define EXP_5 2014/* 1/exp(5sec/5min) */ #define EXP_15 2037/* 1/exp(5sec/15min) */ -#define CALC_LOAD (load,exp,n) \ - load *= exp; \ - load += n*(FIXED_1-exp); \ - load >>= FSHIFT; +/* +* a1 = a0 * e + a * (1 - e) +*/ +static inline unsigned long +calc_load (unsigned long load,unsigned long exp,unsigned long active) +{ +unsigned long newload; + + newload = load * exp + active * (FIXED_1 - exp); +if (active >= load) + newload +=FIXED_1 -1 ; + +return newload /FIXED_1 ; +} + +#define LOAD_INT (x) ((x) >> FSHIFT) +#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100)extern void calc_global_load (unsigned long ticks);
kernel/debug/kdb/kdb_main.c +1 -6
@@ -2586,16 +2586,11 @@ static int kdb_summary(int argc, const char **argv) }kdb_printf ("%02ld:%02ld\n" , val.uptime/(60 *60 ), (val.uptime/60 )%60 ); -/* lifted from fs/proc/proc_misc.c::loadavg_read_proc() */ - -#define LOAD_INT (x) ((x) >> FSHIFT) -#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100)kdb_printf ("load avg %ld.%02ld %ld.%02ld %ld.%02ld\n" ,LOAD_INT (val.loads[0 ]),LOAD_FRAC (val.loads[0 ]),LOAD_INT (val.loads[1 ]),LOAD_FRAC (val.loads[1 ]),LOAD_INT (val.loads[2 ]),LOAD_FRAC (val.loads[2 ])); -#undef LOAD_INT -#undef LOAD_FRAC +/* Display in kilobytes */ #define K (x) ((x) << (PAGE_SHIFT - 10)) kdb_printf("\nMemTotal: %8lu kB\nMemFree: %8lu kB\n"
kernel/sched/loadavg.c +0 -15
@@ -95,21 +95,6 @@ long calc_load_fold_active(struct rq *this_rq, long adjust)return delta; } -/* -* a1 = a0 * e + a * (1 - e) -*/ -static unsigned long -calc_load (unsigned long load,unsigned long exp,unsigned long active) -{ -unsigned long newload; - - newload = load * exp + active * (FIXED_1 - exp); -if (active >= load) - newload +=FIXED_1 -1 ; - -return newload /FIXED_1 ; -} -#ifdef CONFIG_NO_HZ_COMMON /* * Handle NO_HZ for the global load-average.
Signature · 1 line
2.17.1
PATCH 5/11 sched: loadavg: make calc_load_n() public
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
It's going to be used in a later patch. Keep the churn separate.
--- include/linux/sched/loadavg.h | 3 + kernel/sched/loadavg.c | 138 +++++++++++++++++----------------- 2 files changed, 72 insertions(+), 69 deletions(-)
include/linux/sched/loadavg.h +3 -0
@@ -37,6 +37,9 @@ calc_load(unsigned long load, unsigned long exp, unsigned long active)return newload /FIXED_1 ; } +extern unsigned long calc_load_n (unsigned long load,unsigned long exp, +unsigned long active,unsigned int n); +#define LOAD_INT (x) ((x) >> FSHIFT)#define LOAD_FRAC (x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
kernel/sched/loadavg.c +69 -69
150 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 6/11 sched: sched.h: make rq locking and clock functions available in stats.h
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
kernel/sched/sched.h includes "stats.h" half-way through the file. The next patch introduces users of sched.h's rq locking functions and update_rq_clock() in kernel/sched/stats.h. Move those definitions up in the file so they are available in stats.h.
Conflicts:
kernel/sched/sched.h
--- kernel/sched/sched.h | 164 +++++++++++++++++++++---------------------- 1 file changed, 82 insertions(+), 82 deletions(-)
kernel/sched/sched.h +82 -82
@@ -848,6 +848,8 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);#define cpu_curr (cpu) (cpu_rq(cpu)->curr)#define raw_rq () raw_cpu_ptr(&runqueues) +extern void update_rq_clock (struct rq *rq); +static inline u64 __rq_clock_broken (struct rq *rq) {return READ_ONCE (rq->clock);
@@ -959,6 +961,86 @@ static inline void rq_repin_lock(struct rq *rq, struct rq_flags *rf)#endif } +struct rq *__task_rq_lock (struct task_struct *p,struct rq_flags *rf) + __acquires(rq->lock); + +struct rq *task_rq_lock (struct task_struct *p,struct rq_flags *rf) + __acquires(p->pi_lock) + __acquires(rq->lock); + +static inline void __task_rq_unlock (struct rq *rq,struct rq_flags *rf) + __releases(rq->lock) +{ +rq_unpin_lock (rq, rf); +raw_spin_unlock (&rq->lock); +} + +static inline void +task_rq_unlock (struct rq *rq,struct task_struct *p,struct rq_flags *rf) + __releases(rq->lock) + __releases(p->pi_lock) +{ +rq_unpin_lock (rq, rf); +raw_spin_unlock (&rq->lock); +raw_spin_unlock_irqrestore (&p->pi_lock, rf->flags); +} + +static inline void +rq_lock_irqsave (struct rq *rq,struct rq_flags *rf) + __acquires(rq->lock) +{ +raw_spin_lock_irqsave (&rq->lock, rf->flags); +rq_pin_lock (rq, rf); +} + +static inline void +rq_lock_irq (struct rq *rq,struct rq_flags *rf) + __acquires(rq->lock) +{ +raw_spin_lock_irq (&rq->lock); +rq_pin_lock (rq, rf); +} + +static inline void +rq_lock (struct rq *rq,struct rq_flags *rf) + __acquires(rq->lock) +{ +raw_spin_lock (&rq->lock); +rq_pin_lock (rq, rf); +} + +static inline void +rq_relock (struct rq *rq,struct rq_flags *rf) + __acquires(rq->lock) +{ +raw_spin_lock (&rq->lock); +rq_repin_lock (rq, rf); +} + +static inline void +rq_unlock_irqrestore (struct rq *rq,struct rq_flags *rf) + __releases(rq->lock) +{ +rq_unpin_lock (rq, rf); +raw_spin_unlock_irqrestore (&rq->lock, rf->flags); +} + +static inline void +rq_unlock_irq (struct rq *rq,struct rq_flags *rf) + __releases(rq->lock) +{ +rq_unpin_lock (rq, rf); +raw_spin_unlock_irq (&rq->lock); +} + +static inline void +rq_unlock (struct rq *rq,struct rq_flags *rf) + __releases(rq->lock) +{ +rq_unpin_lock (rq, rf); +raw_spin_unlock (&rq->lock); +} +#ifdef CONFIG_NUMA enum numa_topology_type { NUMA_DIRECT,
@@ -1623,8 +1705,6 @@ static inline void rq_last_tick_reset(struct rq *rq)#endif } -extern void update_rq_clock (struct rq *rq); -extern void activate_task (struct rq *rq,struct task_struct *p,int flags);extern void deactivate_task (struct rq *rq,struct task_struct *p,int flags);
@@ -1698,86 +1778,6 @@ static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { }static inline void sched_avg_update (struct rq *rq) { }#endif -struct rq *__task_rq_lock (struct task_struct *p,struct rq_flags *rf) - __acquires(rq->lock); - -struct rq *task_rq_lock (struct task_struct *p,struct rq_flags *rf) - __acquires(p->pi_lock) - __acquires(rq->lock); - -static inline void __task_rq_unlock (struct rq *rq,struct rq_flags *rf) - __releases(rq->lock) -{ -rq_unpin_lock (rq, rf); -raw_spin_unlock (&rq->lock); -} - -static inline void -task_rq_unlock (struct rq *rq,struct task_struct *p,struct rq_flags *rf) - __releases(rq->lock) - __releases(p->pi_lock) -{ -rq_unpin_lock (rq, rf); -raw_spin_unlock (&rq->lock); -raw_spin_unlock_irqrestore (&p->pi_lock, rf->flags); -} - -static inline void -rq_lock_irqsave (struct rq *rq,struct rq_flags *rf) - __acquires(rq->lock) -{ -raw_spin_lock_irqsave (&rq->lock, rf->flags); -rq_pin_lock (rq, rf); -} - -static inline void -rq_lock_irq (struct rq *rq,struct rq_flags *rf) - __acquires(rq->lock) -{ -raw_spin_lock_irq (&rq->lock); -rq_pin_lock (rq, rf); -} - -static inline void -rq_lock (struct rq *rq,struct rq_flags *rf) - __acquires(rq->lock) -{ -raw_spin_lock (&rq->lock); -rq_pin_lock (rq, rf); -} - -static inline void -rq_relock (struct rq *rq,struct rq_flags *rf) - __acquires(rq->lock) -{ -raw_spin_lock (&rq->lock); -rq_repin_lock (rq, rf); -} - -static inline void -rq_unlock_irqrestore (struct rq *rq,struct rq_flags *rf) - __releases(rq->lock) -{ -rq_unpin_lock (rq, rf); -raw_spin_unlock_irqrestore (&rq->lock, rf->flags); -} - -static inline void -rq_unlock_irq (struct rq *rq,struct rq_flags *rf) - __releases(rq->lock) -{ -rq_unpin_lock (rq, rf); -raw_spin_unlock_irq (&rq->lock); -} - -static inline void -rq_unlock (struct rq *rq,struct rq_flags *rf) - __releases(rq->lock) -{ -rq_unpin_lock (rq, rf); -raw_spin_unlock (&rq->lock); -} -#ifdef CONFIG_SMP #ifdef CONFIG_PREEMPT
Signature · 1 line
2.17.1
PATCH 7/11 sched: introduce this_rq_lock_irq()
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
do_sched_yield() disables IRQs, looks up this_rq() and locks it. The next patch is adding another site with the same pattern, so provide a convenience function for it.
--- kernel/sched/core.c | 4 +--- kernel/sched/sched.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-)
kernel/sched/core.c +1 -3
@@ -4817,9 +4817,7 @@ SYSCALL_DEFINE0(sched_yield)struct rq_flags rf;struct rq *rq; -local_irq_disable (); - rq =this_rq (); -rq_lock (rq, &rf); + rq =this_rq_lock_irq (&rf);schedstat_inc (rq->yld_count); current->sched_class->yield_task (rq);
kernel/sched/sched.h +12 -0
@@ -1041,6 +1041,18 @@ rq_unlock(struct rq *rq, struct rq_flags *rf)raw_spin_unlock (&rq->lock); } +static inline struct rq * +this_rq_lock_irq (struct rq_flags *rf) + __acquires(rq->lock) +{ +struct rq *rq; + +local_irq_disable (); + rq =this_rq (); +rq_lock (rq, rf); +return rq; +} +#ifdef CONFIG_NUMA enum numa_topology_type { NUMA_DIRECT,
Signature · 1 line
2.17.1
PATCH 8/11 psi: pressure stall information for CPU, memory, and IO
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
When systems are overcommitted and resources become contended, it's hard to tell exactly the impact this has on workload productivity, or how close the system is to lockups and OOM kills. In particular, when machines work multiple jobs concurrently, the impact of overcommit in terms of latency and throughput on the individual job can be enormous.
In order to maximize hardware utilization without sacrificing individual job health or risk complete machine lockups, this patch implements a way to quantify resource pressure in the system.
A kernel built with CONFIG_PSI=y creates files in /proc/pressure/ that expose the percentage of time the system is stalled on CPU, memory, or IO, respectively. Stall states are aggregate versions of the per-task delay accounting delays:
cpu: some tasks are runnable but not executing on a CPU
memory: tasks are reclaiming, or waiting for swapin or thrashing cache
io: tasks are waiting for io completions
These percentages of walltime can be thought of as pressure percentages, and they give a general sense of system health and productivity loss incurred by resource overcommit. They can also indicate when the system is approaching lockup scenarios and OOMs.
To do this, psi keeps track of the task states associated with each CPU and samples the time they spend in stall states. Every 2 seconds, the samples are averaged across CPUs - weighted by the CPUs' non-idle time to eliminate artifacts from unused CPUs - and translated into percentages of walltime. A running average of those percentages is maintained over 10s, 1m, and 5m periods (similar to the loadaverage).
Conflicts:
kernel/sched/Makefile
kernel/sched/sched.h
--- Documentation/accounting/psi.txt | 64 +++ include/linux/psi.h | 28 ++ include/linux/psi_types.h | 92 +++++ include/linux/sched.h | 10 + init/Kconfig | 15 + kernel/fork.c | 4 + kernel/sched/Makefile | 1 + kernel/sched/core.c | 12 +- kernel/sched/psi.c | 657 +++++++++++++++++++++++++++++++ kernel/sched/sched.h | 3 + kernel/sched/stats.h | 86 ++++ mm/compaction.c | 5 + mm/filemap.c | 15 +- mm/page_alloc.c | 9 + mm/vmscan.c | 11 + 15 files changed, 1006 insertions(+), 6 deletions(-) create mode 100644 Documentation/accounting/psi.txt create mode 100644 include/linux/psi.h create mode 100644 include/linux/psi_types.h create mode 100644 kernel/sched/psi.c
Documentation/accounting/psi.txt new file +64 -0
@@ -0,0 +1,64 @@ +================================ +PSI - Pressure Stall Information +================================ + +:Date: April, 2018 +:Author: Johannes Weiner <[email protected]> + +When CPU, memory or IO devices are contended, workloads experience +latency spikes, throughput losses, and run the risk of OOM kills. + +Without an accurate measure of such contention, users are forced to +either play it safe and under-utilize their hardware resources, or +roll the dice and frequently suffer the disruptions resulting from +excessive overcommit. + +The psi feature identifies and quantifies the disruptions caused by +such resource crunches and the time impact it has on complex workloads +or even entire systems. + +Having an accurate measure of productivity losses caused by resource +scarcity aids users in sizing workloads to hardware--or provisioning +hardware according to workload demand. + +As psi aggregates this information in realtime, systems can be managed +dynamically using techniques such as load shedding, migrating jobs to +other systems or data centers, or strategically pausing or killing low +priority or restartable batch jobs. + +This allows maximizing hardware utilization without sacrificing +workload health or risking major disruptions such as OOM kills. + +Pressure interface +================== + +Pressure information for each resource is exported through the +respective file in /proc/pressure/ -- cpu, memory, and io. + +The format for CPU is as such: + +some avg10=0.00 avg60=0.00 avg300=0.00 total=0 + +and for memory and IO: + +some avg10=0.00 avg60=0.00 avg300=0.00 total=0 +full avg10=0.00 avg60=0.00 avg300=0.00 total=0 + +The "some" line indicates the share of time in which at least some +tasks are stalled on a given resource. + +The "full" line indicates the share of time in which all non-idle +tasks are stalled on a given resource simultaneously. In this state +actual CPU cycles are going to waste, and a workload that spends +extended time in this state is considered to be thrashing. This has +severe impact on performance, and it's useful to distinguish this +situation from a state where some tasks are stalled but the CPU is +still doing productive work. As such, time spent in this subset of the +stall state is tracked separately and exported in the "full" averages. + +The ratios are tracked as recent trends over ten, sixty, and three +hundred second windows, which gives insight into short term events as +well as medium and long term trends. The total absolute stall time is +tracked and exported as well, to allow detection of latency spikes +which wouldn't necessarily make a dent in the time averages, or to +average trends over custom time frames.
include/linux/psi.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef _LINUX_PSI_H +#define _LINUX_PSI_H + +#include <linux/psi_types.h> +#include <linux/sched.h> + +#ifdef CONFIG_PSI + +extern bool psi_disabled; + +void psi_init (void ); + +void psi_task_change (struct task_struct *task,int clear,int set); + +void psi_memstall_tick (struct task_struct *task,int cpu); +void psi_memstall_enter (unsigned long *flags); +void psi_memstall_leave (unsigned long *flags); + +#else /* CONFIG_PSI */ + +static inline void psi_init (void ) {} + +static inline void psi_memstall_enter (unsigned long *flags) {} +static inline void psi_memstall_leave (unsigned long *flags) {} + +#endif /* CONFIG_PSI */ + +#endif /* _LINUX_PSI_H */
include/linux/psi_types.h new file +92 -0
92 lines not on this page · raw message
include/linux/sched.h +10 -0
@@ -25,6 +25,7 @@#include <linux/latencytop.h> #include <linux/sched/prio.h> #include <linux/signal_types.h> +#include <linux/psi_types.h> #include <linux/mm_types_task.h> #include <linux/task_io_accounting.h>
@@ -668,6 +669,10 @@ struct task_struct { unsigned sched_contributes_to_load:1; unsigned sched_migrated:1; unsigned sched_remote_wakeup:1; +#ifdef CONFIG_PSI + unsigned sched_psi_wake_requeue:1; +#endif +/* Force alignment to the next boundary: */ unsigned :0;
@@ -926,6 +931,10 @@ struct task_struct {siginfo_t *last_siginfo;struct task_io_accounting ioac; +#ifdef CONFIG_PSI +/* Pressure stall state */ +unsigned int psi_flags; +#endif #ifdef CONFIG_TASK_XACCT /* Accumulated RSS usage: */ u64 acct_rss_mem1;
@@ -1355,6 +1364,7 @@ extern struct pid *cad_pid;#define PF_KTHREAD 0x00200000/* I am a kernel thread */ #define PF_RANDOMIZE 0x00400000/* Randomize virtual address space */ #define PF_SWAPWRITE 0x00800000/* Allowed to write to swap */ +#define PF_MEMSTALL 0x01000000/* Stalled due to lack of memory */ #define PF_NO_SETAFFINITY 0x04000000/* Userland is not allowed to meddle with cpus_allowed */ #define PF_MCE_EARLY 0x08000000/* Early kill for mce process policy */ #define PF_MUTEX_TESTER 0x20000000/* Thread belongs to the rt mutex tester */
init/Kconfig +15 -0
@@ -470,6 +470,21 @@ config TASK_IO_ACCOUNTING Say N if unsure. +config PSI + bool "Pressure stall information tracking" + help + Collect metrics that indicate how overcommitted the CPU, memory, + and IO capacity are in the system. + + If you say Y here, the kernel will create /proc/pressure/ with the + pressure statistics files cpu, memory, and io. These will indicate + the share of walltime in which some or all tasks in the system are + delayed due to contention of the respective resource. + + For more details see Documentation/accounting/psi.txt. + + Say N if unsure. + endmenu # "CPU/Task time and stats accounting" source "kernel/rcu/Kconfig"
kernel/fork.c +4 -0
@@ -1667,6 +1667,10 @@ static __latent_entropy struct task_struct *copy_process( p->default_timer_slack_ns = current->timer_slack_ns; +#ifdef CONFIG_PSI + p->psi_flags =0 ; +#endif +task_io_accounting_init (&p->ioac);acct_clear_integrals (p);
kernel/sched/Makefile +1 -0
@@ -27,3 +27,4 @@ obj-$(CONFIG_CGROUP_CPUACCT) += cpuacct.o obj-$(CONFIG_CPU_FREQ) += cpufreq.o obj-$(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) += cpufreq_schedutil.o obj-$(CONFIG_MEMBARRIER) += membarrier.o +obj-$(CONFIG_PSI) += psi.o
kernel/sched/core.c +10 -2
@@ -756,8 +756,10 @@ static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags)if (!(flags &ENQUEUE_NOCLOCK ))update_rq_clock (rq); -if (!(flags &ENQUEUE_RESTORE )) +if (!(flags &ENQUEUE_RESTORE )) {sched_info_queued (rq, p); +psi_enqueue (p, flags &ENQUEUE_WAKEUP ); + } p->sched_class->enqueue_task (rq, p, flags); }
@@ -767,8 +769,10 @@ static inline void dequeue_task(struct rq *rq, struct task_struct *p, int flags)if (!(flags &DEQUEUE_NOCLOCK ))update_rq_clock (rq); -if (!(flags &DEQUEUE_SAVE )) +if (!(flags &DEQUEUE_SAVE )) {sched_info_dequeued (rq, p); +psi_dequeue (p, flags &DEQUEUE_SLEEP ); + } p->sched_class->dequeue_task (rq, p, flags); }
@@ -2071,6 +2075,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) cpu =select_task_rq (p, p->wake_cpu,SD_BALANCE_WAKE , wake_flags);if (task_cpu (p) != cpu) { wake_flags |=WF_MIGRATED ; +psi_ttwu_dequeue (p);set_task_cpu (p, cpu); }
@@ -3032,6 +3037,7 @@ void scheduler_tick(void) curr->sched_class->task_tick (rq, curr,0 );cpu_load_update_active (rq);calc_global_load_tick (rq); +psi_task_tick (rq);rq_unlock (rq, &rf);
@@ -5962,6 +5968,8 @@ void __init sched_init(void)init_schedstats (); +psi_init (); + scheduler_running =1 ; }
kernel/sched/psi.c new file +657 -0
657 lines not on this page · raw message
kernel/sched/sched.h +3 -0
@@ -268,6 +268,7 @@ extern bool dl_cpu_busy(unsigned int cpu);#ifdef CONFIG_CGROUP_SCHED #include <linux/cgroup.h> +#include <linux/psi.h> struct cfs_rq ;struct rt_rq ;
@@ -1717,6 +1718,8 @@ static inline void rq_last_tick_reset(struct rq *rq)#endif } +extern void update_rq_clock (struct rq *rq); +extern void activate_task (struct rq *rq,struct task_struct *p,int flags);extern void deactivate_task (struct rq *rq,struct task_struct *p,int flags);
kernel/sched/stats.h +86 -0
92 lines not on this page · raw message
mm/compaction.c +5 -0
@@ -22,6 +22,7 @@#include <linux/kthread.h> #include <linux/freezer.h> #include <linux/page_owner.h> +#include <linux/psi.h> #include "internal.h" #ifdef CONFIG_COMPACTION
@@ -2038,11 +2039,15 @@ static int kcompactd(void *p) pgdat->kcompactd_classzone_idx = pgdat->nr_zones -1 ;while (!kthread_should_stop ()) { +unsigned long pflags; +trace_mm_compaction_kcompactd_sleep (pgdat->node_id);wait_event_freezable (pgdat->kcompactd_wait,kcompactd_work_requested (pgdat)); +psi_memstall_enter (&pflags);kcompactd_do_work (pgdat); +psi_memstall_leave (&pflags); }return 0 ;
mm/filemap.c +11 -4
@@ -37,6 +37,7 @@#include <linux/cleancache.h> #include <linux/rmap.h> #include <linux/delayacct.h> +#include <linux/psi.h> #include "internal.h" #define CREATE_TRACE_POINTS
@@ -977,11 +978,14 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,struct wait_page_queue wait_page;wait_queue_entry_t *wait = &wait_page.wait;bool thrashing = false; +unsigned long pflags;int ret =0 ; -if (bit_nr == PG_locked && !PageSwapBacked (page) && +if (bit_nr == PG_locked && !PageUptodate (page) &&PageWorkingset (page)) { -delayacct_thrashing_start (); +if (!PageSwapBacked (page)) +delayacct_thrashing_start (); +psi_memstall_enter (&pflags); thrashing = true; }
@@ -1023,8 +1027,11 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,finish_wait (q, wait); -if (thrashing) -delayacct_thrashing_end (); +if (thrashing) { +if (!PageSwapBacked (page)) +delayacct_thrashing_end (); +psi_memstall_leave (&pflags); + }/* * A signal could leave PageWaiters set. Clearing it here if
mm/page_alloc.c +9 -0
@@ -67,6 +67,7 @@#include <linux/ftrace.h> #include <linux/lockdep.h> #include <linux/nmi.h> +#include <linux/psi.h> #include <asm/sections.h> #include <asm/tlbflush.h>
@@ -3371,15 +3372,20 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, enum compact_priority prio, enum compact_result *compact_result) { struct page *page; +unsigned long pflags;unsigned int noreclaim_flag;if (!order)return NULL ; +psi_memstall_enter (&pflags); noreclaim_flag =memalloc_noreclaim_save (); + *compact_result =try_to_compact_pages (gfp_mask, order, alloc_flags, ac, prio); +memalloc_noreclaim_restore (noreclaim_flag); +psi_memstall_leave (&pflags);if (*compact_result <=COMPACT_INACTIVE )return NULL ;
@@ -3568,11 +3574,13 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order,struct reclaim_state reclaim_state;int progress;unsigned int noreclaim_flag; +unsigned long pflags;cond_resched ();/* We now go into synchronous reclaim */ cpuset_memory_pressure_bump (); +psi_memstall_enter (&pflags); noreclaim_flag =memalloc_noreclaim_save ();fs_reclaim_acquire (gfp_mask); reclaim_state.reclaimed_slab =0 ;
@@ -3584,6 +3592,7 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order, current->reclaim_state =NULL ;fs_reclaim_release (gfp_mask);memalloc_noreclaim_restore (noreclaim_flag); +psi_memstall_leave (&pflags);cond_resched ();
mm/vmscan.c +11 -0
@@ -49,6 +49,7 @@#include <linux/prefetch.h> #include <linux/printk.h> #include <linux/dax.h> +#include <linux/psi.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -3134,6 +3135,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, {struct zonelist *zonelist;unsigned long nr_reclaimed; +unsigned long pflags;int nid;unsigned int noreclaim_flag;struct scan_control sc = {
@@ -3162,9 +3164,13 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, sc.gfp_mask, sc.reclaim_idx); +psi_memstall_enter (&pflags); noreclaim_flag =memalloc_noreclaim_save (); + nr_reclaimed =do_try_to_free_pages (zonelist, &sc); +memalloc_noreclaim_restore (noreclaim_flag); +psi_memstall_leave (&pflags);trace_mm_vmscan_memcg_reclaim_end (nr_reclaimed);
@@ -3329,6 +3335,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)int i;unsigned long nr_soft_reclaimed;unsigned long nr_soft_scanned; +unsigned long pflags;struct zone *zone;struct scan_control sc = { .gfp_mask =GFP_KERNEL ,
@@ -3338,6 +3345,9 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) .may_unmap = 1, .may_swap = 1, }; + +psi_memstall_enter (&pflags); +count_vm_event (PAGEOUTRUN ); do {
@@ -3432,6 +3442,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) out:snapshot_refaults (NULL , pgdat); +psi_memstall_leave (&pflags);/* * Return the order kswapd stopped reclaiming at as * prepare_kswapd_sleep() takes it into account. If another caller
Signature · 1 line
2.17.1
PATCH 9/11 psi: cgroup support
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
On a system that executes multiple cgrouped jobs and independent workloads, we don't just care about the health of the overall system, but also that of individual jobs, so that we can ensure individual job health, fairness between jobs, or prioritize some jobs over others.
This patch implements pressure stall tracking for cgroups. In kernels with CONFIG_PSI=y, cgroup2 groups will have cpu.pressure, memory.pressure, and io.pressure files that track aggregate pressure stall times for only the tasks inside the cgroup.
Conflicts:
Documentation/cgroup-v2.txt
kernel/cgroup/cgroup.c
--- Documentation/accounting/psi.txt | 9 +++ Documentation/cgroup-v2.txt | 17 +++++ include/linux/cgroup-defs.h | 4 ++ include/linux/cgroup.h | 15 ++++ include/linux/psi.h | 25 +++++++ init/Kconfig | 4 ++ kernel/cgroup/cgroup.c | 44 +++++++++++- kernel/sched/psi.c | 118 ++++++++++++++++++++++++++++--- 8 files changed, 227 insertions(+), 9 deletions(-)
Documentation/accounting/psi.txt +9 -0
@@ -62,3 +62,12 @@ well as medium and long term trends. The total absolute stall time is tracked and exported as well, to allow detection of latency spikes which wouldn't necessarily make a dent in the time averages, or to average trends over custom time frames. + +Cgroup2 interface +================= + +In a system with a CONFIG_CGROUP=y kernel and the cgroup2 filesystem +mounted, pressure stall information is also tracked for tasks grouped +into cgroups. Each subdirectory in the cgroupfs mountpoint contains +cpu.pressure, memory.pressure, and io.pressure files; the format is +the same as the /proc/pressure/ files.
Documentation/cgroup-v2.txt +17 -0
@@ -957,6 +957,11 @@ All time durations are in microseconds. which indicates that the group may consume upto $MAX in each $PERIOD duration. If only one number is written, $MAX is updated. + cpu.pressure + A read-only nested-key file which exists on non-root cgroups. + + Shows pressure stall information for CPU. See + Documentation/accounting/psi.txt for details. Memory
@@ -1194,6 +1199,12 @@ PAGE_SIZE multiple when read back. Swap usage hard limit. If a cgroup's swap usage reaches this limit, anonymous meomry of the cgroup will not be swapped out. + memory.pressure + A read-only nested-key file which exists on non-root cgroups. + + Shows pressure stall information for memory. See + Documentation/accounting/psi.txt for details. + Usage Guidelines ~~~~~~~~~~~~~~~~
@@ -1329,6 +1340,12 @@ IO Interface Files 8:16 rbps=2097152 wbps=max riops=max wiops=max + io.pressure + A read-only nested-key file which exists on non-root cgroups. + + Shows pressure stall information for IO. See + Documentation/accounting/psi.txt for details. + Writeback ~~~~~~~~~
include/linux/cgroup-defs.h +4 -0
@@ -19,6 +19,7 @@#include <linux/percpu-rwsem.h> #include <linux/workqueue.h> #include <linux/bpf-cgroup.h> +#include <linux/psi_types.h> #ifdef CONFIG_CGROUPS
@@ -368,6 +369,9 @@ struct cgroup {/* used to schedule release agent */ struct work_struct release_agent_work; +/* used to track pressure stalls */ +struct psi_group psi; +/* used to store eBPF programs */ struct cgroup_bpf bpf;
include/linux/cgroup.h +15 -0
@@ -626,6 +626,11 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp)pr_cont_kernfs_path (cgrp->kn); } +static inline struct psi_group *cgroup_psi (struct cgroup *cgrp) +{ +return &cgrp->psi; +} +static inline void cgroup_init_kthreadd (void ) {/*
@@ -679,6 +684,16 @@ static inline union kernfs_node_id *cgroup_get_kernfs_id(struct cgroup *cgrp)return NULL ; } +static inline struct cgroup *cgroup_parent (struct cgroup *cgrp) +{ +return NULL ; +} + +static inline struct psi_group *cgroup_psi (struct cgroup *cgrp) +{ +return NULL ; +} +static inline bool task_under_cgroup_hierarchy (struct task_struct *task,struct cgroup *ancestor) {
include/linux/psi.h +25 -0
@@ -4,6 +4,9 @@#include <linux/psi_types.h> #include <linux/sched.h> +struct seq_file ; +struct css_set ; +#ifdef CONFIG_PSI extern bool psi_disabled;
@@ -16,6 +19,14 @@ void psi_memstall_tick(struct task_struct *task, int cpu);void psi_memstall_enter (unsigned long *flags);void psi_memstall_leave (unsigned long *flags); +int psi_show (struct seq_file *s,struct psi_group *group,enum psi_res res); + +#ifdef CONFIG_CGROUPS +int psi_cgroup_alloc (struct cgroup *cgrp); +void psi_cgroup_free (struct cgroup *cgrp); +void cgroup_move_task (struct task_struct *p,struct css_set *to); +#endif +#else /* CONFIG_PSI */ static inline void psi_init (void ) {}
@@ -23,6 +34,20 @@ static inline void psi_init(void) {}static inline void psi_memstall_enter (unsigned long *flags) {}static inline void psi_memstall_leave (unsigned long *flags) {} +#ifdef CONFIG_CGROUPS +static inline int psi_cgroup_alloc (struct cgroup *cgrp) +{ +return 0 ; +} +static inline void psi_cgroup_free (struct cgroup *cgrp) +{ +} +static inline void cgroup_move_task (struct task_struct *p,struct css_set *to) +{ +rcu_assign_pointer (p->cgroups, to); +} +#endif +#endif /* CONFIG_PSI */ #endif /* _LINUX_PSI_H */
init/Kconfig +4 -0
@@ -481,6 +481,10 @@ config PSI the share of walltime in which some or all tasks in the system are delayed due to contention of the respective resource. + In kernels with cgroup support, cgroups (cgroup2 only) will + have cpu.pressure, memory.pressure, and io.pressure files, + which aggregate pressure stalls for the grouped tasks only. + For more details see Documentation/accounting/psi.txt. Say N if unsure.
kernel/cgroup/cgroup.c +43 -1
86 lines not on this page · raw message
kernel/sched/psi.c +110 -8
144 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 10/11 kernel/sched/psi.c: simplify cgroup_move_task()
In reply to Jack WangFrom: Olof Johansson <[email protected]>
The existing code triggered an invalid warning about 'rq' possibly being used uninitialized. Instead of doing the silly warning suppression by initializa it to NULL, refactor the code to bail out early instead.
Warning was:
kernel/sched/psi.c: In function `cgroup_move_task':
kernel/sched/psi.c:639:13: warning: `rq' may be used uninitialized in this function [-Wmaybe-uninitialized]
--- kernel/sched/psi.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
kernel/sched/psi.c +22 -21
@@ -633,38 +633,39 @@ void psi_cgroup_free(struct cgroup *cgroup)*/ void cgroup_move_task (struct task_struct *task,struct css_set *to) { -bool move_psi = !psi_disabled;unsigned int task_flags =0 ;struct rq_flags rf;struct rq *rq; -if (move_psi) { - rq =task_rq_lock (task, &rf); +if (psi_disabled) { +/* +* Lame to do this here, but the scheduler cannot be locked +* from the outside, so we move cgroups from inside sched/. +*/ +rcu_assign_pointer (task->cgroups, to); +return ; + } -if (task_on_rq_queued (task)) - task_flags =TSK_RUNNING ; -else if (task->in_iowait) - task_flags =TSK_IOWAIT ; + rq =task_rq_lock (task, &rf); -if (task->flags &PF_MEMSTALL ) - task_flags |=TSK_MEMSTALL ; +if (task_on_rq_queued (task)) + task_flags =TSK_RUNNING ; +else if (task->in_iowait) + task_flags =TSK_IOWAIT ; -if (task_flags) -psi_task_change (task, task_flags,0 ); - } +if (task->flags &PF_MEMSTALL ) + task_flags |=TSK_MEMSTALL ; -/* -* Lame to do this here, but the scheduler cannot be locked -* from the outside, so we move cgroups from inside sched/. -*/ +if (task_flags) +psi_task_change (task, task_flags,0 ); + +/* See comment above */ rcu_assign_pointer (task->cgroups, to); -if (move_psi) { -if (task_flags) -psi_task_change (task,0 , task_flags); +if (task_flags) +psi_task_change (task,0 , task_flags); -task_rq_unlock (rq, task, &rf); - } +task_rq_unlock (rq, task, &rf); }#endif /* CONFIG_CGROUPS */
Signature · 1 line
2.17.1
PATCH 11/11 psi: make disabling/enabling easier for vendor kernels
In reply to Jack WangFrom: Johannes Weiner <[email protected]>
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;
--- .../admin-guide/kernel-parameters.txt | 4 +++ include/linux/psi.h | 3 +- init/Kconfig | 9 ++++++ kernel/sched/psi.c | 30 +++++++++++++------ kernel/sched/stats.h | 8 ++--- 5 files changed, 40 insertions(+), 14 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3322,6 +3322,10 @@ before loading. See Documentation/blockdev/ramdisk.txt. + psi= [KNL] Enable or disable pressure stall information + tracking. + Format: <bool> + psmouse.proto= [HW,MOUSE] Highest PS2 mouse protocol extension to probe for; one of (bare|imps|exps|lifebook|any). psmouse.rate= [HW,MOUSE] Set desired mouse report rate, in reports
include/linux/psi.h +2 -1
@@ -1,6 +1,7 @@#ifndef _LINUX_PSI_H#define _LINUX_PSI_H +#include <linux/jump_label.h> #include <linux/psi_types.h> #include <linux/sched.h>
@@ -9,7 +10,7 @@ struct css_set;#ifdef CONFIG_PSI -extern bool psi_disabled; +extern struct static_key_false psi_disabled;void psi_init (void );
init/Kconfig +9 -0
@@ -489,6 +489,15 @@ config PSI Say N if unsure. +config PSI_DEFAULT_DISABLED + bool "Require boot parameter to enable pressure stall information tracking" + default n + depends on PSI + help + If set, pressure stall information tracking will be disabled + per default but can be enabled through passing psi_enable=1 + on the kernel commandline during boot. + endmenu # "CPU/Task time and stats accounting" source "kernel/rcu/Kconfig"
kernel/sched/psi.c +21 -9
@@ -136,8 +136,18 @@static int psi_bug__read_mostly ; -bool psi_disabled__read_mostly ; -core_param (psi_disabled, psi_disabled, bool,0644 ); +DEFINE_STATIC_KEY_FALSE (psi_disabled); + +#ifdef CONFIG_PSI_DEFAULT_DISABLED +bool psi_enable; +#else +bool psi_enable = true; +#endif +static int __init setup_psi (char *str) +{ +return kstrtobool (str, &psi_enable) ==0 ; +} +__setup ("psi=" , setup_psi);/* Running averages - we need to be higher-res than loadavg */ #define PSI_FREQ (2*HZ+1)/* 2 sec intervals */
@@ -169,8 +179,10 @@ static void group_init(struct psi_group *group)void __init psi_init (void ) { -if (psi_disabled) +if (!psi_enable) { +static_branch_enable (&psi_disabled);return ; + } psi_period =jiffies_to_nsecs (PSI_FREQ );group_init (&psi_system);
@@ -549,7 +561,7 @@ void psi_memstall_enter(unsigned long *flags)struct rq_flags rf;struct rq *rq; -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ; *flags = current->flags &PF_MEMSTALL ;
@@ -579,7 +591,7 @@ void psi_memstall_leave(unsigned long *flags)struct rq_flags rf;struct rq *rq; -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ;if (*flags)
@@ -600,7 +612,7 @@ void psi_memstall_leave(unsigned long *flags)#ifdef CONFIG_CGROUPS int psi_cgroup_alloc (struct cgroup *cgroup) { -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return 0 ; cgroup->psi.pcpu = alloc_percpu(struct psi_group_cpu);
@@ -612,7 +624,7 @@ int psi_cgroup_alloc(struct cgroup *cgroup)void psi_cgroup_free (struct cgroup *cgroup) { -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ;cancel_delayed_work_sync (&cgroup->psi.clock_work);
@@ -637,7 +649,7 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to)struct rq_flags rf;struct rq *rq; -if (psi_disabled) { +if (static_branch_likely (&psi_disabled)) {/* * Lame to do this here, but the scheduler cannot be locked * 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) {int full; -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return -EOPNOTSUPP ;update_stats (group);
kernel/sched/stats.h +4 -4
@@ -66,7 +66,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup) {int clear =0 , set =TSK_RUNNING ; -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ;if (!wakeup || p->sched_psi_wake_requeue) {
@@ -86,7 +86,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep) {int clear =TSK_RUNNING , set =0 ; -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ;if (!sleep) {
@@ -102,7 +102,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)static inline void psi_ttwu_dequeue (struct task_struct *p) { -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ;/* * 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)static inline void psi_task_tick (struct rq *rq) { -if (psi_disabled) +if (static_branch_likely (&psi_disabled))return ;if (unlikely (rq->curr->flags &PF_MEMSTALL ))
Signature · 1 line
2.17.1
Greg KH
maintainerQuoted 5 lines · Jack Wang
Hi Folks,
This is a backport for PSI feature from:
http://git.cmpxchg.org/cgit.cgi/linux-psi.git/log/?h=psi-4.17
Quoted 8 lines
The patches are included since 4.20.
We're run LTP tests and stress test with these patches on 4.14.93, no problem found.
I send them out for review, also maybe there are other guys are intereseted.
I kept the conflict note in commit message, so it's easier to review.
This is nice, but why? We can't take new features into the stable kernel trees. For Android devices (which do want PSI), all of the patches are already backported into the android-common 4.14 branch, right? Or does this differ from that backport somehow?
thanks,
greg k-h
Re: [stable-4.14 01/11] mm: workingset: don't drop refault information prematurely
In reply to Jack WangQuoted 2 lines · Jack Wang
Patch series "psi: pressure stall information for CPU, memory, and IO", v4.
This really doesn't look like stable material, it's a fundamental new feature rather than a "fix".
Linus
Re: [stable-4.14 01/11] mm: workingset: don't drop refault information prematurely
Quoted 9 lines · Linus Torvalds
Quoted 2 lines · Jack Wang
Patch series "psi: pressure stall information for CPU, memory, and IO", v4.
This really doesn't look like stable material, it's a fundamental new feature rather than a "fix".
Linus
Thanks for reply, Linus.
The intention was to get a review and to see if any others can be beneficial.
Wasn't expecting to be merge by 4.14 upstream.
I mentioned in the cover letter.
https://www.spinics.net/lists/stable/msg289978.html
Regards,
--
Jack Wang
Linux Kernel Developer
1&1 IONOS Cloud GmbH | Greifswalder Str. 207 | 10405 Berlin | Germany
Phone: +49 30 57700-8042 | Fax: +49 30 57700-8598
E-mail: [email protected] | Web: www.ionos.de
Head Office: Berlin, Germany
District Court Berlin Charlottenburg, Registration number: HRB 125506 B Executive Management: Christoph Steffens, Matthias Steinberg, Achim Weiss
Member of United Internet
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient of this e-mail, you are hereby notified that saving, distribution or use of the content of this e-mail in any way is prohibited. If you have received this e-mail in error, please notify the sender and delete the e-mail.
snip
Quoted 8 lines
This is nice, but why? We can't take new features into the stable kernel trees. For Android devices (which do want PSI), all of the patches are already backported into the android-common 4.14 branch, right? Or does this differ from that backport somehow?
thanks,
greg k-h
(Resend to reply to all, sorry)
Thanks Greg,
We want the feature for our product. Yeah, I know we have stable-rules, didn't expect
the patches to be included, just in case other guys also need PSI.
I'm not aware of android-common did the backport already, could you point me the link?
I checked in
https://android.googlesource.com/kernel/common/+/refs/heads/android-4.14*
I didn't find the psi support.
Regards,
Jack
Greg KH
maintainerQuoted 17 lines · Jinpu Wang
snip
Quoted 8 lines
This is nice, but why? We can't take new features into the stable kernel trees. For Android devices (which do want PSI), all of the patches are already backported into the android-common 4.14 branch, right? Or does this differ from that backport somehow?
thanks,
greg k-h
(Resend to reply to all, sorry)
Thanks Greg,
We want the feature for our product. Yeah, I know we have stable-rules, didn't expect
the patches to be included, just in case other guys also need PSI.
Quoted 7 lines
I'm not aware of android-common did the backport already, could you point me the link?
I checked in
https://android.googlesource.com/kernel/common/+/refs/heads/android-4.14*I didn't find the psi support.
Ah, I was wrong, sorry, it has been submitted to AOSP, but not merged yet. Here's the 4.14 patches queued up and ready to go:
https://android-review.googlesource.com/q/topic:%22psi+4.14+backport%22+(status:open%20OR%20status:merged)
The 4.9 and 4.19 branches also have them queued up:
https://android-review.googlesource.com/q/topic:%22psi+4.9+backport%22+(status:open%20OR%20status:merged) https://android-review.googlesource.com/q/topic:%22psi+4.19+backport%22+(status:open%20OR%20status:merged)
I talked to the developer this week and he said he was waiting for a few of the remaining patches to be merged upstream first before merging to AOSP to ensure that nothing diverged. Hopefully that should happen in a few weeks or so, after the merge window is open and maintainers reopen their development branches.
thanks,
greg k-h
Quoted 41 lines · Greg KH <[email protected]> 于2019年3月14日周四 下午6:29写道:
Quoted 17 lines · Jinpu Wang
snip
Quoted 8 lines
This is nice, but why? We can't take new features into the stable kernel trees. For Android devices (which do want PSI), all of the patches are already backported into the android-common 4.14 branch, right? Or does this differ from that backport somehow?
thanks,
greg k-h
(Resend to reply to all, sorry)
Thanks Greg,
We want the feature for our product. Yeah, I know we have stable-rules, didn't expect
the patches to be included, just in case other guys also need PSI.Quoted 7 lines
I'm not aware of android-common did the backport already, could you point me the link?
I checked in
https://android.googlesource.com/kernel/common/+/refs/heads/android-4.14*I didn't find the psi support.
Ah, I was wrong, sorry, it has been submitted to AOSP, but not merged yet. Here's the 4.14 patches queued up and ready to go:
https://android-review.googlesource.com/q/topic:%22psi+4.14+backport%22+(status:open%20OR%20status:merged)The 4.9 and 4.19 branches also have them queued up:
https://android-review.googlesource.com/q/topic:%22psi+4.9+backport%22+(status:open%20OR%20status:merged) https://android-review.googlesource.com/q/topic:%22psi+4.19+backport%22+(status:open%20OR%20status:merged)I talked to the developer this week and he said he was waiting for a few of the remaining patches to be merged upstream first before merging to AOSP to ensure that nothing diverged. Hopefully that should happen in a few weeks or so, after the merge window is open and maintainers reopen their development branches.
Quoted 3 lines
thanks,
greg k-h
Thanks Greg,
It's very helpful, I indeed missed some patches.
I will check their backport.
Regards,
Jack