From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 E9D21399375 for ; Wed, 15 Jul 2026 14:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784126573; cv=none; b=e5jr3MYWa5re8qVOkClOYkdk5OK9QGXFQt+D4sWfI3V8K5w80dnPUPLmdaNPkh2gSXDLTR/oJtupgaENEa05L3gqRyhb8jzUI9WJ81bjYMxTEWjnpnF6s34Bc3kTDKPwj9A54bbSmBSROg/fL8ebSSq+NYgFGw5i3gpb1MaJivQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784126573; c=relaxed/simple; bh=sYqPmx6v3W2wEWiHzEqjNrRvkmevkrgkVzb0EybhPCE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q76eoIOxDYSdf677BGAubD8l/sg4uzaoQpAbO3WsD6WG2qKLvvLHwJBuZBgYFynWzDzarwx8s/ZIItta3n1dyuJ3jDl3PlQwriur4/c9awfwCnRRBv3EFiAck4/WJK7Kkgfn63V9rw6brfeyoV1eTSH5qjIAMQnc+ZxI3IzGyoo= 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=hQY+Xmy7; arc=none smtp.client-ip=209.85.221.46 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="hQY+Xmy7" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-47f365afc5aso2155920f8f.0 for ; Wed, 15 Jul 2026 07:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1784126568; x=1784731368; 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=zxylkB/9Q330ZTK+3xtMFXAr8pY156LcQll6mFT3qQU=; b=hQY+Xmy7kFoY9bUZ8yURr8kw7vLnARrOsfdmopSRk0f4ion0e7ao3QnV7ea8wUWY5P GzM13LJsOv+nc7N6bDQV+mTgFt8XrAGtVbi4yuUCS2Y4Om+vXptA5dGIU6hW5KSfrbBM HeBkdjXYxK+FN02ay3XdxNT1MfGyEwWll4CtBK8/cyCLYiwU77w+4yPRStHL11+3UxDb JsZyD37oafnP5vYsWvp/CxcfOLYDE9yEBXTGFOuCLdT2Ds9ex6l9aIsmJttv+33/LKha uDiVyk1JfrqptbnIL8VFZ1B0bvgRn76pwzZ7X3sD5O1lH6PeqXGh1RGXTg6+ADpFrmmR l31g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784126568; x=1784731368; 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=zxylkB/9Q330ZTK+3xtMFXAr8pY156LcQll6mFT3qQU=; b=A6IImQz0iHlNYaz7Nlqj129gCLnT92UsvGRc+Ytr+UoLfmP44OnWnqNPoAgDAESqrD FhV+Wvmw6THmSzRNwTp7Xa4D2puQ5/cJw2DiouqnX7gXHlZ+4pWCxAqOdZ2elyVdSMAR aQgajUErHQHwMkQUrCISD3oLaCsG43ssaRyQgpW9LvM/UCUgCt+M1HdHjUpnuF8cjTn5 CoBPDqt7cgyhDGHoa960DXWS+lJZXcVeRRn9hthAUvn4MMz46mTFwnPGCiFcHICJIIhM NlVe3hUQ6Hpr3R04jYJYEIL8dHzJsE1oJGR/oHuu23KN0Kl9y2LRiXS4zTzF3J0xKNQs ialw== X-Forwarded-Encrypted: i=1; AHgh+Roe2Q9j4oGLXwOqO7MZeYQK0WJ6CnnsezpWDYeVtzWU6Bjur24NmP8WCmFzkHKb/TR9smXV1cgheaLRdQQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwUGVciZ5c8UDtRLMwear1N2EAun+QRixiKPGpT0At7WVQ/j8S/ B87kcf+cWD9bVhKKMUoC+nBpp96s7q21ev8F3+0j7Rp3x48FYVmFv0gtmX9oHAVoWJ8= X-Gm-Gg: AfdE7cnYqKLOaQBDUvgUeRdC+LBW85G8omnB7I7y0JdyvdBaeXAohnYEi2VXjX2yAu8 5oEQtwOWthHtrARqLV9if699l45YhmpGQsrF7yY6yp7lzlb0TaIQNGwWCm0goj1Uh2qFqw3VCb8 /iqsJvigkzMVucz39GmsaqNx87GQjstNlhY+6DLKC3Yy7Irzrjact2I7Sjwr/NzXxoTNGjh1V5Z ggRVYs0EEAhY2wtyylwfQPdvow4AsocC3qHHOMLs1Rrnwarrt2KuQmceVDo4X3UxqEzzNQP2iVr DUrkEZOcqMQDpjAt8pc8JnCI+Ghn2pdbl4g3pT3oISOy25DODS1gf8B4gMIorSWVvUE3w85KUqx AxFSO+vEx58gA1JqFi1AWHzqUvk9R6RMZ3TQ5AChZlIbZcSqheCnWou0RGuOqnj7k9k1dmWYhzB MKZ2lh4OHXfAWm8Q== X-Received: by 2002:a05:6000:25c8:b0:462:d07e:4bc4 with SMTP id ffacd0b85a97d-47f4886edd1mr8716611f8f.7.1784126567792; Wed, 15 Jul 2026 07:42:47 -0700 (PDT) Received: from localhost ([2a02:8071:8280:d6e0:1353:8eb8:c84a:b6d4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f464c4320sm16428786f8f.32.2026.07.15.07.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 07:42:43 -0700 (PDT) Date: Wed, 15 Jul 2026 16:42:38 +0200 From: Johannes Weiner To: Altan Hacigumus Cc: Andrew Morton , David Hildenbrand , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jiayuan Chen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/vmscan: clear hopeless kswapd when global direct reclaim makes progress Message-ID: <20260715144238.GR276793@cmpxchg.org> References: <20260711043946.68421-1-ahacigu.linux@gmail.com> <20260713112001.GE276793@cmpxchg.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 Tue, Jul 14, 2026 at 07:30:12PM -0700, Altan Hacigumus wrote: > On Mon, Jul 13, 2026 at 4:20 AM Johannes Weiner wrote: > > > > On Fri, Jul 10, 2026 at 09:39:46PM -0700, Altan Hacigumus wrote: > > > Direct reclaim clears the hopeless kswapd state only once the node > > > becomes balanced - added by commit dc9fe9b7056a ("mm/vmscan: mitigate > > > spurious kswapd_failures reset from direct reclaim") so that cgroup > > > memory.high reclaim cannot repeatedly revive a kswapd that is unable to > > > balance the node. Before it, any reclaim progress revived kswapd. > > > > > > However, this restriction also prevents global direct reclaim from > > > reviving kswapd. Under sustained memory pressure, global direct reclaim > > > may continue making progress without the node ever reaching the high > > > watermark, leaving reclaim to allocating tasks. > > > > > > The effect is visible on systems where a database workload mlocks most > > > of memory and the remainder is under continuous pressure: allocations > > > stall long enough that ordinary tasks (e.g. ssh) become slow or > > > unresponsive, while kswapd sits idle. > > > > > > Unlike memcg reclaim, global direct reclaim follows the same node-wide > > > reclaim path as kswapd. Clear the hopeless state when global direct > > > reclaim makes progress, while continuing to require a balanced node for > > > memcg reclaim. kswapd_try_clear_hopeless() becomes static since struct > > > scan_control is private to vmscan.c. > > > > > > On a workload with most memory mlocked and the remainder under sustained > > > churn, with swap enabled, comparing the same 60s window: > > > base patched > > > allocstall (all zones) 413441 6532 > > > pgsteal_direct 15889552 255619 > > > pgsteal_kswapd 0 26079382 > > > PSI memory full avg60 13.10% 9.37% > > > > > > Direct reclaim was already reclaiming many pages in the baseline; > > > this change lets kswapd resume doing that work asynchronously. > > > > But does kswapd actually stop? > > > > I don't see how you avoid re-introducing the issue described in > > dc9fe9b7056a. Direct reclaim picking up a few pages is no guarantee > > that kswapd is able to restore the watermarks and stop running. > > > > The distinction between global reclaim and memcg reclaim seems > > handwavy to me. Either can free a couple of pages on the node. Who is > > doing it has little bearing on the question whether kswapd can balance > > the node and go to sleep? > > kswapd still stops for the same reason as before. Its own reclaim > progress never clears the hopeless state; only pgdat_balanced() does. > If it stops making progress, it reaches MAX_RECLAIM_RETRIES and parks > again. This change only allows successful global direct reclaim to > revive it. Whether a revived kswapd can rebalance the node is not > guaranteed - nor required: under sustained pressure the change is about > who performs the reclaim, kswapd asynchronously instead of every > allocating task synchronously. This is exactly the bug described in dc9fe9b7056a: A single direct reclaimer gets lucky, which kickstarts a very aggressive burst of kswapd activity. Sure, the commit lists memcg reclaim as a trigger, but there is nothing in that scenario that would make this memcg specific. The observation is simply that a single direct reclaimer getting lucky does not mean that kswapd can now balance the watermarks. Trivially true if your unreclaimable set exceeds memory - high_wmark. > The distinction is mechanical rather than "handwavy"; global direct > reclaim follows the same reclaim path with the same protection rules as > kswapd, whereas memcg reclaim does not: reclaim targeting a cgroup > ignores that cgroup's own memory.min/memory.low protection (see > mem_cgroup_unprotected()), so it can succeed where kswapd cannot. Thats > why the patch gates the reset on pgdat_balanced() for memcg reclaim, but > not for global direct reclaim. I don't think the distinction is meaningful in this case. The memory.low/memory.min aspect just makes a bad signal worse. It doesn't make the global reclaim signal good. Please take a look at the history of the hopeless kswapd concept. You have to follow the patches past the recent "hopeless" naming because the mechanism has been around for longer. We have moved trigger points around a few times now, and you're very likely to just reintroduce a problem somebody fixed recently.