Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp413149lqa; Sat, 27 Apr 2024 07:22:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUngyyoiH+coBYMtqpNGoxw89m/p3XavK/o30A74XZAoJmX8I7t/dmEDEWErhwIEudGR5Wgw7PI5izXeqGcs34PIgIAM/eQDYHiokl2ZQ== X-Google-Smtp-Source: AGHT+IEMTwzQ4s+DJw4UxAlceMe85fxtFBJODch9JGwYjj8a+5Mj/LC3hG87LruVKphYmlK3qaU1 X-Received: by 2002:a17:90a:f013:b0:2ad:da23:da0b with SMTP id bt19-20020a17090af01300b002adda23da0bmr6150161pjb.34.1714227770304; Sat, 27 Apr 2024 07:22:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714227770; cv=pass; d=google.com; s=arc-20160816; b=brz6apU3g0ALhod0CgVEhlXqZelmJND2jG3tADh7MyeZOZnPhTvr+pPRZ6V5NsmoQM 9SaPCFE4fjBd4P/8Srk114QBn9kg/zGdjczoxop+eXmA0l/bxOsILv48iGuTSNxe7ET7 h4VPHdJqm9vchIuwVJ6keFfKBWOHJVeXl4XzFFC4zlXcnS7OmR/FgpyaGCUKjOBflwMM pzq+AIWw3f9BVncBJQSRqAYJ93XS4hD+1Z3Pd/AVbch7rern5pFRLGK4cIE2f4jYhYlr tkAT/AFZ+ri9iJXkbVOUEq0Qfc3+e6FSZTMp44b+np/L9fxqq7zLcsQaiI28t3BDayCi kXxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=my9A5bfRcuk8Vub7UGZ+fWvF69oRVjwTLMcPliiDick=; fh=ps0z9+gCvgCRdWVedDWaoxwcecfjG9xOSExkwXCIl94=; b=pbC+CDUju5dYvqdwT+OZZ07/18RrZGHpVY27Q+ft2nbLgs5hu6BD8hR+2RWiD7AIFj X1pfWHpgGS/GtF0cFnTjfWhkW/gNbQbKOHbOqoJOQc5K3v5wmo8/BtYoQ0FCDnb1SG8K R/prXUYN9ScN9OTtxVeak5VLO4eakMGHmDJ8pXnTMOUJLKPhQXTQ64caZ6/1XwJuJBls mI26tVhkwEFJoEUmtvGO10OHv797EqTYoI2Zz0znEWP90jqY+RHA301Qe9W59gehVo1b hL1MTCFxahDUES86jmJtpL2iGwNw4b7SOF20hLJWMevxxy+4PGWhX1DnSalQFkV16vSp Eg+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=2sOhvJeI; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-161063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p20-20020a63c154000000b005e4dce697c0si17343389pgi.655.2024.04.27.07.22.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 07:22:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=2sOhvJeI; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-161063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 917A3281744 for ; Sat, 27 Apr 2024 14:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C28350264; Sat, 27 Apr 2024 14:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="2sOhvJeI" Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A94B84F8A0 for ; Sat, 27 Apr 2024 14:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714227763; cv=none; b=OfqtwwmA8aT1nFO/+NpqcMgEovgasyXrO8hRXGiZ9E3//Tseax0fcdPHvxTeFqeLVr15VxuPm2P4n1tuR+2fSm8paMqPGYWxAdOfepQLv9aLUpDMXGjQzzoVp/Y+9pNbVa8SetyIrThsVnHbvw1K+D2DijgKjaYrHPCqfgOK2r8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714227763; c=relaxed/simple; bh=nTwNWxEsxbK6ttMKH6RkgIHZODyzl7FbYPFbXctiX3o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IDFDNZYaw1VSz1vpoBKxO0s9AhpMhbvpE/htdzpiw9Fw+NW3KNSi6xCeUax4HDbm6jQVC3gQwimHAv3yGUTslTI/kASdVbgjQUw1+ghY7o3DVS/NNeriPDT54/FtgDP6oUE4M1A3R8ivg8pHTEqb8DW/wPE5OdnqAo+S5WK5RN4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=2sOhvJeI; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3c85a9b9143so823370b6e.0 for ; Sat, 27 Apr 2024 07:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1714227759; x=1714832559; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=my9A5bfRcuk8Vub7UGZ+fWvF69oRVjwTLMcPliiDick=; b=2sOhvJeILVS4NS5Cwe7xWykq1hpBIkpt9I/oD3H1GTPGg3QQGGwMgTRqBTgQsCG4Jj cHx5W7lrOz+fQkZRtlAzcppzNtU5bpn0hNqttyJu11feIe2Iy0Zcdj7D8qbXmVLEpbVY RW2y5XhflnE/PrvfdGGD9NWTVt2z2I0oyU9ljlhyFOjxLWYEJtu4Arzmg2BDrV6dUo4Y ZXPoKeDRZ0D5G+BMty3b2LJ2z8ybV3/Q/eejq3KQv6bNTDVypEXJuqarZdv4YZqPSJI8 fpjD1U1+wROLIHCuOd/NhMFJXax54LC/EVLRsuJcKFQ/jcUf/KodwUenmRbU3S1VAAS0 i6LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714227759; x=1714832559; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=my9A5bfRcuk8Vub7UGZ+fWvF69oRVjwTLMcPliiDick=; b=gEEVmPyQ/UzWJbwVxGwShxnvdaxV9SD1SSsV7CBSKIjT7gWizo4bK0mPWLY7NnmPEA pzyFykQCj6wqytsK5ITtWiV6sfKEo06nJkSrQkKTDwm6BmZ1HQbTTruurG5XlE4kPVkC GvxPXkPvphzHP3FgrPCsk4yoNk6T8tB2edYl/PlPnN3l9bjjs4hIWrVtSwE6YgLcyjAA xZjTMWETXPLPq/DOQ/VhhgH+0IEBh48XSznlu3d4Rthbc9WhRy8vXGKl33dWAXxuU39z 5oW95ZNKqlSIjVPFOQAJFuq9ZF0KBppeLpRieP7GUy85JY1zBZ+vP9qTXyem9056FrIc xX7Q== X-Forwarded-Encrypted: i=1; AJvYcCXOyBxrAk1q0TZrlHA1EsRgmZMqGYN0EU9g+gufCPL4u6q1AuxOVFrXWeMIp948YgRxocsADWVGJ2XmSGvybYMqvQQfBmpgzAeWJ2wM X-Gm-Message-State: AOJu0Yy/kOszlRYDMlfUgHLgL5igL0VlXvq7LcWDue9TMOU4T+dqNr70 Bh05rVEgDCj/v1cKGkkNiQ5uTyfhk1IqVmBOSTYz3CgGKyUdY8NpcA6NZRjQGxPrC8IcmfmwkI3 H X-Received: by 2002:a05:6808:a88:b0:3c8:47a3:3d01 with SMTP id q8-20020a0568080a8800b003c847a33d01mr5963751oij.34.1714227759436; Sat, 27 Apr 2024 07:22:39 -0700 (PDT) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id y13-20020ad445ad000000b0069b4f48003bsm1847901qvu.100.2024.04.27.07.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 07:22:38 -0700 (PDT) Date: Sat, 27 Apr 2024 10:22:34 -0400 From: Johannes Weiner To: Shakeel Butt Cc: Yosry Ahmed , Andrew Morton , Michal Hocko , Roman Gushchin , Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 5/7] memcg: pr_warn_once for unexpected events and stats Message-ID: <20240427142234.GA1155473@cmpxchg.org> References: <20240427003733.3898961-1-shakeel.butt@linux.dev> <20240427003733.3898961-6-shakeel.butt@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Apr 26, 2024 at 06:18:13PM -0700, Shakeel Butt wrote: > On Fri, Apr 26, 2024 at 05:58:16PM -0700, Yosry Ahmed wrote: > > On Fri, Apr 26, 2024 at 5:38 PM Shakeel Butt wrote: > > > > > > To reduce memory usage by the memcg events and stats, the kernel uses > > > indirection table and only allocate stats and events which are being > > > used by the memcg code. To make this more robust, let's add warnings > > > where unexpected stats and events indexes are used. > > > > > > Signed-off-by: Shakeel Butt > > > --- > > > mm/memcontrol.c | 43 ++++++++++++++++++++++++++++++++++--------- > > > 1 file changed, 34 insertions(+), 9 deletions(-) > > > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > index 103e0e53e20a..36145089dcf5 100644 > > > --- a/mm/memcontrol.c > > > +++ b/mm/memcontrol.c > > > @@ -671,9 +671,11 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx) > > > return node_page_state(lruvec_pgdat(lruvec), idx); > > > > > > i = memcg_stats_index(idx); > > > - if (i >= 0) { > > > + if (likely(i >= 0)) { > > > pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); > > > x = READ_ONCE(pn->lruvec_stats->state[i]); > > > + } else { > > > + pr_warn_once("%s: stat item index: %d\n", __func__, idx); > > > } > > > > Can we make these more compact by using WARN_ON_ONCE() instead: > > > > if (WARN_ON_ONCE(i < 0)) > > return 0; > > > > I guess the advantage of using pr_warn_once() is that we get to print > > the exact stat index, but the stack trace from WARN_ON_ONCE() should > > make it obvious in most cases AFAICT. if (WARN_ONCE(i < 0, "stat item %d not in memcg_node_stat_items\n", i)) return 0; should work? > > No strong opinions either way. > > One reason I used pr_warn_once() over WARN_ON_ONCE() is the syzbot > trigger. No need to trip the bot over this error condition. The warn splat is definitely quite verbose. But I think that would only be annoying initially, in case a site was missed. Down the line, it seems helpful to have this stand out to somebody who is trying to add a new cgroup stat and forgets to update the right enums.