Re: [PATCH] mm: avoid unconditional one-tick sleep when swapcache_prepare fails

From: Huang, Ying
Date: Sat Sep 28 2024 - 22:43:25 EST


Hi, Barry,

Barry Song <21cnbao@xxxxxxxxx> writes:

> From: Barry Song <v-songbaohua@xxxxxxxx>
>
> Commit 13ddaf26be32 ("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.

In general, I think that this works. Why not extend the solution to
cover schedule_timeout_uninterruptible() in __read_swap_cache_async()
too? We can call wake_up() when we clear SWAP_HAS_CACHE. To avoid
overhead to call wake_up() when there's no task waiting, we can use an
atomic to count waiting tasks.

[snip]

--
Best Regards,
Huang, Ying