It decides to reallocate when the remaining space isn't enough
to hold the new data. NF_CT_EXT_MIN_SIZE is used to make sure it
doesn't allocate anything smaller than the minimum slab size and
hopefully avoid reallocations in the future. Unless I'm
misunderstanding what ksize() does, the easiest way to get
rid of this would be to replace NF_CT_EXT_MIN_SIZE by ksize(0).
Even better would be to not only avoid waste on the first allocation,
but also on reallocations. This would look something like this:
__nf_ct_ext_add():
{
struct nf_ct_ext *new;
- int i, newlen, newoff;
+ int i, newlen, newoff, reallen;
...
if (newlen >= ct->ext->real_len) {
+ reallen = ksize(newlen);
- new = kmalloc(newlen, gfp);
+ new = kmalloc(reallen, gfp);
if (!new)
return NULL;
...
- new->real_len = newlen;
+ new->real_len = reallen;
ct->ext = new;
}
--