Re: [PATCH] psi: Treat ksm swapping in copy as memstall

From: Johannes Weiner
Date: Thu Jan 27 2022 - 20:29:13 EST


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.

That psi_memstall_enter() in swap_readpage() was added by commit
937790699be9c8100e5358625e7dfa8b32bd33f2. It's for catching the
scenarios that don't go through submit_bio(). When you look at
submit_bio(), it counts stalls only if we have workingset pages:

/*
* If we're reading data that is part of the userspace workingset, count
* submission time as memory stall. When the device is congested, or
* the submitting cgroup IO-throttled, submission can be a significant
* part of overall IO time.
*/
if (unlikely(bio_op(bio) == REQ_OP_READ &&
bio_flagged(bio, BIO_WORKINGSET))) {
unsigned long pflags;

psi_memstall_enter(&pflags);
submit_bio_noacct(bio);
psi_memstall_leave(&pflags);
return;
}

I hope that clarifies it. I'll send a patch to fix up swap_readpage().

Thanks