@@ -762,6 +762,7 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t n, size_t size, gfp_t fla
extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_t flags)
__realloc_size(3);
+extern size_t kvsize(void *addr);
extern void kvfree(const void *addr);
extern void kvfree_sensitive(const void *addr, size_t len);
@@ -610,6 +610,21 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
EXPORT_SYMBOL(kvmalloc_node);
/**
+ * kvsize() - Report full size of underlying allocation of adddr
+ * @addr: Pointer to kmalloc'ed or vmalloc'ed memory
+ *
+ * kvsize reports full size of underlying allocation of a kmalloc'ed addr
+ * or a vmalloc'ed addr.
+ */
+size_t kvsize(void *addr)
+{
+ if (is_vmalloc_addr(addr))
+ return vsize(addr);
+
+ return ksize(addr);
+}
+
+/**
* kvfree() - Free memory.
* @addr: Pointer to allocated memory.
*
Introduce a new help kvsize() to report full size of underlying allocation of a kmalloc'ed addr or vmalloc'ed addr. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> --- include/linux/slab.h | 1 + mm/util.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)