Re: [PATCH v1 25/26] mm: memcontrol: eliminate the problem of dying memory cgroup for LRU folios

Qi Zheng
2025-11-20T13:45:31Z

On 11/20/25 7:56 PM, Chen Ridong wrote:
>
>
> On 2025/10/28 21:58, Qi Zheng wrote:
>> static void reparent_locks(struct mem_cgroup *src, struct mem_cgroup *dst)
>> {
>> + int nid, nest = 0;
>> +
>> spin_lock_irq(&objcg_lock);
>> + for_each_node(nid) {
>> + spin_lock_nested(&mem_cgroup_lruvec(src,
>> + NODE_DATA(nid))->lru_lock, nest++);
>> + spin_lock_nested(&mem_cgroup_lruvec(dst,
>> + NODE_DATA(nid))->lru_lock, nest++);
>> + }
>> }
>>
>> static void reparent_unlocks(struct mem_cgroup *src, struct mem_cgroup *dst)
>> {
>> + int nid;
>> +
>> + for_each_node(nid) {
>> + spin_unlock(&mem_cgroup_lruvec(dst, NODE_DATA(nid))->lru_lock);
>> + spin_unlock(&mem_cgroup_lruvec(src, NODE_DATA(nid))->lru_lock);
>> + }
>> spin_unlock_irq(&objcg_lock);
>> }
>>
>
> The lock order follows S0→D0→S1→D1→…, and the correct unlock sequence should be Dn→Sn→…→D1→S0
>
> However, the current unlock implementation uses D0→S0→D1→S1→…
>
> I’m not certain whether this unlock order will cause any issues—could this lead to potential
> problems like deadlocks or lock state inconsistencies?

As long as the order in which the locks are held is consistent, there
should be no deadlock problem?

>