mm/slub: attempt to find layouts up to 1/2 waste in calculate_order()
authorVlastimil Babka <vbabka@suse.cz>
Fri, 8 Sep 2023 09:47:09 +0000 (11:47 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Mon, 2 Oct 2023 09:55:41 +0000 (11:55 +0200)
commit5886fc82b6e3166dd1ba876809888fc39028d626
treef7a5224f726ed8ff16f0f7ff121c63645accbb78
parent0fe2735d5e2e00601339aab3658e05f3707a1745
mm/slub: attempt to find layouts up to 1/2 waste in calculate_order()

The main loop in calculate_order() currently tries to find an order with
at most 1/4 waste. If that's impossible (for particular large object
sizes), there's a fallback that will try to place one object within
slab_max_order.

If we expand the loop boundary to also allow up to 1/2 waste as the last
resort, we can remove the fallback and simplify the code, as the loop
will find an order for such sizes as well. Note we don't need to allow
more than 1/2 waste as that will never happen - calc_slab_order() would
calculate more objects to fit, reducing waste below 1/2.

Successfully finding an order in the loop (compared to the fallback)
will also have the benefit in trying to satisfy min_objects, because the
fallback was passing 1. Thus the resulting slab orders might be larger
(not because it would improve waste, but to reduce pressure on shared
locks), which is one of the goals of calculate_order().

For example, with nr_cpus=1 and 4kB PAGE_SIZE, slub_max_order=3, before
the patch we would get the following orders for these object sizes:

 2056 to 10920 - order-3 as selected by the loop
10928 to 12280 - order-2 due to fallback, as <1/4 waste is not possible
12288 to 32768 - order-3 as <1/4 waste is again possible

After the patch:

2056 to 32768 - order-3, because even in the range of 10928 to 12280 we
                try to satisfy the calculated min_objects.

As a result the code is simpler and gives more consistent results.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Feng Tang <feng.tang@intel.com>
Reviewed-and-tested-by: Jay Patel <jaypatel@linux.ibm.com>
mm/slub.c