From: Danilo Krummrich Date: Tue, 30 Jul 2024 18:49:42 +0000 (+0200) Subject: mm: vrealloc: consider spare memory for __GFP_ZERO X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ff4675c58f8cbbb3c2be7512466105d764224055;p=users%2Fjedix%2Flinux-maple.git mm: vrealloc: consider spare memory for __GFP_ZERO Zero spare memory when shrinking a buffer with __GFP_ZERO. Link: https://lkml.kernel.org/r/20240730185049.6244-3-dakr@kernel.org Fixes: 1f39ee9615a8 ("mm: vmalloc: implement vrealloc()") Signed-off-by: Danilo Krummrich Signed-off-by: Andrew Morton --- diff --git a/mm/vmalloc.c b/mm/vmalloc.c index f364bba9a5cb..4339c56be3c8 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4070,12 +4070,15 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) old_size = get_vm_area_size(vm); } + /* + * TODO: Shrink the vm_area, i.e. unmap and free unused pages. What + * would be a good heuristic for when to shrink the vm_area? + */ if (size <= old_size) { - /* - * TODO: Shrink the vm_area, i.e. unmap and free unused pages. - * What would be a good heuristic for when to shrink the - * vm_area? - */ + /* Zero out spare memory. */ + if (want_init_on_alloc(flags)) + memset((void *)p + size, 0, old_size - size); + return (void *)p; }