Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1236399rdb; Fri, 2 Feb 2024 20:34:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1l0TklRVwo1Ah/TagFXdC2sZ4Md/F9QaOshiBcrnG7skiTScEgmv5LQqcfHODU18ymezi X-Received: by 2002:a17:907:7843:b0:a37:1f76:35ba with SMTP id lb3-20020a170907784300b00a371f7635bamr1869520ejc.51.1706934852699; Fri, 02 Feb 2024 20:34:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706934852; cv=pass; d=google.com; s=arc-20160816; b=KYI9c6YMuzO4ITksZcJuEfSut8d+dq4hR9wwWpOJbLGErfjwxoic+mj1u4HomBRa3m FugtCwp2GNosWglX/OV59jFG3N3fPQ2ZX09ROgECMSlBoOvlR3FVWWPxrxeVdZG6AOvf yyBMdK/1rA1sSHn6lep13FEU1VqtHE93IFcv+tkNjOubf1VAXyoBOdqftg51kCBzOc0P FVp9XZo/erMh4b7zXh/NAoHonJdOZeoOSlkTk3k2BacHZWdK+DpaHNpUc2K9V7aRLvTj iCN1F1VPukUCU3IskT6YsOXRJORX8Xudn6jKoE2lhiqB9PM67GTjqKsUDEEJSIz40iyP a5vQ== 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=DisFQpTn7TdXti+Sfq7OuBraM//Uzb0Fy3Abq9El6XY=; fh=NeOyKSVx9eAH9pRNy/ZSg1DI5ru8tveWlPfraus9vVM=; b=nQiSZxfaiLc5mUmABiEMEBpnj9eFahOgtfmm3NHsYhj1QlRwLKyA/C/D8hCNkQpPe4 1s0Fid8i/yAO6gZYHmuy+T0ZgbEGznumCUFydVX1Dg69rCYC6Vzhyk4Yd/BDOdg0niC2 zW3k31VUKJ9rcarPIPp/+9JPxrKaVw0QImgwKTNT8nzdJQ3jutPORjeboiTAa1C76DjQ AwLvkvo/n1f7qbDPU22gIUfcC/k2tgGBoL963N4fHN9mZ4wac2znosQ1E5a7jDYVtXyf aCu0gcYPdCgmva7CNBvEdn/+YxMmZmZ+hztOqccpwt38mJi2dnf3k/8yADTAG5sXKNmj vNtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p+Xx0GOw; 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-50915-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50915-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXioZ9HHYv5hEJF464NgwONwE+SiZi1ZxAIjAcmN0fOpfJQR84bmv/CJECpFbBbftT9zgQaH/HHQGYS6E7Qse1FXAKvs3c2QILWIVXFLQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qq20-20020a17090720d400b00a363e5c3f3csi1516345ejb.569.2024.02.02.20.34.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 20:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50915-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p+Xx0GOw; 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-50915-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50915-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 601351F21FA3 for ; Sat, 3 Feb 2024 04:34:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3082A125C4; Sat, 3 Feb 2024 04:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p+Xx0GOw" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 6F26B10965 for ; Sat, 3 Feb 2024 04:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706934203; cv=none; b=JTbUVTW4nl2H+weKFB6sNq6nWHuhJpZ94h7q9ZQyGd26s/IHfpOA53KcVQ5Lg846oblxQS1O2U6AhyDSQPd1oRWdcnFJiquO0Ir9Eul1NkdRMiz6lB4FEG63eZXkscMG5dkbWIMplIM+k/XA4EhfzDPeggl1VuX+euS6Ol1Wz9g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706934203; c=relaxed/simple; bh=p8DcI038LCJsFfjS2X5a3TzYgQ4CoD5oN3YW/KgGnIA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Th1C2cVQqwTT05chi+glr21glxPwHSXJUxR6lrxvIvRLXeCI98bSLBGGqxHIyW08wz5zW7vhP6txU9iT+o3kSLjJH481HsNZGVLL+UTOa1OBzg6aKKDwcJG+N10sJJTWwKDiD9XgxWuN+qXPFWXTHUwVKaG054QzyNQwJ+AOB+U= 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=p+Xx0GOw; arc=none smtp.client-ip=209.85.167.48 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-lf1-f48.google.com with SMTP id 2adb3069b0e04-51124d86022so4443517e87.0 for ; Fri, 02 Feb 2024 20:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706934199; x=1707538999; 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=DisFQpTn7TdXti+Sfq7OuBraM//Uzb0Fy3Abq9El6XY=; b=p+Xx0GOwwrGruHma2C/KjDFHKT+6BXpw1qrsX+w+b5oE3Q2i++kYTipuDA5ZV0MILC iYPJcCo93sW2X2N7wkw/jNo/goirEaY/OeVVjN3tLRkDCQvxM8D03lEcyT6589h8yrV6 lBB7brbF2fiXfujAQaZzfd3fc4xfup5p/QNEEFf1FH5XUEib1saiRD0Mnj8P2rw/Obp0 uWjjONzAchhsaOYI/pVqgxvdpbgec7hLRNHig9e376h9KptW0YatZgIlKCi07jHzhdky S6heF0xjHPBLx3vTKc9PvoL4uDgqSEYRTw02UfNZdzFiWsc+Ly7nil4A5V/ZsN6BBQYD QEFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706934199; x=1707538999; 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=DisFQpTn7TdXti+Sfq7OuBraM//Uzb0Fy3Abq9El6XY=; b=Qt0QdwAdq+sZH6fteB8bsPIf41JVSwAHHJ6CnWeR6U3N3at5SnT53Fn++hmcFI3Dt9 zrEB10iAASqMk5PLZ6/9g8+8hR1+HrsHGPhelj8/TXyKL/ftb3MrqY8624TsLcwlJ7t8 uQSciF7AyZNLk68lSHLMZwNKSzN2ku/EClu8shFUUSMC+BMZybZ0+Lr1Q+/z5Ddmgjyz KPOVDdjRI9IHJP7P0XeCcx0c8xSpvXWsCgCqZYctMN15Vq8YrvgPOdRyiZgZ4JZ+yZPJ vQrfK7Q5/iOX517CQiiYSnge72z5+/CEoZgahZCGtj93O2mwdNewoT9/G+Z0GK3hafgh m6UA== X-Gm-Message-State: AOJu0YxIZGNMEImpbhr8umBDfthtKsIlz3BkKk4lHlhgW4vF/dbycmM0 I0Mojx1Pa7q7GspiFbLtDUW+PyOKAvFJw3GVdraxpc+QdXhWLs/pp05/VgHufabpbs6efTFIDq7 IeIN4uRs1RqVlpO7qy5H4kZVN23vV8SSxFEJ4 X-Received: by 2002:a19:8c5a:0:b0:511:320d:872f with SMTP id i26-20020a198c5a000000b00511320d872fmr3316565lfj.37.1706934199201; Fri, 02 Feb 2024 20:23:19 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240203003414.1067730-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Fri, 2 Feb 2024 20:22:39 -0800 Message-ID: Subject: Re: [PATCH mm-hotfixes-unstable] mm: memcg: fix struct memcg_vmstats_percpu size and alignment To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Greg Thelen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 2, 2024 at 8:13=E2=80=AFPM Shakeel Butt w= rote: > > On Fri, Feb 2, 2024 at 4:34=E2=80=AFPM Yosry Ahmed wrote: > > > > Commit da10d7e140196 ("mm: memcg: optimize parent iteration in > > memcg_rstat_updated()") added two additional pointers to the end of > > struct memcg_vmstats_percpu with CACHELINE_PADDING to put them in a > > separate cacheline. This caused the struct size to increase from 1200 t= o > > 1280 on my config (80 extra bytes instead of 16). > > > > Upon revisiting, the relevant struct members do not need to be on a > > separate cacheline, they just need to fit in a single one. This is a > > percpu struct, so there shouldn't be any contention on that cacheline > > anyway. Move the members to the beginning of the struct and cachealign > > the first member. Add a comment about the members that need to fit > > together in a cacheline. > > > > The struct size is now 1216 on my config with this change. > > > > Fixes: da10d7e140196 ("mm: memcg: optimize parent iteration in memcg_rs= tat_updated()") > > Reported-by: Greg Thelen > > Signed-off-by: Yosry Ahmed > > --- > > mm/memcontrol.c | 19 +++++++++---------- > > 1 file changed, 9 insertions(+), 10 deletions(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index d9ca0fdbe4ab0..09f09f37e397e 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -621,6 +621,15 @@ static inline int memcg_events_index(enum vm_event= _item idx) > > } > > > > struct memcg_vmstats_percpu { > > + /* Stats updates since the last flush */ > > + unsigned int stats_updates ____cacheline_ali= gned; > > Why do you need ____cacheline_aligned here? From what I understand for > the previous patch you want stats_updates, parent and vmstats on the > same cacheline, right? Yes. I am trying to ensure that stats_updates sits at the beginning of a cacheline to ensure they all fit in one cacheline. Is this implicitly guaranteed somehow? > > I would say just remove the CACHELINE_PADDING() from the previous > patch and we are good. IIUC, without CACHELINE_PADDING(), they may end up on different cache lines, depending on the size of the arrays before them in the struct (which depends on several configs). Am I misunderstanding? > > In the followup I plan to add usage of __cacheline_group_begin() and > __cacheline_group_end() usage in memcg code. If you want, take a stab > at it. For now, I am just looking for something simple to fix the struct size proliferation for v6.8, but this would be interesting to see. I wonder how __cacheline_group_end() works since the end is decided already by __cacheline_group_begin() and the cacheline size.