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 18271C3DA64 for ; Thu, 1 Aug 2024 07:40:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A21EA6B00A2; Thu, 1 Aug 2024 03:40:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D3256B00A3; Thu, 1 Aug 2024 03:40:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 899026B00A4; Thu, 1 Aug 2024 03:40:28 -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 6BEA16B00A2 for ; Thu, 1 Aug 2024 03:40:28 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1E43CA08ED for ; Thu, 1 Aug 2024 07:40:28 +0000 (UTC) X-FDA: 82402878936.26.FD91138 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by imf19.hostedemail.com (Postfix) with ESMTP id DE4851A0015 for ; Thu, 1 Aug 2024 07:40:25 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=a3Y8tU0A; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722497963; 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=/u+SH4i1Z7tjJAmzXcks2waJHC8XQ7VaoTerFrtHEN0=; b=IBFUwkUO4o/j01V5W3CkoklEn3hothHZHTWtxlJmryvKJnHm70LfER5v5OhdgskR9+LgHy OsPXnEC4k3Q7XyjKyWGgKMitD7NSyHpiDQljaoGN2jGkHFb0J4t+fBhPjcxhyWQY1ZVrnC zi4BpEFXb/DXjuuvpiglKqh3CroX3ng= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722497963; a=rsa-sha256; cv=none; b=W0NMG6hmkFgCdUJhoQb9PVttHdJo+AGVh3Y8Ei1D2TkmiHpNpNkTBO/IfnIAw8t9TOJ3+K XuIqrP7ljjDkKL38yPhLaFrq2DO53DCUlW8dFC2iS0WbNR6G9rRuOt7dG1+m9sLLAEpZJT UQYdK/Ukh4vdFWF2qCuQWG/2DTA/zYU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=a3Y8tU0A; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev Message-ID: <1f6b254f-9cb9-412e-b249-8efe1d4157d3@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1722498023; h=from:from: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; bh=/u+SH4i1Z7tjJAmzXcks2waJHC8XQ7VaoTerFrtHEN0=; b=a3Y8tU0AFKNAPurAuJwvW1gPaQoLKgF4o5a3ubZhr6ExwgDRneIMW/p8t815nAVbWP2oPB CvLQBA2YyuExTus+UPHw1EVawPqCXOWZ07o1n3MwLg3MjcP4TlpVK2z9EFeV6tCMgosJIa VBhzrY02K8sN4mJEzi3MomWKS5V+cD0= Date: Thu, 1 Aug 2024 15:40:16 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v5 2/2] mm: zswap: fix global shrinker error handling logic To: Takero Funaki , Johannes Weiner , Yosry Ahmed , Nhat Pham , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240731004918.33182-1-flintglass@gmail.com> <20240731004918.33182-3-flintglass@gmail.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20240731004918.33182-3-flintglass@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DE4851A0015 X-Stat-Signature: ueobm5yotgom19h793p9rpdppt89qaii X-Rspam-User: X-HE-Tag: 1722498025-508749 X-HE-Meta: U2FsdGVkX18sMFoG8oBZRvTBvibJpiYhgxSkCJ/kLNehVfe8Yp9xXbxizNln9Z+aYyStEM8XTKRYPvqQA3OEe1ja8oLlKe0tMb8e8m/OA6HSRgCOUhS4aR88YOL3/yG+F4jKqBaqe62cvgLh0tWktDsAmQhN8lJYCX/77SrEw5z04qZIpIxzqtkGobjTZIeFdG6QVtr7uGF/dN9Nso0KJ/g2ppJopTQn5cit4hAi6nnQDOjfo4DI4UfE2g/iQVabzkmKMaWVmXJMY9s0eXElb+yfwcG9ntdRsSsqLQA8dAE2xkZG3lVIxojLcbSjD4lK9SotwZGuaofH0jirp29ep/UBgnyCFKgXFeP7azY6WVFBOwvLkHZlRnPDyaofLBTGvhaiHhFNCj7N7Oai6au9ukSuLlj9fjoRCgzcS2SyJHOXxGuTglaoq3MEbq31XpfBCcpzohxRBYsQN/S3PrsucPKpeDKrW18dCEzqwyX3XbhD2muaQSVJk8khIhmykY5gauCqcaPpCnEjDrB4ibxfWBxBOAvC4hv7HXUe0JfIZqQLTQyFL+eO4soizGlXbrBMbVQITTj+GdQEimX7ZqRF/1/PCjJFOqMq3I324y0sXDlvZCHeLYlxiOFcvz+n7M7frf4S3YCVQbWD7i5mVsQiXgj9TI7/ajvm0jvbB0LtQuKrQQ/OIYo36FkVREJlpxzzhazN12PhitBIjNraQ7YTsWmLTqJE4CB4ceY54k7iY8gLu+z7FmLhQYmvZ+yB+jnlEx78lpSrC0/5zZbnJJ3OVDDhQAwH73rH+1BLaxfCFd8+/5bb85A+cOWyVXFyvSJFEh0OrDiwhfoNTzS+E8JEN7SQkYSj9S3zQBlhQvenQ32JB4+WeqnvuvJXAdutPA1+NXTOGFB42T7DSumVbjTe+2gJY4Z3Gh+Yt5w8UNomF0/K9xADUixmZdb+kXdQx2XRGkzW+HixADstPE8RXoq c6fL7cQX rJXr+FKwvw2w6L32vH+mcNLPJZbkwfQCcM41EwLqTWsh8ozM55y4n/F96l9p5exqDZAnTqhKfGsojctdxMxoiJHMm/mChEe9eoYb2rmbrff0k692yyqL5tZyURSD6mr6rwUmkIjXEdGytG5Q= 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: List-Subscribe: List-Unsubscribe: On 2024/7/31 08:49, Takero Funaki wrote: > This patch fixes the zswap global shrinker, which did not shrink the > zpool as expected. > > The issue addressed is that shrink_worker() did not distinguish between > unexpected errors and expected errors, such as failed writeback from an > empty memcg. The shrinker would stop shrinking after iterating through > the memcg tree 16 times, even if there was only one empty memcg. > > With this patch, the shrinker no longer considers encountering an empty > memcg, encountering a memcg with writeback disabled, or reaching the end > of a memcg tree walk as a failure, as long as there are memcgs that are > candidates for writeback. Systems with one or more empty memcgs will now > observe significantly higher zswap writeback activity after the zswap > pool limit is hit. > > To avoid an infinite loop when there are no writeback candidates, this > patch tracks writeback attempts during memcg tree walks and limits > reties if no writeback candidates are found. > > To handle the empty memcg case, the helper function shrink_memcg() is > modified to check if the memcg is empty and then return -ENOENT. > > Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware") > Signed-off-by: Takero Funaki Looks good to me: Reviewed-by: Chengming Zhou Thanks. > --- > mm/zswap.c | 40 +++++++++++++++++++++++++++++++++------- > 1 file changed, 33 insertions(+), 7 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 3c16a1192252..d46caa42ed4f 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1287,10 +1287,10 @@ static struct shrinker *zswap_alloc_shrinker(void) > > static int shrink_memcg(struct mem_cgroup *memcg) > { > - int nid, shrunk = 0; > + int nid, shrunk = 0, scanned = 0; > > if (!mem_cgroup_zswap_writeback_enabled(memcg)) > - return -EINVAL; > + return -ENOENT; > > /* > * Skip zombies because their LRUs are reparented and we would be > @@ -1304,21 +1304,34 @@ static int shrink_memcg(struct mem_cgroup *memcg) > > shrunk += list_lru_walk_one(&zswap_list_lru, nid, memcg, > &shrink_memcg_cb, NULL, &nr_to_walk); > + scanned += 1 - nr_to_walk; > } > + > + if (!scanned) > + return -ENOENT; > + > return shrunk ? 0 : -EAGAIN; > } > > static void shrink_worker(struct work_struct *w) > { > struct mem_cgroup *memcg; > - int ret, failures = 0; > + int ret, failures = 0, attempts = 0; > unsigned long thr; > > /* Reclaim down to the accept threshold */ > thr = zswap_accept_thr_pages(); > > /* > - * Global reclaim will select cgroup in a round-robin fashion. > + * Global reclaim will select cgroup in a round-robin fashion from all > + * online memcgs, but memcgs that have no pages in zswap and > + * writeback-disabled memcgs (memory.zswap.writeback=0) are not > + * candidates for shrinking. > + * > + * Shrinking will be aborted if we encounter the following > + * MAX_RECLAIM_RETRIES times: > + * - No writeback-candidate memcgs found in a memcg tree walk. > + * - Shrinking a writeback-candidate memcg failed. > * > * We save iteration cursor memcg into zswap_next_shrink, > * which can be modified by the offline memcg cleaner > @@ -1356,9 +1369,14 @@ static void shrink_worker(struct work_struct *w) > spin_unlock(&zswap_shrink_lock); > > if (!memcg) { > - if (++failures == MAX_RECLAIM_RETRIES) > + /* > + * Continue shrinking without incrementing failures if > + * we found candidate memcgs in the last tree walk. > + */ > + if (!attempts && ++failures == MAX_RECLAIM_RETRIES) > break; > > + attempts = 0; > goto resched; > } > > @@ -1366,8 +1384,16 @@ static void shrink_worker(struct work_struct *w) > /* drop the extra reference */ > mem_cgroup_put(memcg); > > - if (ret == -EINVAL) > - break; > + /* > + * There are no writeback-candidate pages in the memcg. > + * This is not an issue as long as we can find another memcg > + * with pages in zswap. Skip this without incrementing attempts > + * and failures. > + */ > + if (ret == -ENOENT) > + continue; > + ++attempts; > + > if (ret && ++failures == MAX_RECLAIM_RETRIES) > break; > resched: