From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-31.mta0.migadu.com [91.218.175.31]) (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 2F2D9472F7A for ; Tue, 18 Aug 2026 12:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.31 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787057380; cv=none; b=lBji1pKdy/cSABhf76wVuSOSkQiV2TxiIlMt198oMqdmjEv2lZnfQNIPXb/73/acw4vLJiMroeHnssl1dfRGe+8MzJoOq9e+FSObnCDIaTql0F5DRjYAJITjAjnObV+zNoWKA2Kb/+YwK1W4brFta+/UW+A+XA+0bsikp5Yhs5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787057380; c=relaxed/simple; bh=WrdvhNIs/76p08YQHs7pDu53eddRmYXbRgACIw7TFno=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SGThE5zI/JiS0xNU0QSDRyeW7trwqq9tvCjC+hGByX9bMAB1+4/ru2GLL30hop9RZPSFxhSREZ+tMMwnVEeUAqyTwB9x8ZDEGpYCLzeFRAjxRWYcbA4wLJnI3YJpgu6HcuOg5tPvt+yhNYh5Vt4OUk64bVqkm9ANHfs1Rd4GNfw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Ub9/9q1+; arc=none smtp.client-ip=91.218.175.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Ub9/9q1+" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=WrdvhNIs/76p08YQHs7pDu53eddRmYXbRgACIw7TFno=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787057374; v=1; x=1787662174; b=Ub9/9q1+4Tas0J6qkKbDl1licKm9PUEF1AYNa0WchO+T9Mv2M4QyPJOIJhfk2xoIuCxA48Jo GUP/4OfFAJmZZHXFpOonudi6dhWW/7dSdZf2L3pIPyn1swY2s52mX/pOOc8uwkFhs9S6r+1RJXV kZDpkah622EglOw1HgqDAP8Y= X-Envelope-To: linux-kernel@vger.kernel.org Received: from teawater-KVM-Virtual-Machine (39.156.73.13) by smtp.migadu.com with ESMTPS id 0c819b097754d81c; Tue, 18 Aug 2026 12:49:34 +0000 X-Migadu-Flow: FLOW_OUT From: "Hui Zhu" 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 , Baolin Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH mm-unstable v3 0/2] mm/vmscan: fix NR_ISOLATED accounting and throttling for MGLRU Date: Tue, 18 Aug 2026 20:48:55 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hui Zhu The legacy reclaim path updates the NR_ISOLATED_ANON/FILE node counters around isolation and throttles direct reclaimers via too_many_isolated() when isolated folios pile up. The MGLRU eviction path does neither: evict_folios() isolates folios without touching the counters and never consults too_many_isolated(). Patch 1 updates NR_ISOLATED_ANON/FILE around isolation in evict_folios(), reusing the existing nr_isolated. Without this the counters stay at zero while MGLRU reclaim is active, so compaction's too_many_isolated() cannot see the pages MGLRU has isolated. Patch 2 extracts the throttling loop from shrink_inactive_list() into throttle_is_throttled() and calls it from evict_folios() as well, keeping the two reclaim paths unified, in line with what was done previously for writeback reclaim. This way the MGLRU eviction path is throttled when isolated folios pile up instead of thrashing the shrinking LRU lists - the scenario the too_many_isolated() check exists for. A dying task fakes reclaim progress exactly like the legacy path so it exits reclaim quickly. Testing ======= Test on 8G RAM qemu. The reproducer confines stress-ng workers in a 192M memcg and swaps through dm-delay (300ms write latency) so pageout is slow and isolated folios pile up; the workload is intentionally extreme to force the throttle path. Throttle events are counted via the mm_vmscan_throttled tracepoint. The test scripts and test log is in [1]. Test 1, reclaim throttling, parallel direct reclaim in the memcg: before after throttle events (ISOLATED) 0 512488 - from kswapd 0 0 nr_isolated_anon peak 0 1450 - samples above the too_many_isolated threshold 0/1086 293/1057 pgscan_direct 1253539938 148299282 pswpout 3383673 6502879 Without the series MGLRU reclaim spins on the shrinking LRU lists while nr_isolated_* stays at 0 and nothing is throttled: pgscan_direct runs to 1.25 billion with only 3.3M pages swapped out. With the series the counters are updated, isolated folios cross the too_many_isolated threshold (293 of 1057 samples) and direct reclaimers are throttled; scanning drops by an order of magnitude while pswpout goes up, i.e. the reclaimers back off and let the slow swap device finish writing out the isolated folios instead of thrashing. kswapd stays exempt. Test 2, counters visible to compaction, same pressure plus compact_memory in parallel: before after nr_isolated peak 59 2271 The "before" 59 is compaction's own transient isolation; reclaim's isolation is invisible. With patch 1 it becomes visible to compaction's too_many_isolated(). (Compaction's own throttling threshold, (inactive + active) / 16, is ~23k pages on this box and needs more pile-up than the box can generate; test 1 exercises the same throttling mechanism end to end on the reclaim side.) [1] https://gist.github.com/teawater/d3968aac92eb6bd1378beb54a82933f4 Changelog: v3: Accoding to the commens of Baolin, remove the redundant nr_isolated check before restoring the NR_ISOLATED_* counters in evict_folios(). rename the extracted helper to throttle_is_throttled() to avoid confusion with the existing wake_throttle_isolated() naming space. Use for_each_evictable_type() in the MGLRU throttle to check each evictable type's isolation instead of only the type returned by get_type_to_scan(), since isolate_folios() may fall back to the other type. Re-run the tests and update the test log. v2: Accoding to the commens of Kairun, Rebased on mm-unstable. Split into two patches; patch 2 is new and adds the too_many_isolated() throttling to the MGLRU eviction path, which v1 did not cover. Add test infomations. Hui Zhu (2): mm/vmscan: fix missing NR_ISOLATED counter update in MGLRU reclaim path mm/vmscan: apply too_many_isolated() throttling to MGLRU eviction mm/vmscan.c | 76 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 12 deletions(-) -- 2.53.0