Commit e0126e64 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] implement kmem_cache_size()

Currently there is no way to find out the effective object size of a slab
cache.  XFS has lots of IRIX-derived code that want to do zalloc() style
allocations on zones (which are implemented as slab caches in XFS/Linux)
and thus needs to know about it.  There are three ways do implement it:

a) implement kmem_cache_zalloc
b) make the xfs zone a struct of kmem_cache_t and a size variable
c) implement kmem_cache_size

The current XFS tree does a) but I absolutely don't like it as encourages
people to use kmem_cache_zalloc for new code instead of thinking about how
to utilize slab object reuse.  b) would be easy, but I guess kmem_cache_size
is usefull enough to get into the kernel.  Here's the patch:
parent 5ff53a14
...@@ -57,6 +57,7 @@ extern int kmem_cache_destroy(kmem_cache_t *); ...@@ -57,6 +57,7 @@ extern int kmem_cache_destroy(kmem_cache_t *);
extern int kmem_cache_shrink(kmem_cache_t *); extern int kmem_cache_shrink(kmem_cache_t *);
extern void *kmem_cache_alloc(kmem_cache_t *, int); extern void *kmem_cache_alloc(kmem_cache_t *, int);
extern void kmem_cache_free(kmem_cache_t *, void *); extern void kmem_cache_free(kmem_cache_t *, void *);
extern unsigned int kmem_cache_size(kmem_cache_t *);
extern void *kmalloc(size_t, int); extern void *kmalloc(size_t, int);
extern void kfree(const void *); extern void kfree(const void *);
......
...@@ -105,6 +105,7 @@ EXPORT_SYMBOL(kmem_cache_destroy); ...@@ -105,6 +105,7 @@ EXPORT_SYMBOL(kmem_cache_destroy);
EXPORT_SYMBOL(kmem_cache_shrink); EXPORT_SYMBOL(kmem_cache_shrink);
EXPORT_SYMBOL(kmem_cache_alloc); EXPORT_SYMBOL(kmem_cache_alloc);
EXPORT_SYMBOL(kmem_cache_free); EXPORT_SYMBOL(kmem_cache_free);
EXPORT_SYMBOL(kmem_cache_size);
EXPORT_SYMBOL(kmalloc); EXPORT_SYMBOL(kmalloc);
EXPORT_SYMBOL(kfree); EXPORT_SYMBOL(kfree);
EXPORT_SYMBOL(vfree); EXPORT_SYMBOL(vfree);
......
...@@ -1647,6 +1647,15 @@ void kfree (const void *objp) ...@@ -1647,6 +1647,15 @@ void kfree (const void *objp)
local_irq_restore(flags); local_irq_restore(flags);
} }
unsigned int kmem_cache_size(kmem_cache_t *cachep)
{
#if DEBUG
if (cachep->flags & SLAB_RED_ZONE)
return (cachep->objsize - 2*BYTES_PER_WORD);
#endif
return cachep->objsize;
}
kmem_cache_t * kmem_find_general_cachep (size_t size, int gfpflags) kmem_cache_t * kmem_find_general_cachep (size_t size, int gfpflags)
{ {
cache_sizes_t *csizep = cache_sizes; cache_sizes_t *csizep = cache_sizes;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment