Re: [PATCH v4 3/8] mm: list_lru: move list dead check to lock_list_lru_of_memcg()
From: Liam R . Howlett
Date: Thu May 21 2026 - 13:25:48 EST
On 26/05/21 11:02AM, Johannes Weiner wrote:
> 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.
>
> Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Acked-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@xxxxxxxxxx>
> Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
Reviewed-by: Liam R. Howlett (Oracle) <liam@xxxxxxxxxxxxx>
> ---
> mm/list_lru.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/mm/list_lru.c b/mm/list_lru.c
> index 9a68177619bf..9da6fce19832 100644
> --- a/mm/list_lru.c
> +++ b/mm/list_lru.c
> @@ -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, struct mem_cgroup *memcg,
> 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
> --
> 2.54.0
>