Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4880622pjb; Mon, 27 Jul 2020 07:29:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2UPdP6MiBOmdBbe4kb7hXAXaUiuOKCnfXik0A2v22uf2Uh2jMV8L9fR5n71xBFoV8+PvH X-Received: by 2002:a05:6402:c0c:: with SMTP id co12mr8948566edb.384.1595860151158; Mon, 27 Jul 2020 07:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860151; cv=none; d=google.com; s=arc-20160816; b=c/2IH3wx8EPwYxXAtAs6OD+c5gUgG2yLjkHukUi2jyEbszv9jfJwNFwQqF1badPaj0 lilhwMwj00LBkP753wCYNKR3dcmWHycaQ/7vnx3VwhYdHu8rukTDNOAIEeyiaH7KnbHl 0SQKDDyY916/Jl4P9P1g6mJ0t/NqCKAY2OfYt5BL+EZ4yi2LO9kvq8GbMXEikyAOC3Vo IgT3X7n5nAKP4hoO1+yd2LU9Sg9sEmvfFsHHSaVxZrjaOkwMcG+4AZleakZuiJIn0qlw gs3P7bwjODPegodjxTksGfpj29o7h8mxY07c8Yg0tgXVFvgULzZuFQ+a/2rFc7mxcuKx b1wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1DBzqB2ul9bzcUKTRIPI08NF5+vxnKKzC0XITlnruPI=; b=pFkw395MYNyQ3VKrTlt4ISy9pTxxEfix6qpEK9R7REv/Xn84pIQvRKLRxF1abWG6lo yuk08qVQ0RdlRnuUOUylR16fW4q61uBeCOQ86akG1/RqQ5NhpXJ1ukYSsi+E2LD+zamn QZ6NRbdXYWloqPwHZAFVU8TabRndC19qLm8TvKbsMIRdOKkkkkjT3bVuT2pYZ4HyT6Lq JxZeBwWeFG1FhoPoToBY0Z0GjJsSZEtm8j8I27dVjxYD+QtiNpW6KyqcSD3RIkAxW3ls oPaBiKO2TI5jVZFT3710Pqj01b6e8/6JhS++VrPpt6DpUIN3vaSW/3lr0V9GQo/lioHW XPSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yCDGDpR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rk3si4341135ejb.12.2020.07.27.07.28.49; Mon, 27 Jul 2020 07:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yCDGDpR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732454AbgG0OZd (ORCPT + 99 others); Mon, 27 Jul 2020 10:25:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:55502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732449AbgG0OZb (ORCPT ); Mon, 27 Jul 2020 10:25:31 -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 8BBD82075A; Mon, 27 Jul 2020 14:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859931; bh=kxqUQb49SOv6aFV5YU78vQgw0KFWI/YswWv7rMQ+cRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yCDGDpR5IN/5t3rxSlKCao+CYLQwjFyNKNQJKndaSTRHl5K/j2u8UbAwk6JOSZ4An lB146onXMmc/NR2k1D8GipFDmUz1m8fNb2rOqF8qTDUVLer1A+rx2N7315raUcEw3D 6DeTGg5eZ+8VR2OhyGTMZAzypYXO0eolOiaTlln0= 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 5.7 161/179] mm/memcg: fix refcount error while moving and swapping Date: Mon, 27 Jul 2020 16:05:36 +0200 Message-Id: <20200727134940.518638857@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -5658,7 +5658,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; @@ -5849,7 +5848,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;