[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220430002555.3881-1-vvghjk1234@gmail.com>
Date: Sat, 30 Apr 2022 09:25:55 +0900
From: Wonhyuk Yang <vvghjk1234@...il.com>
To: Christoph Lameter <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Vlastimil Babka <vbabka@...e.cz>,
Roman Gushchin <roman.gushchin@...ux.dev>
Cc: Wonhyuk Yang <vvghjk1234@...il.com>,
Hyeonggon Yoo <42.hyeyoo@...il.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: [Patch v3] mm/slub: Remove repeated action in calculate_order()
To calculate order, calc_slab_order() is called repeatly changing the
fract_leftover. Thus, the branch which is not dependent on
fract_leftover is executed repeatly. So make it run only once.
Plus, when min_object reached to 1, we set fract_leftover to 1. In
this case, we can calculate order by max(slub_min_order,
get_order(size)) instead of calling calc_slab_order().
No functional impact expected.
Signed-off-by: Wonhyuk Yang <vvghjk1234@...il.com>
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@...il.com>
---
mm/slub.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index ed5c2c03a47a..1fe4d62b72b8 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3795,9 +3795,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++) {
@@ -3820,6 +3817,11 @@ static inline int calculate_order(unsigned int size)
unsigned int max_objects;
unsigned int nr_cpus;
+ if (unlikely(order_objects(slub_min_order, size) > MAX_OBJS_PER_PAGE)) {
+ order = get_order(size * MAX_OBJS_PER_PAGE) - 1;
+ goto out;
+ }
+
/*
* Attempt to find best configuration for a slab. This
* works by first attempting to generate a layout with
@@ -3865,14 +3867,8 @@ static inline int calculate_order(unsigned int size)
* We were unable to place multiple objects in a slab. Now
* lets see if we can place a single object there.
*/
- order = calc_slab_order(size, 1, slub_max_order, 1);
- if (order <= slub_max_order)
- return order;
-
- /*
- * Doh this slab cannot be placed using slub_max_order.
- */
- order = calc_slab_order(size, 1, MAX_ORDER, 1);
+ order = max_t(unsigned int, slub_min_order, get_order(size));
+out:
if (order < MAX_ORDER)
return order;
return -ENOSYS;
--
2.30.2
Powered by blists - more mailing lists