Skip to content

Commit 41d1743

Browse files
Muchun Songtorvalds
authored andcommitted
mm: list_lru: fix the return value of list_lru_count_one()
Since commit 2788cf0 ("memcg: reparent list_lrus and free kmemcg_id on css offline"), ->nr_items can be negative during memory cgroup reparenting. In this case, list_lru_count_one() will return an unusual and huge value, which can surprise users. At least for now it hasn't affected any users. But it is better to let list_lru_count_ont() returns zero when ->nr_items is negative. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Muchun Song <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Shakeel Butt <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 60ec6a4 commit 41d1743

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mm/list_lru.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,16 @@ unsigned long list_lru_count_one(struct list_lru *lru,
176176
{
177177
struct list_lru_node *nlru = &lru->node[nid];
178178
struct list_lru_one *l;
179-
unsigned long count;
179+
long count;
180180

181181
rcu_read_lock();
182182
l = list_lru_from_memcg_idx(nlru, memcg_cache_id(memcg));
183183
count = READ_ONCE(l->nr_items);
184184
rcu_read_unlock();
185185

186+
if (unlikely(count < 0))
187+
count = 0;
188+
186189
return count;
187190
}
188191
EXPORT_SYMBOL_GPL(list_lru_count_one);

0 commit comments

Comments
 (0)