Re: [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is different
From: Alex Shi
Date: Thu Nov 14 2019 - 01:01:18 EST
å 2019/11/13 äå9:45, Matthew Wilcox åé:
>>> Why not simply:
>>>
>>> rcu_read_lock();
>>> lruvec = mem_cgroup_page_lruvec(page, pgdat);
>>> rcu_read_unlock();
>>>
>>> if (locked_lruvec == lruvec)
>> The rcu_read_unlock here is for guarding the locked_lruvec/lruvec comparsion.
>> Otherwise memcg/lruvec maybe changed, like, from memcg migration etc. I guess.
> How does holding the RCU lock guard the comparison? You're comparing two
> pointers for equality. Nothing any other CPU can do at this point will
> change the results of that comparison.
>
Hi Matthew, Thanks for reply!
The reason of guarding lruvec compasion here is a bit undistinct, in fact, it guards the page's memcg from free/migrate etc, since the lruvec is kind of binding to each of memcg. The detailed explanation could be found in lock_page_memcg().
Thanks
Alex