The patch titled Subject: mm: vrealloc: consider spare memory for __GFP_ZERO has been added to the -mm mm-unstable branch. Its filename is mm-vmalloc-implement-vrealloc-fix-3.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-vmalloc-implement-vrealloc-fix-3.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Danilo Krummrich <dakr@xxxxxxxxxx> Subject: mm: vrealloc: consider spare memory for __GFP_ZERO Date: Tue, 30 Jul 2024 20:49:42 +0200 Zero spare memory when shrinking a buffer with __GFP_ZERO. Link: https://lkml.kernel.org/r/20240730185049.6244-3-dakr@xxxxxxxxxx Fixes: 1f39ee9615a8 ("mm: vmalloc: implement vrealloc()") Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/vmalloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/mm/vmalloc.c~mm-vmalloc-implement-vrealloc-fix-3 +++ a/mm/vmalloc.c @@ -4077,12 +4077,15 @@ void *vrealloc_noprof(const void *p, siz 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; } _ Patches currently in -mm which might be from dakr@xxxxxxxxxx are mm-vmalloc-implement-vrealloc.patch mm-vmalloc-implement-vrealloc-fix.patch mm-vmalloc-implement-vrealloc-fix-2.patch mm-vmalloc-implement-vrealloc-fix-3.patch mm-kvmalloc-align-kvrealloc-with-krealloc.patch mm-kvmalloc-align-kvrealloc-with-krealloc-fix.patch mm-kvmalloc-align-kvrealloc-with-krealloc-fix-2.patch