public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] implement ksize()
@ 2002-11-03 17:15 Christoph Hellwig
  0 siblings, 0 replies; only message in thread
From: Christoph Hellwig @ 2002-11-03 17:15 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

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.


--- 1.13/include/linux/slab.h	Wed Sep 25 20:41:05 2002
+++ edited/include/linux/slab.h	Sun Nov  3 03:08:32 2002
@@ -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));
 
--- 1.156/kernel/ksyms.c	Thu Oct 31 10:28:34 2002
+++ edited/kernel/ksyms.c	Sun Nov  3 03:09:00 2002
@@ -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);
--- 1.46/mm/slab.c	Fri Nov  1 16:34:38 2002
+++ edited/mm/slab.c	Sun Nov  3 13:18:29 2002
@@ -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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-11-03 17:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-03 17:15 [PATCH] implement ksize() Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox