From nobody Mon Apr 6 10:46:24 2026 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 369F235839F for ; Fri, 20 Mar 2026 08:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773995653; cv=none; b=InNybM4gpdVRTpK3WrJa8D7vr4JjSVog6XCMnFdsUQ619fAlkG5w9p3gZ7IUCb7YSVnjyoBSu1P/i/Da65l7/pmun6doHRYeXKVS3Bkp/3SBihi8ZJDsjHHT0D2hHXmV8To6FbphKQUAr+BDkT+8UXFS0KRNTX7VTMktJyJmWUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773995653; c=relaxed/simple; bh=2AAVSIwGuSZOIOVcEwsUW5cyjghiJr/c+uxCdMNx61g=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=UrkeJ3Az52aWdbcJ90JUPEl7CZ6dhd8IX9GoFKJdHo5xjG/42BicE9ULGEJ9rq1t/OC5BE3tSaBaWDohCgtoH6a05GdUL9qTYYBpzHkXg1jCn+iAs3XrVWaKAv/b/I6FCLQD0RI3faNagjc+/Q0pJ7GIwn8B3nnqEn8hYHQeT7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b=LeVWHFjD; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b="LeVWHFjD" Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 62K8XoeD067731; Fri, 20 Mar 2026 16:33:50 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (BJMBX01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4fcbQm2GsZz2PgdgW; Fri, 20 Mar 2026 16:32:16 +0800 (CST) Received: from bj03382pcu03.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 20 Mar 2026 16:33:47 +0800 From: "zhaoyang.huang" To: Andrew Morton , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Qi Zheng , Matthew Wilcox , Shakeel Butt , Lorenzo Stoakes , , , Zhaoyang Huang , Subject: [PATCH] mm: skip dirty file folios during isolation of legacy LRU Date: Fri, 20 Mar 2026 16:33:39 +0800 Message-ID: <20260320083339.1813195-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 62K8XoeD067731 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unisoc.com; s=default; t=1773995639; bh=3FdDd4Jim0m2IcD1xKAeykn7Nj6vOcTm39v8GFas/5k=; h=From:To:Subject:Date; b=LeVWHFjDZjL2S6E4U/kbymvzVWPy1E95nW/Z6htCs/bzoJ87fNBe1RmB37pu/2MQf AMke/73cRl0ZARIUNcHvMO1rhJeCwM4Djq/uTjJe+6Cw4hK0Y36mZHq4T0VI12sIGN A+pFBDusO5VxHfh0B1gxPXqCyYx7yMW5hz8tqNOGLgoCbAiKAqCtIsAblBGHGzHCGw sFlW7eY9jIZJiolHhFldo63b5/T6voaQSWXGVk0RnJ6OQP1ueK0G7cW+EX1bZGStnv Uo6+Y5AAXW5dxFiMKX+cVYnSAjpcLLX4xgsABalGWa8Iz0xt58efMYrG97z3FClDzH 5bbK7F9G2pVeQ== Content-Type: text/plain; charset="utf-8" From: Zhaoyang Huang Since dirty file folios are no longer writeout in reclaiming after 'commit 84798514db50 ("mm: Remove swap_writepage() and shmem_writepage()")', there is no need to isolate them which could help to improve the scan efficiency and decrease the unnecessary TLB flush. This commit would like to bring the dirty file folios detection forward to isolation phase as well as the statistics which could affect wakeup the flusher thread under legacy LRU. In terms of MGLRU, the dirty file folios have been brought to younger gen when sort_folios. Signed-off-by: Zhaoyang Huang --- mm/vmscan.c | 103 ++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 10f1e7d716ca..79e5910ac62e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1103,7 +1103,6 @@ static unsigned int shrink_folio_list(struct list_hea= d *folio_list, struct address_space *mapping; struct folio *folio; enum folio_references references =3D FOLIOREF_RECLAIM; - bool dirty, writeback; unsigned int nr_pages; =20 cond_resched(); @@ -1142,26 +1141,7 @@ static unsigned int shrink_folio_list(struct list_he= ad *folio_list, if (!sc->may_unmap && folio_mapped(folio)) goto keep_locked; =20 - /* - * The number of dirty pages determines if a node is marked - * reclaim_congested. kswapd will stall and start writing - * folios if the tail of the LRU is all dirty unqueued folios. - */ - folio_check_dirty_writeback(folio, &dirty, &writeback); - if (dirty || writeback) - stat->nr_dirty +=3D nr_pages; =20 - if (dirty && !writeback) - stat->nr_unqueued_dirty +=3D nr_pages; - - /* - * Treat this folio as congested if folios are cycling - * through the LRU so quickly that the folios marked - * for immediate reclaim are making it to the end of - * the LRU a second time. - */ - if (writeback && folio_test_reclaim(folio)) - stat->nr_congested +=3D nr_pages; =20 /* * If a folio at the tail of the LRU is under writeback, there @@ -1717,12 +1697,14 @@ static unsigned long isolate_lru_folios(unsigned lo= ng nr_to_scan, unsigned long nr_zone_taken[MAX_NR_ZONES] =3D { 0 }; unsigned long nr_skipped[MAX_NR_ZONES] =3D { 0, }; unsigned long skipped =3D 0, total_scan =3D 0, scan =3D 0; + unsigned long nr_dirty =3D 0, nr_unqueued_dirty =3D 0, nr_congested =3D 0; unsigned long nr_pages; unsigned long max_nr_skipped =3D 0; LIST_HEAD(folios_skipped); =20 while (scan < nr_to_scan && !list_empty(src)) { struct list_head *move_to =3D src; + bool dirty, writeback; struct folio *folio; =20 folio =3D lru_to_folio(src); @@ -1749,6 +1731,30 @@ static unsigned long isolate_lru_folios(unsigned lon= g nr_to_scan, */ scan +=3D nr_pages; =20 + if (!folio_trylock(folio)) + goto move; + /* + * The number of dirty pages determines if a node is marked + * reclaim_congested. kswapd will stall and start writing + * folios if the tail of the LRU is all dirty unqueued folios. + */ + folio_check_dirty_writeback(folio, &dirty, &writeback); + folio_unlock(folio); + + if (dirty || writeback) + nr_dirty +=3D nr_pages; + + if (dirty && !writeback) + nr_unqueued_dirty +=3D nr_pages; + /* + * Treat this folio as congested if folios are cycling + * through the LRU so quickly that the folios marked + * for immediate reclaim are making it to the end of + * the LRU a second time. + */ + if (writeback && folio_test_reclaim(folio)) + nr_congested +=3D nr_pages; + if (!folio_test_lru(folio)) goto move; if (!sc->may_unmap && folio_mapped(folio)) @@ -1798,6 +1804,35 @@ static unsigned long isolate_lru_folios(unsigned lon= g nr_to_scan, trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan, total_scan, skipped, nr_taken, lru); update_lru_sizes(lruvec, lru, nr_zone_taken); + /* + * If dirty folios are scanned that are not queued for IO, it + * implies that flushers are not doing their job. This can + * happen when memory pressure pushes dirty folios to the end of + * the LRU before the dirty limits are breached and the dirty + * data has expired. It can also happen when the proportion of + * dirty folios grows not through writes but through memory + * pressure reclaiming all the clean cache. And in some cases, + * the flushers simply cannot keep up with the allocation + * rate. Nudge the flusher threads in case they are asleep. + */ + if (nr_unqueued_dirty =3D=3D scan) { + wakeup_flusher_threads(WB_REASON_VMSCAN); + /* + * For cgroupv1 dirty throttling is achieved by waking up + * the kernel flusher here and later waiting on folios + * which are in writeback to finish (see shrink_folio_list()). + * + * Flusher may not be able to issue writeback quickly + * enough for cgroupv1 writeback throttling to work + * on a large system. + */ + if (!writeback_throttling_sane(sc)) + reclaim_throttle(lruvec_pgdat(lruvec), VMSCAN_THROTTLE_WRITEBACK); + } + sc->nr.dirty +=3D nr_dirty; + sc->nr.congested +=3D nr_congested; + sc->nr.unqueued_dirty +=3D nr_unqueued_dirty; + return nr_taken; } =20 @@ -2038,35 +2073,7 @@ static unsigned long shrink_inactive_list(unsigned l= ong nr_to_scan, lru_note_cost_unlock_irq(lruvec, file, stat.nr_pageout, nr_scanned - nr_reclaimed); =20 - /* - * If dirty folios are scanned that are not queued for IO, it - * implies that flushers are not doing their job. This can - * happen when memory pressure pushes dirty folios to the end of - * the LRU before the dirty limits are breached and the dirty - * data has expired. It can also happen when the proportion of - * dirty folios grows not through writes but through memory - * pressure reclaiming all the clean cache. And in some cases, - * the flushers simply cannot keep up with the allocation - * rate. Nudge the flusher threads in case they are asleep. - */ - if (stat.nr_unqueued_dirty =3D=3D nr_taken) { - wakeup_flusher_threads(WB_REASON_VMSCAN); - /* - * For cgroupv1 dirty throttling is achieved by waking up - * the kernel flusher here and later waiting on folios - * which are in writeback to finish (see shrink_folio_list()). - * - * Flusher may not be able to issue writeback quickly - * enough for cgroupv1 writeback throttling to work - * on a large system. - */ - if (!writeback_throttling_sane(sc)) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); - } =20 - sc->nr.dirty +=3D stat.nr_dirty; - sc->nr.congested +=3D stat.nr_congested; - sc->nr.unqueued_dirty +=3D stat.nr_unqueued_dirty; sc->nr.writeback +=3D stat.nr_writeback; sc->nr.immediate +=3D stat.nr_immediate; sc->nr.taken +=3D nr_taken; --=20 2.25.1