All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@intel.com>
To: Yosry Ahmed <yosryahmed@google.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: Thu, 23 Mar 2023 13:37:59 +0800	[thread overview]
Message-ID: <87bkkkrps8.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <CAJD7tkb21yjzrd=u+XEPqnzL7tFe6pH2bZ_vnbEfCpZsiCdfYQ@mail.gmail.com> (Yosry Ahmed's message of "Wed, 22 Mar 2023 20:27:24 -0700")

Yosry Ahmed <yosryahmed@google.com> writes:

> On Wed, Mar 22, 2023 at 8:17 PM Huang, Ying <ying.huang@intel.com> wrote:
>>
>> Yosry Ahmed <yosryahmed@google.com> writes:
>>
>> > On Wed, Mar 22, 2023 at 6:50 PM Huang, Ying <ying.huang@intel.com> wrote:
>> >>
>> >> Yosry Ahmed <yosryahmed@google.com> writes:
>> >>
>> >> > On Sun, Mar 19, 2023 at 7:56 PM Huang, Ying <ying.huang@intel.com> wrote:
>> >> >>
>> >> >> Yosry Ahmed <yosryahmed@google.com> writes:
>> >> >>
>> >> >> > On Thu, Mar 16, 2023 at 12:51 AM Huang, Ying <ying.huang@intel.com> wrote:
>> >> >> >>
>> >> >> >> Yosry Ahmed <yosryahmed@google.com> writes:
>> >> >> >>
>> >> >> >> > On Sun, Mar 12, 2023 at 7:13 PM Huang, Ying <ying.huang@intel.com> wrote:
>> >> >> >> >>
>> >> >> >> >> Yosry Ahmed <yosryahmed@google.com> writes:
>> >> >> >> >>

[snip]

>> >>
>> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> > xarray (b) is indexed by swap id as well
>> >> >> >> > and contain swap entry or zswap entry. Reverse mapping might be
>> >> >> >> > needed.
>> >> >> >>
>> >> >> >> Reverse mapping isn't needed.
>> >> >> >
>> >> >> >
>> >> >> > It would be needed if xarray (a) is indexed by the swap id. I am not
>> >> >> > sure I understand how it can be indexed by the swap entry if the
>> >> >> > indirection is enabled.
>> >> >> >
>> >> >> >>
>> >> >> >>
>> >> >> >> > In this case we have an extra overhead of 12-16 bytes + 8 bytes for
>> >> >> >> > xarray (b) entry + memory overhead from 2nd xarray + reverse mapping
>> >> >> >> > where needed.
>> >> >> >> >
>> >> >> >> > There is also the extra cpu overhead for an extra lookup in certain paths.
>> >> >> >> >
>> >> >> >> > Is my analysis correct? If yes, I agree that the original proposal is
>> >> >> >> > good if the reverse mapping can be avoided in enough situations, and
>> >> >> >> > that we should consider such alternatives otherwise. As I mentioned
>> >> >> >> > above, I think it comes down to whether we can completely restrict
>> >> >> >> > cluster readahead to rotating disks or not -- in which case we need to
>> >> >> >> > decide what to do for shmem and for anon when vma readahead is
>> >> >> >> > disabled.
>> >> >> >>
>> >> >> >> We can even have a minimal indirection implementation.  Where, swap
>> >> >> >> cache and swap_map[] are kept as they ware before, just one xarray is
>> >> >> >> added.  The xarray is indexed by swap id (or swap_desc index) to store
>> >> >> >> the corresponding swap entry.
>> >> >> >>
>> >> >> >> When indirection is disabled, no extra overhead.
>> >> >> >>
>> >> >> >> When indirection is enabled, the extra overhead is just 8 bytes per
>> >> >> >> swapped page.
>> >> >> >>
>> >> >> >> The basic migration support can be build on top of this.
>> >> >> >>
>> >> >> >> I think that this could be a baseline for indirection support.  Then
>> >> >> >> further optimization can be built on top of it step by step with
>> >> >> >> supporting data.
>> >> >> >
>> >> >> >
>> >> >> > I am not sure how this works with zswap. Currently swap_map[]
>> >> >> > implementation is specific for swapfiles, it does not work for zswap
>> >> >> > unless we implement separate swap counting logic for zswap &
>> >> >> > swapfiles. Same for the swapcache, it currently supports being indexed
>> >> >> > by a swap entry, it would need to support being indexed by a swap id,
>> >> >> > or have a separate swap cache for zswap. Having separate
>> >> >> > implementation would add complexity, and we would need to perform
>> >> >> > handoffs of the swap count/cache when a page is moved from zswap to a
>> >> >> > swapfile.
>> >> >>
>> >> >> We can allocate a swap entry for each swapped page in zswap.
>> >> >
>> >> >
>> >> > This is exactly what the current implementation does and what we want
>> >> > to move away from. The current implementation uses zswap as an
>> >> > in-memory compressed cache on top of an actual swap device, and each
>> >> > swapped page in zswap has a swap entry allocated. With this
>> >> > implementation, zswap cannot be used without a swap device.
>> >>
>> >> I totally agree that we should avoid to use an actual swap device under
>> >> zswap.  And, as an swap implementation, zswap can manage the swap entry
>> >> inside zswap without an underlying actual swap device.  For example,
>> >> when we swap a page to zswap (actually compress), we can allocate a
>> >> (virtual) swap entry in the zswap.  I understand that there's overhead
>> >> to manage the swap entry in zswap.  We can consider how to reduce the
>> >> overhead.
>> >
>> > I see. So we can (for example) use one of the swap types for zswap,
>> > and then have zswap code handle this entry according to its
>> > implementation. We can then have an xarray that maps swap ID -> swap
>> > entry, and this swap entry is used to index the swap cache and such.
>> > When a swapped page is moved between backends we update the swap ID ->
>> > swap entry xarray.
>> >
>> > This is one possible implementation that I thought of (very briefly
>> > tbh), but it does have its problems:
>> > For zswap:
>> > - Managing swap entries inside zswap unnecessarily.
>> > - We need to maintain a swap entry -> zswap entry mapping in zswap --
>> > similar to the current rbtree, which is something that we can get rid
>> > of with the initial proposal if we embed the zswap_entry pointer
>> > directly in the swap_desc (it can be encoded to avoid breaking the
>> > abstraction).
>> >
>> > For mm/swap in general:
>> > - When we allocate a swap entry today, we store it in folio->private
>> > (or page->private), which is used by the unmapping code to be placed
>> > in the page tables or shmem page cache. With this implementation, we
>> > need to store the swap ID in page->private instead, which means that
>> > every time we need to access the swap cache during reclaim/swapout we
>> > need to lookup the swap entry first.
>> > - On the fault path, we need two lookups instead of one (swap ID ->
>> > swap entry, swap entry -> swap cache), not sure how this affects fault
>> > latency.
>> > - Each swap backend will have its own separate implementation of swap
>> > counting, which is hard to maintain and very error-prone since the
>> > logic is backend-agnostic.
>> > - Handing over a page from one swap backend to another includes
>> > handing over swap cache entries and swap counts, which I imagine will
>> > involve considerable synchronization.
>> >
>> > Do you have any thoughts on this?
>>
>> Yes.  I understand there's additional overhead.  I have no clear idea
>> about how to reduce this now.  We need to think about that in depth.
>>
>> The bottom line is whether this is worse than the current zswap
>> implementation?
>
> It's not just zswap, as I note above, this design would introduce some
> overheads to the core swapping code as well as long as the indirection
> layer is active. I am particularly worried about the extra lookups on
> the fault path.

Maybe you can measure the time for the radix tree lookup?  And compare
it with the total fault time?

> For zswap, we already have a lookup today, so maintaining swap entry
> -> zswap entry mapping would not be a regression, but I am not sure
> about the extra overhead to manage swap entries within zswap. Keep in
> mind that using swap entries for zswap probably implies having a
> fixed/max size for zswap (to be able to manage the swap entries
> efficiently similar to swap devices), which is a limitation that the
> initial proposal was hoping to overcome.

We have limited bits in PTE, so the max number of zswap entries will be
limited anyway.  And, we don't need to manage swap entries in the same
way as disks (which need to consider sequential writing etc.).

Best Regards,
Huang, Ying

[snip]


  reply	other threads:[~2023-03-23  5:39 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 [this message]
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
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=87bkkkrps8.fsf@yhuang6-desk2.ccr.corp.intel.com \
    --to=ying.huang@intel.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=yosryahmed@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.