Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: vmscan: simplify the logic for activating dirty file folios

After commit 6b0dfabb3555 ("fs: Remove aops->writepage"), we no longer
attempt to write back filesystem folios through reclaim.

However, in the shrink_folio_list() function, there still remains some
logic related to writeback control of dirty file folios. The original
logic was that, for direct reclaim, or when folio_test_reclaim() is false,
or the PGDAT_DIRTY flag is not set, the dirty file folios would be
directly activated to avoid being scanned again; otherwise, it will try to
writeback the dirty file folios. However, since we can no longer perform
writeback on dirty folios, the dirty file folios will still be activated.

Additionally, under the original logic, if we continue to try writeback
dirty file folios, we will also check the references flag,
sc->may_writepage, and may_enter_fs(), which may result in dirty file
folios being left in the inactive list. This is unreasonable. Even if
these dirty folios are scanned again, we still cannot clean them.

Therefore, the checks on these dirty file folios appear to be redundant
and can be removed. Dirty file folios should be directly moved to the
active list to avoid being scanned again. Since we set the PG_reclaim
flag for the dirty folios, once the writeback is completed, they will be
moved back to the tail of the inactive list to be retried for quick
reclaim.

Link: https://lkml.kernel.org/r/ba5c49955fd93c6850bcc19abf0e02e1573768aa.1760687075.git.baolin.wang@linux.alibaba.com
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baolin Wang and committed by
Andrew Morton
2f05435d b34619af

+3 -26
-4
include/linux/mmzone.h
··· 1060 1060 } ____cacheline_internodealigned_in_smp; 1061 1061 1062 1062 enum pgdat_flags { 1063 - PGDAT_DIRTY, /* reclaim scanning has recently found 1064 - * many dirty file pages at the tail 1065 - * of the LRU. 1066 - */ 1067 1063 PGDAT_WRITEBACK, /* reclaim scanning has recently found 1068 1064 * many pages under writeback 1069 1065 */
+3 -22
mm/vmscan.c
··· 1409 1409 1410 1410 mapping = folio_mapping(folio); 1411 1411 if (folio_test_dirty(folio)) { 1412 - /* 1413 - * Only kswapd can writeback filesystem folios 1414 - * to avoid risk of stack overflow. But avoid 1415 - * injecting inefficient single-folio I/O into 1416 - * flusher writeback as much as possible: only 1417 - * write folios when we've encountered many 1418 - * dirty folios, and when we've already scanned 1419 - * the rest of the LRU for clean folios and see 1420 - * the same dirty folios again (with the reclaim 1421 - * flag set). 1422 - */ 1423 - if (folio_is_file_lru(folio) && 1424 - (!current_is_kswapd() || 1425 - !folio_test_reclaim(folio) || 1426 - !test_bit(PGDAT_DIRTY, &pgdat->flags))) { 1412 + if (folio_is_file_lru(folio)) { 1427 1413 /* 1428 1414 * Immediately reclaim when written back. 1429 1415 * Similar in principle to folio_deactivate() ··· 1418 1432 */ 1419 1433 node_stat_mod_folio(folio, NR_VMSCAN_IMMEDIATE, 1420 1434 nr_pages); 1421 - folio_set_reclaim(folio); 1435 + if (!folio_test_reclaim(folio)) 1436 + folio_set_reclaim(folio); 1422 1437 1423 1438 goto activate_locked; 1424 1439 } ··· 6114 6127 if (sc->nr.writeback && sc->nr.writeback == sc->nr.taken) 6115 6128 set_bit(PGDAT_WRITEBACK, &pgdat->flags); 6116 6129 6117 - /* Allow kswapd to start writing pages during reclaim.*/ 6118 - if (sc->nr.unqueued_dirty && 6119 - sc->nr.unqueued_dirty == sc->nr.file_taken) 6120 - set_bit(PGDAT_DIRTY, &pgdat->flags); 6121 - 6122 6130 /* 6123 6131 * If kswapd scans pages marked for immediate 6124 6132 * reclaim and under writeback (nr_immediate), it ··· 6854 6872 6855 6873 clear_bit(LRUVEC_NODE_CONGESTED, &lruvec->flags); 6856 6874 clear_bit(LRUVEC_CGROUP_CONGESTED, &lruvec->flags); 6857 - clear_bit(PGDAT_DIRTY, &pgdat->flags); 6858 6875 clear_bit(PGDAT_WRITEBACK, &pgdat->flags); 6859 6876 } 6860 6877