mm/vmpressure: scale window size based on machine memory and CPU count
Subsystems (2)
PATCH 1/1 mm/vmpressure: scale window size based on machine memory and CPU count
the vmpressure window size was recently fixed at 512 pages regardless of machine size, this patch makes it scale based on the machine memory and CPU count.
--- mm/vmpressure.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/vmpressure.c +13 -3
@@ -32,10 +32,20 @@* As the vmscan reclaimer logic works with chunks which are multiple of * SWAP_CLUSTER_MAX, it makes sense to use it for the window size as well. * -* TODO: Make the window size depend on machine size, as we do for vmstat -* thresholds. Currently we set it to 512 pages (2MB for 4KB pages). +* Window size is now scaled based on RAM and CPU size, similarly to how +* vmstat checks them. */ -static const unsigned long vmpressure_win =SWAP_CLUSTER_MAX *16 ; +static unsigned long vmpressure_win; + +static int __init vmpressure_win_init (void ) +{ +unsigned long mem =totalram_pages () >> (27 -PAGE_SHIFT ); + + vmpressure_win =SWAP_CLUSTER_MAX *max (16UL , +2UL *fls (num_online_cpus ()) * (1 +fls (mem))); +return 0 ; +} +core_initcall (vmpressure_win_init);/* * These thresholds are used when we account memory pressure through
Signature · 1 line
2.53.0
Andrew Morton
maintainerQuoted 3 lines · On Fri, 27 Feb 2026 10:33:33 -0600 Benjamin Lee McQueen <[email protected]> wrote:
the vmpressure window size was recently fixed at 512 pages regardless of machine size, this patch makes it scale based on the machine memory and CPU count.
Why? Presumably the current code is causing some problem - please fully describe that.
Quoted 13 lines
mm/vmpressure.c +3
-3@@ -32,10 +32,20 @@* As the vmscan reclaimer logic works with chunks which are multiple of * SWAP_CLUSTER_MAX, it makes sense to use it for the window size as well. * -* TODO: Make the window size depend on machine size, as we do for vmstat -* thresholds. Currently we set it to 512 pages (2MB for 4KB pages). +* Window size is now scaled based on RAM and CPU size, similarly to how +* vmstat checks them. */ -static const unsigned long vmpressure_win =SWAP_CLUSTER_MAX *16 ; +static unsigned long vmpressure_win;
mm/vmpressure.c line 48
Quoted 10 lines
mm/vmpressure.c +10
-0+ +static int __init vmpressure_win_init (void ) +{ +unsigned long mem =totalram_pages () >> (27 -PAGE_SHIFT ); + + vmpressure_win =SWAP_CLUSTER_MAX *max (16UL , +2UL *fls (num_online_cpus ()) * (1 +fls (mem))); +return 0 ; +} +core_initcall (vmpressure_win_init);
Whitespace is odd.
PATCH v2 1/1 mm/vmpressure: scale window size based on machine memory and CPU count
on systems of different sizes, the fixed 512 page window may not be suitable and cause excessive false positive memory pressure notifications.
or should window size be capped to avoid excessive notification delays on very large systems?
v2: better commit msg, also tried to fix the whitespace.
also my bad for the multiple sends, i couldn't get the format right..
--- mm/vmpressure.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/vmpressure.c +13 -3
@@ -32,10 +32,20 @@* As the vmscan reclaimer logic works with chunks which are multiple of * SWAP_CLUSTER_MAX, it makes sense to use it for the window size as well. * -* TODO: Make the window size depend on machine size, as we do for vmstat -* thresholds. Currently we set it to 512 pages (2MB for 4KB pages). +* Window size is now scaled based on RAM and CPU size, similarly to how +* vmstat checks them. */ -static const unsigned long vmpressure_win =SWAP_CLUSTER_MAX *16 ; +static unsigned long vmpressure_win; + +static int __init vmpressure_win_init (void ) +{ +unsigned long mem =totalram_pages () >> (27 -PAGE_SHIFT ); + + vmpressure_win =SWAP_CLUSTER_MAX *max (16UL , +2UL *fls (num_online_cpus ()) * (1 +fls (mem))); +return 0 ; +} +core_initcall (vmpressure_win_init);/* * These thresholds are used when we account memory pressure through
Signature · 1 line
2.53.0
PATCH 1/1 mm/vmpressure: scale window size based on machine memory and CPU count
In reply to Benjamin Lee McQueenon systems of different sizes, the fixed 512 page window may not be suitable and cause excessive false positive memory pressure notifications.
or should window size be capped to avoid excessive notification delays on very large systems?
v2: better commit msg, also tried to fix the whitespace.
--- mm/vmpressure.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/vmpressure.c +13 -3
@@ -32,10 +32,20 @@* As the vmscan reclaimer logic works with chunks which are multiple of * SWAP_CLUSTER_MAX, it makes sense to use it for the window size as well. * -* TODO: Make the window size depend on machine size, as we do for vmstat -* thresholds. Currently we set it to 512 pages (2MB for 4KB pages). +* Window size is now scaled based on RAM and CPU size, similarly to how +* vmstat checks them. */ -static const unsigned long vmpressure_win =SWAP_CLUSTER_MAX *16 ; +static unsigned long vmpressure_win; + +static int __init vmpressure_win_init (void ) +{ +unsigned long mem =totalram_pages () >> (27 -PAGE_SHIFT ); + + vmpressure_win =SWAP_CLUSTER_MAX *max (16UL , +2UL *fls (num_online_cpus ()) * (1 +fls (mem))); +return 0 ; +} +core_initcall (vmpressure_win_init);/* * These thresholds are used when we account memory pressure through
Signature · 1 line
2.51.0
PATCH v2 1/1 mm/vmpressure: scale window size based on machine memory and CPU count
In reply to Benjamin Lee McQueenon systems of different sizes, the fixed 512 page window may not be suitable and cause excessive false positive memory pressure notifications.
or should window size be capped to avoid excessive notification delays on very large systems?
v2: better commit msg, also tried to fix the whitespace.
also my bad for the multiple sends, i couldn't get the format right..
--- mm/vmpressure.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/vmpressure.c +13 -3
@@ -32,10 +32,20 @@* As the vmscan reclaimer logic works with chunks which are multiple of * SWAP_CLUSTER_MAX, it makes sense to use it for the window size as well. * -* TODO: Make the window size depend on machine size, as we do for vmstat -* thresholds. Currently we set it to 512 pages (2MB for 4KB pages). +* Window size is now scaled based on RAM and CPU size, similarly to how +* vmstat checks them. */ -static const unsigned long vmpressure_win =SWAP_CLUSTER_MAX *16 ; +static unsigned long vmpressure_win; + +static int __init vmpressure_win_init (void ) +{ +unsigned long mem =totalram_pages () >> (27 -PAGE_SHIFT ); + + vmpressure_win =SWAP_CLUSTER_MAX *max (16UL , +2UL *fls (num_online_cpus ()) * (1 +fls (mem))); +return 0 ; +} +core_initcall (vmpressure_win_init);/* * These thresholds are used when we account memory pressure through
Signature · 1 line
2.53.0