From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 C28B73BF692 for ; Mon, 29 Jun 2026 11:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782732057; cv=none; b=A4UsaIAtLEOVIrgJm/3/i4wXlMw79slrRvMY8Sl6eXoIChiW1/2siF0LmuGAxt0cIJEJuUtXtXyi58tNWW0OVOdzc3QTOTqy0nq2FfVHgGAkkt8dfccWI6CBEKjxOgv5bDNgWmLPDXdVoKMcOikS5OHgv8O3Y2OzxS9g39KHISc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782732057; c=relaxed/simple; bh=oBlqxgiOGageFSYmE0C05QIao61wUq0bgS3LnT7IDh0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qK4mcTjEfw6i7CRVE0aFKmHiM1IFJ1KGUQVMLzVFqcACSXTGJyuVsNDQKNKZLHw9KsQrq7X7AVjiU7Cshtnx2SYYSp2dHNNde+g0EGMSsADtu4dnr+pWoPX9D7Juwu5Unrk3dKN5g8lIuFc+zMYXYfCDi+yrSv2qCdON4/WiQDQ= 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=TRIh3zGt; arc=none smtp.client-ip=209.85.214.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TRIh3zGt" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2ca1479dfe0so2523235ad.1 for ; Mon, 29 Jun 2026 04:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782732055; x=1783336855; darn=vger.kernel.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=ViL3fRcEiOH5DjjJbtd4DZVU5q2T+7FWxEKjKuEIV8w=; b=TRIh3zGt417/hY8IHIlpEzZ/YXKoVu7/O7FAtWrMgJlqFeYkyL+cz40M74u5vUEKRI WrBdRl+qUc4Tha9B9jKEBDygW/vxLm8ISjcXuZMOzXrWmuyFdjR8AIzBBrw29wqCnLP8 BKU5sDdtf8VNbWpDGhr5jx9DfCyI8nMwxWRnMjtSWncGFSGF5adJYF5YPuMRjXVX7/AH 3aujJviJ6avSKhkOE7m1s9l4h88GcCxk8thUUTAH9B3AlASboGUAQ3fYqgsC3eIV0is8 /pMsHpWN6cb9uXYuVV9ZZ8gsAHlHA1I7rclXjyUOmZGxVaUVUOWImMC38cWhjeXuTVCp MLQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782732055; x=1783336855; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ViL3fRcEiOH5DjjJbtd4DZVU5q2T+7FWxEKjKuEIV8w=; b=NRmnipWSjtnx88qazsmkKyql3+umjkKYGxQmWKkaqUq7UgI0Tf762eiQ/jfHqo9yPC cD32Xpc2GQvonG964gRDXsvPqC78kPWhckrvHH9im6hYeg9QrdUFgdIIz72kRFLF+xRc fjiNIBU1jNQnmq54tp+HCFgA14lKjojcOvj0Ix2207X70HvmlX3OA2JkqQco0V00iqd6 zWnxqw1kVQT1ubMXONgtd+90nQMv7oWrdk7KgZ8GGxtshrLhQVtKisuvHcTvR1tOPAzm 95l3Gz4DuMtySn65Ei0JhuQvO7CJO4ESqWcrkO/LTUk60yWhAUvRct5bvEKqJHu5uEy7 qy5w== X-Forwarded-Encrypted: i=1; AHgh+RoD4oeSDKj+JV586gFAaamp2uM6Geui6sqEu9jQi3CVaP9K2vy+akJ+wPsiFWLmIBWK0y/Z3ft5l76hUEM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy70NANlIetJJS++pV0+CdJShzR7nGmU+lQ81i3yw6akxZnmdOv U7ze8ci3t/+ds6yEkX8tFniFrid5Nct+M47z3gPegxTsT1QBi2/3Qu38 X-Gm-Gg: AfdE7cm6stztHjcRcKbMF9QbM9bxpWCO7dsFNRp7UcMDqUN1P19kCs98G2wiUgnkfAN OVLKRD3MZMaokpGOgGE4T8/y/gzd5gVf7i9PgKd9JJvkXLyGklL8H5USN9pCKsyFoP52ARTgLCi R4BIXTwjzLrLYJznefhaSLYiAP5ebT0DD38UVjdC+jgYVvmbcx6lS9rGnWhhD/ykOIs+v1tLj24 XB6MNo6eML0k5JGT9y/uJ8u5I+P7u6yBnUtFAu51hSTL5YsWM98UfgTjeCrL9bdLj8NGsO02zN3 YV1wb3nKRHiVKiJHhszpCuAbreZWhDzfvMh7rJ/vp7rfQ1PNYVntQQBroQWDrCANpcN3rcmbzMq XG/HtoDbqGEiIn+DgO/zedgj8U+e0YJoUzc8vXAEA+4pNcqTExP4Xq+H9VdB7kh1XiBPCXIRFhV VNRm+BvyyF/90EhCbXv088GAFcjjagaqxlS4SQXUSL/PBqQKRdepk= X-Received: by 2002:a17:903:690:b0:2c9:97a7:71b1 with SMTP id d9443c01a7336-2ca26545886mr67075ad.44.1782732055099; Mon, 29 Jun 2026 04:20:55 -0700 (PDT) Received: from localhost.localdomain ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7f63d09f0sm92759085ad.56.2026.06.29.04.20.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Jun 2026 04:20:54 -0700 (PDT) From: Hao Jia To: akpm@linux-foundation.org, tj@kernel.org, hannes@cmpxchg.org, shakeel.butt@linux.dev, mhocko@kernel.org, yosry@kernel.org, mkoutny@suse.com, nphamcs@gmail.com, chengming.zhou@linux.dev, muchun.song@linux.dev, roman.gushchin@linux.dev Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Hao Jia , stable@vger.kernel.org Subject: [PATCH v5 1/6] mm/zswap: Fix global shrinker when memory cgroup is disabled Date: Mon, 29 Jun 2026 19:20:27 +0800 Message-Id: <20260629112032.20423-2-jiahao.kernel@gmail.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20260629112032.20423-1-jiahao.kernel@gmail.com> References: <20260629112032.20423-1-jiahao.kernel@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hao Jia When memory cgroup is disabled, mem_cgroup_iter() always returns NULL. Therefore, the global shrinker shrink_worker() always takes the !memcg branch. After MAX_RECLAIM_RETRIES empty walks, the worker simply gives up, so it fails to write back anything. Therefore, when memory cgroup is disabled, fall through with the !memcg branch and shrink the root memcg directly. Stop the loop once shrink_memcg() reports -ENOENT, since the root LRU is the only target and -ENOENT means it has been exhausted. Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware") Cc: stable@vger.kernel.org Reported-by: Yosry Ahmed Closes: https://lore.kernel.org/all/CAO9r8zPVzMKFbCixxD-qgtRrkFxWVrHiZZeLc=eyTPKPVQgX4g@mail.gmail.com Signed-off-by: Hao Jia --- mm/zswap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 761cd699e0a3..0f8f04f22888 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1356,7 +1356,12 @@ static void shrink_worker(struct work_struct *w) } while (memcg && !mem_cgroup_tryget_online(memcg)); spin_unlock(&zswap_shrink_lock); - if (!memcg) { + /* + * Reaching a NULL memcg means a full hierarchy pass completed. + * Exclude the memcg-disabled case, where it is always NULL, and + * fall through to shrink the root LRU directly. + */ + if (!memcg && !mem_cgroup_disabled()) { /* * Continue shrinking without incrementing failures if * we found candidate memcgs in the last tree walk. @@ -1378,8 +1383,15 @@ static void shrink_worker(struct work_struct *w) * with pages in zswap. Skip this without incrementing attempts * and failures. */ - if (ret == -ENOENT) + if (ret == -ENOENT) { + /* + * With memcg disabled the root LRU is the only target, so + * we should abort if it has no writeback-candidate pages. + */ + if (mem_cgroup_disabled()) + break; continue; + } ++attempts; if (ret && ++failures == MAX_RECLAIM_RETRIES) -- 2.34.1