From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.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 656813822B4 for ; Thu, 30 Jul 2026 19:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785438127; cv=none; b=iZe/rbQGncwwhOSxiWSH9xSC7COCBre2TPrS2FOTPmB0C5UhHH1/DuLrK5XTzc3PvRBv9M89lCKn1qxhJ4X9Ft3FK4fb2UWpt27G2mlDsCQ1uhGDou/W0oC6hnMD9YU4LfMOGJKusB2u4PornD2ih2YEx0DAMn2k2NEUqgBl9vA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785438127; c=relaxed/simple; bh=013H1I9/4OHiS5zhZMxrwaHnsOF1mfy4INGhmCqtxrE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gzkCkEE542uuBI8f5fM8tgpJqyVnO3fDKTKFSHjkbTRNNK45AAyF0XvC68zLxMdQhylRBIY9eTFMN1qQCzChHEswfJyq8nzww8SbDSVQpmxa0dGapG7EqApnFjX+A7sS+7h/NRMCaeuhJvv19LHj6aB0lUA4T6Y5TLhQhJgBffI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=rSDOML1E; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="rSDOML1E" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-92ed3993c1eso11623285a.1 for ; Thu, 30 Jul 2026 12:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1785438124; x=1786042924; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=n1yOof5RfumCoH1r75oUvzt/UONr8poJqHsdkRardoM=; b=rSDOML1ERxTMZl1JTs+XTfmfSxlucOzySkLOGfM1L0g7prB+tzjEatOdlcMHinnf2k u9NzOEEUjYLYVr05QqQZSHMcp/J3E//OfJSRcowvnmbrityzK7Oiwj6OseP3Zd4EAK6G N4pTRaPqkiVSI0WwVxsbP7S4d90BKSb2TxFM0srB7dfsDslx6o4kYq6dWTd2jC/eO82A Ni8delzyYMj5HqNRc2TtlLLCqE74/L6nfSQhWqTlczyNnNczMbioopbC/12Ou9NmqHiw xHcuqQXij3tsO3pADwdyY6w2Tcf7ex1a2+hRjCZUjHT28lhZ8mLy4nYNQF1ho/5sBvTS PK7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785438124; x=1786042924; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=n1yOof5RfumCoH1r75oUvzt/UONr8poJqHsdkRardoM=; b=gFZs948y9FlRi1XK8txx5UyHFo8q3qnSohnIA7cg/jCbVH1HhrVjyhS8iEWkCYp8J7 GG6OiActd2PasvSEehm/oho9vx6MGFPt17OGk1GjYtfjXnqg4EirmsFov7xfer1FeZ1m ozaOD1kccVPIRCCF59Qi4m1V4SHmHsxoSQeVJwR8UzjvKUJ8QwBHhOMKjUhSs6LLZ6oK 9cGVmwoxUHIH4OW2D2NNHMBVRYmdhoHWOqncEAqUFcqf16ewpYnMaAdCQNbFkem34YNI 3EEAgREnHUt0FnsDgM1lPNUOA1hJmkMA4dS5bfkLnueF21Ci0SVFrJ2GIg43Zz7UcNH2 jhEQ== X-Forwarded-Encrypted: i=1; AHgh+RqIZA4J280GqP62gw7G9b4wA64Pmv/4kvbl+nPKImaX5R+k37HxCxw5Nx8cn1w2TVIVRMYqka9dNrc+vFU=@vger.kernel.org X-Gm-Message-State: AOJu0YyHYcHtRJP4lNdnWevdvd6fj6MBN8Wpp98qc8AjK9D2z135tseg tfrRRMRPF/ZzUKoeFdUmYo5l9nXsk+qq1FsziwqGbWIWKN4Z+YdwKW3p79HeMjpxWsU= X-Gm-Gg: AR+sD13yN2IrmOvcKUZuVoWFH/OvE9hdLFfjlKJQ3TBnNf4B5uBuOrudCttza0/PN3M xLIVTTa0rW2MiofdfZqIjlvx4p7aQV/WCRI9p60iUhxzq2Qe3LZy9EO1dC9uTDzOI+12cYyqT0t UAK8buUwQjctlrdRO9J8tS1D9ZjV2EiofE+s4k4Cu2TmNykCJl7y9OeIeJXTKjF8r0RxPva11Da y5g6L7xlTkNJix60FpMXTUWMX77+KigR621Pc5kgIED04tFLnmijSlCk3Ts6l8OkEnE1WxHMwi6 BCFOHgY/En85WFutYdbQsbg2Tfgo3aEvi3uZ4R8pVuXnZEUT1bVSu3+O8U3Jp84z2K1+hjNy7hv g6s+2YL3pbsbijnNBrx20UzESBswPmJ7tiGl/FjPZ5qz5v5CWYFMReHo+zXFW2QvH+TV8pkL5S+ SgR6QznqxPxp+ET76B0UpDFWVIEaWeOH7YuINsS7c2vQUKw+lKW8abQvR93Tw= X-Received: by 2002:a05:620a:460a:b0:932:dd83:c54 with SMTP id af79cd13be357-93485ff2ecemr442630085a.42.1785438095030; Thu, 30 Jul 2026 12:01:35 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-933e712fc05sm475477685a.29.2026.07.30.12.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 12:01:33 -0700 (PDT) Date: Thu, 30 Jul 2026 15:01:30 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Hao Jia , Nhat Pham , Andrew Morton , tj@kernel.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 Subject: Re: [PATCH v3 1/2] mm/zswap: Fix global shrinker when memory cgroup is disabled Message-ID: References: <20260729084206.77793-1-jiahao.kernel@gmail.com> <20260729084206.77793-2-jiahao.kernel@gmail.com> <20260729155858.c7aabff48166a9bca4d68ac3@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Jul 30, 2026 at 10:48:38AM -0700, Yosry Ahmed wrote: > > > Yeah, it isn't. Probably we should drop "Closes". I assume Hao added > > > it because checkpatch annoyingly complains if you add "Reported-by" > > > without "Closes", so Hao just linked to the thread where I pointed out > > > the bug. > > > > Yeah, checkpatch will complain if it's missing. > > We often ignore checkpatch if it's unreasonable. > > > >> AI review asked a couple of questions: > > >> https://sashiko.dev/#/patchset/20260729084206.77793-1-jiahao.kernel@gmail.com > > > > > > The review on patch #1 is something theoretical, we discussed it at > > > length in previous versions. > > > > > > For patch #2: > > > > > >> Does this batching logic break NUMA fairness? > > >> > > >> Because for_each_node_state() always starts from the lowest node > > >> ID and breaks when the scan budget is exhausted, subsequent > > >> calls to shrink_memcg() will restart at the lowest node ID again. > > >> > > >> If the lowest node (typically Node 0) consistently has enough > > >> items to exhaust the scan budget, wouldn't we exclusively evict > > >> pages from it while ignoring older pages on other nodes? Could > > >> this cause LRU inversion across nodes, keeping older pages in > > >> memory on Node 1 while hot pages on Node 0 are evicted? > > > > > > Yes, unfairness is possible. > > > > > > For global shrinking, it's probably not an issue. We reclaim until we > > > hit the acceptance threshold and it's very unlikely this will happen > > > before iterating all nodes (given that the batch size is 32 pages). > > > However, with the shrink_memcg() path, we only reclaim one batch, so > > > there's a chance we'll always reclaim it from node 0. > > > > > > Maybe we should just drop the early bailout and accept potentially > > > doing more writeback than needed. Hao, WDYT? > > > > > If we scan and attempt to write back SWAP_CLUSTER_MAX zswap entries per > > node, it might lead to excessive writeback on machines with many NUMA > > nodes. Furthermore, I'm concerned about introducing higher latency in > > synchronous shrink paths like zswap_store()—especially on systems with a > > large number of NUMA nodes, where it could end up writing back hundreds > > of pages in a single call. > > > > Maybe we could do something like this instead? That way, in the > > worst-case scenario, it falls back to the baseline behavior without > > introducing any extra latency risks. > > This basically errs on the side of honouring the batch size > (under-reclaim) instead of doing more writeback, right? > > I think I prefer erring on the side of doing more writeback, as it > would ultimately result in less LRU inversion, and we are already > doing writeback proactively during reclaim through the shrinker. Yes, LRU inversions are worse than reclaiming a few extra pages from the cold tail of the LRU. It's not cumulative after all, it just means we take a bigger bite and can take more stores before the next shrink. > The other option we can explore is keeping the existing logic with the > bailout, but start iterating the nodes at the folio's node in the > zswap_store() path. Basically pass an nid to shrink_memcg() and always > start there. This will avoid always reclaiming from node 0, and the > node of the folio being stored is more likely to be under pressure and > need the writeback. I am not sure how complex this would be and > whether it's worth doing. > > Johannes, Nhats, any thoughts on this? What happens if simply we do a hard SWAP_CLUSTER_MAX on each node? With cgroups, we put the zswap entry on the list_lru head of the node and memcg where the incoming page was. So if you're going after one specific cgroup, it's not like you *actually* reclaim 32 entries on each node of the system. You just write back from nodes where that cgroup has entries. The global shrinker also does one cgroup at a time (zswap_next_shrink) before checking the limit again, so that's fairly fine-grained too. Without cgroups, you could have zswap entries on all nodes. But if you have so many nodes that this would constitute hundreds of pages, presumably that's still a drop in the bucket compared to overall memory capacity. SWAP_CLUSTER_MAX isn't that big a number. So I don't think we need to get fancy. Just do SWAP_CLUSTER_MAX on each node. Delete that nr_to_walk carry-over between them.