Re: [PATCH RESEND] slab: introduce the flag SLAB_MINIMIZE_WASTE
From: Christopher Lameter
Date: Fri Apr 27 2018 - 12:41:55 EST
On Thu, 26 Apr 2018, Mikulas Patocka wrote:
> > Hmmm... order 4 for these caches may cause some concern. These should stay
> > under costly order I think. Otherwise allocations are no longer
> > guaranteed.
> You said that slub has fallback to smaller order allocations.
Yes it does...
> The whole purpose of this "minimize waste" approach is to use higher-order
> allocations to use memory more efficiently, so it is just doing its job.
> (for these 3 caches, order-4 really wastes less memory than order-3 - on
> my system TCPv6 and sighand_cache have size 2112, task_struct 2752).
Hmmm... Ok if the others are fine with this as well. I got some pushback
there in the past.
> We could improve the fallback code, so that if order-4 allocation fails,
> it tries order-3 allocation, and then falls back to order-0. But I think
> that these failures are rare enough that it is not a problem.
I also think that would be too many fallbacks.
> > > + /* Increase order even more, but only if it reduces waste */
> > > + if (test_order_obj <= 32 &&
> > Where does the 32 come from?
> It is to avoid extremely high order for extremely small slabs.
> For example, see kmalloc-96.
> 10922 96-byte objects would fit into 1MiB
> 21845 96-byte objects would fit into 2MiB
That is the result of considering absolute byte wastage..
> The algorithm would recognize this one more object that fits into 2MiB
> slab as "waste reduction" and increase the order to 2MiB - and we don't
> want this.
> So, the general reasoning is - if we have 32 objects in a slab, then it is
> already considered that wasted space is reasonably low and we don't want
> to increase the order more.
> Currently, kmalloc-96 uses order-0 - that is reasonable (we already have
> 42 objects in 4k page, so we don't need to use higher order, even if it
> wastes one-less object).
The old code uses the concept of a "fraction" to calculate overhead. The
code here uses absolute counts of bytes. Fraction looks better to me.