mempool: add unlikely and likely hints
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 7 Apr 2014 22:37:35 +0000 (15:37 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 7 Apr 2014 23:35:55 +0000 (16:35 -0700)
Add unlikely and likely hints to the function mempool_free.  It lays out
the code in such a way that the common path is executed straighforward and
saves a cache line.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/mempool.c

index 659aa42bad1621756878dc41ce65e3cbd86ed0fb..905434f18c9738a18cd20364131a952336325411 100644 (file)
@@ -304,9 +304,9 @@ void mempool_free(void *element, mempool_t *pool)
         * ensures that there will be frees which return elements to the
         * pool waking up the waiters.
         */
-       if (pool->curr_nr < pool->min_nr) {
+       if (unlikely(pool->curr_nr < pool->min_nr)) {
                spin_lock_irqsave(&pool->lock, flags);
-               if (pool->curr_nr < pool->min_nr) {
+               if (likely(pool->curr_nr < pool->min_nr)) {
                        add_element(pool, element);
                        spin_unlock_irqrestore(&pool->lock, flags);
                        wake_up(&pool->wait);