Skip to content

Commit 3f28bbe

Browse files
ryncsnakpm00
authored andcommitted
mm/list_lru: don't pass unnecessary key parameters
Patch series "mm/list_lru: Split list_lru lock into per-cgroup scope". When LOCKDEP is not enabled, lock_class_key is an empty struct that is never used. But the list_lru initialization function still takes a placeholder pointer as parameter, and the compiler cannot optimize it because the function is not static and exported. Remove this parameter and move it inside the list_lru struct. Only use it when LOCKDEP is enabled. Kernel builds with LOCKDEP will be slightly larger, while !LOCKDEP builds without it will be slightly smaller (the common case). Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kairui Song <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Chengming Zhou <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Qi Zheng <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Waiman Long <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3738290 commit 3f28bbe

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

include/linux/list_lru.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,28 @@ struct list_lru {
5656
bool memcg_aware;
5757
struct xarray xa;
5858
#endif
59+
#ifdef CONFIG_LOCKDEP
60+
struct lock_class_key *key;
61+
#endif
5962
};
6063

6164
void list_lru_destroy(struct list_lru *lru);
6265
int __list_lru_init(struct list_lru *lru, bool memcg_aware,
63-
struct lock_class_key *key, struct shrinker *shrinker);
66+
struct shrinker *shrinker);
6467

6568
#define list_lru_init(lru) \
66-
__list_lru_init((lru), false, NULL, NULL)
69+
__list_lru_init((lru), false, NULL)
6770
#define list_lru_init_memcg(lru, shrinker) \
68-
__list_lru_init((lru), true, NULL, shrinker)
71+
__list_lru_init((lru), true, shrinker)
72+
73+
static inline int list_lru_init_memcg_key(struct list_lru *lru, struct shrinker *shrinker,
74+
struct lock_class_key *key)
75+
{
76+
#ifdef CONFIG_LOCKDEP
77+
lru->key = key;
78+
#endif
79+
return list_lru_init_memcg(lru, shrinker);
80+
}
6981

7082
int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
7183
gfp_t gfp);

mm/list_lru.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ static void memcg_destroy_list_lru(struct list_lru *lru)
562562
}
563563
#endif /* CONFIG_MEMCG */
564564

565-
int __list_lru_init(struct list_lru *lru, bool memcg_aware,
566-
struct lock_class_key *key, struct shrinker *shrinker)
565+
int __list_lru_init(struct list_lru *lru, bool memcg_aware, struct shrinker *shrinker)
567566
{
568567
int i;
569568

@@ -583,8 +582,10 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware,
583582

584583
for_each_node(i) {
585584
spin_lock_init(&lru->node[i].lock);
586-
if (key)
587-
lockdep_set_class(&lru->node[i].lock, key);
585+
#ifdef CONFIG_LOCKDEP
586+
if (lru->key)
587+
lockdep_set_class(&lru->node[i].lock, lru->key);
588+
#endif
588589
init_one_lru(&lru->node[i].lru);
589590
}
590591

mm/workingset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ static int __init workingset_init(void)
813813
if (!workingset_shadow_shrinker)
814814
goto err;
815815

816-
ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key,
817-
workingset_shadow_shrinker);
816+
ret = list_lru_init_memcg_key(&shadow_nodes, workingset_shadow_shrinker,
817+
&shadow_nodes_key);
818818
if (ret)
819819
goto err_list_lru;
820820

0 commit comments

Comments
 (0)