mm, vmscan: Don't turn on cache_trim_mode at the highest scan priority
Subsystems (3)
PATCH 1/1 mm, vmscan: Don't turn on cache_trim_mode at the highest scan priority
With cache_trim_mode on, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to turn on the mode because it's going to prevent anon pages from reclaimed even if there are huge ammount of anon pages that are very cold so should be reclaimed. Even worse, that can lead kswapd_failures to be MAX_RECLAIM_RETRIES and stop until direct reclaim eventually works to resume kswapd.
--- mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/vmscan.c +2 -1
@@ -2268,7 +2268,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)* anonymous pages. */ file =lruvec_page_state (target_lruvec,NR_INACTIVE_FILE ); -if (file >> sc->priority && !(sc->may_deactivate &DEACTIVATE_FILE )) +if (sc->priority !=1 && file >> sc->priority && + !(sc->may_deactivate &DEACTIVATE_FILE )) sc->cache_trim_mode =1 ;else sc->cache_trim_mode =0 ;
Signature · 1 line
2.17.1
Quoted 7 lines · Byungchul Park
With
cache_trim_modeon, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to turn on the mode because it's going to prevent anon pages from reclaimed even if there are huge ammount of anon pages that are very cold so should be reclaimed. Even worse, that can leadkswapd_failuresto beMAX_RECLAIM_RETRIESand stop until direct reclaim eventually works to resume kswapd.
Is a theory or something observed in the real world? If it's the former, would this change risk breaking existing use cases? It's the latter, where are the performance numbers to show what it looks like before and after this patch?
Quoted 10 lines
Signed-off-by Byungchul Park <[email protected]>--- mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/vmscan.c +0
-0
mm/vmscan.c static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc) · line 2271
Quoted 5 lines
mm/vmscan.c +1
-1@@ -2268,7 +2268,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)* anonymous pages. */ file =lruvec_page_state (target_lruvec,NR_INACTIVE_FILE ); -if (file >> sc->priority && !(sc->may_deactivate &DEACTIVATE_FILE )) + if (sc->priority != 1 && file >> sc->priority &
Why 1?
Quoted 4 lines
mm/vmscan.c +1
-0+ !(sc->may_deactivate & DEACTIVATE_FILE)) sc->cache_trim_mode =1 ; else sc->cache_trim_mode = 0;
Quoted 11 lines · Yu Zhao
Quoted 7 lines · Byungchul Park
With
cache_trim_modeon, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to turn on the mode because it's going to prevent anon pages from reclaimed even if there are huge ammount of anon pages that are very cold so should be reclaimed. Even worse, that can leadkswapd_failuresto beMAX_RECLAIM_RETRIESand stop until direct reclaim eventually works to resume kswapd.Is a theory or something observed in the real world? If it's the former, would this change risk breaking existing use cases? It's the
I faced the latter case.
Quoted 2 lines
latter, where are the performance numbers to show what it looks like before and after this patch?
Before:
Whenever the system meets the condition to turn on cache_trim_mode but few cache pages to trim, kswapd fails without scanning anon pages that are plenty and cold for sure and it retries 8 times and looks *stopped for ever*.
After:
When the system meets the condition to turn on cache_trim_mode but few cache pages to trim, kswapd finally works at the highest scan priority. So kswap looks working well even in the same condition.
Quoted 5 lines
Quoted 5 lines
Signed-off-by Byungchul Park <[email protected]>--- mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 12 lines
mm/vmscan.c static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc) · line 2271
Quoted 10 lines
mm/vmscan.c +1
-1@@ -2268,7 +2268,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)* anonymous pages. */ file =lruvec_page_state (target_lruvec,NR_INACTIVE_FILE ); -if (file >> sc->priority && !(sc->may_deactivate &DEACTIVATE_FILE )) + if (sc->priority != 1 && file >> sc->priority &Why 1?
It means the highest scan priority. The priority goes from DEF_PRIORITY to 1.
Byungchul
Quoted 4 lines
Quoted 4 lines
mm/vmscan.c +1
-0+ !(sc->may_deactivate & DEACTIVATE_FILE)) sc->cache_trim_mode =1 ; else sc->cache_trim_mode = 0;
Quoted 11 lines · Byungchul Park
Quoted 9 lines · Yu Zhao
Quoted 7 lines · Byungchul Park
With
cache_trim_modeon, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to turn on the mode because it's going to prevent anon pages from reclaimed even if there are huge ammount of anon pages that are very cold so should be reclaimed. Even worse, that can leadkswapd_failuresto beMAX_RECLAIM_RETRIESand stop until direct reclaim eventually works to resume kswapd.
Quoted 7 lines
Quoted 2 lines
Is a theory or something observed in the real world? If it's the former, would this change risk breaking existing use cases? It's the
I faced the latter case.
Quoted 2 lines
latter, where are the performance numbers to show what it looks like before and after this patch?
Let me ask again: where are the performance numbers to show what it looks like before and after this patch?
Quoted 7 lines
Before:
Whenever the system meets the condition to turn on
cache_trim_modebut few cache pages to trim, kswapd fails without scanning anon pages that are plenty and cold for sure and it retries 8 times and looks *stopped for ever*.
Quoted 5 lines
After:
When the system meets the condition to turn on
cache_trim_modebut few cache pages to trim, kswapd finally works at the highest scan priority. So kswap looks working well even in the same condition.
These are not performance numbers -- what test cases can prove what's described here?
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Byungchul Park <[email protected]>--- mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 12 lines
mm/vmscan.c static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc) · line 2271
Quoted 10 lines
mm/vmscan.c +1
-1@@ -2268,7 +2268,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)* anonymous pages. */ file =lruvec_page_state (target_lruvec,NR_INACTIVE_FILE ); -if (file >> sc->priority && !(sc->may_deactivate &DEACTIVATE_FILE )) + if (sc->priority != 1 && file >> sc->priority &Why 1?
Quoted 2 lines
It means the highest scan priority. The priority goes from
DEF_PRIORITYto 1.
This is not true -- sc->priority can go all the way to zero.
Quoted 6 lines
Byungchul
Quoted 4 lines
Quoted 4 lines
mm/vmscan.c +1
-0+ !(sc->may_deactivate & DEACTIVATE_FILE)) sc->cache_trim_mode =1 ; else sc->cache_trim_mode = 0;
Andrew Morton
maintainerQuoted 15 lines · On Sat, 17 Feb 2024 00:11:25 -0500 Yu Zhao <[email protected]> wrote:
Quoted 14 lines · Byungchul Park
Quoted 11 lines · Yu Zhao
Quoted 7 lines · Byungchul Park
With
cache_trim_modeon, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to turn on the mode because it's going to prevent anon pages from reclaimed even if there are huge ammount of anon pages that are very cold so should be reclaimed. Even worse, that can leadkswapd_failuresto beMAX_RECLAIM_RETRIESand stop until direct reclaim eventually works to resume kswapd.Is a theory or something observed in the real world? If it's the former, would this change risk breaking existing use cases? It's the
Quoted 14 lines
Quoted 4 lines
I faced the latter case.
Quoted 2 lines
latter, where are the performance numbers to show what it looks like before and after this patch?
Let me ask again: where are the performance numbers to show what it looks like before and after this patch?
Quoted 6 lines
Before:
Whenever the system meets the condition to turn on
cache_trim_modebut few cache pages to trim, kswapd fails without scanning anon pages that are plenty and cold for sure and it retries 8 times and looks *stopped for ever*.
Does "stopped for ever" mean that kswapd simply stops functioning?
If so, that's a pretty serious issue. Please fully describe all of this in the changelog. Please also address Yu Zhao's review comments and send us a v2 patch? Thanks.
Quoted 25 lines · Andrew Morton
Quoted 23 lines · On Sat, 17 Feb 2024 00:11:25 -0500 Yu Zhao <[email protected]> wrote:
Quoted 11 lines · Byungchul Park
Quoted 9 lines · Yu Zhao
Quoted 7 lines · Byungchul Park
With
cache_trim_modeon, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to turn on the mode because it's going to prevent anon pages from reclaimed even if there are huge ammount of anon pages that are very cold so should be reclaimed. Even worse, that can leadkswapd_failuresto beMAX_RECLAIM_RETRIESand stop until direct reclaim eventually works to resume kswapd.Quoted 7 lines
Quoted 2 lines
Is a theory or something observed in the real world? If it's the former, would this change risk breaking existing use cases? It's the
I faced the latter case.
Quoted 2 lines
latter, where are the performance numbers to show what it looks like before and after this patch?
Let me ask again: where are the performance numbers to show what it looks like before and after this patch?
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Before:
Whenever the system meets the condition to turn on
cache_trim_modebut few cache pages to trim, kswapd fails without scanning anon pages that are plenty and cold for sure and it retries 8 times and looks *stopped for ever*.Does "stopped for ever" mean that kswapd simply stops functioning?
Yes. kswapd stops its functioning. Even worse, after being stopped, any request to wake up kswapd fails until ->kswapd_failures gets reset to 0 by direct reclaim or something.
It's more like a bug fix than a performance improvement.
Quoted 3 lines
If so, that's a pretty serious issue. Please fully describe all of this in the changelog. Please also address Yu Zhao's review comments and send us a v2 patch? Thanks.
I will post v2 with vmstat numbers between before and after.
Byungchul