]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm: list_lru: move list dead check to lock_list_lru_of_memcg()
authorJohannes Weiner <hannes@cmpxchg.org>
Wed, 27 May 2026 20:45:11 +0000 (16:45 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 9 Jun 2026 01:21:24 +0000 (18:21 -0700)
Only the MEMCG variant of lock_list_lru() needs to check if there is a
race with cgroup deletion and list reparenting.  Move the check to the
caller, so that the next patch can unify the lock_list_lru() variants.

Link: https://lore.kernel.org/20260527204757.2544958-5-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Liam R. Howlett (Oracle) <liam@infradead.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nico Pache <npache@redhat.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/list_lru.c

index 5497034e80f3046fb42b9f208b606042cfae4730..7d0523e44010d2cfaa627afcbfbe496505220083 100644 (file)
@@ -68,17 +68,12 @@ list_lru_from_memcg_idx(struct list_lru *lru, int nid, int idx)
        return &lru->node[nid].lru;
 }
 
-static inline bool lock_list_lru(struct list_lru_one *l, bool irq)
+static inline void lock_list_lru(struct list_lru_one *l, bool irq)
 {
        if (irq)
                spin_lock_irq(&l->lock);
        else
                spin_lock(&l->lock);
-       if (unlikely(READ_ONCE(l->nr_items) == LONG_MIN)) {
-               unlock_list_lru(l, irq);
-               return false;
-       }
-       return true;
 }
 
 static inline struct list_lru_one *
@@ -90,9 +85,13 @@ lock_list_lru_of_memcg(struct list_lru *lru, int nid,
        rcu_read_lock();
 again:
        l = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(*memcg));
-       if (likely(l) && lock_list_lru(l, irq)) {
-               rcu_read_unlock();
-               return l;
+       if (likely(l)) {
+               lock_list_lru(l, irq);
+               if (likely(READ_ONCE(l->nr_items) != LONG_MIN)) {
+                       rcu_read_unlock();
+                       return l;
+               }
+               unlock_list_lru(l, irq);
        }
        /*
         * Caller may simply bail out if raced with reparenting or