Commit 01626a1
mm: avoid unconditional one-tick sleep when swapcache_prepare fails
Commit 13ddaf2 ("mm/swap: fix race when skipping swapcache")
introduced an unconditional one-tick sleep when `swapcache_prepare()`
fails, which has led to reports of UI stuttering on latency-sensitive
Android devices. To address this, we can use a waitqueue to wake up tasks
that fail `swapcache_prepare()` sooner, instead of always sleeping for a
full tick. While tasks may occasionally be woken by an unrelated
`do_swap_page()`, this method is preferable to two scenarios: rapid
re-entry into page faults, which can cause livelocks, and multiple
millisecond sleeps, which visibly degrade user experience.
Oven's testing shows that a single waitqueue resolves the UI stuttering
issue. If a 'thundering herd' problem becomes apparent later, a waitqueue
hash similar to `folio_wait_table[PAGE_WAIT_TABLE_SIZE]` for page bit
locks can be introduced.
[[email protected]: wake_up only when swapcache_wq waitqueue is active]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Fixes: 13ddaf2 ("mm/swap: fix race when skipping swapcache")
Signed-off-by: Barry Song <[email protected]>
Reported-by: Oven Liyang <[email protected]>
Tested-by: Oven Liyang <[email protected]>
Cc: Kairui Song <[email protected]>
Cc: "Huang, Ying" <[email protected]>
Cc: Yu Zhao <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Chris Li <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Yosry Ahmed <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: Kalesh Singh <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>1 parent 1834300 commit 01626a1
1 file changed
+13
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4187 | 4187 | | |
4188 | 4188 | | |
4189 | 4189 | | |
| 4190 | + | |
| 4191 | + | |
4190 | 4192 | | |
4191 | 4193 | | |
4192 | 4194 | | |
| |||
4199 | 4201 | | |
4200 | 4202 | | |
4201 | 4203 | | |
| 4204 | + | |
4202 | 4205 | | |
4203 | 4206 | | |
4204 | 4207 | | |
| |||
4297 | 4300 | | |
4298 | 4301 | | |
4299 | 4302 | | |
| 4303 | + | |
4300 | 4304 | | |
| 4305 | + | |
4301 | 4306 | | |
4302 | 4307 | | |
4303 | 4308 | | |
| |||
4604 | 4609 | | |
4605 | 4610 | | |
4606 | 4611 | | |
4607 | | - | |
| 4612 | + | |
4608 | 4613 | | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
4609 | 4617 | | |
4610 | 4618 | | |
4611 | 4619 | | |
| |||
4620 | 4628 | | |
4621 | 4629 | | |
4622 | 4630 | | |
4623 | | - | |
| 4631 | + | |
4624 | 4632 | | |
| 4633 | + | |
| 4634 | + | |
| 4635 | + | |
4625 | 4636 | | |
4626 | 4637 | | |
4627 | 4638 | | |
| |||
0 commit comments