From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755659AbaFRUlL (ORCPT ); Wed, 18 Jun 2014 16:41:11 -0400 Received: from zene.cmpxchg.org ([85.214.230.12]:37559 "EHLO zene.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755561AbaFRUlI (ORCPT ); Wed, 18 Jun 2014 16:41:08 -0400 From: Johannes Weiner To: Andrew Morton Cc: Michal Hocko , Hugh Dickins , Tejun Heo , Vladimir Davydov , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [patch 08/13] mm: memcontrol: catch root bypass in move precharge Date: Wed, 18 Jun 2014 16:40:40 -0400 Message-Id: <1403124045-24361-9-git-send-email-hannes@cmpxchg.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403124045-24361-1-git-send-email-hannes@cmpxchg.org> References: <1403124045-24361-1-git-send-email-hannes@cmpxchg.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michal Hocko --- mm/memcontrol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 382af03a040a..b6b5f7f98618 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6375,6 +6375,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--) { @@ -6383,8 +6387,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; mc.precharge++; -- 2.0.0 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johannes Weiner Subject: [patch 08/13] mm: memcontrol: catch root bypass in move precharge Date: Wed, 18 Jun 2014 16:40:40 -0400 Message-ID: <1403124045-24361-9-git-send-email-hannes@cmpxchg.org> References: <1403124045-24361-1-git-send-email-hannes@cmpxchg.org> Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cmpxchg.org; s=zene; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZUidrARWEWL2hUsG+5GvwvmbF2rywECV+kcYZ+bk1aw=; b=MtGmrAl/1JQD5Y+wM21h5f3aFAOfYblNaI+YmxYHqtIjKfN+XcWgy4AeCB2Ui6oPtuScrJMAF3qSmwp3bJh6cf0dgZirYFEphfciIA5E3vjj9WaIDiKmMC/j6dmO86dYR4Y9WjxRFg2nVSbbUAehC8H3I8n9x66tRb4XFXtZXDo=; In-Reply-To: <1403124045-24361-1-git-send-email-hannes@cmpxchg.org> Sender: owner-linux-mm@kvack.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Andrew Morton Cc: Michal Hocko , Hugh Dickins , Tejun Heo , Vladimir Davydov , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org 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 Acked-by: Michal Hocko --- mm/memcontrol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 382af03a040a..b6b5f7f98618 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6375,6 +6375,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--) { @@ -6383,8 +6387,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; mc.precharge++; -- 2.0.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org