aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2016-03-15 17:57:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-15 19:55:16 -0400
commit62cccb8c8e7a3ca233f49d5e7dcb1557d25465cd (patch)
tree43a902faf461c65393a4efebf9ff9622017b92b1 /mm/memcontrol.c
parent6a93ca8fde3cfce0f00f02281139a377c83e8d8c (diff)
mm: simplify lock_page_memcg()
Now that migration doesn't clear page->mem_cgroup of live pages anymore, it's safe to make lock_page_memcg() and the memcg stat functions take pages, and spare the callers from memcg objects. [akpm@linux-foundation.org: fix warnings] Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Suggested-by: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: Vladimir Davydov <vdavydov@virtuozzo.com> Cc: Michal Hocko <mhocko@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r--mm/memcontrol.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 64506b2eef34..3e4199830456 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1690,7 +1690,7 @@ cleanup:
1690 * This function protects unlocked LRU pages from being moved to 1690 * This function protects unlocked LRU pages from being moved to
1691 * another cgroup and stabilizes their page->mem_cgroup binding. 1691 * another cgroup and stabilizes their page->mem_cgroup binding.
1692 */ 1692 */
1693struct mem_cgroup *lock_page_memcg(struct page *page) 1693void lock_page_memcg(struct page *page)
1694{ 1694{
1695 struct mem_cgroup *memcg; 1695 struct mem_cgroup *memcg;
1696 unsigned long flags; 1696 unsigned long flags;
@@ -1699,25 +1699,18 @@ struct mem_cgroup *lock_page_memcg(struct page *page)
1699 * The RCU lock is held throughout the transaction. The fast 1699 * The RCU lock is held throughout the transaction. The fast
1700 * path can get away without acquiring the memcg->move_lock 1700 * path can get away without acquiring the memcg->move_lock
1701 * because page moving starts with an RCU grace period. 1701 * because page moving starts with an RCU grace period.
1702 *
1703 * The RCU lock also protects the memcg from being freed when
1704 * the page state that is going to change is the only thing
1705 * preventing the page from being uncharged.
1706 * E.g. end-writeback clearing PageWriteback(), which allows
1707 * migration to go ahead and uncharge the page before the
1708 * account transaction might be complete.
1709 */ 1702 */
1710 rcu_read_lock(); 1703 rcu_read_lock();
1711 1704
1712 if (mem_cgroup_disabled()) 1705 if (mem_cgroup_disabled())
1713 return NULL; 1706 return;
1714again: 1707again:
1715 memcg = page->mem_cgroup; 1708 memcg = page->mem_cgroup;
1716 if (unlikely(!memcg)) 1709 if (unlikely(!memcg))
1717 return NULL; 1710 return;
1718 1711
1719 if (atomic_read(&memcg->moving_account) <= 0) 1712 if (atomic_read(&memcg->moving_account) <= 0)
1720 return memcg; 1713 return;
1721 1714
1722 spin_lock_irqsave(&memcg->move_lock, flags); 1715 spin_lock_irqsave(&memcg->move_lock, flags);
1723 if (memcg != page->mem_cgroup) { 1716 if (memcg != page->mem_cgroup) {
@@ -1733,16 +1726,18 @@ again:
1733 memcg->move_lock_task = current; 1726 memcg->move_lock_task = current;
1734 memcg->move_lock_flags = flags; 1727 memcg->move_lock_flags = flags;
1735 1728
1736 return memcg; 1729 return;
1737} 1730}
1738EXPORT_SYMBOL(lock_page_memcg); 1731EXPORT_SYMBOL(lock_page_memcg);
1739 1732
1740/** 1733/**
1741 * unlock_page_memcg - unlock a page->mem_cgroup binding 1734 * unlock_page_memcg - unlock a page->mem_cgroup binding
1742 * @memcg: the memcg returned by lock_page_memcg() 1735 * @page: the page
1743 */ 1736 */
1744void unlock_page_memcg(struct mem_cgroup *memcg) 1737void unlock_page_memcg(struct page *page)
1745{ 1738{
1739 struct mem_cgroup *memcg = page->mem_cgroup;
1740
1746 if (memcg && memcg->move_lock_task == current) { 1741 if (memcg && memcg->move_lock_task == current) {
1747 unsigned long flags = memcg->move_lock_flags; 1742 unsigned long flags = memcg->move_lock_flags;
1748 1743