* [PATCH] mm/slub: reduce the calculation times of 'MAX_OBJS_PER_PAGE'
@ 2023-03-16 1:25 gouhao
0 siblings, 0 replies; only message in thread
From: gouhao @ 2023-03-16 1:25 UTC (permalink / raw)
To: cl, penberg, rientjes, iamjoonsoo.kim, akpm, vbabka,
roman.gushchin, 42.hyeyoo, keescook
Cc: linux-mm, linux-kernel, linux-hardening
From: Gou Hao <gouhao@uniontech.com>
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@uniontech.com>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-16 1:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 1:25 [PATCH] mm/slub: reduce the calculation times of 'MAX_OBJS_PER_PAGE' gouhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox