linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: mateusznosek0@gmail.com
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Mateusz Nosek <mateusznosek0@gmail.com>,
	cl@linux.com, penberg@kernel.org, rientjes@google.com,
	iamjoonsoo.kim@lge.com, akpm@linux-foundation.org
Subject: [PATCH] mm/slab.c: micro-optimization spare one branch in main flow
Date: Wed, 16 Sep 2020 22:05:39 +0200	[thread overview]
Message-ID: <20200916200539.23268-1-mateusznosek0@gmail.com> (raw)

From: Mateusz Nosek <mateusznosek0@gmail.com>

By small refactoring two 'unlikely' branches are changed so that if
not one of them is true then only one branch occurs in 'likely' path
of the function in question. Change verified in assembly generated
by gcc 8.3.0.

Signed-off-by: Mateusz Nosek <mateusznosek0@gmail.com>
---
 mm/slab.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 2cb494d98fe9..e04ea756bcbc 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4186,9 +4186,10 @@ size_t __ksize(const void *objp)
 	struct kmem_cache *c;
 	size_t size;
 
-	BUG_ON(!objp);
-	if (unlikely(objp == ZERO_SIZE_PTR))
+	if (unlikely(ZERO_OR_NULL_PTR(objp))) {
+		BUG_ON(!objp);
 		return 0;
+	}
 
 	c = virt_to_cache(objp);
 	size = c ? c->object_size : 0;
-- 
2.20.1



                 reply	other threads:[~2020-09-16 20:06 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=20200916200539.23268-1-mateusznosek0@gmail.com \
    --to=mateusznosek0@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    /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