mm-kvmalloc-align-kvrealloc-with-krealloc.patch removed from -mm tree
The quilt patch titled
Subject: mm: kvmalloc: align kvrealloc() with krealloc()
has been removed from the -mm tree. Its filename was
mm-kvmalloc-align-kvrealloc-with-krealloc.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Danilo Krummrich <[email protected]>
Subject: mm: kvmalloc: align kvrealloc() with krealloc()
Date: Mon, 22 Jul 2024 18:29:24 +0200
Besides the obvious (and desired) difference between krealloc() and kvrealloc(), there is some inconsistency in their function signatures and behavior:
- krealloc() frees the memory when the requested size is zero, whereas kvrealloc() simply returns a pointer to the existing allocation.
- krealloc() behaves like kmalloc() if a NULL pointer is passed, whereas kvrealloc() does not accept a NULL pointer at all and, if passed, would fault instead.
- krealloc() is self-contained, whereas kvrealloc() relies on the caller to provide the size of the previous allocation.
Inconsistent behavior throughout allocation APIs is error prone, hence make kvrealloc() behave like krealloc(), which seems superior in all mentioned aspects.
Besides that, implementing kvrealloc() by making use of krealloc() and vrealloc() provides oppertunities to grow (and shrink) allocations more efficiently. For instance, vrealloc() can be optimized to allocate and map additional pages to grow the allocation or unmap and free unused pages to shrink the allocation.
---
arch/arm64/kvm/nested.c | 1 arch/powerpc/platforms/pseries/papr-vpd.c | 5 - drivers/gpu/drm/drm_exec.c | 3 fs/xfs/xfs_log_recover.c | 2 include/linux/slab.h | 4 kernel/resource.c | 3 lib/fortify_kunit.c | 3 mm/util.c | 100 ++++++++++++++------ 8 files changed, 77 insertions(+), 44 deletions(-)
arch/arm64/kvm/nested.c renamed from arch/arm64/kvm/nested.c~mm-kvmalloc-align-kvrealloc-with-krealloc +0 -1
@@ -62,7 +62,6 @@ int kvm_vcpu_init_nested(struct kvm_vcpu*/ num_mmus =atomic_read (&kvm->online_vcpus) *S2_MMU_PER_VCPU ; tmp =kvrealloc (kvm->arch.nested_mmus, -size_mul (sizeof (*kvm->arch.nested_mmus), kvm->arch.nested_mmus_size),size_mul (sizeof (*kvm->arch.nested_mmus), num_mmus),GFP_KERNEL_ACCOUNT | __GFP_ZERO);if (!tmp)
arch/powerpc/platforms/pseries/papr-vpd.c renamed from arch/powerpc/platforms/pseries/papr-vpd.c~mm-kvmalloc-align-kvrealloc-with-krealloc +1 -4
@@ -156,10 +156,7 @@ static int vpd_blob_extend(struct vpd_blconst char *old_ptr = blob->data;char *new_ptr; - new_ptr = old_ptr ? -kvrealloc (old_ptr, old_len, new_len,GFP_KERNEL_ACCOUNT ) : -kvmalloc (len,GFP_KERNEL_ACCOUNT ); - + new_ptr =kvrealloc (old_ptr, new_len,GFP_KERNEL_ACCOUNT );if (!new_ptr)return -ENOMEM ;
drivers/gpu/drm/drm_exec.c renamed from drivers/gpu/drm/drm_exec.c~mm-kvmalloc-align-kvrealloc-with-krealloc +1 -2
@@ -145,8 +145,7 @@ static int drm_exec_obj_locked(struct drsize_t size = exec->max_objects *sizeof (void *);void *tmp; - tmp =kvrealloc (exec->objects, size, size +PAGE_SIZE , -GFP_KERNEL ); + tmp =kvrealloc (exec->objects, size +PAGE_SIZE ,GFP_KERNEL );if (!tmp)return -ENOMEM ;
fs/xfs/xfs_log_recover.c renamed from fs/xfs/xfs_log_recover.c~mm-kvmalloc-align-kvrealloc-with-krealloc +1 -1
@@ -2128,7 +2128,7 @@ xlog_recover_add_to_cont_trans( old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; old_len = item->ri_buf[item->ri_cnt-1 ].i_len; - ptr =kvrealloc (old_ptr, old_len, len + old_len,GFP_KERNEL ); + ptr =kvrealloc (old_ptr, len + old_len,GFP_KERNEL );if (!ptr)return -ENOMEM ;memcpy (&ptr[old_len], dp, len);
include/linux/slab.h renamed from include/linux/slab.h~mm-kvmalloc-align-kvrealloc-with-krealloc +2 -2
@@ -841,8 +841,8 @@ kvmalloc_array_node_noprof(size_t n, siz#define kvcalloc_node (...) alloc_hooks(kvcalloc_node_noprof(__VA_ARGS__))#define kvcalloc (...) alloc_hooks(kvcalloc_noprof(__VA_ARGS__)) -extern void *kvrealloc_noprof (const void *p,size_t oldsize,size_t newsize,gfp_t flags) -__realloc_size (3 ); +void *kvrealloc_noprof (const void *p,size_t size,gfp_t flags) +__realloc_size (2 );#define kvrealloc (...) alloc_hooks(kvrealloc_noprof(__VA_ARGS__))extern void kvfree (const void *addr);
kernel/resource.c renamed from kernel/resource.c~mm-kvmalloc-align-kvrealloc-with-krealloc +1 -2
@@ -450,8 +450,7 @@ int walk_system_ram_res_rev(u64 start, u/* re-alloc */ struct resource *rams_new; - rams_new =kvrealloc (rams, rams_size *sizeof (struct resource ), - (rams_size +16 ) *sizeof (struct resource ), + rams_new =kvrealloc (rams, (rams_size +16 ) *sizeof (struct resource ),GFP_KERNEL );if (!rams_new) goto out;
lib/fortify_kunit.c renamed from lib/fortify_kunit.c~mm-kvmalloc-align-kvrealloc-with-krealloc +1 -2
@@ -306,8 +306,7 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(vmalloc) orig =kvmalloc (prev_size, gfp); \KUNIT_EXPECT_TRUE (test, orig !=NULL ); \checker (((expected_pages) *PAGE_SIZE ) *2 , \ -kvrealloc (orig, prev_size, \ - ((alloc_pages) *PAGE_SIZE ) *2 , gfp), \ +kvrealloc (orig, ((alloc_pages) *PAGE_SIZE ) *2 , gfp), \kvfree (p)); \ }while (0 )DEFINE_ALLOC_SIZE_TEST_PAIR (kvmalloc)
mm/util.c renamed from mm/util.c~mm-kvmalloc-align-kvrealloc-with-krealloc +70 -30
126 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are
mm-krealloc-consider-spare-memory-for-__gfp_zero.patch mm-krealloc-clarify-valid-usage-of-__gfp_zero.patch