Re: [PATCH v9 06/14] mm: multi-gen LRU: minimal implementation

From: Barry Song
Date: Sat Mar 19 2022 - 07:17:06 EST


> + unsigned long *min_seq, bool can_swap, bool *need_aging)
> +{
> + int gen, type, zone;
> + long old = 0;
> + long young = 0;
> + long total = 0;
> + struct lru_gen_struct *lrugen = &lruvec->lrugen;
> +
> + for (type = !can_swap; type < ANON_AND_FILE; type++) {
> + unsigned long seq;
> +
> + for (seq = min_seq[type]; seq <= max_seq; seq++) {
> + long size = 0;
> +
> + gen = lru_gen_from_seq(seq);
> +
> + for (zone = 0; zone < MAX_NR_ZONES; zone++)
> + size += READ_ONCE(lrugen->nr_pages[gen][type][zone]);
> +
> + total += size;
> + if (seq == max_seq)
> + young += size;
> + if (seq + MIN_NR_GENS == max_seq)
> + old += size;
> + }
> + }
> +
> + /* try to spread pages out across MIN_NR_GENS+1 generations */
> + if (min_seq[LRU_GEN_FILE] + MIN_NR_GENS > max_seq)
> + *need_aging = true;
> + else if (min_seq[LRU_GEN_FILE] + MIN_NR_GENS < max_seq)
> + *need_aging = false;
> + else if (young * MIN_NR_GENS > total)
> + *need_aging = true;

Could we have some doc here? Given MIN_NR_GENS=2 and MAX_NR_GENS=4,
it seems you mean if we have three generations and the youngest pages are more
than 1/2 of the total pages, we need aging?


> + else if (old * (MIN_NR_GENS + 2) < total)
> + *need_aging = true;

it seems you mean if the oldest pages are less than 1/4 of the total pages,
we need aging? Can we have comments to explain why here?

your commit message only says " The aging produces young generations.
Given an lruvec, it increments max_seq when max_seq-min_seq+1
approaches MIN_NR_GENS." it can't explain what the code is doing
here.


> + else
> + *need_aging = false;
> +
> + return total > 0 ? total : 0;
> +}

Thanks
Barry