Re: [Unionfs] Re: [-mm patch] UNION_FS must depend on SLAB

hooanon05
2007-02-21T03:55:49Z

Josef Sipek:
> That's the only user of malloc_sizes. It is supposed to be an optimization -
> we get the smallest sized piece of memory even if we don't need all of it.
> This way we don't reallocate & memcpy needlessly.

How about exporting ksize to modules, and introduce a new function such
like this?
Of course, adding gfp_t to its parameter list make this function more generic.

void *kzrealloc(void *p, int nused, int new_sz)
{
void *q;

if (new_sz <= nused)
return p;
if (new_sz <= ksize(p)) {
memset(p + nused, 0, new_sz - nused);
return p;
}

q = kmalloc(new_sz, GFP_KERNEL);
if (unlikely(!q))
return NULL;
memcpy(q, p, nused);
memset(q + nused, 0, new_sz - nused);
kfree(p);
return q;
}

Junjiro Okajima