From patchwork Tue Jul 7 21:38:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11650347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8B5E60D for ; Tue, 7 Jul 2020 21:38:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A56A72075B for ; Tue, 7 Jul 2020 21:38:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fyRqItPO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A56A72075B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A07E66B0029; Tue, 7 Jul 2020 17:38:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9B7D56B0081; Tue, 7 Jul 2020 17:38:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D0CE6B0082; Tue, 7 Jul 2020 17:38:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id 783C36B0029 for ; Tue, 7 Jul 2020 17:38:39 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0AFF3180AD806 for ; Tue, 7 Jul 2020 21:38:39 +0000 (UTC) X-FDA: 77012594358.07.seat71_48041fc26eb7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id CAB411803F9B2 for ; Tue, 7 Jul 2020 21:38:38 +0000 (UTC) X-Spam-Summary: 1,0,0,87ae385df9be3508,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:966:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2553:2559:2562:2916:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:4385:5007:6261:6653:7903:9010:9040:10004:10400:11026:11232:11473:11658:11914:12043:12050:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13439:14093:14096:14097:14181:14394:14659:14721:21060:21080:21444:21450:21451:21627:21795:30051:30054:30056:30080:30090:30091,0,RBL:209.85.222.172:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrkdc5aiijcnuqr6wsb4788ze9noc31784pgsbgrwxjf4c1c38tkc4yskx9xr.4ohs13dkbf4z89jebcduqs6gqekx876sp8ccuco3pd89e95iz6wkt5koej1swia.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_ SUMMARY: X-HE-Tag: seat71_48041fc26eb7 X-Filterd-Recvd-Size: 5180 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 21:38:38 +0000 (UTC) Received: by mail-qk1-f172.google.com with SMTP id z63so39601177qkb.8 for ; Tue, 07 Jul 2020 14:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=86ZO0cDUMoFRuQFL1rAuMjsl3l6Acwgz3uk4qfYDTYw=; b=fyRqItPO3JMzl5UDYTAG3aDxi1u1Zt9gxagsbBYONe2VYOkTXrvOxV9OxonWeofXTR vnmLUGaW4hRzibnGl/5JFMXpFkWZY0wXAxajpYmGcAKooeoHcbgdVQkp86VuWSjLt4HO ltAXffK1FBIb/mmNBkZz5ugvlYqOCmx1wTUoTQWLrAYWmKQZU79luODl7ifDKTX9E5/0 o3i+4WxTh2YSdP5RrnZmhyj/s+f0Pen/sh0c4p5LOUv2K8qiAx1xnSNKXTs9BDJu022l qiHm03WzbshWw2HbpRFpvbm6Qy+TdL8lmMudjOwWWAy1Ckn7DFDUve5wBZYXenxETYXL C/6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=86ZO0cDUMoFRuQFL1rAuMjsl3l6Acwgz3uk4qfYDTYw=; b=oeAAdAXK9dOcoJAftFVoEsneSYJwR7ap2CzdCJ8Aj7Pmz85gXNqJN34tXdjJjF0qGV d+HTi4X37a4Qb3Cw7Va6C2/RLjIMEWlUwWmIIcHqDpdQo1Mj/gzxzs046fBYXqveWisb qoy+Pa+R5jyck+QBqztGlEEGZezMtloOvKg92ZbvvTKi2655K45dKKJm8YigWqSEyz9/ F4pPtuuxrgDYtopIBbB+pl8GpF3u4EHfdpYj06y/nDVlq6OfVSNTDoqB6UwRHoFLM2OE 3OyxhQ3HePU3QH58T1D4p8BoHDecVwBffVVWgUPRpFnd48kWxIs3nzDC/04OVGh+Z/NN NOhg== X-Gm-Message-State: AOAM530l3Uvh0/vl9lWgSbOfBOu1FdQDNRf9zuK7uVdX1X5XublvAEib BZLJch30PbP4XHImGMNbvjY7NQ== X-Google-Smtp-Source: ABdhPJyKszth8tMIh6pR8yN8ofbc6P/8A7gz4EHsL6ItN6YAaqlN/yFzMzgexhDoqfLyvZIwxxJyOA== X-Received: by 2002:a37:4289:: with SMTP id p131mr24422127qka.28.1594157917451; Tue, 07 Jul 2020 14:38:37 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id o12sm26346467qtl.48.2020.07.07.14.38.35 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Tue, 07 Jul 2020 14:38:36 -0700 (PDT) Date: Tue, 7 Jul 2020 14:38:18 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Johannes Weiner , Alex Shi , Shakeel Butt , Hugh Dickins , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm/memcg: fix refcount error while moving and swapping Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: CAB411803F9B2 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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") Cc: Signed-off-by: Hugh Dickins --- This was frustrating while testing Alex Shi's patches a few weeks ago, and no fault of those. I may have misattributed the "Fixes", which was itself fixing an earlier, which were both backported to v3.19; or maybe it goes back way further than those, I didn't pursue it - not top of the list of user complaints! Certainly goes back before the refcount_add() in v4.20, which replaced a VM_BUG_ON(atomic_read <= 0). mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- 5.8-rc4/mm/memcontrol.c 2020-06-28 15:52:13.360672658 -0700 +++ linux/mm/memcontrol.c 2020-07-05 18:11:51.136542439 -0700 @@ -5669,7 +5669,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; @@ -5860,7 +5859,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;