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=-7.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 C1187C433DF for ; Fri, 31 Jul 2020 15:07:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F72621744 for ; Fri, 31 Jul 2020 15:07:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="xVA3qKqV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F72621744 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C2B4C8D0038; Fri, 31 Jul 2020 11:07:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDD548D000B; Fri, 31 Jul 2020 11:07:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF2C28D0038; Fri, 31 Jul 2020 11:07:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 9AF1A8D000B for ; Fri, 31 Jul 2020 11:07:21 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 342B13627 for ; Fri, 31 Jul 2020 15:07:21 +0000 (UTC) X-FDA: 77098699482.02.cap33_561625926f84 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 3429910097AB3 for ; Fri, 31 Jul 2020 15:07:14 +0000 (UTC) X-HE-Tag: cap33_561625926f84 X-Filterd-Recvd-Size: 5619 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 31 Jul 2020 15:06:01 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id l64so22228980qkb.8 for ; Fri, 31 Jul 2020 08:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ff/aO+f/ar+IJTfIhhVDXCQGW8FBVjjCHNkbg+nD/8E=; b=xVA3qKqVLrnkHInB3M7U9/5AssU33ep3UEX72ANbYHcwn7OdX9zg75cCCV7x/K2nNa b1BIUmYVhQ7WXkyZkU20DceV3dopjAeMrAqc2guZzTsxJinRGmeOl9Ymg0mAxJlfZqyX dwYhfdty5kF+PHCke0BmgkWLyX4hgJK6CLfLeqvkyR/Mg0M3JCELG8YsRUM4qlT+X8Qj 9dTTHJrGLhq3YOeye2px9l1Reimwbd2nbkT2ixMLy2gWMOJOSQYVmNt5m4cCvztQvyg3 HRo6Eepk55mVeW4q8dcoYYcxuHuazDbeAHUB8zx6SZfLv8OH7zA/kqP9jAj1lVyy234I Vr2w== 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:references :mime-version:content-disposition:in-reply-to; bh=Ff/aO+f/ar+IJTfIhhVDXCQGW8FBVjjCHNkbg+nD/8E=; b=RzU/k4JSqOmdnWlZqcAsrmpY+sIs7d+Yi2th8PJiTujEa5YUc1yopz1r1sCrgpf7x2 lEUarEI09L368cn/twDcC/a1UAe7KFzMR/LbbWwzdkUW+Y43qTfkQ2/OcMaeSwf0Me/X s5J7qntnVOGi30Itu64QptM31lIqyVm5Fo49hAhFURDCEpRyKVKyTePEg34vfPdBKroz vrdGw6LVpIqIDJ+wcJEwocZ6n2NyAhVxWUsKz5GuNf9urWFJl3SzXP52Dyts3cESrFgo Wi7ikhBpRyqqW+oQoESUdJ4C7Z0sGOsXmhzHvp/7/aLxnvUDwVur08TQJ9hS6usE9HFB yNMQ== X-Gm-Message-State: AOAM532K0kLBtCQW1zlEVH/8ACHIWUaFejkOp4e4nMq/8kQqen4qRa0w ziOj4eGgxLIlbM4saSn/xN4KKg== X-Google-Smtp-Source: ABdhPJyYC8OqkZDjHQjI3v8OFXelR/mP7jiMXshyCjcyGLjZUbGbO6kTuC3G6P9+J6dJzwTGPGUOcA== X-Received: by 2002:a37:a0d3:: with SMTP id j202mr4242255qke.365.1596207961101; Fri, 31 Jul 2020 08:06:01 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:11a4]) by smtp.gmail.com with ESMTPSA id w11sm9365133qtc.58.2020.07.31.08.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 08:06:00 -0700 (PDT) Date: Fri, 31 Jul 2020 11:04:58 -0400 From: Johannes Weiner To: Hugh Dickins Cc: Andrew Morton , Roman Gushchin , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH mmotm] mm: memcontrol: decouple reference counting from page accounting fix Message-ID: <20200731150458.GA491801@cmpxchg.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 3429910097AB3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: On Thu, Jul 30, 2020 at 08:17:50PM -0700, Hugh Dickins wrote: > Moving tasks between mem cgroups with memory.move_charge_at_immigrate 3, > while swapping, crashes soon on mmotm (and so presumably on linux-next): > for example, spinlock found corrupted when lock_page_memcg() is called. > It's as if the mem cgroup structures have been freed too early. > > Stab in the dark: what if all the accounting is right, except that the > css_put_many() in __mem_cgroup_clear_mc() is now (worse than) redundant? > Removing it fixes the crashes, but that's hardly surprising; and stats > temporarily hacked into mem_cgroup_css_alloc() and mem_cgroup_css_free() > showed that mem cgroups were not being leaked with this change. > > Note: this removes the last call to css_put_many() from the tree; and > mm-memcg-slab-use-a-single-set-of-kmem_caches-for-all-accounted-allocations.patch > removes the last call to css_get_many(): now that their last references > have gone, I expect them soon to be freed from include/linux/cgroup.h. > > Signed-off-by: Hugh Dickins Thanks, Hugh. This fix looks correct to me. And I'd agree with the put being worse than redundant. Its counterpart in try_charge() has been removed, so this a clear-cut ref imbalance. When moving a task between cgroups, we scan the page tables for pages and swap entries, and then pre-charge the target group while we're still allowed to veto the task move (can_attach). In the actual attach step we then reassign all the pages and swap entries and balance the books in the cgroup the task emigrated from. That precharging used to acquire css references for every page charge and swap entry charge when calling try_charge(). That is gone. Now we move css references along with the page (move_account), and swap entries use the mem_cgroup_id references which pin the css indirectly. Leaving that css_put_many behind in the swap path was an oversight. Acked-by: Johannes Weiner > --- > Fixes mm-memcontrol-decouple-reference-counting-from-page-accounting.patch > > mm/memcontrol.c | 2 -- > 1 file changed, 2 deletions(-) > > --- mmotm/mm/memcontrol.c 2020-07-27 18:55:00.700554752 -0700 > +++ linux/mm/memcontrol.c 2020-07-30 12:05:00.640091618 -0700 > @@ -5887,8 +5887,6 @@ static void __mem_cgroup_clear_mc(void) > if (!mem_cgroup_is_root(mc.to)) > page_counter_uncharge(&mc.to->memory, mc.moved_swap); > > - css_put_many(&mc.to->css, mc.moved_swap); > - > mc.moved_swap = 0; > } > memcg_oom_recover(from);