From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 217A7C54E41 for ; Tue, 5 Mar 2024 09:52:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6ECC56B0080; Tue, 5 Mar 2024 04:52:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 69C9B6B0081; Tue, 5 Mar 2024 04:52:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 564176B0082; Tue, 5 Mar 2024 04:52:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 47BD36B0080 for ; Tue, 5 Mar 2024 04:52:42 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 028D7C0DCC for ; Tue, 5 Mar 2024 09:52:41 +0000 (UTC) X-FDA: 81862520964.20.C33A4EE Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf08.hostedemail.com (Postfix) with ESMTP id 259FD160015 for ; Tue, 5 Mar 2024 09:52:39 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="f/c+F6wZ"; spf=pass (imf08.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709632360; a=rsa-sha256; cv=none; b=WplKOM4rihBXNkVt6vHcFJxAFh9uKOcaoGabyLxjAMqcF+1Y62NpY5BHTSgvQjQvkA0qr6 Yp5MVK3s2/adQ1Itm9Udbi7mG4XPMkZ+CFka1bV7c6Zl3cHoQWltvJh8xt20COHQi0YJpa qsrGxMOM3cjlq1uYkjz1149AiuACNJM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="f/c+F6wZ"; spf=pass (imf08.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709632360; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9NtBCGhumtTg7n+U1XE7MUDBgEdjDUh3gYmeEjgTExU=; b=tMK3PEZ4uHDOAY0YlWY2QhQfbnTL9jnGOC37wQKycer6MB8Se7lNx3jTpsRZ2DmtLYvZj8 Ppfo+n0bG4BqbdEhkVPpNnJQyb2xZd3BYZ/fTzch28h9tXiXmv3KikgGzmTgZctIarIDZh eT9v/5ljNG35c6n1d3KfaQhYKTZVtIE= Message-ID: <97e95dc3-bdc0-4dfd-aca9-2d2880e1fdf5@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709632358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9NtBCGhumtTg7n+U1XE7MUDBgEdjDUh3gYmeEjgTExU=; b=f/c+F6wZ5p32HMFChRJIQfaesCh4QJPszxVhyff9KloGFSWs6joEZMJUJuDEgDh/p/lZIO vh8RkDCS5g93GZiNfANnK3nQs7dv/2ToeSxT9m2TP65iZmkyXyx4EQxfaFydCVaBvOQGoM o6o3djSp8SXKTuKiz3TR3uaGNDPJSnA= Date: Tue, 5 Mar 2024 17:52:31 +0800 MIME-Version: 1.0 Subject: Re: [LSF/MM/BPF TOPIC] Swap Abstraction "the pony" Content-Language: en-US To: Nhat Pham , Chris Li Cc: Matthew Wilcox , lsf-pc@lists.linux-foundation.org, linux-mm , ryan.roberts@arm.com, David Hildenbrand , Barry Song <21cnbao@gmail.com>, Chuanhua Han References: X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 259FD160015 X-Stat-Signature: fopceohon4d6181z4z9m6djeyo6oh5yn X-Rspam-User: X-HE-Tag: 1709632359-780497 X-HE-Meta: U2FsdGVkX18OZihSsx5ABWlrCYDQIsuOsKgivzS28+6fszKwpUQziOu85E6xsV1rrsUpKlXB31mcfN5A9dMY0dhjYohgoleph1M2Rj2q46Ud2oqz+4kvPHF0JRfCDRmXFFvlIERdW3o2S1gHohdLwv0A2VJiAe/U1+HER3s2Q6BVvOfOQsEhBUeXrPOGWy4Z7OaWgj0dC/2pt5ccUsEZQYEX116qMJA7MyYJJsCPpmWdVFhzWYvMv1TSub7OHMZcdrUaRSNo5AdkjtQoHmAZGGTbRQZPC+o8Hm2tXBSOcQQMQhFSXf3stb34SfrWctWZ2BQvtKC0oiaNowf4gXhciILYfeG/xHezEtq6kBWbSwI6atLcqbXuFVA/rCvRqjXq17epMQDC0D2YYVQMFejsYZNQqL4bm+ZS1laHJmZt4CoJVyppq1bgDU8HlDvKaWIzgNYYHutwlamz9E2x4F1IIde9mn2sQTO07wNnwBHMiRC0ioxe1qNh422Lh+ZrfeZbO2PBXZ9lIbd1gNGMcph+fie9R02rChT/zDiLrCJuSAdcHS++3X+M9lRE5zGC2Go3fL4yKc8mhD7l7Dklyh4oj9p1QITrH4ZbS/rGjJueaZy1H0ETXHairjaU1MI+geH8s9kUTiVh2AnSXVt66MSSls5hZPUe8ILSi4oi6NvYwoPCT72GXdNNhxnzehrwlMDClxFjTm6n8val8yqUoDf75sQoU2Gfu0FvuI18WwfZGmvolLTtia8P391g7zxZ402udkeOxvMQdoIO8NkSYaqyfOJhLmixLSkU4pU12Knhr/k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000057, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2024/3/5 17:32, Nhat Pham wrote: > On Tue, Mar 5, 2024 at 2:44 PM Chris Li wrote: >> >> On Mon, Mar 4, 2024 at 7:24 PM Chengming Zhou 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