Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2200669lqa; Tue, 30 Apr 2024 10:38:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHAGXuJNNBMXgwrXgwA1ghutWTrixSS78Xx0P09o0FjzZQdsCgS4GfuFiOyp9fDKnRvXoESDCmNvDkAjbaTSImqToPOTjSE5Y5uzAJeg== X-Google-Smtp-Source: AGHT+IFpqL9upIKGRwaNycvYZsN2xpQEo0Ylu3DUAkhpPIur6Nn7Wd6EGNecWeCcS6JZN1KdmEZ3 X-Received: by 2002:a05:6870:414f:b0:23c:6619:ee3b with SMTP id r15-20020a056870414f00b0023c6619ee3bmr186726oad.13.1714498721185; Tue, 30 Apr 2024 10:38:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714498721; cv=pass; d=google.com; s=arc-20160816; b=Nd4r8AnobenMlBORggvyyBRH6Q/TBLNVNYYCzScZHm+sNqdpJtfJVBHsjrZwPqjpg8 5yYwOxvTU3AWurX4ufaZDLRqpvvUtfH9zii/sSYie5oLaU1K4tEcTNql5VQjPtAmcrSo 0guuNzXIx/vh7RN2KldEj6COF+dG1IBS6rdDgaVqT3qarMqwM74dVLaZJeoxU2ceA+5J k411tBe2aLX2vwkVVstAj5So6VGYxDQ9LDAk8XKXuPVrY5TMZz2gbfoCOpKam2t1LrqG ZRdXe5cuhsCzPc5Q90TBaFhvc7VEZ/IDlakGnSioV7VVB2xJ0dnB/ilHj44z235z2Gk8 ziWg== 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=Sr9nAHajNUvj1PVNKEpFomcU/dFMtEZKQEJ8f6m4Zfw=; fh=k7OS/AJKcwtUnXgEkq0FrLhMtZ79/y+iBZO3DpeowZg=; b=E60QjJEhgMV/QGa+Dtf/jtEh8CpNCYXKn0wzeDS0bU9FZUYt3GSslVb/r3tGJTVUsY hYDdrCrOHgkMOEtBS+LUMAME1eA4YFPCZJ8QMZD4iwSRR5KDYhyYIyqs/UKf69sZvKIB LQ5RNDv9mJ56tM3KefjRl2YKZizYRAZwOxefZpD27udJcQ2SoLVg5SGoyAQeKmmJsmUK O79+LCS++i0WzZ7o2cwCaWnKwAbRTNLZw8xPmYJ4RnOEhUCbUyUDdd4Ppkvl3tmfWjeP PgwekVoF8uJZHcVkWI7b0EjVchSgHeVcycojAU8Gyvz64XyyIsEu/5gAUzJ0Dku0+dy8 Mx/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=rDrUoMeL; 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-164525-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164525-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 q5-20020a63d605000000b005dc894ea130si22734735pgg.384.2024.04.30.10.38.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 10:38:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164525-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=rDrUoMeL; 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-164525-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164525-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 56449282D0A for ; Tue, 30 Apr 2024 17:38:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C09161802BC; Tue, 30 Apr 2024 17:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rDrUoMeL" Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 5F924176FBE for ; Tue, 30 Apr 2024 17:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714498687; cv=none; b=bUFD4KOaQjM9CnG2lqh4KXf3uLOEak2hyCxP+Gso8knuMmod1NSXJmmkskL4L/V3oemkaTVeg+OQ0k+rVoPmuyh9gwJHcYLNeB70EntkICC3VaVMO2BhX4DifeZBYp3FYZXdr1qPRV/zCESUfSkL976LLwDyj9f9ag80OxU262M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714498687; c=relaxed/simple; bh=34hSQktGxkqeDbt0S9syRNAZLeXfMJ0uxs0JRY/gk8k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B4Yorxpx5Y7niMo8NAnXA1CKm2HjsXBUlTbH1udcmLLUZ0Anr4gLvRD8piuZNHWXTr9Z8dyRExknypAZETOqoIUw8znzsk4y7OhZryC9ZsQrci4XWyN5nuEG31RtfFkACNB+ykhNtGT+9HwiThRJObpWvD5OK5GnuQHKmzoP/gw= 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=rDrUoMeL; arc=none smtp.client-ip=91.218.175.172 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: Tue, 30 Apr 2024 10:37:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714498682; 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=Sr9nAHajNUvj1PVNKEpFomcU/dFMtEZKQEJ8f6m4Zfw=; b=rDrUoMeLRwW5XtWb2NqmZp0dC97hSR3bbGx2xYGI39cSLga69nPg3LpplAl0w+cJxThFx6 WI1A3VQgRrOsw5bnc/FxOyfo65mOpbXHHZ+EBs+BATV4HwfB15BkyCHrop8b9mqQbIcK/E BreOvq9mKhCanQS2tkm8jD/prSys/Hw= 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 , "T . J . Mercier" , kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 4/8] memcg: reduce memory for the lruvec and memcg stats Message-ID: References: <20240430060612.2171650-1-shakeel.butt@linux.dev> <20240430060612.2171650-5-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 Tue, Apr 30, 2024 at 01:41:38AM -0700, Yosry Ahmed wrote: > On Mon, Apr 29, 2024 at 11:06 PM Shakeel Butt wrote: > > [...] > > + > > +#define NR_MEMCG_NODE_STAT_ITEMS ARRAY_SIZE(memcg_node_stat_items) > > +#define NR_MEMCG_STATS (NR_MEMCG_NODE_STAT_ITEMS + ARRAY_SIZE(memcg_stat_items)) > > +static int8_t mem_cgroup_stats_index[MEMCG_NR_STAT] __read_mostly; > > NR_MEMCG_STATS and MEMCG_NR_STAT are awfully close and have different > meanings. I think we should come up with better names (sorry nothing > comes to mind) or add a comment to make the difference more obvious. > How about the following comment? /* * Please note that NR_MEMCG_STATS represents the number of memcg stats * we store in memory while MEMCG_NR_STAT represents the max enum value * of the memcg stats. */ > > + > > +static void init_memcg_stats(void) > > +{ > > + int8_t i, j = 0; > > + > > + /* Switch to short once this failure occurs. */ > > + BUILD_BUG_ON(NR_MEMCG_STATS >= 127 /* INT8_MAX */); > > Should we use S8_MAX here too? > Yes. Andrew, can you please add the above comment and replacement of 127 with S8_MAX in the patch? [...] > > > > - pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); > > - x = READ_ONCE(pn->lruvec_stats->state[idx]); > > + i = memcg_stats_index(idx); > > + if (i >= 0) { > > nit: we could return here if (i < 0) like you did in > memcg_page_state() and others below, less indentation. Same for > lruvec_page_state_local(). > I have fixed this in the following patch which adds warnings. Thanks for the reviews.