linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count
@ 2026-02-27 22:15 Benjamin Lee McQueen
  2026-03-02  8:56 ` Michal Hocko
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Lee McQueen @ 2026-02-27 22:15 UTC (permalink / raw)
  To: akpm, david
  Cc: lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb, mhocko,
	linux-mm, linux-kernel, Benjamin Lee McQueen

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.

Signed-off-by: Benjamin Lee McQueen <mcq@disroot.org>
---
 mm/vmpressure.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 3fbb86996c4d..925659f28dcb 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -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
-- 
2.51.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count
  2026-02-27 22:15 [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count Benjamin Lee McQueen
@ 2026-03-02  8:56 ` Michal Hocko
  2026-03-02 12:15   ` Lorenzo Stoakes
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Hocko @ 2026-03-02  8:56 UTC (permalink / raw)
  To: Benjamin Lee McQueen
  Cc: akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb,
	linux-mm, linux-kernel

On Fri 27-02-26 16:15:55, Benjamin Lee McQueen wrote:
> on systems of different sizes, the fixed 512 page window may not
> be suitable and cause excessive false positive memory pressure
> notifications.

Please be more specific about the issue you are trying to have fixed.
The above is way too generic. How much memory the system has, what do
you consider false positive and why. What is the workload. Etc...

> 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 please refrain from sending new versions in a quick succession
and wait for more feedback to come.

Last but not lease if this is a more of an idea rather than something
aimed to be merged make the fact explicit by RFC prefix to PATCH.

There is much more you can read about the process in Documentation/process/

Thanks
-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count
  2026-03-02  8:56 ` Michal Hocko
@ 2026-03-02 12:15   ` Lorenzo Stoakes
  0 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes @ 2026-03-02 12:15 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Benjamin Lee McQueen, akpm, david, Liam.Howlett, vbabka, rppt,
	surenb, linux-mm, linux-kernel

On Mon, Mar 02, 2026 at 09:56:38AM +0100, Michal Hocko wrote:
> On Fri 27-02-26 16:15:55, Benjamin Lee McQueen wrote:
> > on systems of different sizes, the fixed 512 page window may not
> > be suitable and cause excessive false positive memory pressure
> > notifications.
>
> Please be more specific about the issue you are trying to have fixed.
> The above is way too generic. How much memory the system has, what do
> you consider false positive and why. What is the workload. Etc...
>
> > 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 please refrain from sending new versions in a quick succession
> and wait for more feedback to come.
>
> Last but not lease if this is a more of an idea rather than something
> aimed to be merged make the fact explicit by RFC prefix to PATCH.
>
> There is much more you can read about the process in Documentation/process/
>

Agree on all points here.

I'm also concerned that by simply adding this conjectured approach without a
_lot_ of careful testing and examination of real-world cases you risk causing
issues/breaking real world user's assumptions. This is pretty sensitive code.

Definitely this kind of potentially invasive change should always be submitted
as an RFC to begin with.

> Thanks
> --
> Michal Hocko
> SUSE Labs

Cheers, Lorenzo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count
  2026-02-27 16:33 Benjamin Lee McQueen
  2026-02-27 20:28 ` Andrew Morton
@ 2026-02-27 22:18 ` Benjamin Lee McQueen
  1 sibling, 0 replies; 6+ messages in thread
From: Benjamin Lee McQueen @ 2026-02-27 22:18 UTC (permalink / raw)
  To: akpm, david
  Cc: lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb, mhocko,
	linux-mm, linux-kernel, Benjamin Lee McQueen

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.

Signed-off-by: Benjamin Lee McQueen <mcq@disroot.org>
---
 mm/vmpressure.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 3fbb86996c4d..925659f28dcb 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -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
-- 
2.51.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count
  2026-02-27 16:33 Benjamin Lee McQueen
@ 2026-02-27 20:28 ` Andrew Morton
  2026-02-27 22:18 ` Benjamin Lee McQueen
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2026-02-27 20:28 UTC (permalink / raw)
  To: Benjamin Lee McQueen
  Cc: david, lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb,
	mhocko, linux-mm, linux-kernel

On Fri, 27 Feb 2026 10:33:33 -0600 Benjamin Lee McQueen <mcq@disroot.org> 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.


> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -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);

Whitespace is odd.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count
@ 2026-02-27 16:33 Benjamin Lee McQueen
  2026-02-27 20:28 ` Andrew Morton
  2026-02-27 22:18 ` Benjamin Lee McQueen
  0 siblings, 2 replies; 6+ messages in thread
From: Benjamin Lee McQueen @ 2026-02-27 16:33 UTC (permalink / raw)
  To: akpm, david
  Cc: lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb, mhocko,
	linux-mm, linux-kernel, Benjamin Lee McQueen

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.

Signed-off-by: Benjamin Lee McQueen <mcq@disroot.org>
---
 mm/vmpressure.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 3fbb86996c4d..b2989c70dd39 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -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
-- 
2.53.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-02 12:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-27 22:15 [PATCH] mm/vmpressure: scale window size based on machine memory and CPU count Benjamin Lee McQueen
2026-03-02  8:56 ` Michal Hocko
2026-03-02 12:15   ` Lorenzo Stoakes
  -- strict thread matches above, loose matches on Subject: below --
2026-02-27 16:33 Benjamin Lee McQueen
2026-02-27 20:28 ` Andrew Morton
2026-02-27 22:18 ` Benjamin Lee McQueen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox