Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp757026pxb; Fri, 8 Jan 2021 18:27:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwANjqwdVgacccXjqJUjb/gxsZJyt6Ub2aoOf3m6sWumseFMKNDsykvLSSHwMdIQxi2UIKc X-Received: by 2002:a17:906:4348:: with SMTP id z8mr4433791ejm.371.1610159253808; Fri, 08 Jan 2021 18:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610159253; cv=none; d=google.com; s=arc-20160816; b=PO0B+GdosIt7HIuyjlXnq5n8hUIv09M4NUOZV8xPoK52BB02txL5Wg1HIoUHaJKrII N5lHXRcJL0qCsdEudpzHG1WihYuBqoJbpzLOSqBEuqXtBsMseRkyKBGVLMISb5CVjxN8 kIWtOA3ZwWpBFIx3uSE0mhCk4o/BPU6Gq+Us4HWQmLWzNsPgXlnWA4b3tbxqcXqQ9oYb D2MPp+DYOzQl64Kq+Z0wlNT5L62/DNgBO4YJKwRlHYn6F4PkxMP7I1qo/as+iiaUxPW4 YFCVteb+1EA3935DaIWo4ELff+Nbexyq2h4ORQOuO1ExEHS52IrSui1dB6f4w9jVceIQ SWrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=O512iOdiQl7IEgpRDKJFQeplTuWfwibmOqpv/4fzERA=; b=Nm1tt052dQy4C1KkI2LLCF44WOEsbcEcNSvqvcsKugd/j7hsEspGHGKwjU3nPCLlGj 0wW8ef09qIxR3i/9dRfTgbOccgUjRNHWdAODxsG3O1rdL6FHsPBovGo4TRiSq6n6mrYn UVn3Fch7BhG+zBnihD5kWlzDlHFLTJpwGemW7yGRELao+wA171Suxl7TQPMwJolz2T1D R7uqtnfBF6Pwow8HwRFB0iEaqK3h+I1oKWWGVZ916Dr1d6VI6AY9mK4IkqAS47FL8Hcr 5LkOhH2FGhVl4MpRdXvNli/HscUKYOEVChiRl7WOhZzoWMW6aCJh3+aMyQC64HnalybE +2qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ZQSLXT9/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si4235993eja.450.2021.01.08.18.27.09; Fri, 08 Jan 2021 18:27:33 -0800 (PST) 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=@google.com header.s=20161025 header.b="ZQSLXT9/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726410AbhAICYI (ORCPT + 99 others); Fri, 8 Jan 2021 21:24:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726013AbhAICYH (ORCPT ); Fri, 8 Jan 2021 21:24:07 -0500 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC1EC061574 for ; Fri, 8 Jan 2021 18:23:27 -0800 (PST) Received: by mail-oo1-xc2f.google.com with SMTP id x23so2874483oop.1 for ; Fri, 08 Jan 2021 18:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=O512iOdiQl7IEgpRDKJFQeplTuWfwibmOqpv/4fzERA=; b=ZQSLXT9/DFHCTODimbMizY/fKhhRRuE7vZE/TEUrfMucjwAm68A6KiUZ5AXuADWucB jZavZ/PqwcyhqTTMMBrIZZ3QZjVfHd772M0Cyq3wKIVdQX6FY+60PT2ll38GRJeEvMS2 AjVFKUgDTfusb98LzWGlu/gTnG2/2Ck3HsINcLjec8htrGs9245emOxHX6G+31Dn5HbQ b+5fPgvEHhmRAD9Mu3TaNFj/KDud1BTXsKoTcpR1WuFaMBwKEjom8LhOxKu/wHR0vjbW nAyvjc+sTA04P51ck86N1cMejaM3idB0BN37mTP8lGh1KoRlOqz0AwIgpCMhh/uCOj3J 36Iw== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=O512iOdiQl7IEgpRDKJFQeplTuWfwibmOqpv/4fzERA=; b=Wl7bZkfnXAlCLvJgfsw56ASxaP9uA5KDzq7zC6k67vi2zzcX7F/0NJwByzgp5p9FSy RAe1U6aVg+nGBMGjKFOUrP/ePoxLnN8p9tbk93LkY4iPLNk3LbLCAynrVYwpS17mVTr0 IBd91jKQAnzzlcegFqr2F2YeW+hrF23xP0lQsINI33TkX5OFOEjJBPZylC8tY326McYY mC4HXJjceNtIT8reU79ZK+ve//j2kA/GZOxRi7P+LAexRUbZkKkaSNd8jzR7WgkOVK4f leUGOTQTV5uepXjLl77RLjxGWeFPEOfGONqhOC9BXjWs7FCtLCr1M6MHhFYOiAQ/ekH/ B0WQ== X-Gm-Message-State: AOAM532R/ddB02pPWrF/hNRB+oUkF64LWJi2hTUpq5VrTkA5UKfmGcPB qaWqBvQjMzuJ5XLlovOcqQoTMg== X-Received: by 2002:a4a:e294:: with SMTP id k20mr6225934oot.82.1610159006663; Fri, 08 Jan 2021 18:23:26 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id e10sm2150117otr.73.2021.01.08.18.23.25 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Fri, 08 Jan 2021 18:23:26 -0800 (PST) Date: Fri, 8 Jan 2021 18:23:09 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Vlastimil Babka cc: Hugh Dickins , Andrew Morton , Hui Su , Alex Shi , Lorenzo Stoakes , Michal Hocko , Johannes Weiner , Shakeel Butt , Roman Gushchin , Baoquan He , Chris Down , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/memcontrol: fix warning in mem_cgroup_page_lruvec() In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Jan 2021, Vlastimil Babka wrote: > On 1/4/21 6:03 AM, Hugh Dickins wrote: > > Boot a CONFIG_MEMCG=y kernel with "cgroup_disabled=memory" and you are > > met by a series of warnings from the VM_WARN_ON_ONCE_PAGE(!memcg, page) > > recently added to the inline mem_cgroup_page_lruvec(). > > > > An earlier attempt to place that warning, in mem_cgroup_lruvec(), had > > been careful to do so after weeding out the mem_cgroup_disabled() case; > > but was itself invalid because of the mem_cgroup_lruvec(NULL, pgdat) in > > clear_pgdat_congested() and age_active_anon(). > > > > Warning in mem_cgroup_page_lruvec() was once useful in detecting a KSM > > charge bug, so may be worth keeping: but skip if mem_cgroup_disabled(). > > > > Fixes: 9a1ac2288cf1 ("mm/memcontrol:rewrite mem_cgroup_page_lruvec()") > > Signed-off-by: Hugh Dickins > > Acked-by: Vlastimil Babka Thanks. > > > --- > > > > include/linux/memcontrol.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > --- 5.11-rc2/include/linux/memcontrol.h 2020-12-27 20:39:36.751923135 -0800 > > +++ linux/include/linux/memcontrol.h 2021-01-03 19:38:24.822978559 -0800 > > @@ -665,7 +665,7 @@ static inline struct lruvec *mem_cgroup_ > > { > > struct mem_cgroup *memcg = page_memcg(page); > > > > - VM_WARN_ON_ONCE_PAGE(!memcg, page); > > + VM_WARN_ON_ONCE_PAGE(!memcg && !mem_cgroup_disabled(), page); > > Nit: I would reverse the order of conditions as mem_cgroup_disabled() is either > "return true" or a static key. Not that it matters too much on DEBUG_VM configs... tl;dr I'm going to leave the patch as is. You are certainly right that I was forgetting the static-key-ness of mem_cgroup_disabled() when I put the tests that way round: I was thinking of the already-in-a-register-ness of "memcg"; but had also not realized that page_memcg() just did an "&", so condition bits nicely set already. And I think you are right in principle, that the tests should be better the way you suggest, when static key is in use - in the (unusual) mem_cgroup_disabled() case, though not in the usual enabled case. I refuse to confess how many hours I've spent poring over "objdump -ld"s of lock_page_lruvec_irqsave(), and comparing with how it is patched when the kernel is booted with "cgroup_disable=memory". But I have seen builds where my way round worked out better than yours, for both the enabled and disabled cases (SUSE gcc 9.3.1 was good, in the config I was trying on it); and builds where disabled was treated rather poorly my way (with external call to mem_cgroup_disabled() from lock_page_lruvec() and lock_page_lruvec_irqsave(), but inlined into lock_page_lruvec_irq() - go figure! - with SUSE gcc 10.2.1). I suspect a lot depends on what inlining is done, and on that prior page_memcg() doing its "&", and the second mem_cgroup_disabled() which follows immediately in mem_cgroup_lruvec(): different compilers will make different choices, favouring one or the other ordering. I've grown rather tired of it all (and discovered on the way that static keys depend on CONFIG_JUMP_LABEL=y, which I didn't have in a config I've carried forward through "make oldconfig"s for years - thanks); but not found a decisive reason to change the patch. Hugh > > > return mem_cgroup_lruvec(memcg, pgdat); > > } > > > >