Introduce a helper to report full size of underlying allocation of a vmalloc'ed address. Suggested-by: Uladzislau Rezki <urezki@xxxxxxxxx> Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> Cc: Uladzislau Rezki <urezki@xxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> --- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 096d48a..7fbd390 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -297,4 +297,5 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, static inline bool vmalloc_dump_obj(void *object) { return false; } #endif +size_t vsize(void *addr); #endif /* _LINUX_VMALLOC_H */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ca71de7..8499eba 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4057,6 +4057,23 @@ bool vmalloc_dump_obj(void *object) } #endif +/* Report full size of underlying allocation of a vmalloc'ed addr */ +size_t vsize(void *addr) +{ + struct vmap_area *va; + size_t va_size = 0; + + if (!addr) + return 0; + + spin_lock(&vmap_area_lock); + va = __find_vmap_area((unsigned long)addr, &vmap_area_root); + if (va && va->vm) + va_size = va->vm->size; + spin_unlock(&vmap_area_lock); + return va_size; +} + #ifdef CONFIG_PROC_FS static void *s_start(struct seq_file *m, loff_t *pos) __acquires(&vmap_purge_lock) -- 1.8.3.1