Commit 3af0191a authored by Kalesh Singh's avatar Kalesh Singh Committed by Andrew Morton

Multi-gen LRU: fix workingset accounting

On Android app cycle workloads, MGLRU showed a significant reduction in
workingset refaults although pgpgin/pswpin remained relatively unchanged. 
This indicated MGLRU may be undercounting workingset refaults.

This has impact on userspace programs, like Android's LMKD, that monitor
workingset refault statistics to detect thrashing.

It was found that refaults were only accounted if the MGLRU shadow entry
was for a recently evicted folio.  However, recently evicted folios should
be accounted as workingset activation, and refaults should be accounted
regardless of recency.

Fix MGLRU's workingset refault and activation accounting to more closely
match that of the conventional active/inactive LRU.

Link: https://lkml.kernel.org/r/20230523205922.3852731-1-kaleshsingh@google.com
Fixes: ac35a490 ("mm: multi-gen LRU: minimal implementation")
Signed-off-by: default avatarKalesh Singh <kaleshsingh@google.com>
Reported-by: default avatarCharan Teja Kalla <quic_charante@quicinc.com>
Acked-by: default avatarYu Zhao <yuzhao@google.com>
Cc: Brian Geffon <bgeffon@google.com>
Cc: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
Cc: Oleksandr Natalenko <oleksandr@natalenko.name>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 06b27ce3
...@@ -4925,7 +4925,6 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) ...@@ -4925,7 +4925,6 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx)
WRITE_ONCE(lrugen->protected[hist][type][tier - 1], WRITE_ONCE(lrugen->protected[hist][type][tier - 1],
lrugen->protected[hist][type][tier - 1] + delta); lrugen->protected[hist][type][tier - 1] + delta);
__mod_lruvec_state(lruvec, WORKINGSET_ACTIVATE_BASE + type, delta);
return true; return true;
} }
......
...@@ -278,6 +278,7 @@ static bool lru_gen_test_recent(void *shadow, bool file, struct lruvec **lruvec, ...@@ -278,6 +278,7 @@ static bool lru_gen_test_recent(void *shadow, bool file, struct lruvec **lruvec,
static void lru_gen_refault(struct folio *folio, void *shadow) static void lru_gen_refault(struct folio *folio, void *shadow)
{ {
bool recent;
int hist, tier, refs; int hist, tier, refs;
bool workingset; bool workingset;
unsigned long token; unsigned long token;
...@@ -288,10 +289,13 @@ static void lru_gen_refault(struct folio *folio, void *shadow) ...@@ -288,10 +289,13 @@ static void lru_gen_refault(struct folio *folio, void *shadow)
rcu_read_lock(); rcu_read_lock();
if (!lru_gen_test_recent(shadow, type, &lruvec, &token, &workingset)) recent = lru_gen_test_recent(shadow, type, &lruvec, &token, &workingset);
if (lruvec != folio_lruvec(folio))
goto unlock; goto unlock;
if (lruvec != folio_lruvec(folio)) mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + type, delta);
if (!recent)
goto unlock; goto unlock;
lrugen = &lruvec->lrugen; lrugen = &lruvec->lrugen;
...@@ -302,7 +306,7 @@ static void lru_gen_refault(struct folio *folio, void *shadow) ...@@ -302,7 +306,7 @@ static void lru_gen_refault(struct folio *folio, void *shadow)
tier = lru_tier_from_refs(refs); tier = lru_tier_from_refs(refs);
atomic_long_add(delta, &lrugen->refaulted[hist][type][tier]); atomic_long_add(delta, &lrugen->refaulted[hist][type][tier]);
mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + type, delta); mod_lruvec_state(lruvec, WORKINGSET_ACTIVATE_BASE + type, delta);
/* /*
* Count the following two cases as stalls: * Count the following two cases as stalls:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment