Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1463379lqa; Mon, 29 Apr 2024 09:07:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIo7aof3tZ2+Ns8mg5j6aNe+Z4kfuza++41kUUSVm3xTBqPRshUrMKz6fXmLomeiPTQe8X4ZSs2IC13zyuKl4Mhf+PkL00aj0ezrBP3w== X-Google-Smtp-Source: AGHT+IFgWupOFfqI87ss4cVv7E0yVaB9snLo4DQI0aINYsnJn4XYU1Ugy2ZoZ2QmcJEGyK5Wz14Z X-Received: by 2002:a17:90b:88c:b0:2b1:bea1:84e with SMTP id bj12-20020a17090b088c00b002b1bea1084emr2749243pjb.22.1714406850773; Mon, 29 Apr 2024 09:07:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714406850; cv=pass; d=google.com; s=arc-20160816; b=Ib7xbh3I+bBv0ralLQm3Yi49+UQqLxrM/s+TaqRjR+aLsLGmyfXdhE+UckUeGd3crf fq06jc+Gg/JoKerf+7M+RJ8dq7FN6RJJzgxlZu/TOmr2EY56ZlKeWr2wjVKEY/CwvVLs uuUXnWww8/ESykDuw2Fh/WzlAQQuvdsTu6Whg6v+PcZDdmaO6XzXQWuDFoiwue0nDSil Oj6YDlALxgi2CiF+CS5panGfTEDBuZx1PfSU9pK3BxC0BXCHW6I30dFbbfKGVHeXJJcS ZFrO75nWp5Oe0Iy1z1BdYvuH9XAAvNSX31r9Fc8k43RmFCgtD7wDpC54J4guYS36z7ru RfoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=R2nXwXohL2J0wPP0PlowVYkLxMx+ryb/FZdWBx8UgrY=; fh=IsuQBNQYhkGChzqSB/vteDtpE7K1Tm5QTidFr5WcaN4=; b=fotkSrMWY1DQEaQPhZlbIWUeckqFlNlhU5RYTB4MHdj0K6gzh6kG+ch2kNk3y5fe6Z V2fsRgTZpFTjVNQwcsANu/wO3jsX38jaTrGJ5KKAxDCYuSioKvWr3PcXUauke0sAj1Nf 7s93BSfwBqs1XEgvBacfPZXTl5wMSj89m2G1rvLnVHnRqUJ6cA0Wbwun77O4PtxCTo+4 4HBcsLIVxjps1KnqRJIqNU2sAqWzuDYplx5eKwfvEb+t52bRp2z9ioaaYNIdBu+oPxmi ALASazk3mRmuMfhuPakAjSp0HJG1Tyh+nev5rgD/AJiutAdBJ5BxUlRRCU+MUb9pweed Z70Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=lVsWtbiK; 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-162653-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162653-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id gq10-20020a17090b104a00b002b2057ef59esi1133803pjb.120.2024.04.29.09.07.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 09:07:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162653-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=@linux.dev header.s=key1 header.b=lVsWtbiK; 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-162653-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162653-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 9013028475C for ; Mon, 29 Apr 2024 16:06:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B92D984D26; Mon, 29 Apr 2024 16:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lVsWtbiK" Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 149D583A18 for ; Mon, 29 Apr 2024 16:06:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714406790; cv=none; b=qqU/StYvyAR1Dj8BQYxaip+DGNyyXb/ZuxQlj7pJfwc1bnOnjG7hpACyU8vOIF3sDmv7hy3e6TAkzlRkIObblMqK5nrNxumKAj4nYfJnfEgJTwh5kBjLVaRibOIRRWH4b9fbfk8XIa3Am2c5T6XDNFM5YYK2eL1I/mvwtOMygs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714406790; c=relaxed/simple; bh=uPC1BgfoZ/0CNcgBlxO1uJXrO4xZEvVHlQ6M555k1V4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BsinA2viHyuXG6XYmfpyRVUhnVq1PmZ58gv56NdpgwzRn6T9feTwSjuVSt3IyRcE2LMfArbev3DA1tI7ctvgn+PsHxa+fLSqGfKnWEygKoCeUWFTz4yMcuSeSUrXosRkDnjWj/mepYt20E3HJdo2KvAfREYFHMBBzCTk/UB0Bsc= 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=lVsWtbiK; arc=none smtp.client-ip=91.218.175.189 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: Mon, 29 Apr 2024 09:06:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714406787; 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: in-reply-to:in-reply-to:references:references; bh=R2nXwXohL2J0wPP0PlowVYkLxMx+ryb/FZdWBx8UgrY=; b=lVsWtbiK/0p4r9CmGvVnCV6zeaDp1O564nKflx9dr53zJ7/KNLSKPHL4kLZgSDTToYH7Yo vyIq9SIsJw1b/CYQKvjAmTWYJg7bAPBXISxpqdKoUOEBLkDIdn0l4v/Sqv+FmY028v9hJt 0o5LZ9J1li3JG2PkWrpsS42DxUfVMOg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , 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=us-ascii Content-Disposition: inline In-Reply-To: <20240427003733.3898961-6-shakeel.butt@linux.dev> X-Migadu-Flow: FLOW_OUT On Fri, Apr 26, 2024 at 05:37:31PM -0700, 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); > } I think it's generally a CONFIG_DEBUG_VM material. Do we have some extra concerns here? Having pr_warn_on_once() would be nice here.