list_lru: don't call list_lru_from_kmem if the list_head is empty
authorJeff Layton <jlayton@poochiereds.net>
Tue, 8 Sep 2015 22:03:44 +0000 (15:03 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 8 Sep 2015 22:35:28 +0000 (15:35 -0700)
If the list_head is empty then we'll have called list_lru_from_kmem for
nothing.  Move that call inside of the list_empty if block.

Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
Reviewed-by: Vladimir Davydov <vdavydov@parallels.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/list_lru.c

index 909eca2c820e4af45f9c4d519eee744041f18a2b..e1da19fac1b3629f7aeff4815a64681f9ca9bd60 100644 (file)
@@ -99,8 +99,8 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item)
        struct list_lru_one *l;
 
        spin_lock(&nlru->lock);
-       l = list_lru_from_kmem(nlru, item);
        if (list_empty(item)) {
+               l = list_lru_from_kmem(nlru, item);
                list_add_tail(item, &l->list);
                l->nr_items++;
                spin_unlock(&nlru->lock);
@@ -118,8 +118,8 @@ bool list_lru_del(struct list_lru *lru, struct list_head *item)
        struct list_lru_one *l;
 
        spin_lock(&nlru->lock);
-       l = list_lru_from_kmem(nlru, item);
        if (!list_empty(item)) {
+               l = list_lru_from_kmem(nlru, item);
                list_del_init(item);
                l->nr_items--;
                spin_unlock(&nlru->lock);