From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (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 2183214B950 for ; Mon, 20 Jul 2026 04:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784522517; cv=none; b=VfMQ+04T9VszK7qgFQHAmSZRycUvjUIBuk7dM6nfsyWqAybWZ347kUPi6UOFWCZ98wrqJhpsfxxcPcwAN5tjBotr28RpNBeleGB6N8bwt2GwFXbrFDR42I7cXcOFV2RmPrFVLP6cN4dWPGjSyMsm35KArojStG6bS53+0RviTKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784522517; c=relaxed/simple; bh=boc7dbnyk7HNmDINzwY2yiSG1NvGJGZgKnI6qrnX+JM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=roCHxabtsrhydfDwXDLYzVKC1w7f5LwcJf60ycnEF9EyMhKdYLsV3y/0aFwQ+U6h0catRHZFXEpiH56cxIaTx+9ZBFuIbLGYy40woQl4eQ8v21CKurXZ+c/BJfVWPg3vnTNYXM5DZpBBxT712U7bFOzKDv2j+qVxDpdDmX8z+aA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--richardycc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jaaGA8gn; arc=none smtp.client-ip=209.85.215.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--richardycc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jaaGA8gn" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cb5cc1e139bso1301224a12.3 for ; Sun, 19 Jul 2026 21:41:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784522515; x=1785127315; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=mLiAEzbb/58guk3k33Zhp39Nox+evK3TgGMevuJwNcI=; b=jaaGA8gngel8nxC+dQ++Jvh0zTLzHQ/T/uRjk+1l+rS9sJlfqPKGQHkVIgskNjNrm9 a2OlcDZSnAYvaTCmroiRqipfL2k/i1xAHOobFeGmo1k/fuziGzE7lVQO06/faKG+uts+ yIKVhZwPLsnf8cXK1Xfohb0hFiU/b3P80C728jTrV3k+4UjTyCn/pJOjVu7IincfkvF7 WvMNwbvcBw/Uo1giTXh00UUGuDO40NG/tNYCfiq6kqoTXAQbETSwVEA10wzAHBWnmTA4 R3f1/gJQsmAkv+iMwy2E6KfHti958KskWN9/uAItuTa8bx63KC1ZyenVwARM5UgEaXPh V7vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784522515; x=1785127315; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mLiAEzbb/58guk3k33Zhp39Nox+evK3TgGMevuJwNcI=; b=SkvM3q2ERr6cNUIiCUVkWfnvjpGZ9OWvrPacYFd9vqFWlQBeOFRM4o9NelpGK/odt5 LKE/OqotGGRV1xME7l3VG5ANZgT9XmkO3nCQImBE+wYB3ByJup1+34pp7ZXNo320Pf5p bEklOBXJI05ivj8dbwxg9TPDCyQeQQnprLupJjLRsOF/9ZIOFrT696AKnrTlj+srTQij qkQ3gavUdjdZ3UarQyiAa6lcSLB2qtU/NdZEqx2xaRNJrqbdLmnZ7xs77G4Xtre7DHhu 3HchQWirA3JU7lVyiINM8fVxPrNoFIF40u7je4YrTTho30NopFgurTswTL8mn6Ucb1ht RO0g== X-Forwarded-Encrypted: i=1; AHgh+RoX5Dhoc1u9ikR5rffRDVzdOUFSNWaHWisPNmBvkbEFI8mexi1dLNta0rNnoDelZ6VnQUA7uoxpnDe6NC4=@vger.kernel.org X-Gm-Message-State: AOJu0Yww9JjWOs/lPd+pldbE2m1dIlKAgLbtAkxDjTNcrbawhgEuFN1F L4+zJxbAM7rP9DnEHB7xNBT1tTEl7UEpogsTrmGr7q6tVd9Mktlg84dUgLIsgmFqERDUD8yV2sz hDQiS1KliBawpYNen5RZq X-Received: from pggj9.prod.google.com ([2002:a63:cf09:0:b0:ca8:d31f:3177]) (user=richardycc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:918e:b0:3bf:6c04:a819 with SMTP id adf61e73a8af0-3c3ad9e7e87mr12965689637.58.1784522514920; Sun, 19 Jul 2026 21:41:54 -0700 (PDT) Date: Mon, 20 Jul 2026 04:41:03 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260720044103.905191-1-richardycc@google.com> Subject: [PATCH v4] mm: vmscan: abort proactive reclaim early when freezing for suspend From: Richard Chang To: Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Oleg Nesterov Cc: Suren Baghdasaryan , "T . J . Mercier" , Martin Liu , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Richard Chang , Michal Hocko Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=94specifically scanning cgroups in shrink_many() and evicting/aging folios in try_to_shrink_lruvec()=E2=80=94c= an 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. 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. Suggested-by: Michal Hocko Suggested-by: Oleg Nesterov Signed-off-by: Richard Chang --- v2: Update the commit message v3: Return -ERESTARTSYS instead of -EINTR in user_proactive_reclaim v4: Clarify -ERESTARTSYS vs SA_RESTART behavior mm/vmscan.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 35c3bb15ae96..5aa4becacb7f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4929,6 +4929,9 @@ static bool should_abort_scan(struct lruvec *lruvec, = struct scan_control *sc) int i; enum zone_watermarks mark; =20 + if (unlikely(sc->proactive && signal_pending(current))) + return true; + if (sc->nr_reclaimed >=3D max(sc->nr_to_reclaim, compact_gap(sc->order))) return true; =20 @@ -7909,8 +7912,15 @@ int user_proactive_reclaim(char *buf, unsigned long batch_size =3D (nr_to_reclaim - nr_reclaimed) / 4; unsigned long reclaimed; =20 + /* + * Return -ERESTARTSYS to allow the freezer to interrupt the + * task. The syscall will be transparently restarted upon + * resume. For real signals, it either restarts the syscall + * (if SA_RESTART is set) or is converted to -EINTR by the + * signal layer. + */ if (signal_pending(current)) - return -EINTR; + return -ERESTARTSYS; =20 /* * This is the final attempt, drain percpu lru caches in the --=20 2.55.0.229.g6434b31f56-goog