linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: gouhao@uniontech.com
To: cl@linux.com, penberg@kernel.org, rientjes@google.com,
	iamjoonsoo.kim@lge.com, akpm@linux-foundation.org,
	vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com,
	keescook@chromium.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: [PATCH] mm/slub: reduce the calculation times of 'MAX_OBJS_PER_PAGE'
Date: Thu, 16 Mar 2023 09:25:17 +0800	[thread overview]
Message-ID: <20230316012517.10479-1-gouhao@uniontech.com> (raw)

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



                 reply	other threads:[~2023-03-16  1:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230316012517.10479-1-gouhao@uniontech.com \
    --to=gouhao@uniontech.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox