From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73725277818 for ; Mon, 20 Jul 2026 05:23:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784524989; cv=none; b=m+V7WTqGXga46EKPMk+bY881H0TeonLslFlG3z8wIF9/SptnNHnIiw637adRVcwqqz/7sh2KJhS0ax9qAeCezu/oou+2hLBzbLMuhn8mtpiHVHff2Msy1JjXKEwuueNByhnv/dXByfor//qw1LsL4emsgry9V/uX52WrnwIxLfg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784524989; c=relaxed/simple; bh=yRn4It4efXPc1bw3XQsTrEmL0mg9vLiS/Bx/13xou7I=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=djAip6WYObX4cp+DUHRiUorG4BDjhUKAn1UKLUYGxS0egkzhj2g4+w8Fw6O7tNmsK0rVqPo/7dUp43uqOWu7KR8P30VDhVpd8X8u7mzbWnyXGCPeEAclrGDDlwq652/EJ1k/VOeIBlQCQxThnAtkMLA3AiSJuwWCQMXee+dKUPA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=1uNvXdKp; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="1uNvXdKp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 580621F000E9; Mon, 20 Jul 2026 05:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1784524988; bh=yDfZH9hbjyh5mwCLdQi48sM2SkPYDPdFLyTByyg6de4=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=1uNvXdKpOtc7vRh5uAxqp/HXU6KrP771A5oZnX13aAu63VvCaCCHhTeoWZRWa39HJ nXhy4WHfTit2zix7KRAJ9yDplMUdez9FguVpnRx65hlgjlLzNNFSM7CdNjCA/8SR9E nmY9k5ujtU81GvTJdYtuFO/gmr3yBh+alegHWVGU= Date: Sun, 19 Jul 2026 22:23:06 -0700 From: Andrew Morton To: Richard Chang Cc: Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Oleg Nesterov , Suren Baghdasaryan , "T . J . Mercier" , Martin Liu , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko Subject: Re: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend Message-Id: <20260719222306.540829de219e12e21396d260@linux-foundation.org> In-Reply-To: <20260720044103.905191-1-richardycc@google.com> References: <20260720044103.905191-1-richardycc@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 8bit On Mon, 20 Jul 2026 04:41:03 +0000 Richard Chang wrote: > Proactive reclaim (triggered via memory.reclaim or node sysfs) checks > for pending signals in its outer loop in user_proactive_reclaim(). > However, the inner reclaim loops—specifically scanning cgroups in > shrink_many() and evicting/aging folios in try_to_shrink_lruvec()—can > run for a long time before returning to the outer loop, especially on > systems with many cgroups or large memory sizes. > > During system suspend, the PM freezer attempts to freeze all tasks by > sending fake signals (setting TIF_SIGPENDING). Because the inner loops > do not check for pending signals, the proactive reclaim task can remain > stuck in kernel space for seconds, failing to enter the refrigerator in > a timely manner. This leads to suspend failures due to freeze timeouts, > a behavior observed on Android devices. > > This latency issue is specific to proactive reclaim because of its > large, user-defined reclaim targets (could be gigabytes). Since commit > 287d5fedb377 ("mm: memcg: use larger batches for proactive reclaim"), > proactive reclaim uses larger decaying batch sizes (starting at 1/4 of > the remaining target) to maintain throughput. This keeps the task in > the inner reclaim loop for extended periods. In contrast, reactive > reclaim (global/memcg) uses small targets (SWAP_CLUSTER_MAX, typically > 32 pages), allowing it to return to the outer loop and check signals > frequently. So 287d5fedb377 led to suspend failures on MGLRU-using kernels. That's a regression which justifies a Fixes: and a cc:stable, don't people agree? AI review asked a couple of serious-sounding questions: https://sashiko.dev/#/patchset/20260720044103.905191-1-richardycc@google.com > To fix this, add a signal_pending() check to should_abort_scan() for > proactive reclaim paths. Since should_abort_scan() is called within > the inner scanning and eviction loops, this allows proactive reclaim to > abort early and return to the outer loop in user_proactive_reclaim(). > > Additionally, return -ERESTARTSYS instead of -EINTR in > user_proactive_reclaim(). When interrupted by system suspend, returning > -ERESTARTSYS allows the task to enter the refrigerator and automatically > restart the syscall upon resume, making the freezer transparent to > userspace. For real signals, the signal layer will either restart the > syscall (if SA_RESTART is set) or return -EINTR to userspace. > > This fix specifically targets Multi-Gen LRU (MGLRU). Classic LRU's scan > targets per iteration are strictly bounded by get_scan_count(), which > ensures it returns to the outer loop more frequently. > > The check in should_abort_scan() is limited to proactive reclaim > (sc->proactive) to avoid inadvertently affecting reactive reclaim paths, > and is wrapped in unlikely() as it is a slow path. >