From: Chengming Zhou <chengming.zhou@linux.dev>
To: Nhat Pham <nphamcs@gmail.com>, Chris Li <chrisl@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>,
lsf-pc@lists.linux-foundation.org, linux-mm <linux-mm@kvack.org>,
ryan.roberts@arm.com, David Hildenbrand <david@redhat.com>,
Barry Song <21cnbao@gmail.com>,
Chuanhua Han <hanchuanhua@oppo.com>
Subject: Re: [LSF/MM/BPF TOPIC] Swap Abstraction "the pony"
Date: Tue, 5 Mar 2024 17:52:31 +0800 [thread overview]
Message-ID: <97e95dc3-bdc0-4dfd-aca9-2d2880e1fdf5@linux.dev> (raw)
In-Reply-To: <CAKEwX=P=+oT3W0qPMgymtcpXAjD2PfP8n5c9G7VWt9qdjNjYVg@mail.gmail.com>
On 2024/3/5 17:32, Nhat Pham wrote:
> On Tue, Mar 5, 2024 at 2:44 PM Chris Li <chrisl@kernel.org> wrote:
>>
>> On Mon, Mar 4, 2024 at 7:24 PM Chengming Zhou <chengming.zhou@linux.dev> wrote:
>>>
>>> On 2024/3/5 06:58, Matthew Wilcox wrote:
>>>> On Fri, Mar 01, 2024 at 04:53:43PM +0700, Nhat Pham wrote:
>>>>> IMHO, one thing this new abstraction should support is seamless
>>>>> transfer/migration of pages from one backend to another (perhaps from
>>>>> high to low priority backends, i.e writeback).
>>>>>
>>>>> I think this will require some careful redesigns. The closest thing we
>>>>> have right now is zswap -> backing swapfile. But it is currently
>>>>> handled in a rather peculiar manner - the underlying swap slot has
>>>>> already been reserved for the zswap entry. But there's a couple of
>>>>> problems with this:
>>>>>
>>>>> a) This is wasteful. We're essentially having the same piece of data
>>>>> occupying spaces in two levels in the hierarchies.
>>>>> b) How do we generalize to a multi-tier hierarchy?
>>>>> c) This is a bit too backend-specific. It'd be nice if we can make
>>>>> this as backend-agnostic as possible (if possible).
>>>>>
>>>>> Motivation: I'm currently working/thinking about decoupling zswap and
>>>>> swap, and this is one of the more challenging aspects (as I can't seem
>>>>> to find a precedent in the swap world for inter-swap backends pages
>>>>> migration), and especially with respect to concurrent loads (and
>>>>> swapcache interactions).
>>>>
>>>> Have you considered (and already rejected?) the opposite approach --
>>>> coupling zswap and swap more tightly? That is, we always write out
>>>> the original pages today. Why don't we write out the compressed pages
>>>> instead? For the same amount of I/O, we'd free up more memory! That
>>>> sounds like a win to me.
>
> Compressed writeback (for a lack of better term) is in my
> to-think-about list, precisely for the benefits you point out (swap
> space saving + I/O efficiency).
>
> By decoupling, I was primarily aiming to reduce initial swap space
> wastage. Specifically, as of now, we prematurely reserve swap space
> even if the page is successfully stored in zswap. I'd like to avoid
> this (if possible). Compressed writeback could be an orthogonal
> improvement to this.
Looks sensible. Now the zswap middle layer is transparent to frontend users,
which just allocate swap entry and swap out, don't care about whether it's
swapped out to the zswap or swap file.
By decoupling, the frontend users need to know it want to allocate zswap entry
instead of a swap entry, right? Which becomes not transparent to users.
On the other hand, MGLRU could use its more fine-grained information to
decide whether to allocate zswap entry or swap entry, instead of always
going through zswap -> swap layers. Just some random thoughts :)
Thanks.
>
>>
>> I have considered that as well, that is further than writing from one
>> swap device to another. The current swap device currently can't accept
>> write on non page aligned offset. If we allow byte aligned write out
>> size, the whole swap entry offset stuff needs some heavy changes.
>>
>> If we write out 4K pages, and the compression ratio is lower than 50%,
>> it means a combination of two compressed pages can't fit into one
>> page. Which means some of the page read back will need to overflow
>> into another page. We kind of need a small file system to keep track
>> of how the compressed data is stored, because it is not page aligned
>> size any more.
>>
>> We can write out zsmalloc blocks of data as it is, however there is no
>> guarantee the data in zsmalloc blocks have the same LRU order.
>
> zsmalloc used to do this - it writes the entire zspage (which is a
> multiple of pages). I don't think it's a good idea either. Objects in
> the same zspage are of the same size class, and this does NOT
> necessarily imply similar access recency/frequency IMHO.
>
> We need to figure out how to swap out non-page-sized entities before
> compressed writeback becomes a thing.
>
>>
>> It makes more sense when writing higher order > 0 swap pages. e.g
>> writing 64K pages in one buffer, then we can write out compressed data
>> as page boundary aligned and page sizes, accepting the waste on the
>> last compressed page, might not fill up the whole page.
>>
>>>
>>> Right, I also thought about this direction for some time.
>>> Apart from fewer IO, there are more advantages we can see:
>>>
>>> 1. Don't need to allocate a page when write out compressed data.
>>> This method actually has its own problem[1], by allocating a new page and
>>> put on LRU list, wait for writeback and reclaim.
>>> If we write out compressed data directly, so don't need to allocated page,
>>> these problems can be avoided.
>>
>> Does it go through swap cache at all? If not, there will be some
>> interesting synchronization issues when other races swap in the page
>> and modify it.
>
> I agree. If we are to go with this approach, we will need to modify
> the swap cache to synchronize concurrent swapins.
>
> As usual, devils are in the details :)
>
>>
>>>
>>> 2. Don't need to decompress when write out compressed data.
>>
>> Yes.
>>
>>>
>>> [1] https://lore.kernel.org/all/20240209115950.3885183-1-chengming.zhou@linux.dev/
>>>
>>>>
>>>> I'm sure it'd be a big redesign, but that seems to be what we're talking
>>>> about anyway.
>>>>
>>>
>>> Yes, we need to do modifications in some parts:
>>>
>>> 1. zsmalloc: compressed objects can be migrated anytime, we need to support pinning.
>>
>> Or use a bounce buffer to read it out.
>>
>>>
>>> 2. swapout: need to support non-folio write out.
>>
>> Yes. Non page aligned write out will change swap back end design dramatically.
>>
>>>
>>> 3. zswap: zswap need to handle synchronization between compressed write out and swapin,
>>> since they share the same swap entry.
>>
>> Exactly. Same for ZRAM as well.
>>
>
> I agree with this list. 1 sounds the least invasive, but the other 2
> will be quite massive :)
>
>> Chris
>
> Nhat
next prev parent reply other threads:[~2024-03-05 9:52 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 9:24 [LSF/MM/BPF TOPIC] Swap Abstraction "the pony" Chris Li
2024-03-01 9:53 ` Nhat Pham
2024-03-01 18:57 ` Chris Li
2024-03-04 22:58 ` Matthew Wilcox
2024-03-05 3:23 ` Chengming Zhou
2024-03-05 7:44 ` Chris Li
2024-03-05 8:15 ` Chengming Zhou
2024-03-05 18:24 ` Chris Li
2024-03-05 9:32 ` Nhat Pham
2024-03-05 9:52 ` Chengming Zhou [this message]
2024-03-05 10:55 ` Nhat Pham
2024-03-05 19:20 ` Chris Li
2024-03-05 20:56 ` Jared Hulbert
2024-03-05 21:38 ` Jared Hulbert
2024-03-05 21:58 ` Chris Li
2024-03-06 4:16 ` Jared Hulbert
2024-03-06 5:50 ` Chris Li
[not found] ` <CA+ZsKJ7JE56NS6hu4L_uyywxZO7ixgftvfKjdND9e5SOyn+72Q@mail.gmail.com>
2024-03-06 18:16 ` Chris Li
2024-03-06 22:44 ` Jared Hulbert
2024-03-07 0:46 ` Chris Li
2024-03-07 8:57 ` Jared Hulbert
2024-03-06 1:33 ` Barry Song
2024-03-04 18:43 ` Kairui Song
2024-03-04 22:03 ` Jared Hulbert
2024-03-04 22:47 ` Chris Li
2024-03-04 22:36 ` Chris Li
2024-03-06 1:15 ` Barry Song
2024-03-06 2:59 ` Chris Li
2024-03-06 6:05 ` Barry Song
2024-03-06 17:56 ` Chris Li
2024-03-06 21:29 ` Barry Song
2024-03-08 8:55 ` David Hildenbrand
2024-03-07 7:56 ` Chuanhua Han
2024-03-07 14:03 ` [Lsf-pc] " Jan Kara
2024-03-07 21:06 ` Jared Hulbert
2024-03-07 21:17 ` Barry Song
2024-03-08 0:14 ` Jared Hulbert
2024-03-08 0:53 ` Barry Song
2024-03-14 9:03 ` Jan Kara
2024-05-16 15:04 ` Zi Yan
2024-05-17 3:48 ` Chris Li
2024-03-14 8:52 ` Jan Kara
2024-03-08 2:02 ` Chuanhua Han
2024-03-14 8:26 ` Jan Kara
2024-03-14 11:19 ` Chuanhua Han
2024-05-15 23:07 ` Chris Li
2024-05-16 7:16 ` Chuanhua Han
2024-05-17 12:12 ` Karim Manaouil
2024-05-21 20:40 ` Chris Li
2024-05-28 7:08 ` Jared Hulbert
2024-05-29 3:36 ` Chris Li
2024-05-29 3:57 ` Matthew Wilcox
2024-05-29 6:50 ` Chris Li
2024-05-29 12:33 ` Matthew Wilcox
2024-05-30 22:53 ` Chris Li
2024-05-31 3:12 ` Matthew Wilcox
2024-06-01 0:43 ` Chris Li
2024-05-31 1:56 ` Yuanchu Xie
2024-05-31 16:51 ` Chris Li
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=97e95dc3-bdc0-4dfd-aca9-2d2880e1fdf5@linux.dev \
--to=chengming.zhou@linux.dev \
--cc=21cnbao@gmail.com \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=hanchuanhua@oppo.com \
--cc=linux-mm@kvack.org \
--cc=lsf-pc@lists.linux-foundation.org \
--cc=nphamcs@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=willy@infradead.org \
/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).