[PATCH] mm/slub: reduce the calculation times of 'MAX_OBJS_PER_PAGE'
From: gouhao
Date: Wed Mar 15 2023 - 21:28:09 EST
From: Gou Hao <gouhao@xxxxxxxxxxxxx>
when calling calc_slab_order(), 'slub_min_order'
and 'size' are fixed values, if the condition of
'MAX_OBJS_PER_PAGE' is true, it will be returned from
here every time.
So we can calculate the condition of 'MAX_OBJS_PER_PAGE'
before calling calculate_order().
Signed-off-by: Gou Hao <gouhao@xxxxxxxxxxxxx>
---
mm/slub.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 39327e98fce3..ed6d797a5cd8 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4094,9 +4094,6 @@ static inline unsigned int calc_slab_order(unsigned int size,
unsigned int min_order = slub_min_order;
unsigned int order;
- if (order_objects(min_order, size) > MAX_OBJS_PER_PAGE)
- return get_order(size * MAX_OBJS_PER_PAGE) - 1;
-
for (order = max(min_order, (unsigned int)get_order(min_objects * size));
order <= max_order; order++) {
@@ -4457,9 +4454,14 @@ static int calculate_sizes(struct kmem_cache *s)
size = ALIGN(size, s->align);
s->size = size;
s->reciprocal_size = reciprocal_value(size);
- order = calculate_order(size);
- if ((int)order < 0)
+
+ if (order_objects(slub_min_order, size) > MAX_OBJS_PER_PAGE)
+ order = get_order(size * MAX_OBJS_PER_PAGE) - 1;
+ else
+ order = calculate_order(size);
+
+ if ((int)order < 0 || order > slub_max_order)
return 0;
s->allocflags = 0;
--
2.34.1