Re: [PATCH RFC v2 1/9] mm: optimize do_wp_page() for exclusive pages in the swapcache

From: David Hildenbrand
Date: Fri Jan 28 2022 - 08:45:13 EST


On 28.01.22 13:53, Vlastimil Babka wrote:
> On 1/26/22 10:55, David Hildenbrand wrote:
>> Liang Zhang reported [1] that the current COW logic in do_wp_page() is
>> sub-optimal when it comes to swap+read fault+write fault of anonymous
>> pages that have a single user, visible via a performance degradation in
>> the redis benchmark. Something similar was previously reported [2] by
>> Nadav with a simple reproducer.
>
> Can we make the description more self-contained? I.e. describe that
> sub-optimal COW means we copy when it's not necessary, and this can happen
> if swap-out is followed by a swap-in for read and a then a write fault
> (IIUC), because the swap cache reference increases page_count()..

Sure, I can add some more details.

>
>> Let's optimize for pages that have been added to the swapcache but only
>> have an exclusive owner. Try removing the swapcache reference if there is
>> hope that we're the exclusive user.
>
> Can we expect any downside for reclaim efficiency due to the more aggressive
> removal from swapcache? Probably not, as we are doing the removal when the
> page is about to get dirty, so we wouldn't be able to reuse any previously
> swapped out content anyway. Maybe it's even beneficial?

We're only try removing the swapcache reference if it's likely that we
succeed in reusing the page after we succeeded in removing the swapcache
reference (IOW, no other swap entries, no writeback).

So the early "page_count(page) > 1 + PageSwapCache(page)" check is of
big value I think. It should be rare that we remove the reference and
still end up with "page_count(page) != 1".

And if we're reusing the page (re-dirtying it), removing it from the
swapache is the right thing to do: reuse_swap_cache() would have done
the same.

[...]

>>
>> Reported-by: Liang Zhang <zhangliang5@xxxxxxxxxx>
>> Reported-by: Nadav Amit <nadav.amit@xxxxxxxxx>
>> Signed-off-by: David Hildenbrand <david@xxxxxxxxxx>
>
> Acked-by: Vlastimil Babka <vbabka@xxxxxxx>

Thanks!


--
Thanks,

David / dhildenb