[Devel,RHEL7,COMMIT] ms/mm: memcontrol: catch root bypass in move precharge

Submitted by Konstantin Khorenko on Jan. 16, 2017, 4:27 p.m.


Message ID 201701161627.v0GGRCsx028612@finist_cl7.x64_64.work.ct
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Jan. 16, 2017, 4:27 p.m.
The commit is pushed to "branch-rh7-3.10.0-514.vz7.27.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.vz7.27.10
commit a687951828b3083ff9410e98c59bce13d87a52e1
Author: Johannes Weiner <hannes@cmpxchg.org>
Date:   Mon Jan 16 20:27:12 2017 +0400

    ms/mm: memcontrol: catch root bypass in move precharge
    When mem_cgroup_try_charge() returns -EINTR, it bypassed the charge to
    the root memcg.  But move precharging does not catch this and treats
    this case as if no charge had happened, thus leaking a charge against
    root.  Because of an old optimization, the root memcg's res_counter is
    not actually charged right now, but it's still an imbalance and
    subsequent patches will charge the root memcg again.
    Catch those bypasses to the root memcg and properly cancel them before
    giving up the move.
    Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
    Acked-by: Michal Hocko <mhocko@suse.cz>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Tejun Heo <tj@kernel.org>
    Cc: Vladimir Davydov <vdavydov@parallels.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    (cherry picked from commit 692e7c45d95ad1064b6911800e2cfec7fc0236db)
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
 mm/memcontrol.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 32533bf..cddfb93 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6738,6 +6738,10 @@  static int mem_cgroup_do_precharge(unsigned long count)
 		mc.precharge += count;
 		return ret;
+	if (ret == -EINTR) {
+		__mem_cgroup_cancel_charge(root_mem_cgroup, count);
+		return ret;
+	}
 	/* Try charges one by one with reclaim */
 	while (count--) {
@@ -6746,8 +6750,11 @@  static int mem_cgroup_do_precharge(unsigned long count)
 		 * In case of failure, any residual charges against
 		 * mc.to will be dropped by mem_cgroup_clear_mc()
-		 * later on.
+		 * later on.  However, cancel any charges that are
+		 * bypassed to root right away or they'll be lost.
+		if (ret == -EINTR)
+			__mem_cgroup_cancel_charge(root_mem_cgroup, 1);
 		if (ret)
 			return ret;