mm: let kswapd work again for node that used to be hopeless but may not now
Subsystems (5)
PATCH v2 1/1 mm: let kswapd work again for node that used to be hopeless but may not now
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like if NR_FREE_PAGES is less than (low wmark + min wmark)/2.
--->8---
From 6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64 Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not now
A system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than MAX_RECLAIM_RETRIES failures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCING enabled sysctl_numa_balancing_mode set to NUMA_BALANCING_MEMORY_TIERING numa node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off
1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
--- include/linux/mmzone.h | 4 ++++ mm/page_alloc.c | 12 ++++++++++ mm/vmscan.c | 52 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 5 deletions(-)
include/linux/mmzone.h +4 -0
@@ -1331,6 +1331,10 @@ typedef struct pglist_data {enum zone_type kswapd_highest_zoneidx;int kswapd_failures;/* Number of 'reclaimed == 0' runs */ +int nr_may_reclaimable;/* Number of pages that have been +allocated since considered the +node is hopeless due to too many +kswapd_failures. */ #ifdef CONFIG_COMPACTION int kcompactd_max_order;
mm/page_alloc.c +12 -0
@@ -1538,8 +1538,20 @@ inline void post_alloc_hook(struct page *page, unsigned int order,static void prep_new_page (struct page *page,unsigned int order,gfp_t gfp_flags,unsigned int alloc_flags) { +pg_data_t *pgdat =page_pgdat (page); +post_alloc_hook (page, order, gfp_flags); +/* +* New pages might or might not be reclaimable depending on how +* these pages are going to be used. However, since these are +* potentially reclaimable, it's worth hopefully trying reclaim +* by allowing kswapd to work again even if there have been too +* many ->kswapd_failures, if ->nr_may_reclaimable is big enough. +*/ +if (pgdat->kswapd_failures >=MAX_RECLAIM_RETRIES ) + pgdat->nr_may_reclaimable +=1 << order; +if (order && (gfp_flags & __GFP_COMP))prep_compound_page (page, order);
mm/vmscan.c +47 -5
90 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too limited, because OOM killing may not happen, while the access pattern of the workloads may change. We have a preliminary and simple solution for this as follows,
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.
Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if kswapd_failures >= MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to kswapd_failures >= MAX_RECLAIM_RETRIES.
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.
Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, Ying
Quoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 63 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 3 lines
Quoted 3 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Quoted 6 lines
Quoted 4 lines
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway whether tiering is involved or not. The same problem will arise once kswapd stops.
Byungchul
Quoted 21 lines
without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 69 lines · Byungchul Park
Quoted 68 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.
Quoted 8 lines
Quoted 1 line
Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway
To be clear..
The problem, kswapd_failures >= MAX_RECLAIM_RETRIES, can happen whether tiering is involved not not. Once kswapd stops, the system should run without kswapd even after recovered e.g. by killing the hoggers. *Even worse*, tiering mechanism doesn't work in this situation.
I hope what I meant has been delivered.
Byungchul
Quoted 26 lines
whether tiering is involved or not. The same problem will arise once kswapd stops.
Byungchul
Quoted 21 lines
without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Johannes Weiner
maintainerQuoted 79 lines · Byungchul Park
Quoted 69 lines · Byungchul Park
Quoted 68 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Quoted 8 lines
Quoted 1 line
Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway
Quoted 6 lines
To be clear..
The problem,
kswapd_failures>=MAX_RECLAIM_RETRIES, can happen whether tiering is involved not not. Once kswapd stops, the system should run without kswapd even after recovered e.g. by killing the hoggers. *Even worse*, tiering mechanism doesn't work in this situation.
But like Ying said, in other situations it's direct reclaim that kicks in and clears the flag.
The failure-sleep and direct reclaim triggered recovery have been in place since 2017. Both parties who observed an issue with it recently did so in tiering scenarios. IMO a tiering-specific solution makes the most sense.
Quoted 82 lines · Johannes Weiner
Quoted 81 lines · Byungchul Park
Quoted 69 lines · Byungchul Park
Quoted 68 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Quoted 8 lines
Quoted 1 line
Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway
To be clear..
Quoted 7 lines
Quoted 4 lines
The problem,
kswapd_failures>=MAX_RECLAIM_RETRIES, can happen whether tiering is involved not not. Once kswapd stops, the system should run without kswapd even after recovered e.g. by killing the hoggers. *Even worse*, tiering mechanism doesn't work in this situation.But like Ying said, in other situations it's direct reclaim that kicks in and clears the flag.
I already described it in the commit message.
Quoted 1 line
The failure-sleep and direct reclaim triggered recovery have been in
Sure. It's better than nothing.
Quoted 3 lines
place since 2017. Both parties who observed an issue with it recently did so in tiering scenarios. IMO a tiering-specific solution makes the most sense.
So.. Is the follow situation in a non-tiering system okay? Really?
A system runs with kswapd disabled unless hitting min water mark, even if there might be something that kswapd can work on.
I don't undertand why it's okay. Could you explain more? Then why do we use kswapd in background?
Byungchul
Quoted 101 lines · Byungchul Park
Quoted 82 lines · Johannes Weiner
Quoted 81 lines · Byungchul Park
Quoted 69 lines · Byungchul Park
Quoted 68 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Quoted 8 lines
Quoted 1 line
Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway
To be clear..
Quoted 7 lines
Quoted 4 lines
The problem,
kswapd_failures>=MAX_RECLAIM_RETRIES, can happen whether tiering is involved not not. Once kswapd stops, the system should run without kswapd even after recovered e.g. by killing the hoggers. *Even worse*, tiering mechanism doesn't work in this situation.But like Ying said, in other situations it's direct reclaim that kicks in and clears the flag.
I already described it in the commit message.
Quoted 1 line
The failure-sleep and direct reclaim triggered recovery have been in
Sure. It's better than nothing.
Quoted 3 lines
place since 2017. Both parties who observed an issue with it recently did so in tiering scenarios. IMO a tiering-specific solution makes the most sense.
Quoted 7 lines
So.. Is the follow situation in a non-tiering system okay? Really?
A system runs with kswapd disabled unless hitting min water mark, even if there might be something that kswapd can work on.
I don't undertand why it's okay. Could you explain more? Then why do we use kswapd in background?
IIUC, it's okey. One direct reclaiming will be triggered, then kswapd reclaiming will be recovered. So, the performance will not be influenced much.
Do you think that this will impact performance? If so, please try to prove it with test results.
--
Best Regards,
Huang, Ying
Quoted 108 lines · Ying
Quoted 106 lines · Byungchul Park
Quoted 82 lines · Johannes Weiner
Quoted 81 lines · Byungchul Park
Quoted 69 lines · Byungchul Park
Quoted 68 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Quoted 8 lines
Quoted 1 line
Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway
To be clear..
Quoted 7 lines
Quoted 4 lines
The problem,
kswapd_failures>=MAX_RECLAIM_RETRIES, can happen whether tiering is involved not not. Once kswapd stops, the system should run without kswapd even after recovered e.g. by killing the hoggers. *Even worse*, tiering mechanism doesn't work in this situation.But like Ying said, in other situations it's direct reclaim that kicks in and clears the flag.
I already described it in the commit message.
Quoted 1 line
The failure-sleep and direct reclaim triggered recovery have been in
Sure. It's better than nothing.
Quoted 3 lines
place since 2017. Both parties who observed an issue with it recently did so in tiering scenarios. IMO a tiering-specific solution makes the most sense.
So.. Is the follow situation in a non-tiering system okay? Really?
A system runs with kswapd disabled unless hitting min water mark, even if there might be something that kswapd can work on.
Quoted 6 lines
Quoted 2 lines
I don't undertand why it's okay. Could you explain more? Then why do we use kswapd in background?
IIUC, it's okey. One direct reclaiming will be triggered, then kswapd reclaiming will be recovered. So, the performance will not be influenced much.
So is it because the performance will not be influenced much? Hm.. the system would get impacted at the moment when direct reclaim gets triggerred, even though kswapd can mitigate the impact proactively.
However, I don't want to insist strongly if you all consider it's okay.
Changing the topic to tiering, which one looks better between two appoaches to solve the issue that tiering doens't work once the failures hit MAX_RECLAIM_RETRIES:
1) periodically run kswapd
2) run kswapd if there might be reclaimable folios as this patch does
For 2), this patch should be modified a lil bit tho.
Byungchul
Quoted 6 lines
Do you think that this will impact performance? If so, please try to prove it with test results.
--
Best Regards,
Huang, Ying
Quoted 120 lines · Byungchul Park
Quoted 108 lines · Ying
Quoted 106 lines · Byungchul Park
Quoted 82 lines · Johannes Weiner
Quoted 81 lines · Byungchul Park
Quoted 69 lines · Byungchul Park
Quoted 68 lines · Ying
Quoted 43 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
Quoted 7 lines
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Quoted 8 lines
Quoted 1 line
Your description is about tiering too. Can you describe a situation
I mentioned "tiering" while I described how to reproduce because I ran into the situation while testing with tiering system but I don't think it's the necessary condition.
Let me ask you back, why the logic to stop kswapd was considered in the first place? That's because the problem was already observed anyway
To be clear..
Quoted 7 lines
Quoted 4 lines
The problem,
kswapd_failures>=MAX_RECLAIM_RETRIES, can happen whether tiering is involved not not. Once kswapd stops, the system should run without kswapd even after recovered e.g. by killing the hoggers. *Even worse*, tiering mechanism doesn't work in this situation.But like Ying said, in other situations it's direct reclaim that kicks in and clears the flag.
I already described it in the commit message.
Quoted 1 line
The failure-sleep and direct reclaim triggered recovery have been in
Sure. It's better than nothing.
Quoted 3 lines
place since 2017. Both parties who observed an issue with it recently did so in tiering scenarios. IMO a tiering-specific solution makes the most sense.
So.. Is the follow situation in a non-tiering system okay? Really?
A system runs with kswapd disabled unless hitting min water mark, even if there might be something that kswapd can work on.
Quoted 6 lines
Quoted 2 lines
I don't undertand why it's okay. Could you explain more? Then why do we use kswapd in background?
IIUC, it's okey. One direct reclaiming will be triggered, then kswapd reclaiming will be recovered. So, the performance will not be influenced much.
So is it because the performance will not be influenced much? Hm.. the system would get impacted at the moment when direct reclaim gets triggerred, even though kswapd can mitigate the impact proactively.
Quoted 8 lines
However, I don't want to insist strongly if you all consider it's okay.
Changing the topic to tiering, which one looks better between two appoaches to solve the issue that tiering doens't work once the failures hit
MAX_RECLAIM_RETRIES:1) periodically run kswapd
2) run kswapd if there might be reclaimable folios as this patch does
It's hard to capture all situations. Folios may become reclaimable in various ways, some folios become cold, swap devices are added, munlock, folios freeing/allocating, etc. It's hard to detect them all without trying.
It may be not necessary to run kswapd periodically. So, another possibility is to allow wakeup kswapd after some timeout even if kswapd_failures >= MAX_RECLAIM_RETRIES.
--
Best Regards,
Huang, Ying
Quoted 10 lines
For 2), this patch should be modified a lil bit tho.
Byungchul
Quoted 6 lines
Do you think that this will impact performance? If so, please try to prove it with test results.
--
Best Regards,
Huang, Ying
Quoted 49 lines · Ying
Quoted 47 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
Honestly, I don't think so with this description.
The fact that the system hit MAX_RECLAIM_RETRIES means the system is currently hopeless unless reclaiming folios in a stronger way by *direct reclaim*. The solution for this situation should not be about letting more CPUs particiated in reclaiming, again, *at least in this situation*.
What you described here is true only in a normal state where the more CPUs work on reclaiming, the more reclaimable folios can be reclaimed. kswapd can be a helper *only* when there are kswapd-reclaimable folios.
Byungchul
Quoted 34 lines
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 59 lines · Byungchul Park
Quoted 49 lines · Ying
Quoted 47 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
Honestly, I don't think so with this description.
Quoted 8 lines
The fact that the system hit
MAX_RECLAIM_RETRIESmeans the system is currently hopeless unless reclaiming folios in a stronger way by *direct reclaim*. The solution for this situation should not be about letting more CPUs particiated in reclaiming, again, *at least in this situation*.What you described here is true only in a normal state where the more CPUs work on reclaiming, the more reclaimable folios can be reclaimed. kswapd can be a helper *only* when there are kswapd-reclaimable folios.
Sometimes, we cannot reclaim just because we doesn't scan fast enough so the Accessed-bit is set again during scanning. With more CPUs, we can scan faster, so make some progress. But, yes, this only cover one situation, there are other situations too.
--
Best Regards,
Huang, Ying
Quoted 36 lines
Byungchul
Quoted 34 lines
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 66 lines · Ying
Quoted 64 lines · Byungchul Park
Quoted 49 lines · Ying
Quoted 47 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
Honestly, I don't think so with this description.
The fact that the system hit
MAX_RECLAIM_RETRIESmeans the system is currently hopeless unless reclaiming folios in a stronger way by *direct reclaim*. The solution for this situation should not be about letting more CPUs particiated in reclaiming, again, *at least in this situation*.
Quoted 8 lines
Quoted 3 lines
What you described here is true only in a normal state where the more CPUs work on reclaiming, the more reclaimable folios can be reclaimed. kswapd can be a helper *only* when there are kswapd-reclaimable folios.
Sometimes, we cannot reclaim just because we doesn't scan fast enough so the Accessed-bit is set again during scanning. With more CPUs, we can scan faster, so make some progress. But, yes, this only cover one situation, there are other situations too.
What I mean is *the issue we try to solve* is not the situation that can be solved by letting more CPUs participate in reclaiming.
Byungchul
Quoted 40 lines
--
Best Regards,
Huang, YingQuoted 36 lines
Byungchul
Quoted 34 lines
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 71 lines · Byungchul Park
Quoted 70 lines · Ying
Quoted 67 lines · Byungchul Park
Quoted 49 lines · Ying
Quoted 47 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
Honestly, I don't think so with this description.
The fact that the system hit
MAX_RECLAIM_RETRIESmeans the system is currently hopeless unless reclaiming folios in a stronger way by *direct reclaim*. The solution for this situation should not be about letting more CPUs particiated in reclaiming, again, *at least in this situation*.What you described here is true only in a normal state where the more CPUs work on reclaiming, the more reclaimable folios can be reclaimed. kswapd can be a helper *only* when there are kswapd-reclaimable folios.
Quoted 7 lines
Quoted 4 lines
Sometimes, we cannot reclaim just because we doesn't scan fast enough so the Accessed-bit is set again during scanning. With more CPUs, we can scan faster, so make some progress. But, yes, this only cover one situation, there are other situations too.
What I mean is *the issue we try to solve* is not the situation that can be solved by letting more CPUs participate in reclaiming.
Again, in the situation where kswapd has failed more than MAX_RECLAIM_RETRIES, say, holeless, I don't think it makes sense to wake up kswapd every 10 seconds. It'd be more sensible to wake up kwapd only if there are *at least potentially* reclaimable folios.
As Ying said, there's no way to precisely track if reclaimable, but it's worth trying when the possibility becomes positive and looks more reasonable. Thoughts?
Byungchul
Quoted 42 lines
Byungchul
Quoted 40 lines
--
Best Regards,
Huang, YingQuoted 36 lines
Byungchul
Quoted 34 lines
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 77 lines · Byungchul Park
Quoted 76 lines · Byungchul Park
Quoted 74 lines · Ying
Quoted 59 lines · Byungchul Park
Quoted 49 lines · Ying
Quoted 47 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
Honestly, I don't think so with this description.
Quoted 8 lines
The fact that the system hit
MAX_RECLAIM_RETRIESmeans the system is currently hopeless unless reclaiming folios in a stronger way by *direct reclaim*. The solution for this situation should not be about letting more CPUs particiated in reclaiming, again, *at least in this situation*.What you described here is true only in a normal state where the more CPUs work on reclaiming, the more reclaimable folios can be reclaimed. kswapd can be a helper *only* when there are kswapd-reclaimable folios.
Sometimes, we cannot reclaim just because we doesn't scan fast enough so the Accessed-bit is set again during scanning. With more CPUs, we can scan faster, so make some progress. But, yes, this only cover one situation, there are other situations too.
Quoted 7 lines
Quoted 2 lines
What I mean is *the issue we try to solve* is not the situation that can be solved by letting more CPUs participate in reclaiming.
Again, in the situation where kswapd has failed more than
MAX_RECLAIM_RETRIES, say, holeless, I don't think it makes sense to wake up kswapd every 10 seconds. It'd be more sensible to wake up kwapd only if there are *at least potentially* reclaimable folios.
1) numa balancing tiering on
No doubt the patch should work for it since numa balancing tiering doesn't work at all once kswapd stops. We are already applying and using this patch in tests for tiering. It works perfect.
2) numa balancing tiering off
kswapd will be resumed even without this patch if free memory hits min wmark. However, do we have to wait for direct reclaim to work for it? Even though we can proactively prevent direct reclaim using kswapd?
Byungchul
Quoted 48 lines
As Ying said, there's no way to precisely track if reclaimable, but it's worth trying when the possibility becomes positive and looks more reasonable. Thoughts?
Byungchul
Quoted 42 lines
Byungchul
Quoted 40 lines
--
Best Regards,
Huang, YingQuoted 36 lines
Byungchul
Quoted 34 lines
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying
Quoted 86 lines · Byungchul Park
Quoted 77 lines · Byungchul Park
Quoted 76 lines · Byungchul Park
Quoted 74 lines · Ying
Quoted 59 lines · Byungchul Park
Quoted 49 lines · Ying
Quoted 47 lines · Byungchul Park
Quoted 35 lines · Ying
Quoted 33 lines · Byungchul Park
Changes from v1:
1. Don't allow to resume kswapd if the system is under memory pressure that might affect direct reclaim by any chance, like ifNR_FREE_PAGESis less than (low wmark + min wmark)/2.--->8---
From6c73fc16b75907f5da9e6b33aff86bf7d7c9dd64Mon Sep 17 00:00:00 2001
From: Byungchul Park <[email protected]>
Date: Tue, 4 Jun 2024 15:27:56 +0900
Subject: [PATCH v2] mm: let kswapd work again for node that used to be hopeless but may not nowA system should run with kswapd running in background when under memory pressure, such as when the available memory level is below the low water mark and there are reclaimable folios.
However, the current code let the system run with kswapd stopped if kswapd has been stopped due to more than
MAX_RECLAIM_RETRIESfailures until direct reclaim will do for that, even if there are reclaimable folios that can be reclaimed by kswapd. This case was observed in the following scenario:
CONFIG_NUMA_BALANCINGenabledsysctl_numa_balancing_modeset toNUMA_BALANCING_MEMORY_TIERINGnuma node0 (500GB local DRAM, 128 CPUs)
numa node1 (100GB CXL memory, no CPUs)
swap off1) Run a workload with big anon pages e.g. mmap(200GB).
2) Continue adding the same workload to the system.
3) The anon pages are placed in node0 by promotion/demotion.
4) kswapd0 stops because of the unreclaimable anon pages in node0.
5) Kill the memory hoggers to restore the system.Quoted 6 lines
Quoted 3 lines
After restoring the system at 5), the system starts to run without kswapd. Even worse, tiering mechanism is no longer able to work since the mechanism relies on kswapd for demotion.
We have run into the situation that kswapd is kept in failure state for long in a multiple tiers system. I think that your solution is too
My solution just gives a chance for kswapd to work again even if
kswapd_failures>=MAX_RECLAIM_RETRIES, if there are potential reclaimable folios. That's it.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
limited, because OOM killing may not happen, while the access pattern of
I don't get this. OOM will happen as is, through direct reclaim.
A system that fails to reclaim via kswapd may succeed to reclaim via direct reclaim, because more CPUs are used to scanning the page tables.
Honestly, I don't think so with this description.
Quoted 8 lines
The fact that the system hit
MAX_RECLAIM_RETRIESmeans the system is currently hopeless unless reclaiming folios in a stronger way by *direct reclaim*. The solution for this situation should not be about letting more CPUs particiated in reclaiming, again, *at least in this situation*.What you described here is true only in a normal state where the more CPUs work on reclaiming, the more reclaimable folios can be reclaimed. kswapd can be a helper *only* when there are kswapd-reclaimable folios.
Sometimes, we cannot reclaim just because we doesn't scan fast enough so the Accessed-bit is set again during scanning. With more CPUs, we can scan faster, so make some progress. But, yes, this only cover one situation, there are other situations too.
Quoted 7 lines
Quoted 2 lines
What I mean is *the issue we try to solve* is not the situation that can be solved by letting more CPUs participate in reclaiming.
Again, in the situation where kswapd has failed more than
MAX_RECLAIM_RETRIES, say, holeless, I don't think it makes sense to wake up kswapd every 10 seconds. It'd be more sensible to wake up kwapd only if there are *at least potentially* reclaimable folios.
Quoted 5 lines
1) numa balancing tiering on
No doubt the patch should work for it since numa balancing tiering doesn't work at all once kswapd stops. We are already applying and using this patch in tests for tiering. It works perfect.
If my understanding of the code were correct, it doesn't work if there are not many pages allocated after kswapd stops. For example, if some processes use many fast memory become idle.
Quoted 5 lines
2) numa balancing tiering off
kswapd will be resumed even without this patch if free memory hits min wmark. However, do we have to wait for direct reclaim to work for it? Even though we can proactively prevent direct reclaim using kswapd?
Please prove it with data instead of reasoning. You patch adds some overhead in hot page allocation path. If the number of CPU is large, cache ping-pong may be triggered because shared variable (pgdat->nr_may_reclaimable) is accessed.
--
Best Regards,
Huang, Ying
Quoted 50 lines
Byungchul
Quoted 48 lines
As Ying said, there's no way to precisely track if reclaimable, but it's worth trying when the possibility becomes positive and looks more reasonable. Thoughts?
Byungchul
Quoted 42 lines
Byungchul
Quoted 40 lines
--
Best Regards,
Huang, YingQuoted 36 lines
Byungchul
Quoted 34 lines
In a system with NUMA balancing based page promotion and page demotion enabled, page promotion will wake up kswapd, but kswapd may fail in some situations. But page promotion will no trigger direct reclaim or OOM.
Quoted 7 lines
Quoted 4 lines
the workloads may change. We have a preliminary and simple solution for this as follows,
Whether tiering is involved or not, the same problem can arise if kswapd gets stopped due to
kswapd_failures>=MAX_RECLAIM_RETRIES.Your description is about tiering too. Can you describe a situation without tiering?
--
Best Regards,
Huang, YingQuoted 15 lines
Byungchul
Quoted 13 lines
where we will try to wake up kswapd to check every 10 seconds if kswapd is in failure state. This is another possible solution.
Quoted 4 lines
However, the node0 has pages newly allocated after 5), that might or might not be reclaimable. Since those are potentially reclaimable, it's worth hopefully trying reclaim by allowing kswapd to work again.
[snip]
--
Best Regards,
Huang, Ying