Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1566514lqt; Wed, 20 Mar 2024 07:48:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWelVQmGTMgpwf74kKdCZoseT+eLhWRoUfaKGr3j/cs8h6XT5yUXT6+kMsk5eRwn6n5i2NtbD07yVlvUlT+7PiL5B1Ic9BI0nS1CRPHgQ== X-Google-Smtp-Source: AGHT+IHObmbacHmpxvjHCokdNe1ElRD/u3jhNWYNWHopdejDAaVM2JZFOM/eDEc5OtzlS/Yj3aNX X-Received: by 2002:a05:622a:2b4c:b0:42e:da48:fbb3 with SMTP id hb12-20020a05622a2b4c00b0042eda48fbb3mr22233922qtb.41.1710946113465; Wed, 20 Mar 2024 07:48:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710946113; cv=pass; d=google.com; s=arc-20160816; b=pLG9gwE+99JJI0oejjA7VNuUkgYKBq1RhBvh30LGnJCGXw8n0mu6qAZVD6RmHxWmRe ilQ8F/aC9WSMoYdF8isxk8cLWGaqk2P/mx4Z7SNhvJlar+6dxnoaSEwoovyNRtDMVvev PFQAU8mi9vllci+Ca4sfgCQwJCABv1NveWo+cUVXLHB1wCcFpAJG08DzI/cgjeRekaem OWOMaUZD+EORp+130GjhiSxBiFp45y3muMmcZJBxnjBxhQxbd4Z+Eayl57w6Wlg8keOP FQ0iNKpJh22b+SwY1uS9RIVi8jOzcTzwG8ztJkWRQE8fA5bXJgZGjABqUWTeqEEb3Ham u2Hw== ARC-Message-Signature: i=2; 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=/ltmvM0w70xtErdmc5CdiNk2BYEMlEM19F2i3B/Nu+0=; fh=PGLXPqdjE+EzmhCcNFEY85BtoVdoGIoWj1lYndvyeG8=; b=mkLSuzBVM2iKCfase8pDRmUoQB7OCps9Cu0HfyS4Z+dwhXd6EUG17+GCIpea9JLLPK MRxz3tzmCVgL5BnCq1eIN/2qVy3xaQoyBiAGvDIBIjex3K75jQLG/Q8Y0WVeR+kPvFTV 7FVX43gop+Xv+sIoui/wG6wBCd8FKflUY2gERQo97Xth9uBJ8wGINPiOwaB/F9voF9Ni 4jqEjxrGtIbboQNRzBbkr1ANSSonTMyvPWNj97BH3nbtO6AMXwYS+NhI+/ixbp58zm/d YzIBMv496fmoHJ/B/R4JmLxa2z/poN6EMpNy4m2qH4ULNQ/QFy0LK4YLZmkkMgg57u47 svtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ih9Nofii; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-109029-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109029-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f5-20020a05622a104500b00430d0727b10si6991178qte.423.2024.03.20.07.48.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 07:48:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109029-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ih9Nofii; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-109029-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109029-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 25D5F1C21F60 for ; Wed, 20 Mar 2024 14:48:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9DEF482C3; Wed, 20 Mar 2024 14:48:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ih9Nofii" Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (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 66DED39AE3 for ; Wed, 20 Mar 2024 14:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710946107; cv=none; b=qm9M03bkTPCkSTX/Wq2IXFaNmzSOTxD8dCpue+6af5d1tDj46oeiKaLygg3kG9ogE2ppCoR24O7Zb9xHMDBO3DIN48h+oNY389sQF1qVRpVnJC6n7yH4QWL1VW+qO3FIL0uRQM/pg0LSavBfZ8uUEdhEmkZf4EmQLzX/PqOJiJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710946107; c=relaxed/simple; bh=/ltmvM0w70xtErdmc5CdiNk2BYEMlEM19F2i3B/Nu+0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=brqQlVLUWdgzHM5ukud1uh8Zb1rUc++5eqCDRsr/nD0C4f8BjMZsRR0+oAhVV5h/TOQ05ndvecb4T78NE8mCynHABetTcJ40sKtvRVgsOwsKao2+l2FsGXcX44JhFVDDH72jE6Vl7fyMjZg7aEgPGUXDNLkidekTlGj47I44Kwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ih9Nofii; arc=none smtp.client-ip=209.85.221.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-4d46c4e1578so910963e0c.3 for ; Wed, 20 Mar 2024 07:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710946104; x=1711550904; 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=/ltmvM0w70xtErdmc5CdiNk2BYEMlEM19F2i3B/Nu+0=; b=ih9Nofii8CTmBo6oWVu9uzFvWvjcgtG5y9vQZyJ/Ocw7kdOUtnuSsEFLN0Pbi9HMi8 PGjJKyO2aawYeazndoht2s0AdtHQhOl3cb45yBEyj3AqakFH2BifqnD/flo84PENLzTt +Ppe8vXpF8flFq57LVyfDCuyzWV5h23Hc4CMUayvvJF/4BTuQSjfkamLujXH/PiuOV/E if+rHZCLXIuPA2xWWXfrsk9ldOepi8eIipkbYm5ibJdgWV/nd/Xbi5C+g6Ti/CU3/1M9 APkBnx6IHWhinotu0FJ0+jjlqKAYHIuItoy/mKZaBVmZd+u1VDdY8zT/9JsPk5i2i4qp VW9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710946104; x=1711550904; 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=/ltmvM0w70xtErdmc5CdiNk2BYEMlEM19F2i3B/Nu+0=; b=fzRHJ1WGiDfs4GZryd6arAORBhO1tN4TSA5aEGLSG0YeJN4L7I2GDoyQCwpT/MWuCO PSZDvOEtyEccXDW5HfaMPqI0TLZ+PwBqVgrqSAoCCQO8eOPm4+RhMg6yzc5FjW/GxYog 3fxPS3mB+ch8JZ/a6NOWW6WklrDw/YVp84ZKKhTixaFbU9s+wDPY+K6saVWa+fT+y8aD QBaklaJBsnvrAezGydL9ljq20oPqP4N00+QSwcBM95Yh1lQqIo1T2sYNBhp+BnYoU/ml qlutp1zi6P+2ouR6dWqBZu6DCbAM4rFMyTAXUbIas7+fMyl6+ZxWTGNBWGp9ITb9JD6E VTWQ== X-Forwarded-Encrypted: i=1; AJvYcCWSRUoPDeW4fUVHodZCqhQKjWrJPSFayNymDfUmHtperoW/54LdXNsa7pRn4+59DevzEPA3Z2rn9/LVWD/DFuFZIhmehBGDzc0slmLY X-Gm-Message-State: AOJu0YwPMqLW8/tiPQvLhTiYEZQEdVCFib3qE1D1NwhELdq+uPJmzkhg x44hZmoXokOuZfLd7mikx3zw2bql5Kzz0kFu0ejcgI9Zw5+rgy0jqMK3ripX5p9EjJaLLWPzl8a h8ojSizzPcvbbKMZPc3aIJznM3rE= X-Received: by 2002:a05:6122:2514:b0:4c9:98f8:83db with SMTP id cl20-20020a056122251400b004c998f883dbmr18719446vkb.5.1710946104139; Wed, 20 Mar 2024 07:48:24 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240320020823.337644-1-yosryahmed@google.com> <20240320095053.GA294822@cmpxchg.org> In-Reply-To: <20240320095053.GA294822@cmpxchg.org> From: Nhat Pham Date: Wed, 20 Mar 2024 07:48:13 -0700 Message-ID: Subject: Re: [PATCH 1/2] mm: zswap: increase shrinking protection for zswap swapins only To: Johannes Weiner Cc: Yosry Ahmed , Andrew Morton , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 20, 2024 at 2:51=E2=80=AFAM Johannes Weiner wrote: > > On Wed, Mar 20, 2024 at 02:08:22AM +0000, Yosry Ahmed wrote: > > Currently, the number of protected zswap entries corresponding to an > > lruvec are incremented every time we swapin a page. > > Correct. This is the primary signal that the shrinker is being too > aggressive in moving entries to disk and should slow down...? Yup. Currently, there are two scenarios in which we increase zswap protection area: 1. zswap lru movement - for instance, if a page for some reasons is rotated in the LRU. When this happens, we increment the protection size, so that the page at the tail end of the protected area does not lose its protection because of (potentially) spurious LRU churnings. 2. swapin - when this happens, it is a signal that the shrinker is being too... enthusiastic in its reclaiming action. We should be more conservative, hence the increase in protection. I think there's some confusion around this, because we use the same-ish mechanism for two different events. Maybe I should have put yet another fat comment at the callsites of zswap_folio_swapin() too :) > > > This happens regardless of whether or not the page originated in > > zswap. Hence, swapins from disk will lead to increasing protection > > on potentially stale zswap entries. Furthermore, the increased Hmmm my original thinking was that, had we protected the swapped-in page back when it was still in zswap, we would have prevented this IO. And since the pages in zswap are (at least conceptually) "warmer" than the swapped in page, it is appropriate to increase the zswap protection. In fact, I was toying with the idea to max out the protection on swap-in to temporarily cease all zswap shrinking, but that is perhaps overkill :) > > shrinking protection can lead to more pages skipping zswap and going I think this can only happen when the protection is so strong that the zswap pool is full, right? In practice I have never seen this happen though. Did you observe it? We have a fairly aggressive lru-size-based protection decaying as well, so that should not happen... Also technically the protection only applies to the dynamic shrinker - the capacity-driven shrinking is not affected (although it's not very effective - perhaps we can rework this?) > > to disk, eventually leading to even more swapins from disk and > > starting a vicious circle. > > How does shrinker protection affect zswap stores? > > On the contrary, I would expect this patch to create a runaway > shrinker. The more aggressively it moves entries out to disk, the > lower the rate of zswap loads, the more aggressively it moves more > entries out to disk. > > > Instead, only increase the protection when pages are loaded from zswap. > > This also has a nice side effect of removing zswap_folio_swapin() and > > replacing it with a static helper that is only called from zswap_load()= . > > > > No problems were observed in practice, this was found through code > > inspection. > > This is missing test results :) Yeah it'd be nice to see benchmark numbers :) I mean all this protection is heuristics anyway, so maybe I'm just being overly conservative. But only numbers can show this.