Skip to content

Commit cbdc10e

Browse files
Kalesh Singhgregkh
authored andcommitted
Multi-gen LRU: fix per-zone reclaim
commit 669281e upstream. MGLRU has a LRU list for each zone for each type (anon/file) in each generation: long nr_pages[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES]; The min_seq (oldest generation) can progress independently for each type but the max_seq (youngest generation) is shared for both anon and file. This is to maintain a common frame of reference. In order for eviction to advance the min_seq of a type, all the per-zone lists in the oldest generation of that type must be empty. The eviction logic only considers pages from eligible zones for eviction or promotion. scan_folios() { ... for (zone = sc->reclaim_idx; zone >= 0; zone--) { ... sort_folio(); // Promote ... isolate_folio(); // Evict } ... } Consider the system has the movable zone configured and default 4 generations. The current state of the system is as shown below (only illustrating one type for simplicity): Type: ANON Zone DMA32 Normal Movable Device Gen 0 0 0 4GB 0 Gen 1 0 1GB 1MB 0 Gen 2 1MB 4GB 1MB 0 Gen 3 1MB 1MB 1MB 0 Now consider there is a GFP_KERNEL allocation request (eligible zone index <= Normal), evict_folios() will return without doing any work since there are no pages to scan in the eligible zones of the oldest generation. Reclaim won't make progress until triggered from a ZONE_MOVABLE allocation request; which may not happen soon if there is a lot of free memory in the movable zone. This can lead to OOM kills, although there is 1GB pages in the Normal zone of Gen 1 that we have not yet tried to reclaim. This issue is not seen in the conventional active/inactive LRU since there are no per-zone lists. If there are no (not enough) folios to scan in the eligible zones, move folios from ineligible zone (zone_index > reclaim_index) to the next generation. This allows for the progression of min_seq and reclaiming from the next generation (Gen 1). Qualcomm, Mediatek and raspberrypi [1] discovered this issue independently. [1] raspberrypi/linux#5395 Link: https://lkml.kernel.org/r/[email protected] Fixes: ac35a49 ("mm: multi-gen LRU: minimal implementation") Signed-off-by: Kalesh Singh <[email protected]> Reported-by: Charan Teja Kalla <[email protected]> Reported-by: Lecopzer Chen <[email protected]> Tested-by: AngeloGioacchino Del Regno <[email protected]> [mediatek] Tested-by: Charan Teja Kalla <[email protected]> Cc: Yu Zhao <[email protected]> Cc: Barry Song <[email protected]> Cc: Brian Geffon <[email protected]> Cc: Jan Alexander Steffens (heftig) <[email protected]> Cc: Matthias Brugger <[email protected]> Cc: Oleksandr Natalenko <[email protected]> Cc: Qi Zheng <[email protected]> Cc: Steven Barrett <[email protected]> Cc: Suleiman Souhlal <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Aneesh Kumar K V <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1bca8a8 commit cbdc10e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

mm/vmscan.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,7 +4891,8 @@ static int lru_gen_memcg_seg(struct lruvec *lruvec)
48914891
* the eviction
48924892
******************************************************************************/
48934893

4894-
static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx)
4894+
static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_control *sc,
4895+
int tier_idx)
48954896
{
48964897
bool success;
48974898
int gen = folio_lru_gen(folio);
@@ -4941,6 +4942,13 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx)
49414942
return true;
49424943
}
49434944

4945+
/* ineligible */
4946+
if (zone > sc->reclaim_idx) {
4947+
gen = folio_inc_gen(lruvec, folio, false);
4948+
list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]);
4949+
return true;
4950+
}
4951+
49444952
/* waiting for writeback */
49454953
if (folio_test_locked(folio) || folio_test_writeback(folio) ||
49464954
(type == LRU_GEN_FILE && folio_test_dirty(folio))) {
@@ -4989,7 +4997,8 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca
49894997
static int scan_folios(struct lruvec *lruvec, struct scan_control *sc,
49904998
int type, int tier, struct list_head *list)
49914999
{
4992-
int gen, zone;
5000+
int i;
5001+
int gen;
49935002
enum vm_event_item item;
49945003
int sorted = 0;
49955004
int scanned = 0;
@@ -5005,9 +5014,10 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc,
50055014

50065015
gen = lru_gen_from_seq(lrugen->min_seq[type]);
50075016

5008-
for (zone = sc->reclaim_idx; zone >= 0; zone--) {
5017+
for (i = MAX_NR_ZONES; i > 0; i--) {
50095018
LIST_HEAD(moved);
50105019
int skipped = 0;
5020+
int zone = (sc->reclaim_idx + i) % MAX_NR_ZONES;
50115021
struct list_head *head = &lrugen->folios[gen][type][zone];
50125022

50135023
while (!list_empty(head)) {
@@ -5021,7 +5031,7 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc,
50215031

50225032
scanned += delta;
50235033

5024-
if (sort_folio(lruvec, folio, tier))
5034+
if (sort_folio(lruvec, folio, sc, tier))
50255035
sorted += delta;
50265036
else if (isolate_folio(lruvec, folio, sc)) {
50275037
list_add(&folio->lru, list);

0 commit comments

Comments
 (0)