From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 640DC30568E for ; Fri, 17 Jul 2026 08:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784278019; cv=none; b=G2Fdcw2UZiGkU6EVKjR8WxZlbWYjt8B90zlaPmsRXZhzsvIuVUFVStYm/zWQYl2TjAliwtjpnmn9DrbpYTqjXu0tNNCUYz45uL9NI/9L6+OmHDgJdQskhVfrOHq6246HGuTqFKWmO/deuOE0XAUNEySTiu/Nblp+3zFIRUxGtCA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784278019; c=relaxed/simple; bh=A8xpebSaaQSXV4EPEpqxExKI2SAxI2OAwhCC9qjihIw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EQdtt8rAik6Jfmno3Wp3pgAP9fG2/IcP+0sHXbihm3BymWooc42NwGSGMTcu48EEzlG6VWYTF8fdSQEID6TCi91emTSBKc0rbuYwDvNiMfwSGLJh6/p97zGWbNaHlCkGpUtF4+ou73V+gEwLKhBxS1qchOp0eGPTjcF43wKse2g= 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=G/iMfK5h; arc=none smtp.client-ip=209.85.214.177 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="G/iMfK5h" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2cee9b74ee1so40929935ad.3 for ; Fri, 17 Jul 2026 01:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784278018; x=1784882818; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=wHC4U75uHN7griHlGyDVa7HlPfycllJJT0cM4ZMBj1k=; b=G/iMfK5hz9oetWCOcjQTItT13TEPeLr7ZQjjPu6gdgoMvxIN5ozzPvAl08/ZyvYI1b dmUnWgrVsSG67PMfPgVOyr6EX5RnqXNf52G3jDmhHwJvVlFubinE121QtVewg4V/HIOR Wig8In657iCC71m5M1a2nRwPrqLMMOp/9BnciXGu9uKUlybzmsjw10aHzp9VKrq1cwQN 2npZZcF+kNffMcF8XQZpEEUppRsIVrcx9bpxK3X7Zj+0u3EQG4oTo1aNYEl79OL3k8Z0 vVdtjlpJHe9rghfZHBaRk1aASi+vkfKIOYYShXfGxYw3z+599cJLmw2PqHLRhhBbJupc Fovg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784278018; x=1784882818; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=wHC4U75uHN7griHlGyDVa7HlPfycllJJT0cM4ZMBj1k=; b=cpXpIIYhbsVIMK74qS6K5EfhpK6RMzHuIfvYq/9kDGPlM/fsgHLMHbaNERyA/17EDd 5auP2La8Y/98xhgR0dJ8gOhVaobOwg0vGdpPsn5KIiB6g6aynxRldf7AmGs5DpWPcP/J T/aNDoef/AzHbZraxZwjjCq5itjfgNKwIb1MjefeuoEFacaj3iYQHaYfaVkGr0k6+PHc KGRAIa0Mt1Vg0X556xrtLmFBe/zRUMZACYLbFRy4pb/sxLdSYjJbzwIxZUo2Oy00UIEo ppvXKl0Psg988ZBAlTvPTFVnuGLfrk0/QPOw1nOzqgBNfmUxyjCVjhTmmWnJno7kOH2l JKGA== X-Forwarded-Encrypted: i=1; AHgh+Rp7n+Z7BMkZHtR+1UxXfMLRT+HX1Gs/T6qxTd5qIOpysqOvF6MLvQpSfksvo0elhvxKCm/QbqNzZXhefS4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzm1n22vKNsMGfUDEpR/yG9pahwqzOV0m3u4eQ9qTcnqlfz3fMd ETswwchyHO5rPcKrO+wSmN+loVDZ9Y2GCmM818B475COL7OV+mp1mIpVUTHrDQ== X-Gm-Gg: AfdE7clOvQupZKXZRcb3sa8ASjARs/VjDHFSVqGufrYESRznUxsccjCjnVTzpoLLiha LnUCd6MP8eJ0NVbH/4FanHbyVc8Kj4Lht6l6FLykBE2Mapd660Rr83Dq7It4+9mX0Y8ccDEu5X9 TOdhewnRXuu84vwFUXlbsGb/CDD2HCQXaSeCB+KFJz+3MmBDsKEJ21s6XiOl/gLF1QboH0MZX+V rJZ4bxGuYsle2aJU3UQzy5yXBOcadAZGYmYDWfPMrA4HLxMPJYiA3aDCmPLJkHURoootC6pmbgh D467kr+/LSOOLvAhZES0mudUM6B/WwdmRRAQNliH92oPz+Ffftb3FqKn9Za1JdP+hc+MrW5/OhY iEorXNhomyjXF/eXZACNAfhAl+vB03znXmnID5fRExpxSNyePcPAsJZL6/w0tnqgprjO5r9t2aI /uBT/rkcJw8FXxsm9o7IW2gDg= X-Received: by 2002:a17:903:230f:b0:2c9:9a19:df with SMTP id d9443c01a7336-2cf348aae13mr17638315ad.18.1784278017632; Fri, 17 Jul 2026 01:46:57 -0700 (PDT) Received: from [10.125.192.114] ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf347a7c9fsm6699325ad.84.2026.07.17.01.46.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jul 2026 01:46:56 -0700 (PDT) Message-ID: <9c63fae9-0608-5192-665c-2811205a64c6@gmail.com> Date: Fri, 17 Jul 2026 16:46:37 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH 1/2] mm/zswap: Fix global shrinker when memory cgroup is disabled To: Yosry Ahmed , Nhat Pham Cc: Andrew Morton , tj@kernel.org, hannes@cmpxchg.org, shakeel.butt@linux.dev, mhocko@kernel.org, mkoutny@suse.com, chengming.zhou@linux.dev, muchun.song@linux.dev, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Hao Jia , stable@vger.kernel.org References: <20260714081510.16895-1-jiahao.kernel@gmail.com> <20260714081510.16895-2-jiahao.kernel@gmail.com> <20260714193129.f81711f516504b659d544741@linux-foundation.org> <7a1fe347-7ca6-4768-9308-420bf1251f54@gmail.com> <7b35fd4e-7662-10ae-159b-303350e4e59c@gmail.com> From: Hao Jia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026/7/17 08:08, Yosry Ahmed wrote: > On Thu, Jul 16, 2026 at 11:19 AM Nhat Pham wrote: >> >> On Wed, Jul 15, 2026 at 7:21 PM Hao Jia wrote: >>> >>> >>> >>> On 2026/7/16 00:13, Yosry Ahmed wrote: >>>> On Wed, Jul 15, 2026 at 5:31 AM Hao Jia wrote: >>>>> >>>>> >>>>> >>>>> On 2026/7/15 10:31, Andrew Morton wrote: >>>>>> On Tue, 14 Jul 2026 09:52:59 -0700 Yosry Ahmed wrote: >>>>>> >>>>>>>> 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. >>>>>>>> >>>>>>>> With memcg disabled, shrink_memcg() only returns -ENOENT when the root >>>>>>>> LRU is empty, which means the total pages are already below thr. The >>>>>>>> loop then safely bails out via the zswap_total_pages() <= thr 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 >>>>>>>> Closes: https://lore.kernel.org/all/CAO9r8zPVzMKFbCixxD-qgtRrkFxWVrHiZZeLc=eyTPKPVQgX4g@mail.gmail.com >>>>>>>> Signed-off-by: Hao Jia >>>>>>> >>>>>>> Patch 2 doesn't really depend on this one, right? >>>>>>> >>>>>>> If that's the case I think this can (and should be) picked up >>>>>>> separately as a hotfix. Andrew, WDYT? >>>>>> >>>>>> Please update the changelog to clearly describe the userspace-visible >>>>>> effects of the bug, thanks. >>>>> >>>>> I am not entirely sure if my understanding is correct here, but maybe I >>>>> should add something like this to the commit message? >>>>> >>>>> When cgroup_disable=memory is used (or with CONFIG_MEMCG=n), the global >>>>> shrinker fails to write back any pages. Consequently, the zswap pool >>>>> fills up to its limit and rejects further storage, preventing memory >>>>> pressure from being offloaded to the backing swap device. >>>> >>>> I think you can simply write that zswap writeback when the limit is >>>> hit is broken when memcg is disabled. >>> Will do. Thanks! >>> >>>> >>>>> >>>>>> Also, AI review has flagged several possible issues, all appear to be >>>>>> serious: >>>>>> https://sashiko.dev/#/patchset/20260714081510.16895-1-jiahao.kernel@gmail.com >>>>> >>>>> For AI review comments on this patch: >>>>> I suspect this scenario might only exist in theory. For zswap LRU to be >>>>> empty while zswap_total_pages() > thr holds true, it would require a >>>>> prolonged state where there are always more than thr zswap entries on >>>>> the zswap LRU whenever zswap_total_pages() > thr is evaluated, yet the >>>>> zswap LRU happens to be empty during shrink_memcg(root_memcg). >>>>> >>>>> If we want to fix this, perhaps we could do something like this? >>>>> >>>>> Yosry, Nhat, what are your thoughts on this? >>>> >>>> Do we need to do this? The last paragraph in your changelog explains >>>> why this can't happen because zswap_total_pages() should be 0 in this >>>> case. Did I miss something? >>> >>> The loop would require the following sequence to repeat indefinitely: >>> >>> 1、zswap_total_pages() > thr evaluates to true. >>> 2、During shrink_memcg(root_memcg), the zswap LRU is concurrently drained >>> to empty. >>> 3、Before zswap_total_pages() > thr is evaluated again, the zswap LRU is >>> heavily refilled such that zswap_total_pages() > thr holds true once more. >>> >>> For our case to manifest, it would require zswap_total_pages() and the >>> zswap LRU state to repeatedly hit this exact window with perfect >>> alignment over a **prolonged period**. Therefore, I suspect this >>> scenario might only exist in theory. >> >> Yeah seems very artificial indeed. >> >> If we want to be extra careful here, maybe we can put a cond_resched() >> there or replace the continue with goto resched or sth? > > I think it's also possible with the current code with memcg enabled. > It's still possible that the shrinker puts usage under the acceptance > threshold and then a new zswap stores puts it back above the > threshold, and so on. > > Perhaps as Nhat said, just goto resched instead of continue if we're > really worried, but I think even that is not really necessary. > Yes, but to be strictly rigorous, let's add a goto resched; anyway. Thanks, Hao > I think we generally want to clean up and simplify the shrinking loop > in zswap_shrinker(), but I don't have any great ideas.