[PATCH v4 8/9] mm/lru: likely enhancement

From: Alex Shi
Date: Tue Nov 19 2019 - 07:24:23 EST


Use likely() to remove speculations according to pagevec usage.

Signed-off-by: Alex Shi <alex.shi@xxxxxxxxxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxxxx>
Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Roman Gushchin <guro@xxxxxx>
Cc: Shakeel Butt <shakeelb@xxxxxxxxxx>
Cc: Chris Down <chris@xxxxxxxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: cgroups@xxxxxxxxxxxxxxx
Cc: linux-mm@xxxxxxxxx
---
include/linux/memcontrol.h | 8 ++++----
mm/memcontrol.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 19ff453e2822..1787bbc4b059 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1298,12 +1298,12 @@ static inline struct lruvec *relock_page_lruvec_irq(struct page *page,
struct pglist_data *pgdat = page_pgdat(page);
struct lruvec *lruvec;

- if (!locked_lruvec)
+ if (unlikely(!locked_lruvec))
goto lock;

lruvec = mem_cgroup_page_lruvec(page, pgdat);

- if (locked_lruvec == lruvec)
+ if (likely(locked_lruvec == lruvec))
return lruvec;

spin_unlock_irq(&locked_lruvec->lru_lock);
@@ -1320,12 +1320,12 @@ static inline struct lruvec *relock_page_lruvec_irqsave(struct page *page,
struct pglist_data *pgdat = page_pgdat(page);
struct lruvec *lruvec;

- if (!locked_lruvec)
+ if (unlikely(!locked_lruvec))
goto lock;

lruvec = mem_cgroup_page_lruvec(page, pgdat);

- if (locked_lruvec == lruvec)
+ if (likely(locked_lruvec == lruvec))
return lruvec;

spin_unlock_irqrestore(&locked_lruvec->lru_lock, *flags);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 7e6387ad01f0..8c3ba90bdefc 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1257,7 +1257,7 @@ struct lruvec *lock_page_lruvec_irq(struct page *page,
rcu_read_unlock();

/* lruvec may changed in commit_charge() */
- if (lruvec != mem_cgroup_page_lruvec(page, pgdat)) {
+ if (unlikely(lruvec != mem_cgroup_page_lruvec(page, pgdat))) {
spin_unlock_irq(&lruvec->lru_lock);
goto again;
}
@@ -1277,7 +1277,7 @@ struct lruvec *lock_page_lruvec_irqsave(struct page *page,
rcu_read_unlock();

/* lruvec may changed in commit_charge() */
- if (lruvec != mem_cgroup_page_lruvec(page, pgdat)) {
+ if (unlikely(lruvec != mem_cgroup_page_lruvec(page, pgdat))) {
spin_unlock_irqrestore(&lruvec->lru_lock, *flags);
goto again;
}
--
1.8.3.1