@@ -226,6 +226,15 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name,
*/
size_t ksize(const void *objp);
+/**
+ * ksize_full - Report full size of each accounted objp
+ * @objp: pointer to the object
+ *
+ * The difference between ksize() and ksize_full() is that ksize_full()
+ * includes the extra space which is used to store obj_cgroup membership.
+ */
+size_t ksize_full(const void *objp);
+
#ifdef CONFIG_PRINTK
bool kmem_valid_obj(void *object);
void kmem_dump_obj(void *object);
@@ -762,6 +771,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(const 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(const void *addr)
+{
+ if (is_vmalloc_addr(addr))
+ return vsize(addr);
+
+ return ksize_full(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 | 10 ++++++++++ mm/util.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+)