Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp138413lqa; Fri, 26 Apr 2024 17:59:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1hVf+AbUeA/hIR6xUGqxQLPDuyFnmuFKEHvyUsEkwf1UbnAW3EAbrRQheTEmbffUUK8lyCzjGA6M4xXTIWxigHH7IaoRhBlFYqAUdEQ== X-Google-Smtp-Source: AGHT+IGSbkcgAyksz6Gxop+JTT97LFMb3XTVBYQM91YIkllMNC++y4xkoBYPnNtQqD3tLR8CdDgi X-Received: by 2002:a05:6808:2913:b0:3c8:53aa:b2f0 with SMTP id ev19-20020a056808291300b003c853aab2f0mr4707281oib.23.1714179542842; Fri, 26 Apr 2024 17:59:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714179542; cv=pass; d=google.com; s=arc-20160816; b=woylkgQxyiGDHy10EQKJZRzIdCRQ4jqdxTisQMcaPobuQhQvVaWWdqLc64QnZYnwAy yKUHMWK8a39XLojSVSsLH4Yuv8yr1zp1Ajtx/Jqy5AxJVk+OBQY3i8C5FCAAXn1HXuCU sCNshPM3HZ1KFKtnsATYJJVpOK3KyJJZL/nGkn92WbfefF1C1EHK1CGOb6l4vVVO+GYu W52uVHcUQYWb3kzEn/Dnv8ysUp8enFrhIg9cIVjqhI3FhIo9VcSseyaevCGpgQ0Hf+DD yWDNmhRNAZa2Ef4X4xr9EsEY1s++I92BEYKxoSJgqtdhESh1qV0QJtP4WJqPyYN1iFIW AJ+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=HSat3VRqn3nH22+jIzgZ3SLdh3nYoy1+0NoyZK+oZTo=; fh=KjvbvY3OSwOv7+VkyRync/f7OGO5ISRvPVGsB19OljE=; b=f7nidlLEOxiM9VXR5LebI9Xw0thwClIjzjka7bf/HGApDLmM5bSuw3583U1dkQNSSU ZTUgpJNhND6rhkhW3gnONhS8bVloouH6zSWuJJi2Kwxtgt/8EbfCPogILurE01f/z89p KbrvR7V84tOztWnFul7VFS96MxTqr7FMPTL+bCxg34HWAQwoy7kW3v/ip7Rxn8XE3SM3 QJlU4axIdqJh9zbbqFRccp8jK7SvohtsW2BTJPQmwuFvhVH2EZtXwjC1RBE0M6npb2jB ltW6inziumiz8M9g72+czxg4a6ZpVtBpuBU5cAcbXpfqmHB3cjvFbNnVr8WimVcPzSPE 1DBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nw7zDSBq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-160835-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160835-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o18-20020a656152000000b0060278c99018si8564321pgv.627.2024.04.26.17.59.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 17:59:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160835-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nw7zDSBq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-160835-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160835-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 6C3D1283A86 for ; Sat, 27 Apr 2024 00:59:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 000442D057; Sat, 27 Apr 2024 00:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nw7zDSBq" Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 9E0A7320B for ; Sat, 27 Apr 2024 00:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714179536; cv=none; b=iYV0oHJ/Ml15ztVUbtVezkLNFu08PZO8GH+UkBj80wp9nOAn89gtB4VtySwaLsM/pZEmo5EikLISG4GptbS0EuuzS+o5Tc+U3jMcMmGJz5xKJqZDbpUAYbmaQVYCV/wnjM1cclw25u/h4tkciLWGgja5GQssGCNbwX+ALkACisw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714179536; c=relaxed/simple; bh=6ouwrM0c0aq5btYyMAv8dDhjILu6rbOiMes8jZbrJXA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=K4qV3qFXdNLTvjAfeJkoGB6e/PPnw5j7bDzEoOCiOzNMFPhtHnE2uysNcDdAIn3Lw+iQSmPN2DdKwH7OJ7dpEqqNmKQ6LX1uhRe5W0ISID85B4yUQIObKqsQFUUbUzOjWJ287Rvm+jEBbxQW7l1Z/feVzWUWV8q6zU0pXOj/rOY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nw7zDSBq; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-572669fd9f9so693374a12.0 for ; Fri, 26 Apr 2024 17:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714179533; x=1714784333; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HSat3VRqn3nH22+jIzgZ3SLdh3nYoy1+0NoyZK+oZTo=; b=nw7zDSBqcFdE1zlhL9uTB0mmRSpnFy0/Y9aLEfuwzr2OD7mFsF50S7Rezw/6cTDWp1 vKTInRw/Vchgrq971x7wJBqY5c8yf/zowdRF1/pFErlf6wRE37XXjCSyah2+/WpIhqbG UtxUdZa+S+XpgffbfgzExzKccJDg7R+yJH+gxgQJTLvQqQJkjnLaQuODZVgVQz6nkpBl Qx1H/xy5gDSJAZo63D6TaR92/eZspuc5QcCB/xAsEvDQA30cGtYXVQFFmu/b/o82Q9ba rGz+ouT0ekrPJdLV7aD1wHE+7c2lmaSoGgGGSAWiMz9Rza3IKeb8rsVY6FmH3vVIi2Uv csBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714179533; x=1714784333; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HSat3VRqn3nH22+jIzgZ3SLdh3nYoy1+0NoyZK+oZTo=; b=kMHT50vLgumS8lPdkpyp+K9+mddkz7R22KqZHy1uhTyb312EA7IipFW7758OzBsR1A Wj7TAJmdA7U8VxVaL1oIKWMDRQg2t1x1NwOwXxqp2B7RURLRMdtyr8IFhfHH20S/6wT+ 3noBJKgUpJtg2UFv53XAS6Z0ccfTLoFaoHPfsNUJx8/1dkY3swoVTV7+8jrxjLAOoYjI qLij7q68uf1PF8eKr6OWi6Zrq9reHvSY5xYQvuQg96JhCnNdm7vlgjkwsncCvl92Oeoa 5tjC3vpruST5Qkx8iErp2tfw7fk0GIAu+yEDvqM5vV2a0TvqiUBtM/n8yoTmdsmbFs0U w9mg== X-Forwarded-Encrypted: i=1; AJvYcCX2WAXDTP8AbwfD0v0LIp81Bg3AU7FlvNsGhfuUycUduedV1zkYmXhs0Sd5ZxFXQHbEzI8xawRTDir64Fbd9VUERB1PRZrlG1HpWMll X-Gm-Message-State: AOJu0Yzakp0q0nr46ZQFh8iOu/KQ3CxRh1rMiFOUMUerDJY2r5jhPGgi EzuoxnSQ+vFn/xgJSbxjCc6joQxGuRSeBj0KT7BDI5aSDUMOhEdRNPzg2L/vCj8C39ACVeR/LpY vlKNDuxrC66magIgeMJznIDakXq8vN+QYDCGN X-Received: by 2002:a17:906:7f03:b0:a52:6435:ef09 with SMTP id d3-20020a1709067f0300b00a526435ef09mr2951843ejr.76.1714179532735; Fri, 26 Apr 2024 17:58:52 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240427003733.3898961-1-shakeel.butt@linux.dev> <20240427003733.3898961-6-shakeel.butt@linux.dev> In-Reply-To: <20240427003733.3898961-6-shakeel.butt@linux.dev> From: Yosry Ahmed Date: Fri, 26 Apr 2024 17:58:16 -0700 Message-ID: Subject: Re: [PATCH v2 5/7] memcg: pr_warn_once for unexpected events and stats To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 26, 2024 at 5:38=E2=80=AFPM 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 *lruve= c, enum node_stat_item idx) > return node_page_state(lruvec_pgdat(lruvec), idx); > > i =3D memcg_stats_index(idx); > - if (i >=3D 0) { > + if (likely(i >=3D 0)) { > pn =3D container_of(lruvec, struct mem_cgroup_per_node, l= ruvec); > x =3D 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. No strong opinions either way.