Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3368017rdg; Tue, 17 Oct 2023 12:24:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyUXHla63KLJawdtr5OEVlx8BP1ZeFknCO5Evk6/Q1OjjlZb23nKVQGZkf90pU8DBwH/kO X-Received: by 2002:a17:902:da88:b0:1ca:a07b:365 with SMTP id j8-20020a170902da8800b001caa07b0365mr1976722plx.16.1697570677038; Tue, 17 Oct 2023 12:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697570677; cv=none; d=google.com; s=arc-20160816; b=aAegGy3kWV0VZ3fOsHG2laT6Bw+0SACaLRqccJgcMklJptmmMyMfWy8wRyFMkcWSnv Bf7i8FnVng9r0+bFG86FZVo2WyLuy2EgbaE9XiVJSuWCQpAIzR+HCxUfHD7RLe116+Y8 2U2zvXYIODnDHI//GSgoasgL9pbjZ1g3H/UgDQj6DLJwf51N9b+zCe9r0BngK00X7jU0 0fG4cgVmczqXWPI+fu8qfo9if69M6mTAjaHStuYN1vXN2V/SuyR1/CdG70kdm84YpKWc 0mHWbNgckxBTiP2/fPbZD9u/2w1BKrBbum6dreqEzNanVMPL4IKZ9ntDH0Qf85Y8VP8X VwqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=x45oqYNDm1uCzNJ1wOxn/rjABjEKd1PH/2crQaHh9qE=; fh=ch67BP7/MIVM+4TxlI/jIcwifNV5Fb4MVsLLwazo4eQ=; b=sAE3vF7KbiutqyEZn44T8s4Zjey/EMVez7IynAiM5kHJCD+plpFBrbmR2kzOaRvKin y6OsIlBfhS3FHg6im7tscNWo9WFxXC7ugVzoEfgv3lpA45E/lQY5dlTCH8b3WzC8F9az BwcSWwQINUAJ9A43JcBT+0/lllu+WjdQ9oVsbF47xudoDid2TtFd+HzELN16MsdfeXYe p+FaOEErFV2HK5c7ZmYu0zjnbVeQ64t7owadL2CNE3ptMHJicYFhXyJGA1GkbrAbJ3oT Yx5hDo+F9Gpp5m0MNe2gRt5ozYsQKLiSBcOmUCBCE38UgSoOCurXOMeEg2/Js00Q6cSU uw5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fATHKtax; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x14-20020aa7940e000000b006be1dd29127si2133419pfo.127.2023.10.17.12.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 12:24:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fATHKtax; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4D11180FA86B; Tue, 17 Oct 2023 12:24:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343522AbjJQTYd (ORCPT + 99 others); Tue, 17 Oct 2023 15:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343990AbjJQTYb (ORCPT ); Tue, 17 Oct 2023 15:24:31 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E4CC4 for ; Tue, 17 Oct 2023 12:24:29 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7a5a746e355so148810039f.0 for ; Tue, 17 Oct 2023 12:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697570668; x=1698175468; darn=vger.kernel.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=x45oqYNDm1uCzNJ1wOxn/rjABjEKd1PH/2crQaHh9qE=; b=fATHKtaxTWO1mHA67kn+fhIImZnkbZQa7FZQV+O577Drv9qyAfAEVX2EwDnpxj0vmm Cgv7XTCWy5YxQAOsWmAqzR4xURBzaV6p5oGJQ82Ok5zcehyOzEnXi14s2At+MfjFh0IF Da0cRpAZnliRiH55HyLSI6JDuSgMdYPturBLHtq/LwUaDAWMnBTddJ7qd9Dg2ExJGE8W lijyHZ9c/fM7Y8IVesSyuj6S6sGIkwnK8DOqrt5q33IsrUObTFYNdX/lKsFnwvO99sQr 726V7GbfR7wnRNO0tHCMJ/dMprYXq69Aubzht8nNal4FscZQMso9K9qu+6la7ovbfeyq tB/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697570668; x=1698175468; 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=x45oqYNDm1uCzNJ1wOxn/rjABjEKd1PH/2crQaHh9qE=; b=KnIaLmyif7/hTzHMs3I5X3bpjyhFff7FyaRZx9h9QSEPnqn2c0X965/P4MppKoJf/t 0nc8Gt+UTXMT01uHkEQBywwN9JjifavzR1kiqnw1ZKl2F47kUlMnTJmaN8NXD4KYS0wK YPGNHWN1bplEV64FKH7Ar4is3w7TbtG0+B9YDz4T/Jk5e928ZmLAZwNSYBSmDHQTP+Yv kTPZyYObiS2a9LhDmIgiq9h9Bb5Q2FCF1kldkLmTnqH7kI4C+pNyrb8WAVpoVSUsLJH7 kX8rwCpwwjyeaoJMZeXSMWwzxocR8a16nLDL00agrnnCJEGGa12kdAICsBqApafdBwwI iOQg== X-Gm-Message-State: AOJu0YyeL31pCT2CEraSdtSyT+vWAoGn0RITfD5z9HAyZo9Zgj3b87fH afJA7S1sKbNHCjp3k+ipxTe4NMBiN3td3uhB6qA= X-Received: by 2002:a05:6602:1651:b0:79d:27ef:23c3 with SMTP id y17-20020a056602165100b0079d27ef23c3mr2825049iow.5.1697570668445; Tue, 17 Oct 2023 12:24:28 -0700 (PDT) MIME-Version: 1.0 References: <20231017003519.1426574-1-nphamcs@gmail.com> <20231017044745.GC1042487@cmpxchg.org> In-Reply-To: <20231017044745.GC1042487@cmpxchg.org> From: Nhat Pham Date: Tue, 17 Oct 2023 12:24:17 -0700 Message-ID: Subject: Re: [PATCH 0/2] minimize swapping on zswap store failure To: Johannes Weiner Cc: Yosry Ahmed , akpm@linux-foundation.org, cerasuolodomenico@gmail.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, hughd@google.com, corbet@lwn.net, konrad.wilk@oracle.com, senozhatsky@chromium.org, rppt@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, david@ixit.cz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 12:24:35 -0700 (PDT) On Mon, Oct 16, 2023 at 9:47=E2=80=AFPM Johannes Weiner wrote: > > On Mon, Oct 16, 2023 at 05:57:31PM -0700, Yosry Ahmed wrote: > > On Mon, Oct 16, 2023 at 5:35=E2=80=AFPM Nhat Pham w= rote: > > > > > > Currently, when a zswap store attempt fails, the page is immediately > > > swapped out. This could happen for a variety of reasons. For instance= , > > > the compression algorithm could fail (such as when the data is not > > > compressible), or the backend allocator might not be able to find a > > > suitable slot for the compressed page. If these pages are needed > > > later on, users will incur IOs from swapins. > > > > > > This issue prevents the adoption of zswap for potential users who > > > cannot tolerate the latency associated with swapping. In many cases, > > > these IOs are avoidable if we just keep in memory the pages that zswa= p > > > fail to store. > > > > > > This patch series add two new features for zswap that will alleviate > > > the risk of swapping: > > > > > > a) When a store attempt fail, keep the page untouched in memory > > > instead of swapping it out. > > > > What about writeback when the zswap limit is hit? I understand the > > problem, but I am wondering if this is the correct way of fixing it. > > We really need to make zswap work without a backing swapfile, which I > > think is the correct way to fix all these problems. I was working on > > that, but unfortunately I had to pivot to something else before I had > > something that was working. > > > > At Google, we have "ghost" swapfiles that we use just to use zswap > > without a swapfile. They are sparse files, and we have internal kernel > > patches to flag them and never try to actually write to them. > > > > I am not sure how many bandaids we can afford before doing the right > > thing. I understand it's a much larger surgery, perhaps there is a way > > to get a short-term fix that is also a step towards the final state we > > want to reach instead? > > I agree it should also stop writeback due to the limit. > > Note that a knob like this is still useful even when zswap space is > decoupled from disk swap slots. We still are using disk swap broadly > in the fleet as well, so a static ghost file setup wouldn't be a good > solution for us. Swapoff with common swapfile sizes is often not an > option during runtime, due to how slow it is, and the destabilizing > effect it can have on the system unless that's basically completely > idle. As such, we expect to continue deploying swap files for physical > use, and switch the zswap-is-terminal knob depending on the workload. > > The other aspect to this is that workloads that do not want the > swapout/swapin overhead for themselves are usually co-located with > system management software, and/or can share the host with less > latency sensitive workloads, that should continue to use disk swap. > > Due to the latter case, I wonder if a global knob is actually > enough. More likely we'd need per-cgroup control over this. > > [ It's at this point where the historic coupling of zswap to disk > space is especially unfortunate. Because of it, zswap usage counts > toward the memory.swap allowance. If these were separate, we could > have easily set memory.zswap.max=3Dmax, memory.swap.max=3D0 to achieve > the desired effect. > > Alas, that ship has sailed. Even after a decoupling down the line it > would be difficult to change established memory.swap semantics. ] > > So I obviously agree that we still need to invest in decoupling zswap > space from physical disk slots. It's insanely wasteful, especially > with larger memory capacities. But while it would be a fantastic > optimization, I don't see how it would be an automatic solution to the > problem that inspired this proposal. > > We still need some way to reasonably express desired workload policy > in a setup that supports multiple, simultaneous modes of operation. > > > > b) If the store attempt fails at the compression step, allow the page > > > to be stored in its uncompressed form in the zswap pool. This maintai= ns > > > the LRU ordering of pages, which will be helpful for accurate > > > memory reclaim (zswap writeback in particular). > > > > This is dangerous. Johannes and I discussed this before. This means > > that reclaim can end up allocating more memory instead of freeing. > > Allocations made in the reclaim path are made under the assumption > > that we will eventually free memory. In this case, we won't. In the > > worst case scenario, reclaim can leave the system/memcg in a worse > > state than before it started. > > Yeah, this is a concern. It's not such a big deal if it's only a few > pages, and we're still shrinking the footprint on aggregate. But it's > conceivable this can happen systematically with some datasets, in > which case reclaim will drive up the memory consumption and cause > OOMs, or potentially deplete the reserves with PF_MEMALLOC and cause > memory deadlocks. > > This isn't something we can reasonably accept as worst-case behavior. > > > Perhaps there is a way we can do this without allocating a zswap entry? > > > > I thought before about having a special list_head that allows us to > > use the lower bits of the pointers as markers, similar to the xarray. > > The markers can be used to place different objects on the same list. > > We can have a list that is a mixture of struct page and struct > > zswap_entry. I never pursued this idea, and I am sure someone will > > scream at me for suggesting it. Maybe there is a less convoluted way > > to keep the LRU ordering intact without allocating memory on the > > reclaim path. > > That should work. Once zswap has exclusive control over the page, it > is free to muck with its lru linkage. A lower bit tag on the next or > prev pointer should suffice to distinguish between struct page and > struct zswap_entry when pulling stuff from the list. Hmm I'm a bit iffy about pointers bit hacking, but I guess that's the least involved way to store the uncompressed page in the zswap LRU without allocating a zswap_entry for it. Lemme give this a try. If it looks decently clean I'll send it out :) > > We'd also have to teach vmscan.c to hand off the page. It currently > expects that it either frees the page back to the allocator, or puts > it back on the LRU. We'd need a compromise where it continues to tear > down the page and remove the mapping, but then leaves it to zswap. > > Neither of those sound impossible. But since it's a bigger > complication than this proposal, it probably needs a new cost/benefit > analysis, with potentially more data on the problem of LRU inversions. > > Thanks for your insightful feedback, Yosry.