memcg: simplify corner case handling of LRU.
authorKAMEZAWA Hiroyuki <[email protected]>
Fri, 13 Jan 2012 01:18:57 +0000 (17:18 -0800)
committerLinus Torvalds <[email protected]>
Fri, 13 Jan 2012 04:13:07 +0000 (20:13 -0800)
commit36b62ad539498d00c2d280a151abad5f7630fa73
tree553409901df6210e4a698c1991f9d455199e098b
parentdc67d50465f249bb357bf85b3ed1f642eb00130a
memcg: simplify corner case handling of LRU.

This patch simplifies LRU handling of racy case (memcg+SwapCache).  At
charging, SwapCache tend to be on LRU already.  So, before overwriting
pc->mem_cgroup, the page must be removed from LRU and added to LRU
later.

This patch does
        spin_lock(zone->lru_lock);
        if (PageLRU(page))
                remove from LRU
        overwrite pc->mem_cgroup
        if (PageLRU(page))
                add to new LRU.
        spin_unlock(zone->lru_lock);

And guarantee all pages are not on LRU at modifying pc->mem_cgroup.
This patch also unfies lru handling of replace_page_cache() and
swapin.

Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Cc: Ying Han <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/memcontrol.c