diff mbox series

[RFC,bpf-next,v2,05/11] mm: vmalloc: introduce vsize()

Message ID 20230112155326.26902-6-laoar.shao@gmail.com (mailing list archive)
State New
Headers show
Series mm, bpf: Add BPF into /proc/meminfo | expand

Commit Message

Yafang Shao Jan. 12, 2023, 3:53 p.m. UTC
Introduce a helper to report full size of underlying allocation of a
vmalloc'ed address.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 include/linux/vmalloc.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 096d48a..52f925f 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -297,4 +297,19 @@  struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
 static inline bool vmalloc_dump_obj(void *object) { return false; }
 #endif
 
+/* Report full size of underlying allocation of a vmalloc'ed addr */
+static inline size_t vsize(const void *addr)
+{
+	struct vm_struct *area;
+
+	if (!addr)
+		return 0;
+
+	area = find_vm_area(addr);
+	if (unlikely(!area))
+		return 0;
+
+	return area->size;
+}
+
 #endif /* _LINUX_VMALLOC_H */