From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 3FD333DEFF1 for ; Thu, 6 Aug 2026 07:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786000212; cv=none; b=brVmjqWqyJTc5cHyS9ZzwA36LtdlHNcWzV2+Rwefz73ogSBDoyYH7U2CPEbbZQkkubzlXuklqT0xeYJYGok+rcy5gpKCGmPl7PEhXYa21jzo2itrmaiFkcwv4VebJao5WC4UlzWW6TwIh+AQoPl5QUMjpKBRqHN245wuVdHpIf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786000212; c=relaxed/simple; bh=D9JmoKMI2Pmwotp5SEfjJj5F1SbchS7Q2k32kDMtCD0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=brrK3IhXNPdiL/OWvRPrLe4cWQejsghH0ihFNNcdD8nqZKMxDZISU3pi+qkyfP/0G/dsBmlQqn3aF1zCYDaC2fTwz2A/Lw7gzu5nXwxSmkIitRHv46Yv7k7Tc9ql7wM4nIQy/iVrumBvwFJWlnlX+CcyrK92RKfKslijjGJeOHQ= 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=oLfAZVMY; arc=none smtp.client-ip=209.85.210.179 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="oLfAZVMY" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-84862b0d5aeso2233358b3a.2 for ; Thu, 06 Aug 2026 00:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786000210; x=1786605010; 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:content-type; bh=pxkf9l/6VRKPUFdY+I+2JUrRfOgcQ7nzG7Tljs67NVc=; b=oLfAZVMYsURcvMNnJJX66I4qn/Eu34GjnRthIb3aVjz1X4yl1U4Xwnvxd7Z6k7g6oz 6sgY6SrNdxmMAtTNetV8vbMkeOgMHy9ZUVhP3Cgctpc93YMimDBjI1vElbih091gWM01 xNtwUFmgf8dQVu6ykVNa3KN6sexx9VRHb81ZB6/Okyin4mtp6BU5sjY+1imMR8/ikqYq I47oIiUArbuFY4SQmWSyD/I/hahDY3q2rDmKdVI0v9w/rzppQ/Ayz25ynKRzyEUdYv38 1LWqLQgI0LygiZTARKT0OEG0D9bYBUDo45R+li0EIIZPtEvv2sjy5K25cMU1Po822vDH pQkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786000210; x=1786605010; 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:content-type; bh=pxkf9l/6VRKPUFdY+I+2JUrRfOgcQ7nzG7Tljs67NVc=; b=Kpj8jEPAtjuT5fDshY5vcGdeQrjmvPJWEgL3EeLB+FXajl+sK4oM0OsVfTuDA9PLRk dgyS4wVbRFlyg/tLhLXaPdDYZOHrCS4K4ncPvZx8dF4t4IgcPRP0ANG0Icl6l5OT+8+8 0rNizuIgE2CNAXxf6MMVvR4Uv2m1/Y+DB9rLwd0O2UzmLXp0IBXmfSUkK7v8h4dW8wmf SNYWVIqovtAEpuH/+CJcNFsd+V0CKDg6NMvuwQ0Lldn9Hp4AuKDZdAmquF9KAd5TS5BU Qbi1O9nBBCzmgVWnMYi1xHTH96OUc9cIij8Dfd2lkh5saELWB4+Z/vCgf70skxKllBuR 95wA== X-Forwarded-Encrypted: i=1; AHgh+Rqg+y/Uh/CBkpx4+nDNtOOIk2E5fEPCRSTinu+kGAUQAz5gws3wps2eq97G1E4HSxrrJv/jDWeVTQjhfEw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4RHgerZ4pId0NrlW7aBdRSz+NfIlIVsQnndGnVDxq/4G2DI8Q wROsbWrxnZiQKVfKefZe/Y4sqEkviAv+AEEHjsJneh8RohZt2ixmhHyx X-Gm-Gg: AR+sD12m/AoVq/l0+rZPsrDbnsCRQ1B0LBd6d3DUZ2czBKgLgExnGw7xQWXym4KPLNo QtQ/gZY4DjqP3aRuvdr7XQJGRbltU77xtgyoMA7EGS2kW48ULBlcQlur5CuKgklh3ci06jyhC90 p9lepXCkkh4fzOoAgWkCcuDvd20z0usnHySZ7tLK2aTLJTjV3rQcS6BJE6uBv95+VinXTUUYvGX Xtx3ZahZXeS4+HqsMTGN0YLzRN7tESuTO01tEDc23kp1BCz2On6MSjSf06BmhHiO8q+IUon9nEN s4cooIU+gl1Wy/YA1tmFGxWtmPxNdsfv4B/7eQM2ApKW7dBTmB5vczMxMCJkPh6ZNSJdKPKorzi 0CJalY3yOjKsnHGn/yYDhLYhrxazdtkiuDFsd8XNsVd+Lufke16d7c3zl4ttSs/C56sdi4gqzSm Q0BzlDKF6PoPkFMP4IFF8eos2JG1FqhWmCdoBaRoZkcqT8+yM4n1CwjBYiSLfxeXyJvjlt2aFmi saZ7QYqJhvl1Bd8 X-Received: by 2002:a05:6a00:4218:b0:845:ce5f:c926 with SMTP id d2e1a72fcca58-84f2e210308mr14993193b3a.1.1786000210573; Thu, 06 Aug 2026 00:10:10 -0700 (PDT) Received: from localhost.localdomain ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f45bc9cffsm760154b3a.59.2026.08.06.00.10.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 06 Aug 2026 00:10:10 -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 v4 1/2] mm/zswap: Fix global shrinker when memory cgroup is disabled Date: Thu, 6 Aug 2026 15:09:42 +0800 Message-Id: <20260806070943.95542-2-jiahao.kernel@gmail.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20260806070943.95542-1-jiahao.kernel@gmail.com> References: <20260806070943.95542-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 Zswap writeback when the global pool limit is hit fails when memory cgroup is disabled. The pool remains full until it is organically drained by swapins or memory freeing, leading to zswap store failures and pages bypassing getting written directly to the backing swap device, causing LRU inversion (hotter pages with higher fault latency). This happens because mem_cgroup_iter() always returns NULL when memory cgroups are disabled. As a result, the global shrinker shrink_worker() repeatedly takes empty walks. After MAX_RECLAIM_RETRIES failed attempts, the worker gives up without writing back any pages. Therefore, when memory cgroup is disabled, fall through with the !memcg branch and shrink the root memcg directly. With memcg disabled, shrink_memcg() only returns -ENOENT when the root LRU is empty, which means the total pages are already below thr. In the absence of heavy concurrent zswap stores, the loop then safely bails out via the zswap_total_pages() <= thr check; otherwise, it will resume shrinking the memcg after processing the reschedule check. For any other return value from shrink_memcg(), the loop is guaranteed to terminate, either after MAX_RECLAIM_RETRIES failures or once the threshold is met. Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware") Cc: stable@vger.kernel.org Suggested-by: Nhat Pham Acked-by: Nhat Pham Acked-by: Yosry Ahmed Reported-by: Yosry Ahmed Signed-off-by: Hao Jia --- mm/zswap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index b5a17ea20237..48fc7b575e24 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1356,11 +1356,12 @@ static void shrink_worker(struct work_struct *w) } while (memcg && !mem_cgroup_tryget_online(memcg)); spin_unlock(&zswap_shrink_lock); - if (!memcg) { - /* - * Continue shrinking without incrementing failures if - * we found candidate memcgs in the last tree walk. - */ + /* + * A NULL memcg ends a full hierarchy pass (except when memcg is + * disabled, where it is always NULL: fall through to the root LRU). + * Count a failure only if the last pass found no candidates. + */ + if (!memcg && !mem_cgroup_disabled()) { if (!attempts && ++failures == MAX_RECLAIM_RETRIES) break; @@ -1379,7 +1380,7 @@ static void shrink_worker(struct work_struct *w) * and failures. */ if (ret == -ENOENT) - continue; + goto resched; ++attempts; if (ret && ++failures == MAX_RECLAIM_RETRIES) -- 2.34.1