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 78751C54798 for ; Tue, 5 Mar 2024 09:32:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F3A56B0099; Tue, 5 Mar 2024 04:32:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07BBB6B009C; Tue, 5 Mar 2024 04:32:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E39226B009E; Tue, 5 Mar 2024 04:32:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CDB4E6B0099 for ; Tue, 5 Mar 2024 04:32:35 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9C7C1C06DD for ; Tue, 5 Mar 2024 09:32:35 +0000 (UTC) X-FDA: 81862470270.16.C32A1DC Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by imf21.hostedemail.com (Postfix) with ESMTP id E87CC1C0010 for ; Tue, 5 Mar 2024 09:32:33 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="bi/x+JEa"; spf=pass (imf21.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.45 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709631154; 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=O+ntiRiaULzsZcHkfJ0Neom9YxlTH6n0qEidMsHb8tM=; b=fvw13BbmmOvUu1ID40URiue8wV5Vd9wbuw3CFhJs7vDc1prP+2Pj5CLgYJA+3ppYF/jWbd tkBoLgLZDQZBmCc2KwYE+hpvrmO3v0O/PJvyVednAGV4OWTx22VW0YkrgzIke0KsdNCUWx P5+8mm0blrRhzaoOfPjxq4KtWN7WZ/Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709631154; a=rsa-sha256; cv=none; b=Eor+WsXe/R+vxyVtWb0daGgwKXaMrF0LlNTHuuazqzBxrz42mEOGxjvoUDpDU/kIAeQMj5 eSP7alzJunowi9JfWyzmZ8hldJAcTCkJNPmi4fK57sxlctXvxkLtAc+080H30XHRROm+tB Vr9rsxNNE1No2NPcxASHwpL5UHB5LGo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="bi/x+JEa"; spf=pass (imf21.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.45 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ua1-f45.google.com with SMTP id a1e0cc1a2514c-7da728b0597so2291930241.1 for ; Tue, 05 Mar 2024 01:32:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709631153; x=1710235953; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=O+ntiRiaULzsZcHkfJ0Neom9YxlTH6n0qEidMsHb8tM=; b=bi/x+JEaC5cfYqcaqU5JSOKazbvBkzt2D1/ejED6/XZYfuEr3/KVDDHSQioJ8obL1o hKAPxtTr4uZ1ugfsDnY49o0LecGXbU25w9JNcdArqLrXFX40tulV2KOHxqCIcC3ufppd 2loGtbwsu8Dj2rv9EMlQHEXmlaqSrsD1j31T1RsxUFkRYqNzGWaieP7KqOIj3l+imIb5 ZGBvlKoIw9lZXMI/UiFJ3lq/hQj7xcC/i5F8qTO4Rbken6bIJ/biWydn2cwARug+yWmj GJTauOZj6O/3NQ529vTDExXSl0ErqYbOgmR6VCfbssHmtnPbaW9dFPui2TtKMfhhEO+K Lh8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709631153; x=1710235953; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O+ntiRiaULzsZcHkfJ0Neom9YxlTH6n0qEidMsHb8tM=; b=cDXdkE2iBkNsjM5/Ju+UfRfVA7C9Rn73yz66x7S0YHyiN7zcKERfR6+Q/h8DegU/4b He529IEb/9mUpBRfrActSISEfUHSi5dDsuh2HQoHI5iBHfXl4Gj/qGJGy0cyxcQuqo42 IXrUsXpmqCFkhfl5BHgzZJFamrVan4KpWikCArEp/uJ6tRsD7o8SUUAhPT0kjhB7yr8I jbkM6uU1L6L16VIDAFvwtIQGSnMJvAJuvDljhydXJUCfDkFLg7IWEdjDt9CLl8fVWOK/ 5AArQFLOj2aODF3UDwGNf9Nz9D9fswYZrY4Hzgax6k3lBSt6zJslbGNgPaqIgGPGLGJY m9jQ== X-Forwarded-Encrypted: i=1; AJvYcCUvxc4hBafNuZjd2QcNrZstQiSK55AfKF/YEN2Ql6K0bi2pQz7qjmc1Zr7rUdou2D3up/5qivL9W6nppzlGf+79YXE= X-Gm-Message-State: AOJu0YwpuvtZ6MY4Ibhjy21UtZkpPqZiz6YP9Z5U74kNIw+uOsFpw9SI WxKSgGm4hBLTE5soA9+GLv7H978EtTT+QZSJuuS5N6LqNYYET7CsNLPkYHEPz0GXnp43N1sERPs 0dAj1Ui2zjtl5ax06y3Km4zHZJQFKdbqAi5hFRw== X-Google-Smtp-Source: AGHT+IG0aqEJIo4YjaYiVYHm/P+G7bB3N9yhuhtjUORlus6th/WfzvHfm2P+vlJd8do5wPPMKrEJkUotR44RSfElyHs= X-Received: by 2002:a67:e952:0:b0:470:564e:a58e with SMTP id p18-20020a67e952000000b00470564ea58emr1066065vso.2.1709631152857; Tue, 05 Mar 2024 01:32:32 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Nhat Pham Date: Tue, 5 Mar 2024 16:32:21 +0700 Message-ID: Subject: Re: [LSF/MM/BPF TOPIC] Swap Abstraction "the pony" To: Chris Li Cc: Chengming Zhou , Matthew Wilcox , lsf-pc@lists.linux-foundation.org, linux-mm , ryan.roberts@arm.com, David Hildenbrand , Barry Song <21cnbao@gmail.com>, Chuanhua Han Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E87CC1C0010 X-Rspam-User: X-Stat-Signature: aagrh49ncx4gkj5geh6oa1rikzw14etx X-Rspamd-Server: rspam03 X-HE-Tag: 1709631153-118186 X-HE-Meta: U2FsdGVkX1/wYb1gyZJzHNHaRo3AfbpYAHhaFZHENHJRIEKSPnjAooL9fY7sATLmvmdsLBZiPI7FjWJuG6mo5bS79esB6rDoB0XAICwkq9mlylYSM/c5ELJ/GamZt3c4dMmDgdpvGmYzgSBuBvYu3SJZqIm8XZsJfw2tejlIO6RIfZAtwdC18t9Gs54JvHVDvnU2Mt7OWA80RBtClg1971Sir8rbyg9OPudnkVoNML1QTkmmwJQmT+53n9J1AB7fxEJ0NnXfzHsGo24YunUedCanHbuaauQxdQzwrgGzHGPhaaoOrhgRyEsJlyePoBFi6Y4fZc+CeSQm+8dyqEjnH/8cPe5yrDP44eSn+AVzzG+BO1ZAB1xp3bW0G+QW8eQG+u1kViqKqc+0h1uvfIdg1Jo1l/3H3GII8kAEMiMEzRlnC1Z24suuKLqK9K6OYr4ZLIUOk5A0ZnfwnQq9Tw52XGdgDy/i9hZ6yWn2FcsCgzKuJzpnjPjerknbnbsYCvo8RtFqceFmIh0NxrHUI1lShDrw5FHxcEa49GpjZYzbtWVmH0onNeI6NnTKY9Ue4FU1zNsH72ug1qEfO5SjkMwPJtd3vdrKX7pB4d3nQFgyC3/9aPK4fSujkO4cDO0dx84ZHiE+HH1Dr3g31C3pBVEoxeN+l2rOAVBGCTQTXqNkVZNJg62wi9K0qc3n3lb/W9h/kmPFRnFlr+WOmY8AuSXo+T/a3JDZ8W/dJOZWI2coEhYuJVo/2kfm4Tke0O2foyTXklKMglIluwr3DxTRGp0vFQfhf6lmbwKVsxkIZzAH9QWAPLe6/sa3vdjdxcFV/MKzlsiZoYEzf5b1DzVXeZhpUXLwHkuWXrZurqelMA97/68+6IAWxlqxhCDiSGnpfiy/5/zxnGxXH6bSwMNlLsHptHAUx883gMV9sXeeFJbobp9fPDk+tS8avypeA2j3d2lkYCH+RG/f5z/XLFru6u6 mGbLsnZ0 JcEqem+AgEAWRJpea9KOOnQiQewPoPrt9gLDF X-Bogosity: Ham, tests=bogofilter, spamicity=0.050947, 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 Tue, Mar 5, 2024 at 2:44=E2=80=AFPM Chris Li wrote: > > On Mon, Mar 4, 2024 at 7:24=E2=80=AFPM 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 fro= m > > >> 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 an= d > > >> swap, and this is one of the more challenging aspects (as I can't se= em > > >> 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 page= s > > > 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. > > 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 pag= e 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 talk= ing > > > about anyway. > > > > > > > Yes, we need to do modifications in some parts: > > > > 1. zsmalloc: compressed objects can be migrated anytime, we need to sup= port 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 dramatic= ally. > > > > > 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