mm: Omit RCU read lock in list_lru_count_one() when RCU isn't needed

The RCU read lock isn't necessary in list_lru_count_one() when the
condition that requires RCU (CONFIG_MEMCG && !CONFIG_SLOB) isn't met.
The highly-frequent RCU lock and unlock adds measurable overhead to the
shrink_slab() path when it isn't needed. As such, we can simply omit the
RCU read lock in this case to improve performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: priiii1808 <priyanshusinghal0818@gmail.com>
This commit is contained in:
Sultan Alsawaf 2021-09-26 00:29:38 -07:00 committed by Ksawlii
parent 436eb37b50
commit 3764b4f297

View file

@ -174,6 +174,7 @@ EXPORT_SYMBOL_GPL(list_lru_isolate_move);
unsigned long list_lru_count_one(struct list_lru *lru,
int nid, struct mem_cgroup *memcg)
{
#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
struct list_lru_node *nlru = &lru->node[nid];
struct list_lru_one *l;
unsigned long count;
@ -184,6 +185,9 @@ unsigned long list_lru_count_one(struct list_lru *lru,
rcu_read_unlock();
return count;
#else
return READ_ONCE(lru->node[nid].lru.nr_items);
#endif
}
EXPORT_SYMBOL_GPL(list_lru_count_one);