Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp145756lqa; Fri, 26 Apr 2024 18:18:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWa64hVnKEvz15AqpCuFdnABMHCOKqBv7ltiwoDp6iq1ewdfRrtCFlmeO+50ACUt0SpRgN83Usu0fwZ9DB6UecWyqtbu8lblqCw91EvQ== X-Google-Smtp-Source: AGHT+IGp4OsYGqlgfKA7E8EW2UbPOsLUwpLpbrHvRdu7KO9OQa5vR2z4R905lT5LSoEhHPWvxLoh X-Received: by 2002:a17:902:e945:b0:1e4:3c7f:c060 with SMTP id b5-20020a170902e94500b001e43c7fc060mr5215005pll.66.1714180707016; Fri, 26 Apr 2024 18:18:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714180707; cv=pass; d=google.com; s=arc-20160816; b=RCGFDlYwJ9NcjTBjlYydHMof5YObJ7h31dwLf1TQQoq91r8fQ9HhfK8dAmhRJ2faYt tly5/s4QSmKApHtUGiMTJxslnyXgEuvfhvJTlaOaJq5MqVK8Qdb+mzm5auzFJwY7UZwl sPMMxzs2Fea2fvo2IXztoaPfw8KG41Qn6PoXZNddAdNOIZr4tdT8oXWYvjb8Mt3v0vdR aJGZqZcRc7APrjpsSGvDcsjKhK1m03bVLVTQcig6FpEvlONI+HN6okReIRLlDIaphtqR Yv6yNSUkRofRovH0eDRwhJoW89vmWkpcY7lSykrP6/b3pnxVqEAOiRlrQTzBaaAzeruL AHHw== 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:dkim-signature:date; bh=1KyQAvNmH8cK+YgrZdteZGkEfU1LsqfdtvT92BFP4zs=; fh=ifesyHm7lGxO6oBP0o4ljVxzoEpCEqENJ0ry8d3xcQE=; b=sbbJO2jFmoPl7z/Bke57d/q8U0qMr1SKTVsaMBt49At5ISdslPlAmtHThyjmeK9aa1 kQxHmxPt/yllmwjSL9dhG4onX9i5461wxZ+rvGiXPZNMbordUZ6D39UmkJnZ1j7pZ5ti 9jNPWPY97jgxGYehJUiUgj3XnRdNYWEJ0PvOpwPwd5uXuADzavw0z4UB/azJSp5JSpiJ elb7Peg1eWYX1F3j72VYBG3fCfpr2KRzy9ES8MBxUGtzzCQUxTF/omfgyfijBcG3Axes nDyZMkysiailKNEpl6XcaFEGfC+STXRgVDTAFrf8V9waKzqKrdbOv0rzaX7OiqP0IFaF JzHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=dgOep0XN; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-160841-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160841-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b14-20020a170902650e00b001e29483faccsi15414453plk.635.2024.04.26.18.18.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 18:18:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160841-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=@linux.dev header.s=key1 header.b=dgOep0XN; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-160841-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160841-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 A2307283DEF for ; Sat, 27 Apr 2024 01:18:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD3212C6BB; Sat, 27 Apr 2024 01:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dgOep0XN" Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61ED62D03B for ; Sat, 27 Apr 2024 01:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714180700; cv=none; b=gppy6JUb+RdP43wBlW0KfsKb3OjKIi3xd9Y7iBDPuL+z2w44Noe3uAQi9YThJ7NkXt11j6OjOhtnQt6QVKK+ltFfNhdCePq7cf55fOX4Sqo6zVNbuDHdtFzegnwFAINsDW9Qz98Pbyo5jxm6ulWfsFcx+eP+hnq/mG0jArkMUXg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714180700; c=relaxed/simple; bh=PQ9kSUdxKpcoVtjr3Xzztl1OBwFz5xRRUt4ftMTSovk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VtaVxhBVYol9dDNmNz23rWuc+It0obJGNiO79LeFZzxXYkrxqMeya2xe2OGDqwepSnvcFymEe2uC6WlIKWTrmINGRqeGw+kZJF8GVxaoRVFHK1k/Q9mvyrYFBy3HQbEd1X5Rissatvyl/fQ4ZIOyPFuDG9PTL3iU1dbATEKO/2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dgOep0XN; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Fri, 26 Apr 2024 18:18:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714180696; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1KyQAvNmH8cK+YgrZdteZGkEfU1LsqfdtvT92BFP4zs=; b=dgOep0XNlHGarvM2anPP/ocidn8aiFauFWMVL/4H+jO07miUU7fqfv5JREfQWrhxIbJNch USGIoyNCjOMiZoftkwWiZRd68UzI59DYglctp7HxWO1n4Y/jmFQ/NxOkZ2mD17TqSFe77+ 8GmQ9urU6LOMfEywqhlZXcewZn0q3Ac= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , 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: 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: X-Migadu-Flow: FLOW_OUT 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. > > 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.