Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2202759lqa; Tue, 30 Apr 2024 10:42:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXldnSHSsWjjsDM/Ge0zkUPzkjQ2lAeUMPxO7ty5L8EI8aq8oGxD7a+hqjAG/Wy8Om2GOZlwLfPl6/Zn08s0n+fZgk9BjDPh2ClG7saqA== X-Google-Smtp-Source: AGHT+IEiw8ltWCO2SMk0E2gI25Qr4YGPF+IYC2dubPLu9s377b4VcHuN/LsJ5WRmmtckPYGl01WW X-Received: by 2002:a05:620a:936f:b0:792:64b2:b60d with SMTP id sg47-20020a05620a936f00b0079264b2b60dmr537324qkn.22.1714498973601; Tue, 30 Apr 2024 10:42:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714498973; cv=pass; d=google.com; s=arc-20160816; b=ZNFJasQ5Eif7u7+1eYMxMLMBnAtdms/m3oP88ith+OpvcWRUWaiHd1ItrhLQ9tpTIW 0wATkgACqKT1RECrvIdOFqzw16CMH3pTWPOB1j3XOA4KOOWaaenlm0pbdU9ZgMS3cWNP p1/+A9XCniDg0HArV5kC0ZuRmU3VaV9OLUe1aXOyGOCqchzENNA8JmOlMvMsRsbVyfC9 nVC625In0EjyLtHTyM9kK1MQeHUEyvdTO8apAEJn9+v2hgVnviwH0ryiJh2ddZ1lXo+k ZJcCYXR9ormtSG9mF1GxzRaE8Vf3uB6gpNYNhEUSXbnury14ujsEiDfu0wkceaX+SB/h 82BA== 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=oZ74h5LHi7baPDY6W1AyYYfznl65M9Axb+eFJNRztRw=; fh=Q/IW2ymgSup8iHJ/MhkXYyAqJmfAUg//yMJrzdv3aAA=; b=ljcVY7bo+R0V5DWyf61/GYrGYDvAZrJoTr3emHgl+l6qhUWX0DI1kqRQQbLpMvjp9+ jPZwO8qy26jr7JKYFBgjtAUwy4Y56Lr8FeEwasmXI2PIngbInSn43UQ80ri4W9NDHkle 13VZBvQy6BDuksY6EF2qYXHIX0qV5VwWVksCgBpAu27b932VXFFSX+Vj5XiEfS+NN9GN 86ZfvpGX7rlKKtR9Dqk6I9kkCn6lzVs98rnSsvgYbstgfV8cNW5TitfTWAQfVgTW4JRJ d7YbSPtvz2t1vUPZXA1BpoeK/MLADhbKFCuBKzVejM/lcYGDIS15b7KvQWvM/WVMdeAf dV7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cQDg3P8K; 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-164541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ay9-20020a05622a228900b0043ae984992fsi4798822qtb.617.2024.04.30.10.42.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 10:42:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cQDg3P8K; 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-164541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164541-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EC09E1C229BD for ; Tue, 30 Apr 2024 17:42:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E60F18133A; Tue, 30 Apr 2024 17:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cQDg3P8K" Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 A27271802B5 for ; Tue, 30 Apr 2024 17:41:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714498904; cv=none; b=HCxLkaGrpWjuH08JlOYffknow/6p82MZgcoCi2aD6iWdx6AIA7BLcw6OAVBeS7bLvOsvzOFvPuMXYJ+xpZ8RBrIq4qt7wz6JZFtI4dYZARnuLT27CWQAKyNjy9DJ0b9H9+YXgPSItgYTpHNavrXG9gbxlGIh4gFSsBa886hiqwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714498904; c=relaxed/simple; bh=8YWdyvS2Ms1qseheIlyBeSHCXKMJCi8Tg2YpmVn/j5M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Yti2s1QbrXlJtPeBe0IZHabbqX+MuOhHE7HEo38kNqi+flBM4vkTnbixfL6+PUOj1j5gqwzt0w0VJTmem7N7ZEAPhlyJCFzBN6PzpP8cJb1d5BW389Y2216Z/7VOdr5N31mYQfTgtNlXhXr0C/U2k1KM5fbpd0u4la1RI5z0jeE= 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=cQDg3P8K; arc=none smtp.client-ip=209.85.218.42 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-ej1-f42.google.com with SMTP id a640c23a62f3a-a4702457ccbso794729366b.3 for ; Tue, 30 Apr 2024 10:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714498901; x=1715103701; 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=oZ74h5LHi7baPDY6W1AyYYfznl65M9Axb+eFJNRztRw=; b=cQDg3P8K3gdq6g3vJVqejVp8aefX+09bSNJ9neN01VITn1svqAVOo0HDaCwRoNRn+s UNUn1heptWtlWaAr1w6vELsVbG0NeQxW3YV12z4zytAK1mdNbe0S4DXQ4y4Jj29jeSHZ 7hLUYnPaJueVAKTwwnpxh1Dsq1PFcAyM1OqcSxCMU/zwFW6oAstG5nK1KXzBQvsjcC3j og4SpXQKUxVXjXwugwr+BNA6rtNjfWjbqjOL3YT7kAJGxBMq2nA6EG1z3g6dBtJAUFlM K7JqlLPMXIlEVd6XYn53FLF5pw1a48KVmi53RcPw2YJn6ic6imKXT4M/VDn77XBV4mR/ FmTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714498901; x=1715103701; 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=oZ74h5LHi7baPDY6W1AyYYfznl65M9Axb+eFJNRztRw=; b=KRUmgB7PDT7ade9oASBDZ6OW8+PjmpomCp/OyRhJ+3nvCPc3FMaQPrRAsSwP7cpW4i 9WUuEIiUKK/xF33clkqtzRRWva3ZsLEJYpwJ1jFDCc7Vr+Z6g+bYJmYwL01iMGJT7E/k 1sRKMWN+aCZ82LqjyDrvpPK1g+/SBlIHDdrh1Fy99ZrAN9EA0zAvlXj2A42Q8olBgDh+ BSVwdQk5pt1LxXva2qlGh8OeS4mQVZc9KT+rwbH6NpO4IUUsb3hKW6maDr1keJOSZJS4 pnXtuns7hEgU6pDABwVCFuS/eSMxBPEUy38Rx8UCD1RB/0r9wiVUPlC9q8jD3OXmslo2 8icg== X-Forwarded-Encrypted: i=1; AJvYcCWe8LX9+kf9G1uu9nvrmUC2ztGDnI70I4xsDeiscwRKL867C/0jMFJ/pDDQ+HAtf+b8f3lH0qS8UsgkkKutCJh8DtO7UXsCddEMv0vZ X-Gm-Message-State: AOJu0YyHb6pDuIq9aeyU5Chy2AA+YYEFSYUnqz7TJJh9x6xmwVz05Dpm +TsZ4uaJfOJDQHFyLSeFFlNSbbngljgIT7r2j/BYB37ogjQKjh+8hMB6FLMPJ4n+8YfG/2QI15h kOnxvSFDGHOnOnyMrllbNdPwgsG5r5jMrMBfB X-Received: by 2002:a17:906:880e:b0:a51:8145:6877 with SMTP id zh14-20020a170906880e00b00a5181456877mr282005ejb.37.1714498900595; Tue, 30 Apr 2024 10:41:40 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240430060612.2171650-1-shakeel.butt@linux.dev> <20240430060612.2171650-5-shakeel.butt@linux.dev> In-Reply-To: From: Yosry Ahmed Date: Tue, 30 Apr 2024 10:41:01 -0700 Message-ID: Subject: Re: [PATCH v3 4/8] memcg: reduce memory for the lruvec and memcg stats To: Shakeel Butt 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 30, 2024 at 10:38=E2=80=AFAM Shakeel Butt wrote: > > On Tue, Apr 30, 2024 at 01:41:38AM -0700, Yosry Ahmed wrote: > > On Mon, Apr 29, 2024 at 11:06=E2=80=AFPM 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? The comment LGTM. I prefer renaming them though if someone can come up with better names. > > /* > * 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 =3D 0; > > > + > > > + /* Switch to short once this failure occurs. */ > > > + BUILD_BUG_ON(NR_MEMCG_STATS >=3D 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 =3D container_of(lruvec, struct mem_cgroup_per_node, lruve= c); > > > - x =3D READ_ONCE(pn->lruvec_stats->state[idx]); > > > + i =3D memcg_stats_index(idx); > > > + if (i >=3D 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. Yeah I saw that after reviewing this one. FWIW, *if* you respin this, fixing this here would reduce the diff noise in the patch that adds the warnings.