[ofa-general] Re: [PATCH ofed-1.2.c] ehca: backport kmem_cache_zalloc() for 2.6.10/sles10/sles10_sp1
Michael S. Tsirkin
mst at dev.mellanox.co.il
Tue Aug 7 00:09:05 PDT 2007
> Quoting Hoang-Nam Nguyen <hnguyen at linux.vnet.ibm.com>:
> Subject: Re: [PATCH ofed-1.2.c] ehca: backport kmem_cache_zalloc() for 2.6.10/sles10/sles10_sp1
>
> On Tuesday 07 August 2007 07:34, Michael S. Tsirkin wrote:
> > Hmm, I thought about it some more.
> > kmem_cache struct is not exported on recent kernels,
> > so this might br hard to do.
>
> I looked at slab.h in various kernel and see this function
> extern unsigned int kmem_cache_size(kmem_cache_t *);
> which returns buffer_size that is set by kmem_cache_create() to size.
> So the backport will look like:
> static inline
> void *kmem_cache_zalloc(kmem_cache_t *cache, gfp_t flags)
> {
> void *ret = kmem_cache_alloc(cache, flags);
> if (ret)
> memset(ret, 0, kmem_cache_size(cache));
> return ret;
> }
> Would you agree? Do I oversee something else?
Good idea. Go for it, with one caveat: please use
struct kmem_cache rather than the deprecated kmem_cache_t.
Thus:
static inline
void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags)
{
void *ret = kmem_cache_alloc(cache, flags);
if (ret)
memset(ret, 0, kmem_cache_size(cache));
return ret;
}
--
MST
More information about the general
mailing list