From patchwork Sat Jul 20 04:41:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takero Funaki X-Patchwork-Id: 13737610 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 0A706C3DA64 for ; Sat, 20 Jul 2024 04:41:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BF596B0089; Sat, 20 Jul 2024 00:41:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8208F6B008C; Sat, 20 Jul 2024 00:41:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 657F96B0092; Sat, 20 Jul 2024 00:41:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4411D6B0089 for ; Sat, 20 Jul 2024 00:41:44 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B8E2A140A7F for ; Sat, 20 Jul 2024 04:41:43 +0000 (UTC) X-FDA: 82358882886.28.5AB86B0 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf26.hostedemail.com (Postfix) with ESMTP id DC8EA140013 for ; Sat, 20 Jul 2024 04:41:41 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gDv33nXh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of flintglass@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=flintglass@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721450467; a=rsa-sha256; cv=none; b=u/eJbI9CRb1UQudoE/ZHvuoUeTpKo7rBpB4S7/jSQB2lfRKbiT9A/REVza7rlTi9XsepOZ 1r6Kb6saReMo5VzRn/HvB7J3iwkF/g1kang0YcPSuX8Pm73bgpOYxt7cjTtN/dhEyGEG0n FzdM7tohw+lkGpHlUdXwpSQTOnXE3o8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gDv33nXh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of flintglass@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=flintglass@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721450467; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vVw0vATACj76JfvzKQY4usxRkR0Oycm1bE+vKC2rk9g=; b=zmkUBtPo9zHsohPG6HT6LUHuJbZ5ST+SLQWYo55XFDgQuAvgqf9AI2tw8R7KRxZclxcD7J Kx3/PVh4BY865E3sLvteH1CQHGNslAfNnSbXI39wtcGwTwCRmfGKLZV+BCPFz/Hvkh1cmw wcdH3XXeP8qa/GBbyFxFkPwPRV+TxpI= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-70b0e7f6f8bso1319839b3a.3 for ; Fri, 19 Jul 2024 21:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721450500; x=1722055300; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vVw0vATACj76JfvzKQY4usxRkR0Oycm1bE+vKC2rk9g=; b=gDv33nXhTWbZ/1h8n9MTQhfdVRxhkGYQzsi4GDGJ2Pllqn1yvKcBe7yhuI/zjcfMTS n5b07+MYlPsfFtnw5D4rwS1lHKGO4U/PQIgfMSfaPKKS1t4Nb2pichAh/Xaazl2Txm34 f4AQgcGCVpb/Xq5kWMDm/uuwGgXApY1FsVPD6eUGD196963qplKbM8/fCLW532Nt90n6 h6Va61tOXbNFlqgx91v8EuuSV6/23Vwv3+OjW+e6YRZSor9KoeNYPxu5ulLGkJRINqSW 0fWjHJr+wiz6MXcoPVZiVkQhasNFs22/DlBYDJf8PeiUTfAHRvvJuOOgMPHCcUUU/Cqx TR2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721450500; x=1722055300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vVw0vATACj76JfvzKQY4usxRkR0Oycm1bE+vKC2rk9g=; b=gxdrEmkNIoQbseE9fD10lI1PWR2rPZyzxPQi2cLZWAPQ3pbh1lK77zXxzoADPHdqgZ MP4AQuykigw3HMkz7colB35dXRZnvMpZHoiwo9DWcT6gdfFfncRvM4TZzv53WnQYfD1/ AhmYdpk12u7CIXgAFO+DBFSxA5+VtRsdP+1/YH468KWP6zZsbxD1TIXMo4YdJ+3fDx+A rfRUZdKllsQ+kqDuH4YaXQPtYoZ09bM0jkv0NJh4PZNJBBYL8zcHyCYU5uPI774DEotM y4ZDGFJ7yQPTbpqclgTzp4Aw1oGPL5Wbu+P5d67trTqGDtGbE6QE+24nhAvzYHplavf+ 7h3Q== X-Forwarded-Encrypted: i=1; AJvYcCXjl7+Wcg+6GyntsFYEDycTzbsUUmds+ED/Xjz6fYkxm55VJL/ne5nII52pJAiljeBT+jZNzTpQcBBtRH8dctxVnSg= X-Gm-Message-State: AOJu0YxHCUgmbBmna6upIoUMfvxY60kyVfbwDWFa69Yv4bhI3eL1/emv e4kjDpW0NliSSKeiX6NtdFUQQ8/I9PssYc2Qcep12dHLe+aJ3QZm X-Google-Smtp-Source: AGHT+IEBS8Y5Ko/VqlXvrI1x+MdtVUYash+4xiAPzeysJsdDGDKxK2XNTIGZDknK0HVwrl0eHrrHzA== X-Received: by 2002:a05:6a21:710a:b0:1c2:92ad:3331 with SMTP id adf61e73a8af0-1c4285b7637mr683649637.2.1721450500245; Fri, 19 Jul 2024 21:41:40 -0700 (PDT) Received: from cbuild.incus (h101-111-009-128.hikari.itscom.jp. [101.111.9.128]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f315c11sm13023465ad.125.2024.07.19.21.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 21:41:39 -0700 (PDT) From: Takero Funaki To: Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Andrew Morton Cc: Takero Funaki , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] mm: zswap: fix global shrinker error handling logic Date: Sat, 20 Jul 2024 04:41:25 +0000 Message-ID: <20240720044127.508042-3-flintglass@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240720044127.508042-1-flintglass@gmail.com> References: <20240720044127.508042-1-flintglass@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DC8EA140013 X-Stat-Signature: umsp11o5kkh5ruothw5xoepphrzigx5r X-Rspam-User: X-HE-Tag: 1721450501-820955 X-HE-Meta: U2FsdGVkX18g/nOkZJby2XpRwPcxlHNSf+zu8qoNPCPWS/Bj/zZYcBsUMJgDOnclPpKDZ+gCxGA9ZKFhXG5cK1zYjBsrq7hsdbKOqKwVnm/xe3g8aPPz4u8JyMOdeZHe5+UhPyoqSAF3CXs5XEtXqEy25ngx/o2LzajZgUCVhBUL7dp69o+soGETEKr/MIz/Bo1vVoRrbhLllJA5SCMwqu5UVvebXOwsUfMYFD8hyrEwM7e9ZID/3XwUkAgdhXbqMpSHfbNheYxlD6clEg9HqhSmgB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ests=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: This patch fixes zswap global shrinker that did not shrink zpool as expected. The issue it addresses is that `shrink_worker()` did not distinguish between unexpected errors and expected error codes that should be skipped, such as when there is no stored page in a memcg. This led to the shrinking process being aborted on the expected error codes. The shrinker should ignore these cases and skip to the next memcg. However, skipping all memcgs presents another problem. To address this, this patch tracks progress while walking the memcg tree and checks for progress once the tree walk is completed. 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 --- mm/zswap.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6528668c9af3..053d5be81d9a 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1310,10 +1310,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 @@ -1327,14 +1327,19 @@ 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, progress = 0; unsigned long thr; /* Reclaim down to the accept threshold */ @@ -1379,9 +1384,12 @@ static void shrink_worker(struct work_struct *w) */ if (!memcg) { spin_unlock(&zswap_shrink_lock); - if (++failures == MAX_RECLAIM_RETRIES) + + /* tree walk completed but no progress */ + if (!progress && ++failures == MAX_RECLAIM_RETRIES) break; + progress = 0; goto resched; } @@ -1396,10 +1404,13 @@ static void shrink_worker(struct work_struct *w) /* drop the extra reference */ mem_cgroup_put(memcg); - if (ret == -EINVAL) - break; + if (ret == -ENOENT) + continue; + if (ret && ++failures == MAX_RECLAIM_RETRIES) break; + + ++progress; resched: cond_resched(); } while (zswap_total_pages() > thr);