Re: [patch 2/8] mm: memcg-aware global reclaim

Johannes Weiner
2011-09-21T08:44:45Z

Hi Ying,

On Wed, Aug 31, 2011 at 03:58:09PM -0700, Ying Han wrote:
> On Tue, Aug 30, 2011 at 8:14 AM, Johannes Weiner <hannes@cmpxchg.org> wrote:
> > On Tue, Aug 30, 2011 at 12:07:07AM -0700, Ying Han wrote:
> >> On Mon, Aug 29, 2011 at 2:05 PM, Johannes Weiner <hannes@cmpxchg.org> wrote:
> >> > I have now the following comment in mem_cgroup_lru_del_list():
> >> >
> >> >        /*
> >> >         * root_mem_cgroup babysits uncharged LRU pages, but
> >> >         * PageCgroupUsed is cleared when the page is about to get
> >> >         * freed.  PageCgroupAcctLRU remembers whether the
> >> >         * LRU-accounting happened against pc->mem_cgroup or
> >> >         * root_mem_cgroup.
> >> >         */
> >> >
> >> > Does that answer your question?  If not, please tell me, so I can fix
> >> > the comment :-)
> >>
> >> Sorry, not clear to me yet :(
> >>
> >> Is this saying that we can not differentiate the page linked to root
> >> but not charged vs
> >> page linked to memcg which is about to be freed.
> >>
> >> If that is the case, isn't the page being removed from lru first
> >> before doing uncharge (ClearPageCgroupUsed) ?
>
> Sorry for getting back to this late.
>
> > It depends.  From the reclaim path, yes.  But it may be freed through
> > __page_cache_release() for example, which unlinks after uncharge.
>
> That is true. And the comment start making senses to me. Thanks.
>
> The problem here is the inconsistency of the pc->mem_cgroup and
> page->lru for uncharged pages ( !Used). And even further, that is
> caused by (only?) pages silently floating from memcg lru
> to root lru after they are uncharged (before they are freed). And I
> wonder those pages will be short lived.
>
> Guess my question is why those pages have to travel to root and then
> freed quickly, and we just leave them in the memcg lru?

That's not what happens. If they get reclaimed, they are first
removed from the LRU (isolated), then freed. If they get truncated
OTOH, they get uncharged in delete_from_page_cache() and unlinked from
the LRU on the final put_page(). There is no moving around in
between.

The moving to root_mem_cgroup happens to rescue the lru-account from
pc->mem_cgroup of an LRU page before pc->mem_cgroup is overwritten, so
it is only applicable to pages that are charged while on the LRU.
PageCgroupAcctLRU indicates whether a PageLRU page is lru-accounted to
pc->mem_cgroup (set) or root_mem_cgroup (clear).