]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: vrealloc: consider spare memory for __GFP_ZERO
authorDanilo Krummrich <dakr@kernel.org>
Tue, 30 Jul 2024 18:49:42 +0000 (20:49 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 17 Aug 2024 00:52:21 +0000 (17:52 -0700)
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 <dakr@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/vmalloc.c

index f364bba9a5cb0f9e46b34e251b4d2867eacdaba2..4339c56be3c81e4e15549eb8e42d4beb529a6247 100644 (file)
@@ -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;
        }