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 D6B43C6FD1C for ; Wed, 22 Mar 2023 05:57:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF3896B0075; Wed, 22 Mar 2023 01:57:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA2E76B0078; Wed, 22 Mar 2023 01:57:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF66B6B007B; Wed, 22 Mar 2023 01:57:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A91556B0075 for ; Wed, 22 Mar 2023 01:57:13 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 11208A0256 for ; Wed, 22 Mar 2023 05:57:13 +0000 (UTC) X-FDA: 80595476346.11.DA76FB0 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf08.hostedemail.com (Postfix) with ESMTP id 0B933160009 for ; Wed, 22 Mar 2023 05:57:10 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=K9uaoPV1; spf=pass (imf08.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679464631; a=rsa-sha256; cv=none; b=ir4kwcqFPhoUiOABu0EFYBpNcPL5AxKdY/Fcur1obGKi1gxQ+fON6OAt+sra+j7CrvALh9 5XngzGaHrL92c3gzwOawE0donKPZLLpYUaq6ako9v0UZiIJ6kJxvnL/4yOEVwZWao0WVB5 pxmR/X0dImLX315DF6sCfPKAp2UIvxQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=K9uaoPV1; spf=pass (imf08.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679464631; 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=MjRSZ3E4FPF3myRSHuQNVWKlVf9OFsFjSlvFPqK63yY=; b=8RrMrpf4N64t/zIMtTeY6wNMI72exFBF4gqlunKcop1duBGw2rK6iHQVf7+GCG5ov4IPgG /LXk4MeCbKMOKQ+NM8jLBgwdaatDoptYvnQzfwkTds4QYEoHusAWh+id4IdRLvH/TcJxc9 0CG6xSC0j3qLU7xd0d92RBlgxij5Mcg= Received: by mail-ed1-f52.google.com with SMTP id b20so35464058edd.1 for ; Tue, 21 Mar 2023 22:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679464629; 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=MjRSZ3E4FPF3myRSHuQNVWKlVf9OFsFjSlvFPqK63yY=; b=K9uaoPV1/EvjesF/F2elSXV8LqVy11Y7sfQaJpV3gLC8IntgtiiXvvUq8M5iUAACH3 KtqY6tAuAUqadK6mptUPDROxm4JXL746oXVyuPx2t9neG/G546Vut8kGH3DZ3HRgRczI dYfWzufDatZHOm5v1x/zvjwkhiOzeRT12EQde3hEsI8dO7U5p+Gk8w5+Wecxw4zhFcY9 YA0vwUdoVlryjhYnH/MvqS1p5Vix6KDyfNsWtjUCqwFewdexIrX7jPCT2rHuWA/LTNYs YN9dAEscPXftlBNRmFzBzIFAMF7ZUaxm0gsBj85+YSqsdIujH6t7QCe+qJfGIdufFG9y Yk2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679464629; 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=MjRSZ3E4FPF3myRSHuQNVWKlVf9OFsFjSlvFPqK63yY=; b=h2RGl0iqCai9QtQiQHTQR+hp+ZPXQeIi2v4qEMgHTBNjXmHVTz+FHc0yt3BIHPtq3Z qeKlZf7wZoLvwB5ZGvHzpTYRbKXac5z8v/XfESIlB7O7wafrq1JV4wdSVbsKQWehSqQy 0vMPiU7UvHvrdm7Q+KkG7QBrA4wDJAjA8b1844z1fBWLGpZK3vEiNWeZxufjNsKBAPU0 vIAznPx+ZT8D9HcHzUqOcqnT3cfHGDsC2qk+BIzvrQUfedSGMbMI6+5A7TSyp1EWxli0 Rkw3C+HC9MQQje9MvG0Oy0n6KQkS/xFIhBVe536C/Nk2lfwa3HE+ot1p+RPm14Xt62zt 9eTA== X-Gm-Message-State: AO0yUKXVmnue05gaYs31dDkw3GyTPIhe4h0dq1aUOonEf69MGfQD3t/H CDMkvUpItnZtIR5zyuRhlqvdQ5JM1bbWJLfY/fiNZw== X-Google-Smtp-Source: AK7set+dHcf/UU+R9iIpIkN6yffZudtPUNIxQsHGP5N9vwKo3DZ5GNQ08g9HHLJdxQ1tm/0AlkK8iG66+yxaN1Kftc4= X-Received: by 2002:a17:906:34cd:b0:8e5:411d:4d09 with SMTP id h13-20020a17090634cd00b008e5411d4d09mr2567474ejb.15.1679464629204; Tue, 21 Mar 2023 22:57:09 -0700 (PDT) MIME-Version: 1.0 References: <87356e850j.fsf@yhuang6-desk2.ccr.corp.intel.com> <87y1o571aa.fsf@yhuang6-desk2.ccr.corp.intel.com> <87o7ox762m.fsf@yhuang6-desk2.ccr.corp.intel.com> <87bkkt5e4o.fsf@yhuang6-desk2.ccr.corp.intel.com> <87y1ns3zeg.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87y1ns3zeg.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Yosry Ahmed Date: Tue, 21 Mar 2023 22:56:32 -0700 Message-ID: Subject: Re: [LSF/MM/BPF TOPIC] Swap Abstraction / Native Zswap To: "Huang, Ying" Cc: Chris Li , lsf-pc@lists.linux-foundation.org, Johannes Weiner , Linux-MM , Michal Hocko , Shakeel Butt , David Rientjes , Hugh Dickins , Seth Jennings , Dan Streetman , Vitaly Wool , Yang Shi , Peter Xu , Minchan Kim , Andrew Morton , Aneesh Kumar K V , Michal Hocko , Wei Xu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 0B933160009 X-Rspamd-Server: rspam01 X-Stat-Signature: jca8om3ym1bjiq9bggmb38i45wgnn14j X-HE-Tag: 1679464630-734304 X-HE-Meta: U2FsdGVkX1/uCirWXY8Rg9RrTRmXQpZPFZzYIqhGxO928N7ir1lW9pZA7Va0VIvA+mlsIf4QaEY+xfrXil/+OKI8ePtxZ2WKCns5DYELj6MVrof3YRauDP/ASh4nuxjmFXXsTkRdnlw0Sa1ZC1SIaTwspaHwsvkTsKMV/xGClP3ny5QX4D68jWVGIQAIUlXn/S7UWw6W5Wyoh8410vY2eaPOBggIGGoKd8xG8CEO/ky3aDN6rn/mQmcZYGuzcnXMSnUqRnuSykqrXhsqLNQj5+iNCRu9nAwN9MWHZFtGif4nhzXtgh3HNu+PJgK/D0v1doyUbSE6FRwf16FZOUzBtyau5OuJvtElpb8EbwJl2rDzLbukM7ApZQwt9O5MyiFgq3FCJI263p/MOrEBu2vlf6qGSnyjyW8xlb+Dg1jHh5chUC9Ks5h1LqqwfiNNbGbYARV+o9uUrXPO4vtb93TY//8PcUBrFcHS6/9wYLQSklvopd0ZWuloMLav23gG7U+j0YaalMCHafn02N+GjyYKJg4eeTIFnkfrBK9rZLB88hJ7FP/3H7Dub/VmYyTLcGOgDcaXc37czHyJs95PuWAPmF1X1xscNob79JQkxK+DXUh+Im8KkvMEczjTylCNeuSAitM/B+d+cH0cDUg8MKLjubGHypbMVFNESziiH4Z5jWR4Dp0jqDy8fWiPYxQCmwuw0QohSzQKkArmE5qoC9LeO20f719HGIPdhKK9kMB0il/6ZlT2yg5iLy6pw0mtcO+xmxwbvuPdHKcvvLhYp2owhgwWV3I6rPmsMFFMGVjgdVG+s0Ak7Lxp1a56u7hf8MOZQ/ek10HrgAMYRamG8uqfuA5wwTIf8P+HpCpKcHShnErCkGCvNHZHMsNQMbHkZA85c+iS9ZTlFqm95I0gjY4ByyaQJnKjXn5rfbrNW0yuZkTdcJdetoVBxsiSq0SW80Ye30T3jjbRwv0eFpyCSjY O40Ovhss XuIavChenXqbiL8Hqusa/1CQYiiZxsaXAZql242w7wBPEhwB4TFGIoKAXgQNbH1CcCEWhuuf8Vh9VTbOeOGTAL6ilO4aRKk16OxG3aPCv1CoVTf8qZIofV9oVfTL7uXzQAd5lEgJ7xLp8rYXD2IaS4T0XJp2Zmee54CLI6T6xoB1SEz6oI3YdXEj5zVu7PkW66G+Ig2WLF2QiLTSNvxgN0a+1paPiz5GdPi5iqeAhIiQZfrN5L7BKFXahL+AqHgfBz9r+1bODAyBfHmBz//hHwFciRwhiSilN0H4190ZAt2xlPEQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Mar 19, 2023 at 7:56=E2=80=AFPM Huang, Ying = wrote: > > Yosry Ahmed writes: > > > On Thu, Mar 16, 2023 at 12:51=E2=80=AFAM Huang, Ying wrote: > >> > >> Yosry Ahmed writes: > >> > >> > On Sun, Mar 12, 2023 at 7:13=E2=80=AFPM Huang, Ying wrote: > >> >> > >> >> Yosry Ahmed writes: > >> >> > >> >> > >> >> > > >> >> > My current idea is to have one xarray that stores the swap_descs > >> >> > (which include swap_entry, swapcache, swap_count, etc), and only = for > >> >> > rotating disks have an additional xarray that maps swap_entry -> > >> >> > swap_desc for cluster readahead, assuming we can eliminate all ot= her > >> >> > situations requiring a reverse mapping. > >> >> > > >> >> > I am not sure how having separate xarrays help? If we have one xa= rray, > >> >> > might as well save the other lookups on put everything in swap_de= sc. > >> >> > In fact, this should improve the locking today as swapcache / > >> >> > swap_count operations can be lockless or very lightly contended. > >> >> > >> >> The condition of the proposal is "reverse mapping cannot be avoided= for > >> >> enough situation". So, if reverse mapping (or cluster readahead) c= an be > >> >> avoided for enough situations, I think your proposal is good. Othe= rwise, > >> >> I propose to use 2 xarrays. You don't need another reverse mapping > >> >> xarray, because you just need to read the next several swap_entry i= nto > >> >> the swap cache for cluster readahead. swap_desc isn't needed for > >> >> cluster readahead. > >> > > >> > swap_desc would be needed for cluster readahead in my original > >> > proposal as the swap cache lives in swap_descs. Based on the current > >> > implementation, we would need a reverse mapping (swap entry -> > >> > swap_desc) in 3 situations: > >> > > >> > 1) __try_to_reclaim_swap(): when trying to find an empty swap slot a= nd > >> > failing, we fallback to trying to find swap entries that only have a > >> > page in the swap cache (no references in page tables or page cache) > >> > and free them. This would require a reverse mapping. > >> > > >> > 2) swapoff: we need to swap in all entries in a swapfile, so we need > >> > to get all swap_descs associated with that swapfile. > >> > > >> > 3) swap cluster readahead. > >> > > >> > For (1), I think we can drop the dependency of a reverse mapping if = we > >> > free swap entries once we swap a page in and add it to the swap cach= e, > >> > even if the swap count does not drop to 0. > >> > >> Now, we will not drop the swap cache even if the swap count becomes 0 = if > >> swap space utility < 50%. Per my understanding, this avoid swap page > >> writing for read accesses. So I don't think we can change this direct= ly > >> without necessary discussion firstly. > > > > > > Right. I am not sure I understand why we do this today, is it to save > > the overhead of allocating a new swap entry if the page is swapped out > > again soon? I am not sure I understand this statement "this avoid swap > > page > > writing for read accesses". > > > >> > >> > >> > For (2), instead of scanning page tables and shmem page cache to fin= d > >> > swapped out pages for the swapfile, we can scan all swap_descs > >> > instead, we should be more efficient. This is one of the proposal's > >> > potential advantages. > >> > >> Good. > >> > >> > (3) is the one that would still need a reverse mapping with the > >> > current proposal. Today we use swap cluster readahead for anon pages > >> > if we have a spinning disk or vma readahead is disabled. For shmem, = we > >> > always use cluster readahead. If we can limit cluster readahead to > >> > only rotating disks, then the reverse mapping can only be maintained > >> > for swapfiles on rotating disks. Otherwise, we will need to maintain= a > >> > reverse mapping for all swapfiles. > >> > >> For shmem, I think that it should be good to readahead based on shmem > >> file offset instead of swap device offset. > >> > >> It's possible that some pages in the readahead window are from HDD whi= le > >> some other pages aren't. So it's a little hard to enable cluster read > >> for HDD only. Anyway, it's not common to use HDD for swap now. > >> > >> >> > >> >> > If the point is to store the swap_desc directly inside the xarray= to > >> >> > save 8 bytes, I am concerned that having multiple xarrays for > >> >> > swapcache, swap_count, etc will use more than that. > >> >> > >> >> The idea is to save the memory used by reverse mapping xarray. > >> > > >> > I see. > >> > > >> >> > >> >> >> >> > >> >> >> >> > Keep in mind that the current overhead is 1 byte O(max swap= pages) not > >> >> >> >> > O(swapped). Also, 1 byte is assuming we do not use the swap > >> >> >> >> > continuation pages. If we do, it may end up being more. We = also > >> >> >> >> > allocate continuation in full 4k pages, so even if one swap= _map > >> >> >> >> > element in a page requires continuation, we will allocate a= n entire > >> >> >> >> > page. What I am trying to say is that to get an actual comp= arison you > >> >> >> >> > need to also factor in the swap utilization and the rate of= usage of > >> >> >> >> > swap continuation. I don't know how to come up with a formu= la for this > >> >> >> >> > tbh. > >> >> >> >> > > >> >> >> >> > Also, like Johannes said, the worst case overhead (32 bytes= if you > >> >> >> >> > count the reverse mapping) is 0.8% of swapped memory, aka 8= M for every > >> >> >> >> > 1G swapped. It doesn't sound *very* bad. I understand that = it is pure > >> >> >> >> > overhead for people not using zswap, but it is not very awf= ul. > >> >> >> >> > > >> >> >> >> >> > >> >> >> >> >> It seems what you really need is one bit of information to= indicate > >> >> >> >> >> this page is backed by zswap. Then you can have a seperate= pointer > >> >> >> >> >> for the zswap entry. > >> >> >> >> > > >> >> >> >> > If you use one bit in swp_entry_t (or one of the available = swap types) > >> >> >> >> > to indicate whether the page is backed with a swapfile or z= swap it > >> >> >> >> > doesn't really work. We lose the indirection layer. How do = we move the > >> >> >> >> > page from zswap to swapfile? We need to go update the page = tables and > >> >> >> >> > the shmem page cache, similar to swapoff. > >> >> >> >> > > >> >> >> >> > Instead, if we store a key else in swp_entry_t and use this= to lookup > >> >> >> >> > the swp_entry_t or zswap_entry pointer then that's essentia= lly what > >> >> >> >> > the swap_desc does. It just goes the extra mile of unifying= the > >> >> >> >> > swapcache as well and storing it directly in the swap_desc = instead of > >> >> >> >> > storing it in another lookup structure. > >> >> >> >> > >> >> >> >> If we choose to make sizeof(struct swap_desc) =3D=3D 8, that = is, store only > >> >> >> >> swap_entry in swap_desc. The added indirection appears to be= another > >> >> >> >> level of page table with 1 entry. Then, we may use the simil= ar method > >> >> >> >> as supporting system with 2 level and 3 level page tables, li= ke the code > >> >> >> >> in include/asm-generic/pgtable-nopmd.h. But I haven't though= t about > >> >> >> >> this deeply. > >> >> >> > > >> >> >> > Can you expand further on this idea? I am not sure I fully und= erstand. > >> >> >> > >> >> >> OK. The goal is to avoid the overhead if indirection isn't enab= led via > >> >> >> kconfig. > >> >> >> > >> >> >> If indirection isn't enabled, store swap_entry in PTE directly. > >> >> >> Otherwise, store index of swap_desc in PTE. Different functions= (e.g., > >> >> >> to get/set swap_entry in PTE) are implemented based on kconfig. > >> >> > > >> >> > > >> >> > I thought about this, the problem is that we will have multiple > >> >> > implementations of multiple things. For example, swap_count witho= ut > >> >> > the indirection layer lives in the swap_map (with continuation lo= gic). > >> >> > With the indirection layer, it lives in the swap_desc (or somewhe= re > >> >> > else). Same for the swapcache. Even if we keep the swapcache in a= n > >> >> > xarray and not inside swap_desc, it would be indexed by swap_entr= y if > >> >> > the indirection is disabled, and by swap_desc (or similar) if the > >> >> > indirection is enabled. I think maintaining separate implementati= ons > >> >> > for when the indirection is enabled/disabled would be adding too = much > >> >> > complexity. > >> >> > > >> >> > WDYT? > >> >> > >> >> If we go this way, swap cache and swap_count will always be indexed= by > >> >> swap_entry. swap_desc just provides a indirection to make it possi= ble > >> >> to move between swap devices. > >> >> > >> >> Why must we index swap cache and swap_count by swap_desc if indirec= tion > >> >> is enabled? Yes, we can save one xarray indexing if we do so, but = I > >> >> don't think the overhead of one xarray indexing is a showstopper. > >> >> > >> >> I think this can be one intermediate step towards your final target= . > >> >> The changes to current implementation can be smaller. > >> > > >> > IIUC, the idea is to have two xarrays: > >> > (a) xarray that stores a pointer to a struct containing swap_count a= nd > >> > swap cache. > >> > (b) xarray that stores the underlying swap entry or zswap entry. > >> > > >> > When indirection is disabled: > >> > page tables & page cache have swap entry directly like today, xarray > >> > (a) is indexed by swap entry, xarray (b) does not exist. No reverse > >> > mapping needed. > >> > > >> > In this case we have an extra overhead of 12-16 bytes (the struct > >> > containing swap_count and swap cache) vs. 24 bytes of the swap_desc. > >> > > >> > When indirection is enabled: > >> > page tables & page cache have a swap id (or swap_desc index), xarray > >> > (a) is indexed by swap id, > >> > >> xarray (a) is indexed by swap entry. > > > > > > How so? With the indirection enabled, the page tables & page cache > > have the swap id (or swap_desc index), which can point to a swap entry > > or a zswap entry -- which can change when the page is moved between > > zswap & swapfiles. How is xarray (a) indexed by the swap entry in this > > case? Shouldn't be indexed by the abstract swap id so that the > > writeback from zswap is transparent? > > In my mind, > > - swap core will define a abstract interface to swap implementations > (zswap, swap device/file, maybe more in the future), like VFS. > > - zswap will be a special swap implementation (compressing instead of > writing to disk). > > - swap core will manage the indirection layer and swap cache. > > - swap core can move swap pages between swap implementations (e.g., from > zswap to a swap device, or from one swap device to another swap > device) with the help of the indirection layer. > > In this design, the writeback from zswap becomes moving swapped pages > from zswap to a swap device. All the above matches my understanding of this proposal. swap_desc is the proposed indirection layer, and the swap implementations are zswap & swap devices. For now, we only have 2 static swap implementations (zswap->swapfile). In the future, we can make this more dynamic as the need arises. > > > If my understanding were correct, your suggestion is kind of moving > zswap logic to the swap core? And zswap will be always at a higher > layer on top of swap device/file? We do not want to move the zswap logic into the swap core, we want to make the swap core independent of the swap implementation, and zswap is just one possible implementation. > > > >> > >> > >> > 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 i= s > >> > 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. > > > >> > >> > >> >> > >> >> >> >> >> > >> >> >> >> >> Depending on how much you are going to reuse the swap cach= e, you might > >> >> >> >> >> need to have something like a swap_info_struct to keep the= locks happy. > >> >> >> >> > > >> >> >> >> > My current intention is to reimplement the swapcache comple= tely as a > >> >> >> >> > pointer in struct swap_desc. This would eliminate this need= and a lot > >> >> >> >> > of the locking we do today if I get things right. > >> >> >> >> > > >> >> >> >> >> > >> >> >> >> >> > Another potential concern is readahead. With this design= , we have no > >> >> >> >> >> > >> >> >> >> >> Readahead is for spinning disk :-) Even a normal swap file= with an SSD can > >> >> >> >> >> use some modernization. > >> >> >> >> > > >> >> >> >> > Yeah, I initially thought we would only need the swp_entry_= t -> > >> >> >> >> > swap_desc reverse mapping for readahead, and that we can on= ly store > >> >> >> >> > that for spinning disks, but I was wrong. We need for other= things as > >> >> >> >> > well today: swapoff, when trying to find an empty swap slot= and we > >> >> >> >> > start trying to free swap slots used only by the swapcache.= However, I > >> >> >> >> > think both of these cases can be fixed (I can share more de= tails if > >> >> >> >> > you want). If everything goes well we should only need to m= aintain the > >> >> >> >> > reverse mapping (extra overhead above 24 bytes) for swap fi= les on > >> >> >> >> > spinning disks for readahead. > >> >> >> >> > > >> >> >> >> >> > >> >> >> >> >> Looking forward to your discussion. > >> >> >> > >> >> >> Per my understanding, the indirection is to make it easy to move > >> >> >> (swapped) pages among swap devices based on hot/cold. This is s= imilar > >> >> >> as the target of memory tiering. It appears that we can extend = the > >> >> >> memory tiering (mm/memory-tiers.c) framework to cover swap devic= es too? > >> >> >> Is it possible for zswap to be faster than some slow memory medi= a? > >> >> > > >> >> > > >> >> > Agree with Chris that this may require a much larger overhaul. A = slow > >> >> > memory tier is still addressable memory, swap/zswap requires a pa= ge > >> >> > fault to read the pages. I think (at least for now) there is a > >> >> > fundamental difference. We want reclaim to eventually treat slow > >> >> > memory & swap as just different tiers to place cold memory in wit= h > >> >> > different characteristics, but otherwise I think the swapping > >> >> > implementation itself is very different. Am I missing something? > >> >> > >> >> Is it possible that zswap is faster than a really slow memory > >> >> addressable device backed by NAND? TBH, I don't have the answer. > >> > > >> > I am not sure either. > >> > > >> >> > >> >> Anyway, do you need a way to describe the tiers of the swap devices= ? > >> >> So, you can move the cold pages among the swap devices based on tha= t? > >> > > >> > For now I think the "tiers" in this proposal are just zswap and norm= al > >> > swapfiles. We can later extend it to support more explicit tiering. > >> > >> IIUC, in original zswap implementation, there's 1:1 relationship betwe= en > >> zswap and normal swapfile. But now, you make demoting among swap > >> devices more general. Then we need some general way to specify which > >> swap devices are fast and which are slow, and the demoting relationshi= p > >> among them. It can be memory tiers or something else, but we need one= . > > > > > > I think for this proposal, there are only 2 hardcoded tiers. Zswap is > > fast, swapfile is slow. In the future, we can support more dynamic > > tiering if the need arises. > > We can start from a simple implementation. And I think that it's better > to consider the general design too. Try not to make it impossible now. Right. I am proposing we come up with an abstract generic interface for swap implementations, and have 2 implementations statically defined (swapfiles and zswap). If the need arises, we can make swap implementations more dynamic in the future. > > > Best Regards, > Huang, Ying