linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: CGEL <cgel.zte@gmail.com>
To: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	akpm@linux-foundation.org, sfr@canb.auug.org.au,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Yang Yang <yang.yang29@zte.com.cn>,
	ran.xiaokai@zte.com.cn, wang.yong12@zte.com.cn
Subject: Re: [PATCH] psi: Treat ksm swapping in copy as memstall
Date: Thu, 10 Feb 2022 06:52:44 +0000	[thread overview]
Message-ID: <6204b63f.1c69fb81.6011.2908@mx.google.com> (raw)
In-Reply-To: <11c8fcd3-58fc-77f4-addb-18d3a52b51a7@google.com>

On Tue, Feb 08, 2022 at 09:55:48PM -0800, Hugh Dickins wrote:
> On Tue, 8 Feb 2022, CGEL wrote:
> > On Mon, Feb 07, 2022 at 07:22:22PM -0800, Hugh Dickins wrote:
> > > On Fri, 28 Jan 2022, CGEL wrote:
> > > > On Thu, Jan 27, 2022 at 08:29:08PM -0500, Johannes Weiner wrote:
> > > > > On Fri, Jan 21, 2022 at 09:51:08AM +0000, CGEL wrote:
> > > > > >  Wed, Jan 19, 2022 at 07:58:23AM -0500, Johannes Weiner wrote:
> > > > > > > On Wed, Jan 19, 2022 at 06:13:54AM +0000, CGEL wrote:
> > > > > > > > I did a test, when we use zram, it takes longer time for ksm copying than
> > > > > > > > swap_readpage(). Ksm copying average takes 147263ns, swap_readpage()
> > > > > > > > average takes 55639ns. So I think this patch is reasonable.
> > > > > > > 
> > > > > > > Ok, that sounds reasonable to me as well. Please add the
> > > > > > > PageWorkingset() check and resubmit the patch. Thanks!
> > > > > > I am a litte confused about adding PageWorkingset(), since I
> > > > > > think ksm_might_need_to_copy() memstall is like swap_readpage()
> > > > > > memstall and swap_readpage() doesn't add PageWorkingset().
> > > > > 
> > > > > That's actually a bug! It should do that.
> > > > I recently found that too. Please CC to me your new patch, thanks!
> > > > And I will send V2 of this patch "psi: Treat ksm swapping in copy
> > > > as memstall" with PageWorkingset().
> > > 
> > > I'm entirely PSI-ignorant, and reluctant to disagree with Johannes,
> > > but I don't see how your patch to ksm_might_need_to_copy() could be
> > > correct - maybe the "swapping" in your subject is confusing.
> > > 
> > > There is no PSI enter and exit around the page allocation and copying
> > > in wp_page_copy(), so why in the analogous ksm_might_need_to_copy()?
> > >
> > I think it's two questions, first why PSI didn't treat wp_page_copy() as
> > memstall, second why should PSI treat ksm_might_need_to_copy() as memstall.
> > 
> > The first question is unrelated with this patch. I think the reason is PSI
> > focous on memory contending(see Documentation/accounting/psi.rst), and
> > wp_page_copy() is not caused by memory contending. Actually wp_page_copy()
> > will still be called if memory is not contending.
> 
> Agreed.
> 
> > 
> > For the second question, ksm_might_need_to_copy() is called only becaused
> > of swapping, and swap is caused by memory contending, so PSI better treat
> > it as memstall.
> 
> But there I'm not at all convinced.
> 
>  * psi_memstall_enter - mark the beginning of a memory stall section
>  * @flags: flags to handle nested sections
>  *
>  * Marks the calling task as being stalled due to a lack of memory,
>  * such as waiting for a refault or performing reclaim.
> 
> psi_memstall_enter() will have been called if do_swap_page() had to
> read back from swap or wait on page lock; and psi_memstall_enter()
> will be called if ksm_might_need_to_copy()'s alloc_page_vma() or
> mem_cgroup_charge() goes into page reclaim.  Being stalled due to
> a lack of memory is fully covered there.
PSI counts "read back from swap time" as memstall time, because the
reason why we had to "read back from swap" is memory contending had
happened before and caused swap out. ksm_might_need_to_copy() is just
like it, we had to do this copy because of swap out happened before,
not because ksm_might_need_to_copy() may goes into page reclaim. And
if page reclaim happens, doesn't matter, psi_memstall_enter() will
handle nested sections.

> Your argument is that copy_user_highpage() is a significant overhead
> (but not a memstall), and it might have been avoided if there was
> no KSM or no swapping - though doing the copy there often(?) saves
> doing the wp_page_copy() when do_swap_page() goes on to do_wp_page()
> (and that one you're not asking to count).
"Doing the copy" doesn't always means "saves doing the wp_page_copy()".
For example, if there is no FAULT_FLAG_WRITE flag. What about we only
count this case as memstall: ksm_might_need_to_copy() do the copy and
not "saves doing the wp_page_copy()"? As this copy takes 2 times longer
than swap_readpage() when use zram(see early mail on this maillist),
we'd better not just leave it.

> I can understand you wanting to keep track of page copying overhead;
> and I've grown uneasy recently about the way CONFIG_KSM=y can add a
> ksm_might_need_to_copy() overhead for pages which never went near KSM;
> but I still don't see how psi_memstall is appropriate here.
For "ksm_might_need_to_copy() overhead for pages which never went near KSM",
is there a plan to optimize it? Or should I work on this?

Thanks.

> Hugh

      reply	other threads:[~2022-02-10  6:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-16 15:21 [PATCH] psi: Treat ksm swapping in copy as memstall cgel.zte
2022-01-17 12:14 ` Johannes Weiner
2022-01-19  6:13   ` CGEL
2022-01-19 12:58     ` Johannes Weiner
2022-01-21  9:51       ` CGEL
2022-01-28  1:29         ` Johannes Weiner
2022-01-28  2:31           ` CGEL
2022-02-08  3:22             ` Hugh Dickins
2022-02-08 13:09               ` CGEL
2022-02-09  5:55                 ` Hugh Dickins
2022-02-10  6:52                   ` CGEL [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6204b63f.1c69fb81.6011.2908@mx.google.com \
    --to=cgel.zte@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ran.xiaokai@zte.com.cn \
    --cc=sfr@canb.auug.org.au \
    --cc=wang.yong12@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).