From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06A2BC433DF for ; Thu, 30 Jul 2020 08:14:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D45F520838 for ; Thu, 30 Jul 2020 08:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596096889; bh=Nz2Yak96bXsmu5sMXZDJ1xr77ta15hLRSNxX6GjLhPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j0vtgpwl27X6bk/k5Yp7QySbI8SFGigt9nYnJRk+P5ip70aSe/2mqBWZRMpFqfTm7 rE1dM/yLWwMUgEHlfOh6VXoKrtBhMhJyRYaNuyya1Zk0gvlc2+he9ZAXX61l0j5hHC Z1kgFJ2c7qq9YockrVWDXrGUYWx+SdxI9ZTjj7K4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729189AbgG3IOk (ORCPT ); Thu, 30 Jul 2020 04:14:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:51576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729658AbgG3IMV (ORCPT ); Thu, 30 Jul 2020 04:12:21 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E9DAF2074B; Thu, 30 Jul 2020 08:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596096739; bh=Nz2Yak96bXsmu5sMXZDJ1xr77ta15hLRSNxX6GjLhPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F/lOen5SgMDVDDRRz3HSW37eNg2WFB96LXhaHVKnyvgVwtAktGHXIqqITvZwz4+hP /BuKh1DczvbuPmWiob2TYz6Zuuvrqpgy2XYVcrwqKC2IcxWUV5Ef2Iuy5b5yFEgJ6m CUnm8H38jNwQ6JQenyXRwaBT/nV2/OCbY9QhRjQY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hugh Dickins , Andrew Morton , Alex Shi , Johannes Weiner , Shakeel Butt , Michal Hocko , Linus Torvalds Subject: [PATCH 4.4 34/54] mm/memcg: fix refcount error while moving and swapping Date: Thu, 30 Jul 2020 10:05:13 +0200 Message-Id: <20200730074422.847040464@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200730074421.203879987@linuxfoundation.org> References: <20200730074421.203879987@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hugh Dickins commit 8d22a9351035ef2ff12ef163a1091b8b8cf1e49c upstream. It was hard to keep a test running, moving tasks between memcgs with move_charge_at_immigrate, while swapping: mem_cgroup_id_get_many()'s refcount is discovered to be 0 (supposedly impossible), so it is then forced to REFCOUNT_SATURATED, and after thousands of warnings in quick succession, the test is at last put out of misery by being OOM killed. This is because of the way moved_swap accounting was saved up until the task move gets completed in __mem_cgroup_clear_mc(), deferred from when mem_cgroup_move_swap_account() actually exchanged old and new ids. Concurrent activity can free up swap quicker than the task is scanned, bringing id refcount down 0 (which should only be possible when offlining). Just skip that optimization: do that part of the accounting immediately. Fixes: 615d66c37c75 ("mm: memcontrol: fix memcg id ref counter on swap charge move") Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Reviewed-by: Alex Shi Cc: Johannes Weiner Cc: Alex Shi Cc: Shakeel Butt Cc: Michal Hocko Cc: Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2007071431050.4726@eggly.anvils Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4889,7 +4889,6 @@ static void __mem_cgroup_clear_mc(void) if (!mem_cgroup_is_root(mc.to)) page_counter_uncharge(&mc.to->memory, mc.moved_swap); - mem_cgroup_id_get_many(mc.to, mc.moved_swap); css_put_many(&mc.to->css, mc.moved_swap); mc.moved_swap = 0; @@ -5067,7 +5066,8 @@ put: /* get_mctgt_type() gets the page ent = target.ent; if (!mem_cgroup_move_swap_account(ent, mc.from, mc.to)) { mc.precharge--; - /* we fixup refcnts and charges later. */ + mem_cgroup_id_get_many(mc.to, 1); + /* we fixup other refcnts and charges later. */ mc.moved_swap++; } break;