Skip to contentSkip to conversation

implement ksize()

PATCH New Christoph Hellwig 1 participant 1 message Nov 3, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 implement ksize()

It's used to find out the effective allocation size of objects allocated by kmalloc(). This is needed by the uClinux ports in many places but seems also usefull for mmu-using ports.

include/linux/slab.h +1 -0
@@ -60,6 +60,7 @@
 
 extern void *kmalloc(size_t, int);
 extern void kfree(const void *);
+extern unsigned int ksize(const void *);
 
 extern int FASTCALL(kmem_cache_reap(int));
 
kernel/ksyms.c +1 -0
@@ -104,6 +104,7 @@
 EXPORT_SYMBOL(remove_shrinker);
 EXPORT_SYMBOL(kmalloc);
 EXPORT_SYMBOL(kfree);
+EXPORT_SYMBOL(ksize);
 EXPORT_SYMBOL(vfree);
 EXPORT_SYMBOL(__vmalloc);
 EXPORT_SYMBOL(vmalloc);
mm/slab.c +16 -0
@@ -1871,6 +1871,22 @@
 	return cachep->objsize;
 }
 
+unsigned int ksize(const void *objp)
+{
+	kmem_cache_t *c;
+	unsigned long flags;
+	unsigned int size = 0;
+
+	if (objp) {
+		local_irq_save(flags);
+		c = GET_PAGE_CACHE(virt_to_page(objp));
+		size = kmem_cache_size(c);
+		local_irq_restore(flags);
+	}
+
+	return size;
+}
+
 kmem_cache_t * kmem_find_general_cachep (size_t size, int gfpflags)
 {
 	struct cache_sizes *csizep = malloc_sizes;