[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YeVdvVVBvrXH5U0L@cmpxchg.org>
Date: Mon, 17 Jan 2022 07:14:53 -0500
From: Johannes Weiner <hannes@...xchg.org>
To: cgel.zte@...il.com
Cc: akpm@...ux-foundation.org, sfr@...b.auug.org.au,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
Yang Yang <yang.yang29@....com.cn>
Subject: Re: [PATCH] psi: Treat ksm swapping in copy as memstall
Hello Yang,
On Sun, Jan 16, 2022 at 03:21:51PM +0000, cgel.zte@...il.com wrote:
> From: Yang Yang <yang.yang29@....com.cn>
>
> When faults in from swap what used to be a ksm page and that page
> had been swapped in before, system has to make a copy. Obviously
> this kind of copy is related to high memory pressure, so we treat
> it as memstall. Although ksm page merging is not because of high
> memory pressure.
>
> Information of this new kind of stall will help psi to account
> memory pressure more precise.
Thanks for your patch. I'm curious if you have a concrete use case
where this makes a difference, or if this is something you found while
reading the code?
> Signed-off-by: Yang Yang <yang.yang29@....com.cn>
> ---
> mm/ksm.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 4a7f8614e57d..d4ec6773f9b8 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -39,6 +39,7 @@
> #include <linux/freezer.h>
> #include <linux/oom.h>
> #include <linux/numa.h>
> +#include <linux/psi.h>
>
> #include <asm/tlbflush.h>
> #include "internal.h"
> @@ -2569,6 +2570,7 @@ struct page *ksm_might_need_to_copy(struct page *page,
> {
> struct anon_vma *anon_vma = page_anon_vma(page);
> struct page *new_page;
> + unsigned long pflags;
>
> if (PageKsm(page)) {
> if (page_stable_node(page) &&
> @@ -2583,6 +2585,7 @@ struct page *ksm_might_need_to_copy(struct page *page,
> if (!PageUptodate(page))
> return page; /* let do_swap_page report the error */
>
> + psi_memstall_enter(&pflags);
> new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address);
> if (new_page &&
> mem_cgroup_charge(page_folio(new_page), vma->vm_mm, GFP_KERNEL)) {
> @@ -2600,6 +2603,7 @@ struct page *ksm_might_need_to_copy(struct page *page,
> #endif
> }
>
> + psi_memstall_leave(&pflags);
This does unconditional stall accounting for a swapin operation. But
if you take a look at workingset_refault() -> folio_wait_bit_common(),
we only count memory stalls when the page is thrashing, not when it's
a transitionary refault (which happen even when there is enough memory
to hold the workingset). You need to check PageWorkingset() at least.
But again I'd be curious first if this is a practical concern. Swapins
should be IO dominated - or in the case of zswap dominated by the
decompression. Does a page copy really matter?
Powered by blists - more mailing lists