mm: vmalloc_bytes()
Subsystems (3)
PATCH 1/2 mm: vmalloc_bytes()
Add a __ksize() equivalent for vmalloc.
This is being added so we can track amount of memory stranded waiting for an RCU grace period.
Signed-off-by Kent Overstreet <[email protected]>
--- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
include/linux/vmalloc.h +1 -0
@@ -160,6 +160,7 @@ extern void *vcalloc(size_t n, size_t size) __alloc_size(1, 2);extern void vfree (const void *addr);extern void vfree_atomic (const void *addr); +extern size_t vmalloc_bytes (const void *addr);extern void *vmap (struct page **pages,unsigned int count,unsigned long flags,pgprot_t prot);
mm/vmalloc.c +20 -0
@@ -2848,6 +2848,26 @@ void vfree(const void *addr) }EXPORT_SYMBOL (vfree); +/** +* vmalloc_bytes - Return size of a vmalloc() allocation +* @addr: Memory base address +* +* Returns the size of the allocation as passed to vmalloc() rounded up to +* PAGE_SIZE; does not include extra internal allocations. +*/ +size_t vmalloc_bytes (const void *addr) +{ +struct vm_struct *vm =find_vm_area (addr); +if (unlikely (!vm)) { +WARN (1 ,KERN_ERR "vmalloc_bytes() called on nonexistent vm area (%p)\n" , + addr); +return 0 ; + } + +return vm->nr_pages *PAGE_SIZE ; +} +EXPORT_SYMBOL (vmalloc_bytes); +/** * vunmap - release virtual mapping obtained by vmap() * @addr: memory base address
Signature · 1 line
2.43.0
PATCH 2/2 mm: __kvsize()
Add a __ksize() equivalent for kvmalloc.
Signed-off-by Kent Overstreet <[email protected]>
--- include/linux/slab.h | 1 + mm/slab_common.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
include/linux/slab.h +1 -0
@@ -227,6 +227,7 @@ void * __must_check krealloc(const void *objp, size_t new_size, gfp_t flags) __rvoid kfree (const void *objp);void kfree_sensitive (const void *objp);size_t __ksize (const void *objp); +size_t __kvsize (const void *objp); DEFINE_FREE(kfree, void *, if (_T) kfree(_T))
mm/slab_common.c +13 -0
@@ -972,6 +972,19 @@ size_t __ksize(const void *object)return slab_ksize (folio_slab (folio)->slab_cache); } +/** +* __kvsize -- Report full size of underlying allocation +* @object: pointer to the object +* +* __ksize equivalent, but for kvmalloc +*/ +size_t __kvsize (const void *addr) +{ +return is_vmalloc_addr (addr) + ?vmalloc_bytes (addr) + :__ksize (addr); +} +gfp_t kmalloc_fix_flags (gfp_t flags) {gfp_t invalid_mask = flags &GFP_SLAB_BUG_MASK ;
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 10 lines · On Tue, 27 Feb 2024 02:25:14 -0500 Kent Overstreet <[email protected]>…
Add a
__ksize()equivalent for vmalloc.
+++b/mm/vmalloc.cmm/vmalloc.c +4
-0@@ -2848,6 +2848,26 @@ void vfree(const void *addr) }EXPORT_SYMBOL (vfree); +/** +* vmalloc_bytes - Return size of a vmalloc() allocation +* @addr: Memory base address +*
mm/vmalloc.c void vfree(const void *addr) · line 2864
Quoted 10 lines
mm/vmalloc.c +10
-0+* Returns the size of the allocation as passed to vmalloc() rounded up to +* PAGE_SIZE; does not include extra internal allocations. +*/ +size_t vmalloc_bytes (const void *addr) +{ +struct vm_struct *vm =find_vm_area (addr); +if (unlikely (!vm)) { +WARN (1 ,KERN_ERR "vmalloc_bytes() called on nonexistent vm area (%p)\n" , + addr); +return 0 ;
if (WARN(!vm, "..."))
and I don't think the explicit KERN_ERR facility is needed?