vmscan: limit concurrent reclaimers in shrink_zone
Subsystems (8)
PATCH 1/1 vmscan: limit concurrent reclaimers in shrink_zone
Under very heavy multi-process workloads, like AIM7, the VM can get into trouble in a variety of ways. The trouble start when there are hundreds, or even thousands of processes active in the page reclaim code.
Not only can the system suffer enormous slowdowns because of lock contention (and conditional reschedules) between thousands of processes in the page reclaim code, but each process will try to free up to SWAP_CLUSTER_MAX pages, even when the system already has lots of memory free. In Larry's case, this resulted in over 6000 processes fighting over locks in the page reclaim code, even though the system already had 1.5GB of free memory.
It should be possible to avoid both of those issues at once, by simply limiting how many processes are active in the page reclaim code simultaneously.
If too many processes are active doing page reclaim in one zone, simply go to sleep in shrink_zone().
On wakeup, check whether enough memory has been freed already before jumping into the page reclaim code ourselves. We want to use the same threshold here that is used in the page allocator for deciding whether or not to call the page reclaim code in the first place, otherwise some unlucky processes could end up freeing memory for the rest of the system.
---
This patch is against today's MMOTM tree. It has only been compile tested, I do not have an AIM7 system standing by.
Larry, does this fix your issue?
Documentation/sysctl/vm.txt | 18 ++++++++++++++++++ include/linux/mmzone.h | 4 ++++ include/linux/swap.h | 1 + kernel/sysctl.c | 7 +++++++ mm/page_alloc.c | 3 +++ mm/vmscan.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+)
Documentation/sysctl/vm.txt +18 -0
@@ -32,6 +32,7 @@ Currently, these files are in /proc/sys/vm: - legacy_va_layout - lowmem_reserve_ratio - max_map_count +- max_zone_concurrent_reclaim - memory_failure_early_kill - memory_failure_recovery - min_free_kbytes
@@ -278,6 +279,23 @@ The default value is 65536. ============================================================= +max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone. + +With certain workloads, hundreds of processes end up in the page +reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8. + +============================================================= + memory_failure_early_kill: Control how to kill processes when uncorrected memory error (typically
include/linux/mmzone.h +4 -0
@@ -345,6 +345,10 @@ struct zone {/* Zone statistics */ atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS ]; +/* Number of processes running page reclaim code on this zone. */ +atomic_t concurrent_reclaimers; +wait_queue_head_t reclaim_wait; +/* * prev_priority holds the scanning priority for this zone. It is * defined as the scanning priority at which we achieved our reclaim
include/linux/swap.h +1 -0
@@ -254,6 +254,7 @@ extern unsigned long shrink_all_memory(unsigned long nr_pages);extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; +extern int max_zone_concurrent_reclaimers;#ifdef CONFIG_NUMA extern int zone_reclaim_mode;
kernel/sysctl.c +7 -0
@@ -1270,6 +1270,13 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &one, }, + { + .procname = "max_zone_concurrent_reclaimers", + .data = &max_zone_concurrent_reclaimers, + .maxlen = sizeof(max_zone_concurrent_reclaimers), + .mode = 0644, + .proc_handler = proc_dointvec, + },#endif /*
mm/page_alloc.c +3 -0
@@ -3852,6 +3852,9 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat, zone->prev_priority =DEF_PRIORITY ; +atomic_set (&zone->concurrent_reclaimers,0 ); +init_waitqueue_head (&zone->reclaim_wait); +zone_pcp_init (zone);for_each_lru (l) {INIT_LIST_HEAD (&zone->lru[l].list);
mm/vmscan.c +38 -0
@@ -40,6 +40,7 @@#include <linux/memcontrol.h> #include <linux/delayacct.h> #include <linux/sysctl.h> +#include <linux/wait.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -129,6 +130,17 @@ struct scan_control {int vm_swappiness =60 ;long vm_total_pages;/* The total number of pages which the VM controls */ +/* +* Maximum number of processes concurrently running the page +* reclaim code in a memory zone. Having too many processes +* just results in them burning CPU time waiting for locks, +* so we're better off limiting page reclaim to a sane number +* of processes at a time. We do this per zone so local node +* reclaim on one NUMA node will not block other nodes from +* making progress. +*/ +int max_zone_concurrent_reclaimers =8 ; +static LIST_HEAD (shrinker_list);static DECLARE_RWSEM (shrinker_rwsem);
@@ -1600,6 +1612,29 @@ static void shrink_zone(int priority, struct zone *zone,struct zone_reclaim_stat *reclaim_stat =get_reclaim_stat (zone, sc);int noswap =0 ; +if (!current_is_kswapd () &&atomic_read (&zone->concurrent_reclaimers) > + max_zone_concurrent_reclaimers) { +/* +* Do not add to the lock contention if this zone has +* enough processes doing page reclaim already, since +* we would just make things slower. +*/ +sleep_on (&zone->reclaim_wait); + +/* +* If other processes freed enough memory while we waited, +* break out of the loop and go back to the allocator. +*/ +if (zone_watermark_ok (zone, sc->order,low_wmark_pages (zone), +0 ,0 )) { +wake_up (&zone->reclaim_wait); + sc->nr_reclaimed += nr_to_reclaim; +return ; + } + } + +atomic_inc (&zone->concurrent_reclaimers); +/* If we have no swap space, do not bother scanning anon pages. */ if (!sc->may_swap || (nr_swap_pages <=0 )) { noswap =1 ;
@@ -1655,6 +1690,9 @@ static void shrink_zone(int priority, struct zone *zone,shrink_active_list (SWAP_CLUSTER_MAX , zone, sc, priority,0 );throttle_vm_writeout (sc->gfp_mask); + +atomic_dec (&zone->concurrent_reclaimers); +wake_up (&zone->reclaim_wait); }/*
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi, Rik.
Quoted 66 lines · Rik van Riel
Under very heavy multi-process workloads, like AIM7, the VM can get into trouble in a variety of ways. The trouble start when there are hundreds, or even thousands of processes active in the page reclaim code.
Not only can the system suffer enormous slowdowns because of lock contention (and conditional reschedules) between thousands of processes in the page reclaim code, but each process will try to free up to
SWAP_CLUSTER_MAXpages, even when the system already has lots of memory free. In Larry's case, this resulted in over 6000 processes fighting over locks in the page reclaim code, even though the system already had 1.5GB of free memory.It should be possible to avoid both of those issues at once, by simply limiting how many processes are active in the page reclaim code simultaneously.
If too many processes are active doing page reclaim in one zone, simply go to sleep in
shrink_zone().On wakeup, check whether enough memory has been freed already before jumping into the page reclaim code ourselves. We want to use the same threshold here that is used in the page allocator for deciding whether or not to call the page reclaim code in the first place, otherwise some unlucky processes could end up freeing memory for the rest of the system.
Reported-by Larry Woodman <[email protected]>Signed-off-by Rik van Riel <[email protected]>---
This patch is against today's MMOTM tree. It has only been compile tested, I do not have an AIM7 system standing by.Larry, does this fix your issue?
Documentation/sysctl/vm.txt | 18 ++++++++++++++++++
include/linux/mmzone.h| 4 ++++
include/linux/swap.h | 1 +
kernel/sysctl.c | 7 +++++++
mm/page_alloc.c | 3 +++
mm/vmscan.c | 38 ++++++++++++++++++++++++++++++++++++++6 files changed, 71 insertions(+)Documentation/sysctl/vm.txt +0
-0@@ -32,6 +32,7 @@ Currently, these files are in /proc/sys/vm:-
legacy_va_layout
-lowmem_reserve_ratio
-max_map_count
+-max_zone_concurrent_reclaim
-memory_failure_early_kill
-memory_failure_recovery
-min_free_kbytesDocumentation/sysctl/vm.txt +0
-0@@ -278,6 +279,23 @@ The default value is 65536.=============================================================
Documentation/sysctl/vm.txt +6
-0+max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone. + +With certain workloads, hundreds of processes end up in the page
Documentation/sysctl/vm.txt The default value is 65536. · line 297
Quoted 10 lines
Documentation/sysctl/vm.txt +10
-0+reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8. + +=============================================================
I like this. but why do you select default value as constant 8? Do you have any reason?
I think it would be better to select the number proportional to NR_CPU. ex) NR_CPU * 2 or something.
Otherwise looks good to me.
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 11 lines · Minchan Kim
Documentation/sysctl/vm.txt The default value is 65536. · line 297
Quoted 3 lines
Documentation/sysctl/vm.txt +3
-0+The default value is 8. + +=============================================================I like this. but why do you select default value as constant 8? Do you have any reason?
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.Otherwise looks good to me.
Pessimistically, I assume that the pageout code spends maybe 10% of its time on locking (we have seen far, far worse than this with thousands of processes in the pageout code). That means if we have more than 10 threads in the pageout code, we could end up spending more time on locking and less doing real work - slowing everybody down.
I rounded it down to the closest power of 2 to come up with an arbitrary number that looked safe :)
However, this number is per zone - I imagine that really large systems will have multiple memory zones, so they can run with more than 8 processes in the pageout code simultaneously.
Quoted 1 line
Reviewed-by Minchan Kim<[email protected]>
Thank you.
Signature · 7 lines
All rights reversed. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines · Rik van Riel
Quoted 10 lines · Minchan Kim
Documentation/sysctl/vm.txt The default value is 65536. · line 297
Quoted 3 lines
Documentation/sysctl/vm.txt +3
-0+The default value is 8. + +=============================================================I like this. but why do you select default value as constant 8? Do you have any reason?
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.
Quoted 8 lines
Quoted 1 line
Otherwise looks good to me.
Pessimistically, I assume that the pageout code spends maybe 10% of its time on locking (we have seen far, far worse than this with thousands of processes in the pageout code). That means if we have more than 10 threads in the pageout code, we could end up spending more time on locking and less doing real work - slowing everybody down.
Thanks for giving precious information to me. :
We always have a question magic value with no comment.
Actually I don't want to add another magic value without comment. so I would like to add the your good explanation in change log or as comment on code.
Quoted 11 lines
I rounded it down to the closest power of 2 to come up with an arbitrary number that looked safe :)
However, this number is per zone - I imagine that really large systems will have multiple memory zones, so they can run with more than 8 processes in the pageout code simultaneously.
Quoted 1 line
Reviewed-by Minchan Kim<[email protected]>Thank you.
Thanks for quick reply. :)
Quoted 3 lines
--
All rights reversed.
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 202 lines · Rik van Riel
Under very heavy multi-process workloads, like AIM7, the VM can get into trouble in a variety of ways. The trouble start when there are hundreds, or even thousands of processes active in the page reclaim code.
Not only can the system suffer enormous slowdowns because of lock contention (and conditional reschedules) between thousands of processes in the page reclaim code, but each process will try to free up to
SWAP_CLUSTER_MAXpages, even when the system already has lots of memory free. In Larry's case, this resulted in over 6000 processes fighting over locks in the page reclaim code, even though the system already had 1.5GB of free memory.It should be possible to avoid both of those issues at once, by simply limiting how many processes are active in the page reclaim code simultaneously.
If too many processes are active doing page reclaim in one zone, simply go to sleep in
shrink_zone().On wakeup, check whether enough memory has been freed already before jumping into the page reclaim code ourselves. We want to use the same threshold here that is used in the page allocator for deciding whether or not to call the page reclaim code in the first place, otherwise some unlucky processes could end up freeing memory for the rest of the system.
Reported-by Larry Woodman <[email protected]>Signed-off-by Rik van Riel <[email protected]>---
This patch is against today's MMOTM tree. It has only been compile tested, I do not have an AIM7 system standing by.Larry, does this fix your issue?
Documentation/sysctl/vm.txt | 18 ++++++++++++++++++ include/linux/mmzone.h | 4 ++++ include/linux/swap.h | 1 + kernel/sysctl.c | 7 +++++++ mm/page_alloc.c | 3 +++ mm/vmscan.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+)Documentation/sysctl/vm.txt +18
-0@@ -32,6 +32,7 @@ Currently, these files are in /proc/sys/vm: - legacy_va_layout - lowmem_reserve_ratio - max_map_count +- max_zone_concurrent_reclaim - memory_failure_early_kill - memory_failure_recovery - min_free_kbytes@@ -278,6 +279,23 @@ The default value is 65536. ============================================================= +max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone. + +With certain workloads, hundreds of processes end up in the page +reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8. + +============================================================= + memory_failure_early_kill: Control how to kill processes when uncorrected memory error (typicallyinclude/linux/mmzone.h +4
-0@@ -345,6 +345,10 @@ struct zone {/* Zone statistics */ atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS ]; +/* Number of processes running page reclaim code on this zone. */ +atomic_t concurrent_reclaimers; +wait_queue_head_t reclaim_wait; +/* * prev_priority holds the scanning priority for this zone. It is * defined as the scanning priority at which we achieved our reclaim include/linux/swap.h +1
-0@@ -254,6 +254,7 @@ extern unsigned long shrink_all_memory(unsigned long nr_pages);extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; +extern int max_zone_concurrent_reclaimers;#ifdef CONFIG_NUMA extern int zone_reclaim_mode;kernel/sysctl.c +7
-0@@ -1270,6 +1270,13 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &one, }, + { + .procname = "max_zone_concurrent_reclaimers", + .data = &max_zone_concurrent_reclaimers, + .maxlen = sizeof(max_zone_concurrent_reclaimers), + .mode = 0644, + .proc_handler = proc_dointvec, + },#endif /* mm/page_alloc.c +3
-0@@ -3852,6 +3852,9 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat, zone->prev_priority =DEF_PRIORITY ; +atomic_set (&zone->concurrent_reclaimers,0 ); +init_waitqueue_head (&zone->reclaim_wait); +zone_pcp_init (zone);for_each_lru (l) {INIT_LIST_HEAD (&zone->lru[l].list);mm/vmscan.c +35
-0@@ -40,6 +40,7 @@#include <linux/memcontrol.h> #include <linux/delayacct.h> #include <linux/sysctl.h> +#include <linux/wait.h> #include <asm/tlbflush.h> #include <asm/div64.h> @@ -129,6 +130,17 @@ struct scan_control {int vm_swappiness =60 ;long vm_total_pages;/* The total number of pages which the VM controls */ +/* +* Maximum number of processes concurrently running the page +* reclaim code in a memory zone. Having too many processes +* just results in them burning CPU time waiting for locks, +* so we're better off limiting page reclaim to a sane number +* of processes at a time. We do this per zone so local node +* reclaim on one NUMA node will not block other nodes from +* making progress. +*/ +int max_zone_concurrent_reclaimers =8 ; +static LIST_HEAD (shrinker_list);static DECLARE_RWSEM (shrinker_rwsem);@@ -1600,6 +1612,29 @@ static void shrink_zone(int priority, struct zone *zone,struct zone_reclaim_stat *reclaim_stat =get_reclaim_stat (zone, sc);int noswap =0 ; +if (!current_is_kswapd () &&atomic_read (&zone->concurrent_reclaimers) > + max_zone_concurrent_reclaimers) { +/* +* Do not add to the lock contention if this zone has +* enough processes doing page reclaim already, since +* we would just make things slower. +*/ +sleep_on (&zone->reclaim_wait); + +/* +* If other processes freed enough memory while we waited, +* break out of the loop and go back to the allocator. +*/ +if (zone_watermark_ok (zone, sc->order,low_wmark_pages (zone), +0 ,0 )) { +wake_up (&zone->reclaim_wait); + sc->nr_reclaimed += nr_to_reclaim; +return ; + } + } + +atomic_inc (&zone->concurrent_reclaimers); +/* If we have no swap space, do not bother scanning anon pages. */ if (!sc->may_swap || (nr_swap_pages <=0 )) { noswap =1 ;
mm/vmscan.c static void shrink_zone(int priority, struct zone *zone, · line 1698
Quoted 9 lines
mm/vmscan.c +3
-0@@ -1655,6 +1690,9 @@ static void shrink_zone(int priority, struct zone *zone,shrink_active_list (SWAP_CLUSTER_MAX , zone, sc, priority,0 );throttle_vm_writeout (sc->gfp_mask); + +atomic_dec (&zone->concurrent_reclaimers); +wake_up (&zone->reclaim_wait); }/*
FYI everyone, I put together a similar patch(doesnt block explicitly, relies on vm_throttle) for RHEL5(2.6.18 based kernel) and it fixes hangs due to several CPUs spinning on zone->lru_lock. This might eliminate the need to add complexity to the reclaim code. Its impossible to make it parallel enough to allow hundreds or even thousands of processes in this code at the same time.
Will backport this patch & test it as well as testing it on latest kernel.
Larry
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Minchan Kim
I like this. but why do you select default value as constant 8? Do you have any reason?
Quoted 8 lines
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.Otherwise looks good to me.
Reviewed-by Minchan Kim <[email protected]>
This is a per-zone count so perhaps a reasonable default is the number of CPUs on the NUMA node that the zone resides on ?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi, Larry.
Quoted 10 lines · Larry Woodman
Quoted 9 lines · Minchan Kim
I like this. but why do you select default value as constant 8? Do you have any reason?
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.Otherwise looks good to me.
Quoted 7 lines
Quoted 3 lines
Reviewed-by Minchan Kim <[email protected]>This is a per-zone count so perhaps a reasonable default is the number of CPUs on the
NUMA node that the zone resides on ?
For example, It assume one CPU per node.
It means your default value is 1.
On the CPU, process A try to reclaim HIGH zone.
Process B want to reclaim NORMAL zone.
But Process B can't enter reclaim path sincev throttle default value is 1 Even kswap can't reclaim.
I think it's really agressive throttle approach although it would solve your problem.
I have another idea.
We make default value rather big and we provide latency vaule as knob. So first many processes can enter reclaim path. When shrinking time exceeds our konb(ex, some HZ), we can decrease default value of number of concurrent reclaim process. If shrink time is still long alghouth we do it, we can decrease
default vaule again. When shrink time is fast, we can allow to enter reclaim path of another processes as increase the number.
It's like old pdflush mechanism. but it's more complex than Rik's one. If Rik's approach solve this problem well, my approach is rather overkill, I think.
I am looking forward to Rik's approach work well.
Quoted 2 lines
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 8 lines · Larry Woodman
Quoted 7 lines · Minchan Kim
I like this. but why do you select default value as constant 8? Do you have any reason?
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.
Quoted 7 lines
Quoted 4 lines
Otherwise looks good to me.
Reviewed-by Minchan Kim <[email protected]>This is a per-zone count so perhaps a reasonable default is the number of CPUs on the
NUMA node that the zone resides on ?
One reason I made it tunable is so people can easily test what a good value would be :)
Signature · 7 lines
All rights reversed. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 21 lines · Minchan Kim
Hi, Larry.
Quoted 10 lines · Larry Woodman
Quoted 9 lines · Minchan Kim
I like this. but why do you select default value as constant 8? Do you have any reason?
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.Otherwise looks good to me.
Quoted 7 lines
Quoted 3 lines
Reviewed-by Minchan Kim<[email protected]>This is a per-zone count so perhaps a reasonable default is the number of CPUs on the
NUMA node that the zone resides on ?
Quoted 6 lines
For example, It assume one CPU per node.
It means your default value is 1.
On the CPU, process A try to reclaim HIGH zone.
Process B want to reclaim NORMAL zone.
But Process B can't enter reclaim path sincev throttle default value is 1 Even kswap can't reclaim.
1) the value is per zone, so process B can go ahead
2) kswapd is always excempt from this limit, since there is only 1 kswapd per node anyway
Signature · 7 lines
All rights reversed. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 25 lines · Rik van Riel
Quoted 24 lines · Minchan Kim
Hi, Larry.
Quoted 18 lines · Larry Woodman
Quoted 4 lines · Minchan Kim
I like this. but why do you select default value as constant 8? Do you have any reason?
Quoted 8 lines
I think it would be better to select the number proportional to
NR_CPU. ex)NR_CPU* 2 or something.Otherwise looks good to me.
Reviewed-by Minchan Kim<[email protected]>This is a per-zone count so perhaps a reasonable default is the number of CPUs on the
NUMA node that the zone resides on ?
Quoted 8 lines
Quoted 6 lines
For example, It assume one CPU per node.
It means your default value is 1.
On the CPU, process A try to reclaim HIGH zone.
Process B want to reclaim NORMAL zone.
But Process B can't enter reclaim path sincev throttle default value is 1 Even kswap can't reclaim.1) the value is per zone, so process B can go ahead
Sorry. I misunderstood Larry's point.
I though Larry mentioned global limit not per zone.
Quoted 2 lines
2) kswapd is always excempt from this limit, since there is only 1 kswapd per node anyway
Larry could test with Rik's patch for what's good default value. If it proves NR_CPU on node is proper as default value, We can change default value with it.
Quoted 3 lines
--
All rights reversed.
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 9 lines · Minchan Kim
Quoted 4 lines · Rik van Riel
Under very heavy multi-process workloads, like AIM7, the VM can get into trouble in a variety of ways. The trouble start when there are hundreds, or even thousands of processes active in the page reclaim code.
Otherwise looks good to me.
Reviewed-by Minchan Kim<[email protected]>
OK, we found three issues with my patch :)
1) there is a typo in sysctl.c
2) there is another typo in Documentation/vm/sysctl.c
3) the code in vmscan.c has a bug, where tasks without __GFP_IO or __GFP_FS can end up waiting for tasks with __GFP_IO or __GFP_FS, leading to a deadlock
I will fix these issues and send out a new patch.
Signature · 7 lines
All rights reversed. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Rik van Riel
Documentation/sysctl/vm.txt +4
-0+max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone.
Documentation/sysctl/vm.txt The default value is 65536. · line 295
Quoted 10 lines
Documentation/sysctl/vm.txt +10
-0+ +With certain workloads, hundreds of processes end up in the page +reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8.
I don't like the hardcoded number. Is the same number good for a 128MB embedded system as for as 1TB server? Seems doubtful.
This should be perhaps scaled with memory size and number of CPUs?
mm/vmscan.c struct scan_control { · line 142
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* Maximum number of processes concurrently running the page +* reclaim code in a memory zone. Having too many processes +* just results in them burning CPU time waiting for locks, +* so we're better off limiting page reclaim to a sane number +* of processes at a time. We do this per zone so local node +* reclaim on one NUMA node will not block other nodes from +* making progress. +*/ +int max_zone_concurrent_reclaimers =8 ;
__read_mostly
Quoted 6 lines
mm/vmscan.c +1
-0+static LIST_HEAD (shrinker_list);static DECLARE_RWSEM (shrinker_rwsem);@@ -1600,6 +1612,29 @@ static void shrink_zone(int priority, struct zone *zone,struct zone_reclaim_stat *reclaim_stat =get_reclaim_stat (zone, sc);
mm/vmscan.c static void shrink_zone(int priority, struct zone *zone, · line 1622
Quoted 10 lines
mm/vmscan.c +8
-0int noswap =0 ; +if (!current_is_kswapd () &&atomic_read (&zone->concurrent_reclaimers) > + max_zone_concurrent_reclaimers) { +/* +* Do not add to the lock contention if this zone has +* enough processes doing page reclaim already, since +* we would just make things slower. +*/ +sleep_on (&zone->reclaim_wait);
wait_event()? sleep_on is a really deprecated racy interface.
This would still badly thunder the herd if not enough memory is freed , won't it? It would be better to only wake up a single process if memory got freed.
How about for each page freed do a wake up for one thread?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 13 lines · Rik van Riel
Under very heavy multi-process workloads, like AIM7, the VM can get into trouble in a variety of ways. The trouble start when there are hundreds, or even thousands of processes active in the page reclaim code.
Not only can the system suffer enormous slowdowns because of lock contention (and conditional reschedules) between thousands of processes in the page reclaim code, but each process will try to free up to
SWAP_CLUSTER_MAXpages, even when the system already has lots of memory free. In Larry's case, this resulted in over 6000 processes fighting over locks in the page reclaim code, even though the system already had 1.5GB of free memory.
Quoted 4 lines
It should be possible to avoid both of those issues at once, by simply limiting how many processes are active in the page reclaim code simultaneously.
This sounds like a very good argument against using direct reclaim at all. It reminds a bit of the issue we had in XFS with lots of processes pushing the AIL and causing massive slowdowns due to lock contention and cacheline bonucing. Moving all the AIL pushing into a dedicated thread solved that nicely. In the VM we already have that dedicated per-node kswapd thread, so moving off as much as possible work to should be equivalent.
Of course any of this kind of tuning really requires a lot of testing and benchrmarking to verify those assumptions.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 19 lines · Christoph Hellwig
Quoted 13 lines · Rik van Riel
Under very heavy multi-process workloads, like AIM7, the VM can get into trouble in a variety of ways. The trouble start when there are hundreds, or even thousands of processes active in the page reclaim code.
Not only can the system suffer enormous slowdowns because of lock contention (and conditional reschedules) between thousands of processes in the page reclaim code, but each process will try to free up to
SWAP_CLUSTER_MAXpages, even when the system already has lots of memory free. In Larry's case, this resulted in over 6000 processes fighting over locks in the page reclaim code, even though the system already had 1.5GB of free memory.Quoted 4 lines
It should be possible to avoid both of those issues at once, by simply limiting how many processes are active in the page reclaim code simultaneously.
Quoted 7 lines
This sounds like a very good argument against using direct reclaim at all. It reminds a bit of the issue we had in XFS with lots of processes pushing the AIL and causing massive slowdowns due to lock contention and cacheline bonucing. Moving all the AIL pushing into a dedicated thread solved that nicely. In the VM we already have that dedicated per-node kswapd thread, so moving off as much as possible work to should be equivalent.
Some of the new systems have 16 CPUs per-node.
Quoted 4 lines
Of course any of this kind of tuning really requires a lot of testing and benchrmarking to verify those assumptions.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 20 lines · Andi Kleen
Quoted 4 lines · Rik van Riel
Documentation/sysctl/vm.txt +4
-0+max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone.Documentation/sysctl/vm.txt The default value is 65536. · line 295
Quoted 10 lines
Documentation/sysctl/vm.txt +10
-0+ +With certain workloads, hundreds of processes end up in the page +reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8.I don't like the hardcoded number. Is the same number good for a 128MB embedded system as for as 1TB server? Seems doubtful.
Quoted 1 line
This should be perhaps scaled with memory size and number of CPUs?
Remember this a per-zone number.
Quoted 33 lines
mm/vmscan.c struct scan_control { · line 142
Quoted 11 lines
mm/vmscan.c +10
-0+/* +* Maximum number of processes concurrently running the page +* reclaim code in a memory zone. Having too many processes +* just results in them burning CPU time waiting for locks, +* so we're better off limiting page reclaim to a sane number +* of processes at a time. We do this per zone so local node +* reclaim on one NUMA node will not block other nodes from +* making progress. +*/ +int max_zone_concurrent_reclaimers =8 ;
__read_mostlyQuoted 6 lines
mm/vmscan.c +1
-0+static LIST_HEAD (shrinker_list);static DECLARE_RWSEM (shrinker_rwsem);@@ -1600,6 +1612,29 @@ static void shrink_zone(int priority, struct zone *zone,struct zone_reclaim_stat *reclaim_stat =get_reclaim_stat (zone, sc);mm/vmscan.c static void shrink_zone(int priority, struct zone *zone, · line 1622
Quoted 10 lines
mm/vmscan.c +8
-0int noswap =0 ; +if (!current_is_kswapd () &&atomic_read (&zone->concurrent_reclaimers) > + max_zone_concurrent_reclaimers) { +/* +* Do not add to the lock contention if this zone has +* enough processes doing page reclaim already, since +* we would just make things slower. +*/ +sleep_on (&zone->reclaim_wait);
wait_event()?sleep_onis a really deprecated racy interface.
Quoted 7 lines
This would still badly thunder the herd if not enough memory is freed , won't it? It would be better to only wake up a single process if memory got freed.
How about for each page freed do a wake up for one thread?
-Andi
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 20 lines · Andi Kleen
Quoted 4 lines · Rik van Riel
Documentation/sysctl/vm.txt +4
-0+max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone.Documentation/sysctl/vm.txt The default value is 65536. · line 295
Quoted 10 lines
Documentation/sysctl/vm.txt +10
-0+ +With certain workloads, hundreds of processes end up in the page +reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8.I don't like the hardcoded number. Is the same number good for a 128MB embedded system as for as 1TB server? Seems doubtful.
Quoted 1 line
This should be perhaps scaled with memory size and number of CPUs?
The limit is per _zone_, so the number of concurrent reclaimers is automatically scaled by the number of memory zones in the system.
Scaling up the per-zone value as well looks like it could lead to the kind of lock contention we are aiming to avoid in the first place.
Signature · 7 lines
All rights reversed. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Rik van Riel
It should be possible to avoid both of those issues at once, by simply limiting how many processes are active in the page reclaim code simultaneously.
This sounds like a very good argument against using direct reclaim at all.
Not completely possible. Processes that call try_to_free_pages without __GFP_FS or __GFP_IO in their gfp_flags may be holding some kind of lock that kswapd could end up waiting on.
That means those tasks cannot wait on kswapd, because a deadlock could happen.
Having said that, maybe we can get away with making direct reclaim a limited subset of what it does today. Kswapd could be the only process scanning and unmapping ptes, submitting IOs and scanning the active list. Direct reclaim could limit itself to reclaiming clean inactive pages and sleeping in congestion_wait().
Signature · 7 lines
All rights reversed. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 21 lines · Larry Woodman
Quoted 20 lines · Andi Kleen
Quoted 4 lines · Rik van Riel
Documentation/sysctl/vm.txt +4
-0+max_zone_concurrent_reclaim: + +The number of processes that are allowed to simultaneously reclaim +memory from a particular memory zone.Documentation/sysctl/vm.txt The default value is 65536. · line 295
Quoted 10 lines
Documentation/sysctl/vm.txt +10
-0+ +With certain workloads, hundreds of processes end up in the page +reclaim code simultaneously. This can cause large slowdowns due +to lock contention, freeing of way too much memory and occasionally +false OOM kills. + +To avoid these problems, only allow a smaller number of processes +to reclaim pages from each memory zone simultaneously. + +The default value is 8.I don't like the hardcoded number. Is the same number good for a 128MB embedded system as for as 1TB server? Seems doubtful.
Quoted 3 lines
Quoted 1 line
This should be perhaps scaled with memory size and number of CPUs?
Remember this a per-zone number.
A zone could be 64MB or 32GB. And the system could have 1 or 1024 CPUs.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.