Re: [PATCH] mm: move idle swap cache pages to the tail of LRU after COW

From: Huang, Ying
Date: Wed May 19 2021 - 00:56:17 EST


Rik van Riel <riel@xxxxxxxxxxx> writes:

> On Wed, 2021-05-19 at 09:33 +0800, Huang Ying wrote:
>
>> To test the patch, we used pmbench memory accessing benchmark with
>> working-set larger than available memory on a 2-socket Intel server
>> with a NVMe SSD as swap device. Test results shows that the pmbench
>> score increases up to 21.8% with the decreased size of swap cache and
>> swapin throughput.
>
> Nice!
>
>> +++ b/mm/memory.c
>> @@ -3012,6 +3012,11 @@ static vm_fault_t wp_page_copy(struct vm_fault
>> *vmf)
>> munlock_vma_page(old_page);
>> unlock_page(old_page);
>> }
>> + if (page_copied && PageSwapCache(old_page) &&
>> + !page_mapped(old_page) && trylock_page(old_page)) {
>> + try_to_free_idle_swapcache(old_page);
>> + unlock_page(old_page);
>> + }
>
> That's quite the if condition!
>
> Would it make sense to move some of the tests, as well
> as the trylock and unlock into try_to_free_idle_swapcache()
> itself?

Sure. Will put trylock/unlock into try_to_free_idle_swapcache() as
suggested by Linus.

> Especially considering that page_mapped is already tested
> in that function, too...

The two page_mapped() tests are intended. The first one is a quick
check with the page unlocked, the second one is to confirm with the page
locked. Because if the page is unlocked, the swap count may be
transited to map count or vice versa.

Best Regards,
Huang, Ying