* [PATCH 1/4] mm: vmpressure: scale sampling window with machine size
@ 2026-07-15 14:36 deepakraog
2026-07-15 14:36 ` [PATCH 3/4] mm: vrealloc: grow vm_area mappings in place deepakraog
2026-07-22 8:07 ` [PATCH 1/4] mm: vmpressure: scale sampling window with machine size Michal Hocko
0 siblings, 2 replies; 4+ messages in thread
From: deepakraog @ 2026-07-15 14:36 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel
The vmpressure window size was fixed at 512 pages (SWAP_CLUSTER_MAX * 16).
Scale it at boot from total memory and CPU count using the same fls-based
formula as vmstat per-zone thresholds, clamped between 128 and 2048 pages.
Signed-off-by: deepakraog <gaikwad.dcg@gmail.com>
---
mm/vmpressure.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index f053554e5..8925d4ad3 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -33,9 +33,29 @@
* 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).
+ * thresholds. Scales with CPU count and total memory at boot.
*/
-static const unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16;
+static unsigned long vmpressure_win;
+
+static unsigned long __init vmpressure_window_size(void)
+{
+ unsigned long win;
+ int mem;
+
+ mem = totalram_pages() >> (27 - PAGE_SHIFT);
+ win = SWAP_CLUSTER_MAX * (unsigned long)fls(num_online_cpus()) *
+ (1 + fls(mem));
+ win = max(win, SWAP_CLUSTER_MAX * 4UL);
+ win = min(win, SWAP_CLUSTER_MAX * 64UL);
+ return win;
+}
+
+static int __init vmpressure_win_init(void)
+{
+ vmpressure_win = vmpressure_window_size();
+ return 0;
+}
+core_initcall(vmpressure_win_init);
/*
* These thresholds are used when we account memory pressure through
--
Deepak Rao Gaikwad
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/4] mm: vrealloc: grow vm_area mappings in place
2026-07-15 14:36 [PATCH 1/4] mm: vmpressure: scale sampling window with machine size deepakraog
@ 2026-07-15 14:36 ` deepakraog
2026-07-22 8:07 ` [PATCH 1/4] mm: vmpressure: scale sampling window with machine size Michal Hocko
1 sibling, 0 replies; 4+ messages in thread
From: deepakraog @ 2026-07-15 14:36 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki, linux-mm, linux-kernel
When vrealloc() needs more pages than are currently mapped, allocate and
map additional pages at the end of the existing vm_area instead of
always allocating a new area and memcpy()'ing. Fall back to the
existing realloc path when in-place grow is not possible.
Signed-off-by: deepakraog <gaikwad.dcg@gmail.com>
---
mm/vmalloc.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 1afca3568..46cf10c62 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4426,8 +4426,56 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
return (void *)p;
}
+ {
+ unsigned int new_nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
+ unsigned int old_nr_pages = vm->nr_pages;
+
+ if (new_nr_pages > old_nr_pages && !vm_area_page_order(vm) &&
+ !(vm->flags & (VM_FLUSH_RESET_PERMS | VM_USERMAP)) &&
+ gfp_has_io_fs(flags)) {
+ unsigned int extra = new_nr_pages - old_nr_pages;
+ unsigned long addr = (unsigned long)kasan_reset_tag(p);
+ struct vmap_node *vn = addr_to_node(addr);
+ struct page **pages;
+ int ret;
+
+ pages = kvmalloc_array(extra, sizeof(struct page *), gfp);
+ if (!pages)
+ goto need_realloc;
+
+ if (vm_area_alloc_pages(vmalloc_gfp_adjust(gfp, 0), nid,
+ 0, extra, pages) != extra) {
+ kvfree(pages);
+ goto need_realloc;
+ }
+
+ spin_lock(&vn->busy.lock);
+ ret = vmap_pages_range(addr + ((unsigned long)old_nr_pages
+ << PAGE_SHIFT),
+ addr + ((unsigned long)new_nr_pages
+ << PAGE_SHIFT),
+ PAGE_KERNEL, pages, PAGE_SHIFT);
+ spin_unlock(&vn->busy.lock);
+ if (ret < 0) {
+ free_pages_bulk(pages, extra);
+ kvfree(pages);
+ goto need_realloc;
+ }
+
+ memcpy(&vm->pages[old_nr_pages], pages,
+ extra * sizeof(struct page *));
+ kvfree(pages);
+ vm->nr_pages = new_nr_pages;
+ vm->requested_size = size;
+ kasan_vrealloc(p, old_size, size);
+ if (want_init_on_alloc(flags))
+ memset((void *)p + old_size, 0, size - old_size);
+ return (void *)p;
+ }
+ }
+
need_realloc:
- /* TODO: Grow the vm_area, i.e. allocate and map additional pages. */
+ /* Fall back to a fresh vm_area when in-place grow is not possible. */
n = __vmalloc_node_noprof(size, align, flags, nid, __builtin_return_address(0));
if (!n)
--
Deepak Rao Gaikwad
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/4] mm: vmpressure: scale sampling window with machine size
2026-07-15 14:36 [PATCH 1/4] mm: vmpressure: scale sampling window with machine size deepakraog
2026-07-15 14:36 ` [PATCH 3/4] mm: vrealloc: grow vm_area mappings in place deepakraog
@ 2026-07-22 8:07 ` Michal Hocko
2026-07-22 8:52 ` Lorenzo Stoakes (ARM)
1 sibling, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2026-07-22 8:07 UTC (permalink / raw)
To: deepakraog
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, linux-mm, linux-kernel
On Wed 15-07-26 20:06:41, deepakraog wrote:
> The vmpressure window size was fixed at 512 pages (SWAP_CLUSTER_MAX * 16).
> Scale it at boot from total memory and CPU count using the same fls-based
> formula as vmstat per-zone thresholds, clamped between 128 and 2048 pages.
This is not giving us any rationale why this is needed or desirable.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/4] mm: vmpressure: scale sampling window with machine size
2026-07-22 8:07 ` [PATCH 1/4] mm: vmpressure: scale sampling window with machine size Michal Hocko
@ 2026-07-22 8:52 ` Lorenzo Stoakes (ARM)
0 siblings, 0 replies; 4+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-07-22 8:52 UTC (permalink / raw)
To: Michal Hocko
Cc: deepakraog, Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, linux-mm,
linux-kernel
On Wed, Jul 22, 2026 at 10:07:53AM +0200, Michal Hocko wrote:
> On Wed 15-07-26 20:06:41, deepakraog wrote:
> > The vmpressure window size was fixed at 512 pages (SWAP_CLUSTER_MAX * 16).
> > Scale it at boot from total memory and CPU count using the same fls-based
> > formula as vmstat per-zone thresholds, clamped between 128 and 2048 pages.
>
> This is not giving us any rationale why this is needed or desirable.
Agreed, the series are all somewhat corrupted here (seemingly some patches
missing + not sent to the same list of people, unrelated stuff in the same
series, etc.).
I replied to the v2 of this ([0]), in general this is essentially the same thing
submitted by a previous person ([1]), and Deepak acked that ([2]) and agreed
that this isn't worth pursuing.
Cheers, Lorenzo
[0]:https://lore.kernel.org/linux-mm/aljYxLusTzZkTfnH@lucifer/
[1]:https://lore.kernel.org/all/20260227221555.29969-1-mcq@disroot.org/
[2]:https://lore.kernel.org/all/20260716134938.42495-1-gaikwad.dcg@gmail.com/
>
> --
> Michal Hocko
> SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-22 8:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 14:36 [PATCH 1/4] mm: vmpressure: scale sampling window with machine size deepakraog
2026-07-15 14:36 ` [PATCH 3/4] mm: vrealloc: grow vm_area mappings in place deepakraog
2026-07-22 8:07 ` [PATCH 1/4] mm: vmpressure: scale sampling window with machine size Michal Hocko
2026-07-22 8:52 ` Lorenzo Stoakes (ARM)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox