Re: kfree(0) - ok?

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Arjan van de Ven <arjan@...>
Cc: Tim Bird <tim.bird@...>, linux kernel <linux-kernel@...>, Andrew Morton <akpm@...>, Christoph Lameter <clameter@...>
Date: Tuesday, August 14, 2007 - 7:42 pm

On Tue, 14 Aug 2007, Arjan van de Ven wrote:


But that doesn't come free of cost, does it, seeing we've now pushed
the conditional inside kfree() itself. kfree() isn't inlined so we do
save on space but lose out on the extra time overhead for the common
case. Speaking of which ...

[PATCH] {slub, slob}: use unlikely() for kfree(ZERO_OR_NULL_PTR) check

Considering kfree(NULL) would normally occur only in error paths and
kfree(ZERO_SIZE_PTR) is uncommon as well, so let's use unlikely() for
the condition check in SLUB's and SLOB's kfree() to optimize for the
common case. SLAB has this already.

Signed-off-by: Satyam Sharma <satyam@infradead.org>

---

 mm/slob.c |    2 +-
 mm/slub.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/slob.c b/mm/slob.c
index ec33fcd..37a8b9a 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -466,7 +466,7 @@ void kfree(const void *block)
 {
 	struct slob_page *sp;
 
-	if (ZERO_OR_NULL_PTR(block))
+	if (unlikely(ZERO_OR_NULL_PTR(block)))
 		return;
 
 	sp = (struct slob_page *)virt_to_page(block);
diff --git a/mm/slub.c b/mm/slub.c
index 69d02e3..3788537 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2467,7 +2467,7 @@ void kfree(const void *x)
 	 * this comparison would be true for all "negative" pointers
 	 * (which would cover the whole upper half of the address space).
 	 */
-	if (ZERO_OR_NULL_PTR(x))
+	if (unlikely(ZERO_OR_NULL_PTR(x)))
 		return;
 
 	page = virt_to_head_page(x);
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
kfree(0) - ok?, Tim Bird, (Tue Aug 14, 6:59 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Tue Aug 14, 7:13 pm)
Re: kfree(0) - ok?, Arjan van de Ven, (Tue Aug 14, 6:55 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Tue Aug 14, 7:42 pm)
Re: kfree(0) - ok?, Andrew Morton, (Fri Aug 17, 2:22 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:13 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 5:14 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:46 pm)
Re: kfree(0) - ok?, Pekka Enberg, (Fri Aug 17, 5:42 pm)
Re: kfree(0) - ok?, Thomas Gleixner, (Fri Aug 17, 7:40 pm)
Re: kfree(0) - ok?, Jan Engelhardt, (Sat Aug 18, 4:21 am)
Re: kfree(0) - ok?, Pekka Enberg, (Sat Aug 18, 4:10 am)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 9:03 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 8:02 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 7:22 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Fri Aug 17, 4:43 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:17 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 5:32 pm)
Re: kfree(0) - ok?, Jan Engelhardt, (Fri Aug 17, 2:37 pm)
Re: kfree(0) - ok?, Arjan van de Ven, (Fri Aug 17, 2:31 pm)
Re: kfree(0) - ok?, Satyam Sharma, (Fri Aug 17, 2:50 pm)
Re: kfree(0) - ok?, Christoph Lameter, (Tue Aug 14, 8:19 pm)
Re: kfree(0) - ok?, Jason Uhlenkott, (Tue Aug 14, 7:21 pm)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 3:28 am)
Re: kfree(0) - ok?, Giacomo A. Catenazzi, (Wed Aug 15, 5:32 am)
Re: kfree(0) - ok?, Andreas Schwab, (Wed Aug 15, 5:18 am)
Re: kfree(0) - ok?, Jason Uhlenkott, (Wed Aug 15, 4:52 am)
Re: kfree(0) - ok?, Rene Herman, (Wed Aug 15, 4:37 am)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 5:20 am)
Re: kfree(0) - ok?, Rene Herman, (Wed Aug 15, 5:58 am)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 6:20 am)
Re: kfree(0) - ok?, H. Peter Anvin, (Wed Aug 15, 12:01 pm)
Re: kfree(0) - ok?, Kyle Moffett, (Wed Aug 15, 9:58 am)
Re: kfree(0) - ok?, Jan Engelhardt, (Wed Aug 15, 10:06 am)
Re: kfree(0) - ok?, Kyle Moffett, (Wed Aug 15, 10:34 am)
Re: kfree(0) - ok?, Rene Herman, (Wed Aug 15, 6:27 am)
Re: kfree(0) - ok?, Jason Uhlenkott, (Wed Aug 15, 5:43 am)