linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosryahmed@google.com>
To: "Huang, Ying" <ying.huang@intel.com>
Cc: Chris Li <chrisl@kernel.org>,
	lsf-pc@lists.linux-foundation.org,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Linux-MM <linux-mm@kvack.org>,  Michal Hocko <mhocko@kernel.org>,
	Shakeel Butt <shakeelb@google.com>,
	 David Rientjes <rientjes@google.com>,
	Hugh Dickins <hughd@google.com>,
	 Seth Jennings <sjenning@redhat.com>,
	Dan Streetman <ddstreet@ieee.org>,
	 Vitaly Wool <vitaly.wool@konsulko.com>,
	Yang Shi <shy828301@gmail.com>,  Peter Xu <peterx@redhat.com>,
	Minchan Kim <minchan@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Aneesh Kumar K V <aneesh.kumar@linux.ibm.com>,
	 Michal Hocko <mhocko@suse.com>, Wei Xu <weixugc@google.com>
Subject: Re: [LSF/MM/BPF TOPIC] Swap Abstraction / Native Zswap
Date: Tue, 28 Mar 2023 00:59:31 -0700	[thread overview]
Message-ID: <CAJD7tkZSKWicrXZ7h-nqA4d6NhdbC2H-c=szOVfrANCR4__TPA@mail.gmail.com> (raw)
In-Reply-To: <87fs9ppdhz.fsf@yhuang6-desk2.ccr.corp.intel.com>

On Tue, Mar 28, 2023 at 12:01 AM Huang, Ying <ying.huang@intel.com> wrote:
>
> Yosry Ahmed <yosryahmed@google.com> writes:
>
> > On Mon, Mar 27, 2023 at 11:22 PM Huang, Ying <ying.huang@intel.com> wrote:
> >>
> >> Yosry Ahmed <yosryahmed@google.com> writes:
> >>
> >> > On Sun, Mar 26, 2023 at 6:24 PM Huang, Ying <ying.huang@intel.com> wrote:
> >> >>
> >> >> Chris Li <chrisl@kernel.org> writes:
> >> >>
> >> >> > On Fri, Mar 24, 2023 at 12:28:31AM -0700, Yosry Ahmed wrote:
> >> >> >> > In fact, I just suggest to use the minimal design on top of the current
> >> >> >> > implementation as the first step.  Then, you can improve it step by
> >> >> >> > step.
> >> >> >> >
> >> >> >> > The first step could be the minimal effort to implement indirection
> >> >> >> > layer and moving swapped pages between swap implementations.  Based on
> >> >> >> > that, you can build other optimizations, such as pulling swap counting
> >> >> >> > to the swap core.  For each step, we can evaluate the gain and cost with
> >> >> >> > data.
> >> >> >>
> >> >> >> Right, I understand that, but to implement the indirection layer on
> >> >> >> top of the current implementation, then we will need to support using
> >> >> >> zswap without a backing swap device. In order to do this without
> >> >> >
> >> >> > Agree with Ying on the minimal approach here as well.
> >> >> >
> >> >> > There are two ways to approach this.
> >> >> >
> >> >> > 1) Forget zswap, make a minimal implementation to move the page between
> >> >> > two swapfile device. It can be swapfile back to two loop back files.
> >> >> >
> >> >> > Any indirect layer you design will need to convert this usage case
> >> >> > any way.
> >> >> >
> >> >> > 2) Make zswap work without a swapfile.
> >> >> > You can implement the zswap on a fake ghosts swap file.
> >> >> >
> >> >> > If you keep the zswap as frontswap, just make zswap can work without
> >> >> > a real swapfile.
> >> >> >
> >> >> > Make that as your first minimal step. Then it does not need to touch
> >> >> > the swap count changes.
> >> >> >
> >> >> > I view make that step is independent of moving pages between swap device.
> >> >> >
> >> >> > That patch exists and I consider it has value to some users.
> >> >>
> >> >> This sounds like an even smaller approach as the first step.  Further
> >> >> improvement can be built on top of it.
> >> >
> >> > I am not sure how this would be a step towards the abstraction goal we
> >> > have been discussing.
> >> >
> >> > We have been discussing starting out with a minimal indirection layer,
> >> > in the shape of an xarray that maps a swap ID to a swap entry, and
> >> > that can be disabled with a config option.
> >> >
> >> > For such a design to work, we have to implement swap entry management
> >> > & swap counting in zswap, right? Am I missing something?
> >>
> >> Chris suggested to avoid to implement the swap entry management & swap
> >> counting in zswap via using a "fake ghost swap file".  Copied his
> >> suggestion as below,
> >
> > Right, we have been using ghost swapfiles at Google for a while. They
> > are basically sparse files that you can never actually write to, they
> > are just used so that we can use zswap without a backing swap device.
> >
> > What I do not understand is how this is a step towards the ultimate
> > goal of swap abstraction. Is the idea to have the indirection layer
> > only support moving swapped pages between swapfiles, and have those
> > "ghost" swapfiles be on a higher tier than normal swapfiles? In this
> > case, I am guessing we eliminate the writeback logic from zswap itself
> > and move it to this indirection layer.
>
> Yes.  I think the suggested minimal first step includes replacing the
> writeback logic of zswap itself with moving swapped page of swap core
> (indirectly layer).
>
> > I don't have a problem with this approach, it is not really clean as
> > we still treat zswap as a swapfile and have to deal with a lot of
> > unnecessary code like swap slots handling and whatnot.
>
> These are existing code?

I was referring to the fact that today with zswap being tied to
swapfiles we do some necessary work such as searching for swap slots
during swapout. The initial swap_desc approach aimed to avoid that.
With this minimal ghost swapfile approach we retain this unfavorable
behavior.

>
> > We also have to unnecessarily limit the size of zswap with the size of
> > this fake swapfile.
>
> I guess you need to limit the size of zswap anyway, because you need to
> decide when to start to writeback or moving to the lower tiers.

zswap has a knob to limit its size, but based on the actual memory
usage of zswap (i.e the size of compressed pages). There is ongoing
work as well to autotune this if I remember correctly. Having to deal
with both the limit on compressed memory and the limited on the
uncompressed size of swapped pages is cumbersome. Again, we already
have this behavior today, but the initial swap_desc proposal aimed to
avoid it.

>
> > In other words, we retain a lot of limitations that we have today.
>
> As the minimal first step, not the final state.

I am assuming the first step here is using ghost swapfiles to support
zswap without a backing swap device and having an indirection layer
between swapfiles.

A following step can be making this indirection layer support zswap
directly without having to use such a ghost swapfile, if the
cost-benefit analysis proves that this is worthwhile. Is my
understanding correct?

>
> > Keep in mind that supporting ghost swapfiles is something that
> > is exposed to userspace, so we have to commit to supporting it -- it
> > can't just be an incremental step that we will change later.
>
> Yes.  We should really care about ABI.  It's not a good idea to add ABI
> for an intermediate step.  Do we need to change ABI to use a sparse file
> to backing zswap?

I think so. At Google we identify ghost swapfiles by having 0 block
length and mark them in the kernel. The upstream kernel would reject
such a file because it doesn't have a proper swap header. If we use
mkswap to have a proper swap header then swapon rejects the file
because it has holes.

>
> > With all that said, it is certainly a much simpler "solution".
> > Interested to hear thoughts on this, we can certainly pursue it if
> > people think it is the right way to move forward.
>
> Personally, I have no problem to change the design of swap code to add
> useful features.  Just want to check whether we can do that step by step
> and show benefit and cost clearly in each step.

Right. I understand and totally agree, even from a development point
of view it's much better to make big changes incrementally to avoid
doing a lot of work that ends up going nowhere. I am just trying to
make sure that whatever we decide is indeed a step in the right
direction.

Thanks for a very insightful discussion.

>
> Best Regards,
> Huang, Ying
>
> >>
> >> "
> >> >> > 2) Make zswap work without a swapfile.
> >> >> > You can implement the zswap on a fake ghosts swap file.
> >> >> >
> >> >> > If you keep the zswap as frontswap, just make zswap can work without
> >> >> > a real swapfile.
> >> >> >
> >> >> > Make that as your first minimal step. Then it does not need to touch
> >> >> > the swap count changes.
> >> "
> >>
> >> Best Regards,
> >> Huang, Ying
> >>
> >> >>
> >> >> >> > Anyway, I don't think you can just implement all your final solution in
> >> >> >> > one step.  And, I think the minimal design suggested could be a starting
> >> >> >> > point.
> >> >> >>
> >> >> >> I agree that's a great point, I am just afraid that we will avoid
> >> >> >> implementing that full final solution and instead do a lot of work
> >> >> >> inside zswap to make up for the difference (e.g. swap entry
> >> >> >> management, swap counting). Also, that work in zswap may end up being
> >> >> >> unacceptable due to the maintenance burden and/or complexity.
> >> >> >
> >> >> > If you do either 1) or 2), you can keep these two paths separate.
> >> >> >
> >> >> > Even if you want to move the page between zswap and swapfile.
> >> >> >
> >> >> > Idea 3)
> >> >> > You don't have to change the swap count code, you can do a
> >> >> > minimal change moves the page between zswap and another block
> >> >> > device. That way you can get two differenet swap entry with
> >> >> > existing code.
> >> >> >
> >> >> > Chris
> >> >>
> >>
>


  reply	other threads:[~2023-03-28  8:00 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 22:38 [LSF/MM/BPF TOPIC] Swap Abstraction / Native Zswap Yosry Ahmed
2023-02-19  4:31 ` Matthew Wilcox
2023-02-19  9:34   ` Yosry Ahmed
2023-02-28 23:22   ` Chris Li
2023-03-01  0:08     ` Matthew Wilcox
2023-03-01 23:22       ` Chris Li
2023-02-21 18:39 ` Yang Shi
2023-02-21 18:56   ` Yosry Ahmed
2023-02-21 19:26     ` Yang Shi
2023-02-21 19:46       ` Yosry Ahmed
2023-02-21 23:34         ` Yang Shi
2023-02-21 23:38           ` Yosry Ahmed
2023-02-22 16:57             ` Johannes Weiner
2023-02-22 22:46               ` Yosry Ahmed
2023-02-28  4:29                 ` Kalesh Singh
2023-02-28  8:09                   ` Yosry Ahmed
2023-02-28  4:54 ` Sergey Senozhatsky
2023-02-28  8:12   ` Yosry Ahmed
2023-02-28 23:29     ` Minchan Kim
2023-03-02  0:58       ` Yosry Ahmed
2023-03-02  1:25         ` Yosry Ahmed
2023-03-02 17:05         ` Chris Li
2023-03-02 17:47         ` Chris Li
2023-03-02 18:15           ` Johannes Weiner
2023-03-02 18:56             ` Chris Li
2023-03-02 18:23           ` Rik van Riel
2023-03-02 21:42             ` Chris Li
2023-03-02 22:36               ` Rik van Riel
2023-03-02 22:55                 ` Yosry Ahmed
2023-03-03  4:05                   ` Chris Li
2023-03-03  0:01                 ` Chris Li
2023-03-02 16:58       ` Chris Li
2023-03-01 10:44     ` Sergey Senozhatsky
2023-03-02  1:01       ` Yosry Ahmed
2023-02-28 23:11 ` Chris Li
2023-03-02  0:30   ` Yosry Ahmed
2023-03-02  1:00     ` Yosry Ahmed
2023-03-02 16:51     ` Chris Li
2023-03-03  0:33     ` Minchan Kim
2023-03-03  0:49       ` Yosry Ahmed
2023-03-03  1:25         ` Minchan Kim
2023-03-03 17:15           ` Yosry Ahmed
2023-03-09 12:48     ` Huang, Ying
2023-03-09 19:58       ` Chris Li
2023-03-09 20:19       ` Yosry Ahmed
2023-03-10  3:06         ` Huang, Ying
2023-03-10 23:14           ` Chris Li
2023-03-13  1:10             ` Huang, Ying
2023-03-15  7:41               ` Yosry Ahmed
2023-03-16  1:42                 ` Huang, Ying
2023-03-11  1:06           ` Yosry Ahmed
2023-03-13  2:12             ` Huang, Ying
2023-03-15  8:01               ` Yosry Ahmed
2023-03-16  7:50                 ` Huang, Ying
2023-03-17 10:19                   ` Yosry Ahmed
2023-03-17 18:19                     ` Chris Li
2023-03-17 18:23                       ` Yosry Ahmed
2023-03-20  2:55                     ` Huang, Ying
2023-03-20  6:25                       ` Chris Li
2023-03-23  0:56                         ` Huang, Ying
2023-03-23  6:46                           ` Chris Li
2023-03-23  6:56                             ` Huang, Ying
2023-03-23 18:28                               ` Chris Li
2023-03-23 18:40                                 ` Yosry Ahmed
2023-03-23 19:49                                   ` Chris Li
2023-03-23 19:54                                     ` Yosry Ahmed
2023-03-23 21:10                                       ` Chris Li
2023-03-24 17:28                                       ` Chris Li
2023-03-22  5:56                       ` Yosry Ahmed
2023-03-23  1:48                         ` Huang, Ying
2023-03-23  2:21                           ` Yosry Ahmed
2023-03-23  3:16                             ` Huang, Ying
2023-03-23  3:27                               ` Yosry Ahmed
2023-03-23  5:37                                 ` Huang, Ying
2023-03-23 15:18                                   ` Yosry Ahmed
2023-03-24  2:37                                     ` Huang, Ying
2023-03-24  7:28                                       ` Yosry Ahmed
2023-03-24 17:23                                         ` Chris Li
2023-03-27  1:23                                           ` Huang, Ying
2023-03-28  5:54                                             ` Yosry Ahmed
2023-03-28  6:20                                               ` Huang, Ying
2023-03-28  6:29                                                 ` Yosry Ahmed
2023-03-28  6:59                                                   ` Huang, Ying
2023-03-28  7:59                                                     ` Yosry Ahmed [this message]
2023-03-28 14:14                                                       ` Johannes Weiner
2023-03-28 19:59                                                         ` Yosry Ahmed
2023-03-28 21:22                                                           ` Chris Li
2023-03-28 21:30                                                             ` Yosry Ahmed
2023-03-28 20:50                                                       ` Chris Li
2023-03-28 21:01                                                         ` Yosry Ahmed
2023-03-28 21:32                                                           ` Chris Li
2023-03-28 21:44                                                             ` Yosry Ahmed
2023-03-28 22:01                                                               ` Chris Li
2023-03-28 22:02                                                                 ` Yosry Ahmed
2023-03-29  1:31                                                               ` Huang, Ying
2023-03-29  1:41                                                                 ` Yosry Ahmed
2023-03-29 16:04                                                                   ` Chris Li
2023-04-04  8:24                                                                     ` Huang, Ying
2023-04-04  8:10                                                                   ` Huang, Ying
2023-04-04  8:47                                                                     ` Yosry Ahmed
2023-04-06  1:40                                                                       ` Huang, Ying
2023-03-29 15:22                                                                 ` Chris Li
2023-03-10  2:07 ` Luis Chamberlain
2023-03-10  2:15   ` Yosry Ahmed
2023-05-12  3:07 ` Yosry Ahmed

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='CAJD7tkZSKWicrXZ7h-nqA4d6NhdbC2H-c=szOVfrANCR4__TPA@mail.gmail.com' \
    --to=yosryahmed@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=chrisl@kernel.org \
    --cc=ddstreet@ieee.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    --cc=lsf-pc@lists.linux-foundation.org \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=peterx@redhat.com \
    --cc=rientjes@google.com \
    --cc=shakeelb@google.com \
    --cc=shy828301@gmail.com \
    --cc=sjenning@redhat.com \
    --cc=vitaly.wool@konsulko.com \
    --cc=weixugc@google.com \
    --cc=ying.huang@intel.com \
    /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).