[Devel] [PATCH 16/39] mm: slub: introduce virt_to_obj function

Andrey Ryabinin aryabinin at odin.com
Mon Aug 24 03:19:06 PDT 2015


From: Andrey Ryabinin <a.ryabinin at samsung.com>

commit 912f5fbf1d3060f25d6994aed0265c55b974b2e9 upstream.

virt_to_obj takes kmem_cache address, address of slab page, address x
pointing somewhere inside slab object, and returns address of the
beginning of object.

Signed-off-by: Andrey Ryabinin <a.ryabinin at samsung.com>
Acked-by: Christoph Lameter <cl at linux.com>
Cc: Dmitry Vyukov <dvyukov at google.com>
Cc: Konstantin Serebryany <kcc at google.com>
Cc: Dmitry Chernenkov <dmitryc at google.com>
Signed-off-by: Andrey Konovalov <adech.fo at gmail.com>
Cc: Yuri Gribov <tetra2005 at gmail.com>
Cc: Konstantin Khlebnikov <koct9i at gmail.com>
Cc: Sasha Levin <sasha.levin at oracle.com>
Cc: Christoph Lameter <cl at linux.com>
Cc: Joonsoo Kim <iamjoonsoo.kim at lge.com>
Cc: Dave Hansen <dave.hansen at intel.com>
Cc: Andi Kleen <andi at firstfloor.org>
Cc: Ingo Molnar <mingo at elte.hu>
Cc: Thomas Gleixner <tglx at linutronix.de>
Cc: "H. Peter Anvin" <hpa at zytor.com>
Cc: Pekka Enberg <penberg at kernel.org>
Cc: David Rientjes <rientjes at google.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
Signed-off-by: Andrey Ryabinin <aryabinin at odin.com>
---
 include/linux/slub_def.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index d7d4571..bd48c92 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -123,4 +123,20 @@ static inline void sysfs_slab_remove(struct kmem_cache *s)
 }
 #endif
 
+
+/**
+ * virt_to_obj - returns address of the beginning of object.
+ * @s: object's kmem_cache
+ * @slab_page: address of slab page
+ * @x: address within object memory range
+ *
+ * Returns address of the beginning of object
+ */
+static inline void *virt_to_obj(struct kmem_cache *s,
+				const void *slab_page,
+				const void *x)
+{
+	return (void *)x - ((x - slab_page) % s->size);
+}
+
 #endif /* _LINUX_SLUB_DEF_H */
-- 
2.4.6




More information about the Devel mailing list