Skip to content

Commit 77bbf72

Browse files
ryncsn1Naim
authored andcommitted
mm/mglru: relocate the LRU scan batch limit to callers
Same as active / inactive LRU, MGLRU isolates and scans folios in batches. The batch split is done hidden deep in the helper, which makes the code harder to follow. The helper's arguments are also confusing since callers usually request more folios than the batch size, so the helper almost never processes the full requested amount. Move the batch splitting into the top loop to make it cleaner, there should be no behavior change. Reviewed-by: Axel Rasmussen <axelrasmussen@google.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reviewed-by: Barry Song <baohua@kernel.org> Signed-off-by: Kairui Song <kasong@tencent.com>
1 parent 727bab3 commit 77bbf72

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

mm/vmscan.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,11 +4554,11 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
45544554
int scanned = 0;
45554555
int isolated = 0;
45564556
int skipped = 0;
4557-
int scan_batch = min(nr_to_scan, MAX_LRU_BATCH);
4558-
int remaining = scan_batch;
4557+
unsigned long remaining = nr_to_scan;
45594558
struct lru_gen_folio *lrugen = &lruvec->lrugen;
45604559
struct mem_cgroup *memcg = lruvec_memcg(lruvec);
45614560

4561+
VM_WARN_ON_ONCE(nr_to_scan > MAX_LRU_BATCH);
45624562
VM_WARN_ON_ONCE(!list_empty(list));
45634563

45644564
if (get_nr_gens(lruvec, type) == MIN_NR_GENS)
@@ -4615,7 +4615,7 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
46154615
count_memcg_events(memcg, item, isolated);
46164616
count_memcg_events(memcg, PGREFILL, sorted);
46174617
__count_vm_events(PGSCAN_ANON + type, isolated);
4618-
trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, scan_batch,
4618+
trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
46194619
scanned, skipped, isolated,
46204620
type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
46214621
if (type == LRU_GEN_FILE)
@@ -4859,7 +4859,7 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)
48594859

48604860
static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
48614861
{
4862-
long nr_to_scan;
4862+
long nr_batch, nr_to_scan;
48634863
unsigned long scanned = 0;
48644864
int swappiness = get_swappiness(lruvec, sc);
48654865

@@ -4870,7 +4870,8 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
48704870
if (nr_to_scan <= 0)
48714871
break;
48724872

4873-
delta = evict_folios(nr_to_scan, lruvec, sc, swappiness);
4873+
nr_batch = min(nr_to_scan, MAX_LRU_BATCH);
4874+
delta = evict_folios(nr_batch, lruvec, sc, swappiness);
48744875
if (!delta)
48754876
break;
48764877

@@ -5490,6 +5491,7 @@ static int run_aging(struct lruvec *lruvec, unsigned long seq,
54905491
static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_control *sc,
54915492
int swappiness, unsigned long nr_to_reclaim)
54925493
{
5494+
int nr_batch;
54935495
DEFINE_MAX_SEQ(lruvec);
54945496

54955497
if (seq + MIN_NR_GENS > max_seq)
@@ -5506,8 +5508,8 @@ static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_co
55065508
if (sc->nr_reclaimed >= nr_to_reclaim)
55075509
return 0;
55085510

5509-
if (!evict_folios(nr_to_reclaim - sc->nr_reclaimed, lruvec, sc,
5510-
swappiness))
5511+
nr_batch = min(nr_to_reclaim - sc->nr_reclaimed, MAX_LRU_BATCH);
5512+
if (!evict_folios(nr_batch, lruvec, sc, swappiness))
55115513
return 0;
55125514

55135515
cond_resched();

0 commit comments

Comments
 (0)