Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp128112rdh; Mon, 18 Dec 2023 13:54:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXJhrtud7hxaXdnn/EIAjsBNaTaLSYC2rm0kG2lp9aCFPqeIbG7lve/yJh4LBJRe67lHQZ X-Received: by 2002:a05:6358:63aa:b0:172:e0d4:43c9 with SMTP id k42-20020a05635863aa00b00172e0d443c9mr1595915rwh.10.1702936499515; Mon, 18 Dec 2023 13:54:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702936499; cv=none; d=google.com; s=arc-20160816; b=eXJN9sL6L+J955eyF7CGE0D1l3zEw9CqmgFYlpKpW2CP1ujtIrEsmjIDxH1eBcmVnq LUoJPyDPpmxEgej3fG/nUzjeTY8ZZE8SI1ndZS765VPUL1d406Ls5ULSFM3c/6YJAILJ YCoAaLWkAGe80h/G6kXV8Sf/TaU8mij+k400L4zXjNdT5bRnf2jU8AezZipkMqE/tKka u8G85gwCwenSdgw+PKZt4h80+u6RhPNC9AEcpkHT9vgECKdkdBZiGpg2c3PNzprFLcWF hqXAGDEcjcRBdbhFOEqS6pmvNhNB9BcgKqGvLsstuKVff4E6vT2Kw5nQjyJCVgRwpoYj AMyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nqsrGRSNXs2jP/UwD+ksz1Ps/gXN9w1X+zQo7BqyXLo=; fh=z3+pYQhXEzNus6Ifp6st3nfqNM/FWPIMqe4I1A6juZo=; b=Vpv/aD1mZotAv9oO9ZfCehLkpdA/DDcBLBxrcOyF4fn67NOldZZxH3XCQPsCr5SGnM NOB1Bz4w1zC8zkTg6hwDleAy0/zbhep4bCIY8UymGIEKo973Vei4Lfjvi/6WnhDKNrOK 8Nwxod4SqO+d5FPAKNM2HTtojvZl1TondVEwBcqSGZECpfyrKhfQXkwosRUkevnJORYi qsri1eRGZKxGPP74PGgNGIGX+w/ZL2CG8ZT5aRNuDMdXLgQ/bOY20MHt01UrpVcMVD9q huASpSD9/W7KPtHPk7qUEdEzpm6IXqWo+OwZjG/jUZCBlkol67zs39kuBPMsClJRhnse chVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CREFUUaD; spf=pass (google.com: domain of linux-kernel+bounces-4429-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4429-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g15-20020a056a000b8f00b0068fcc84dda7si18550899pfj.327.2023.12.18.13.54.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 13:54:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4429-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CREFUUaD; spf=pass (google.com: domain of linux-kernel+bounces-4429-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4429-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1CEAC2845B3 for ; Mon, 18 Dec 2023 21:54:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2ED8873487; Mon, 18 Dec 2023 21:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CREFUUaD" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AB4874087 for ; Mon, 18 Dec 2023 21:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f170.google.com with SMTP id 71dfb90a1353d-4b3203cdc78so600752e0c.2 for ; Mon, 18 Dec 2023 13:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702936489; x=1703541289; 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=nqsrGRSNXs2jP/UwD+ksz1Ps/gXN9w1X+zQo7BqyXLo=; b=CREFUUaDngnwzcLfkMO8Xe8wArCgVeSWTdpgNKrNRa5RW1YZyYzuyFhkYad/H7UIhb 9XADF1RQi2dhT+M0FGUfI6KPaqynSZivw8ak7+CCvh/rJYwxUUHvuMKApnfkt1kw/718 IgToQlcq0yiv6NI1OdQ2bhHYi10IvY8gEe5Bo0HnPIWTW29jCpYQ3sIm5FIqg3i6VTOB mQD1YN6cBe8N/J5YrBQG4U5eXxI3ki6eNFDbYeeT44e6y9k/gWfSxVRk/yelNIXhkPz+ 9eNCE6aQm2A0zTUEgnXt9ayinJ0t1Hzl1GcnSLa106UQaoB6RmKMUQUvTaFSJUutMxBs CVgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702936489; x=1703541289; 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=nqsrGRSNXs2jP/UwD+ksz1Ps/gXN9w1X+zQo7BqyXLo=; b=OtJ8yc8zHfEQpxKKZf2IxLWc3BZvZ06CRor4xAS2zWiNX40fD1HVuW3KFK7JcnDUDC Oz2rBqLAdR4mnC7auGl37BS3rumJpC1bOaqoWsJuYZ3E3atrqGwdQsNYTtoxpz2yGikm RNS8PpKW6TTtt2UtgehodblSwKTrmB+F+Ts4zRZ8VYCgY4/KYwwOTHNrCBtuCak4XZyF 3Upq6+2vYOW0qi2MTNyHM1drtGys1Et1rLd8VzRDtzafyZbMKgh7oV3/X1W0YX0BW+GS hExOBUlxE2osGNYpgYOQUWHY9bvCqFby1r51FMVErL8tx2nUzF/6KsWl0QoSpE1Oa+Mu ULWg== X-Gm-Message-State: AOJu0Yz/yT33tMFeFI07jvU9MkXb3osIGzGDlG3vz6UVvWuovLBYDgb/ lTbX8kf363WJQOhkD26NL3XXC33PfTbvATNiijDNpQ== X-Received: by 2002:a05:6122:3129:b0:4b2:c555:386 with SMTP id cg41-20020a056122312900b004b2c5550386mr12663985vkb.28.1702936488976; Mon, 18 Dec 2023 13:54:48 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231207192406.3809579-1-nphamcs@gmail.com> <20231218144431.GB19167@cmpxchg.org> In-Reply-To: From: Yosry Ahmed Date: Mon, 18 Dec 2023 13:54:11 -0800 Message-ID: Subject: Re: [PATCH v6] zswap: memcontrol: implement zswap writeback disabling To: Nhat Pham Cc: Johannes Weiner , akpm@linux-foundation.org, tj@kernel.org, lizefan.x@bytedance.com, cerasuolodomenico@gmail.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, 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, linux-doc@vger.kernel.org, david@ixit.cz, chrisl@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 11:21=E2=80=AFAM Nhat Pham wrot= e: > > On Mon, Dec 18, 2023 at 6:44=E2=80=AFAM Johannes Weiner wrote: > > > > On Fri, Dec 15, 2023 at 01:21:57PM -0800, Yosry Ahmed wrote: > > > On Thu, Dec 7, 2023 at 11:24=E2=80=AFAM Nhat Pham = wrote: > > > > > > > > During our experiment with zswap, we sometimes observe swap IOs due= to > > > > occasional zswap store failures and writebacks-to-swap. These swapp= ing > > > > IOs prevent many users who cannot tolerate swapping from adopting z= swap > > > > to save memory and improve performance where possible. > > > > > > > > This patch adds the option to disable this behavior entirely: do no= t > > > > writeback to backing swapping device when a zswap store attempt fai= l, > > > > and do not write pages in the zswap pool back to the backing swap > > > > device (both when the pool is full, and when the new zswap shrinker= is > > > > called). > > > > > > > > This new behavior can be opted-in/out on a per-cgroup basis via a n= ew > > > > cgroup file. By default, writebacks to swap device is enabled, whic= h is > > > > the previous behavior. Initially, writeback is enabled for the root > > > > cgroup, and a newly created cgroup will inherit the current setting= of > > > > its parent. > > > > > > > > Note that this is subtly different from setting memory.swap.max to = 0, as > > > > it still allows for pages to be stored in the zswap pool (which its= elf > > > > consumes swap space in its current form). > > > > > > > > This patch should be applied on top of the zswap shrinker series: > > > > > > > > https://lore.kernel.org/linux-mm/20231130194023.4102148-1-nphamcs@g= mail.com/ > > > > > > > > as it also disables the zswap shrinker, a major source of zswap > > > > writebacks. > > > > > > > > Suggested-by: Johannes Weiner > > > > Signed-off-by: Nhat Pham > > > > Reviewed-by: Yosry Ahmed > > > > > > Taking a step back from all the memory.swap.tiers vs. > > > memory.zswap.writeback discussions, I think there may be a more > > > fundamental problem here. If the zswap store failure is recurrent, > > > pages can keep going back to the LRUs and then sent back to zswap > > > eventually, only to be rejected again. For example, this can if zswap > > > is above the acceptance threshold, but could be even worse if it's th= e > > > allocator rejecting the page due to not compressing well enough. In > > > the latter case, the page can keep going back and forth between zswap > > > and LRUs indefinitely. > > > > > > You probably did not run into this as you're using zsmalloc, but it > > Which is why I recommend everyone to use zsmalloc, and change the > default allocator to it in Kconfig :) > Internally, we have a cap on the compression ratio, after which we reject pages because it doesn't make sense to store them (e.g. zsmalloc will store them in a full page anyway, or the compressed size + metadata isn't worth it). I think this is where we should head upstream as well, you proposed something in the right direction with storing uncompressed pages in zswap. IOW, I think such pages should be taken out of the LRUs one way or another.