diff mbox series

[2/2] mm: __kvsize()

Message ID 20240227072515.3736069-2-kent.overstreet@linux.dev (mailing list archive)
State New
Headers show
Series [1/2] mm: vmalloc_bytes() | expand

Commit Message

Kent Overstreet Feb. 27, 2024, 7:25 a.m. UTC
Add a __ksize() equivalent for kvmalloc.

Cc: linux-mm@kvack.org
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 include/linux/slab.h |  1 +
 mm/slab_common.c     | 13 +++++++++++++
 2 files changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/slab.h b/include/linux/slab.h
index b5f5ee8308d0..9ef26837c72d 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -227,6 +227,7 @@  void * __must_check krealloc(const void *objp, size_t new_size, gfp_t flags) __r
 void 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))
 
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 238293b1dbe1..6ec0f6543f34 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -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;