Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp708085lqb; Fri, 24 May 2024 10:37:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOndju8JnJx63KLlewkoGTrJqizbNure4j3d0fLkQqeQ/tSX7dGrklT/K7keykpRcd6xWLAMHW3SKXGDJqlnloZJYy6l42sWDfnWvq4A== X-Google-Smtp-Source: AGHT+IF+Eomg6PkKolhBl1DcnVKsMbmKgtFGU7twuXmohYvh3OOcg/wDifIDwckJuaPTG64TkbOr X-Received: by 2002:a05:6a00:1d14:b0:6ec:f28b:659f with SMTP id d2e1a72fcca58-6f8f32a904cmr3153632b3a.3.1716572228321; Fri, 24 May 2024 10:37:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716572228; cv=pass; d=google.com; s=arc-20160816; b=wWHvrxuvKkokMQAz7Urw00Zu5ZgBMIzGZmMu6X0j37tII4kbcGSAJ7BagmJco+aJRA lTg+prGlm4KDL6VJ926mdMRTsJQKMdyoxF7WIW6fYy+gEZXmt7d0Za/eEKcvjGZCrR9M 85TXL/tXmS+bQLdwPsFoXMqUq0QWxWrXpdmU/h2DJDQSAxHPnGsg1ewKUl6P4O878+kM nxW2Rv00bM5jysTPNQaUuatlN3tDAp9uBhF8cX8vzZ1WA+6KA5T7WXUQ4dLgN54b3tuO MWlTtpX6h1bTQrgk40ll9fMzRSf8OF4//IyRY4qQTz6qoy/ZU8NeL05RexqSPBY8fCzy 4SZQ== 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=wUyEyvPVhRUH4S+rRRLUtExiOqqOJDk147Gd3ruQKmU=; fh=/YlLw9NETPZffDJIyiyP7DDmHn94gcuwvX+jMPiNpnI=; b=Cs2Nd/NFsAQWO3sYOp9O9+lJWjXsAbWb+9/hNa8XkWN+oUdP0+TZw8gx9d3GfkVXnl jNRP3o0kR/2kubhdi99kiUl171eB8Q5zxvsc/HNOUS/7258pnZI/4O2Hfpboynq4E/UF iDGPvLY+K0rVHAuj2t1rP4x6byz5mXJtb6PnYHf9DYSjow5zV3jHoFg63HCTYU3HRx59 eqBrbpLYYn0qnRI/mWxU+l1vG8JZ28nQMd/uDv96hk1aNU8BJyk5czL8QA5QkKja30tt bseCKVANmuzzRu2B3lNG5NdZm7L7pZi5qMCLIpxy5sSFM7YHCXf2t/ppoDv/fU8x2Lkr R/ZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yxWdXENZ; 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-188980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f8fc046476si1801165b3a.21.2024.05.24.10.37.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 10:37:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188980-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=@google.com header.s=20230601 header.b=yxWdXENZ; 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-188980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188980-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E8EB02824F4 for ; Fri, 24 May 2024 17:37:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A802229403; Fri, 24 May 2024 17:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yxWdXENZ" Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 CB126179B7 for ; Fri, 24 May 2024 17:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716572220; cv=none; b=OXQwpDsY6H5IdxGc4APiQUL7Vc/mzARFAWUnH7ibD9P8WOlB6KtvSFAKzz3DH2NSf7zQQJyNeAMdarmffi8ci26aTgbYUuAU9w7zjojSyAV0+9d9QSAKBzFLv+331hVs4DXcE8vXPceonaKpj3t2QywI7IssumalVDlfc4SLW00= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716572220; c=relaxed/simple; bh=ibcYNZiSaxk9EBTq4JLd0V3zMQ/xYLqk8gCrm4L9wgE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=smDrZE1SvsLGq4tr43vvho98Q29RSy3qYD1JxvhZuMfTuN8haBzLtrQzK+qrAmiKfMTOUQQTJS4BkLrLMa9dHUSOqYV0IzSZ3X+cFcJczGs/4YaHnmjQI7GgEpHcTeI+mDnWbeoGg2z0NHdNXTYI+uSi+QBEygGiBpmuALXEcxc= 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=yxWdXENZ; arc=none smtp.client-ip=209.85.219.177 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-yb1-f177.google.com with SMTP id 3f1490d57ef6-df4df150f29so3204627276.0 for ; Fri, 24 May 2024 10:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716572218; x=1717177018; 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=wUyEyvPVhRUH4S+rRRLUtExiOqqOJDk147Gd3ruQKmU=; b=yxWdXENZBQUAb7eCw7tEuGoiUNWDM/XpTgAl0uOxI42E9faLZFDuRUD18AXmyi4SJQ Dnbroej4fqJ+78HTSJSkhPKvyFL5B7hmpv6I9Mf7XgXrOCrTiuLUp3P+HGavYmA7mZD/ jA/pEjmJauBnCDEsaUjA3EG30ZVWwVzvvTEYsIs5oC0fOR09bRRpJBNJcAOcjK4+7j4X QU34xYIv1laWqn0tFslRR0tE5GNC0Hy8Ied3Lfj7tmL7dRpkbAUAF7aN0FyQTMMi2pMG FGDfUIneELF0tv1pMaxLROl3tVSuLupCjfz+SrGMcm2zulAqckK+jQVoDTs0xoHeh0Da 3+YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716572218; x=1717177018; 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=wUyEyvPVhRUH4S+rRRLUtExiOqqOJDk147Gd3ruQKmU=; b=AgICoNyftvZQOpB2lXpiB7ae0moi+5sJQxjaFOhSamv00PWxAK8YmhVkbQUA8D43lp 7P7Gaf9nErFRrz0R+62lqHNWazrsuF+Dt3CfFRxotQehAi5pHHB0vbM3J+cv2yfexPcs EK1QkdbyT4umLOPmgEq2ofSqi5bo9AW2ltt9lV7NeHv/k10M6aoo3N+prVf2Xt7OYNGT XRAmoZAT528EiSEkHPRC9zeqd6LiMCNkCZCFdmHXe1nJ/FBHn+OXro3//CPjz3czIVOD oeXjyC/EWsVFQRDbH2P87TEB/+2dORtXqS3Yh8xkPyFejNMLfHFM5O1ay7i8BGu/lBCF YtMg== X-Forwarded-Encrypted: i=1; AJvYcCXeKC/Mry8GOyNzhYhHXASeLUDlJq8toqurzhgyqtf4seJjR5BslUkAZJzCaHzvkQ6RuJpemfIRTM1nVkVpxtYNNZHx2hO3kWzOXA6r X-Gm-Message-State: AOJu0YyYh/xCjydZoJp7aDxW8/1+27Y/5JdkUA2F/PDtH7SaH8baOi8Y iHFKBgfOihGVWDAvCA1CfID/uDjfyaPbRLyDmUqeyzFzt4CJkbzLUfmcHvj4mFBelYv70cwsyTF ehIkkSeBEXbtrwGDQUcE8KdncGwfJpAJQZU5L X-Received: by 2002:a25:b845:0:b0:de6:1057:c85f with SMTP id 3f1490d57ef6-df7721890b4mr2711368276.22.1716572217394; Fri, 24 May 2024 10:36:57 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240519174650.559538-1-tjmercier@google.com> In-Reply-To: From: "T.J. Mercier" Date: Fri, 24 May 2024 10:36:45 -0700 Message-ID: Subject: Re: [RFC] cgroup: Fix /proc/cgroups count for v2 To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Tejun Heo , Zefan Li , Johannes Weiner , shakeel.butt@linux.dev, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 24, 2024 at 7:23=E2=80=AFAM Michal Koutn=C3=BD wrote: > > Hello. Hi Michal, thanks for taking a look. > On Sun, May 19, 2024 at 05:46:48PM GMT, "T.J. Mercier" wrote: > > The number of cgroups using a controller is an important metric since > > kernel memory is used for each cgroup, and some kernel operations scale > > with the number of cgroups for some controllers (memory, io). So users > > have an interest in minimizing/tracking the number of them. > > I agree this is good for debugging or quick checks of unified hierarchy > enablement status. > > > To deal with num_cgroups being reported as 1 for those utility > > controllers regardless of the number of cgroups that exist and support > > their use, > > But '1' is correct number no? Those utility controllers are v1-only and > their single group only exists on (default) root. Sometimes? Take freezer as an example. If you don't mount it on v1 then /proc/cgroups currently advertises the total number of v2 cgroups. I thought that was reasonable since there exists a cgroup.freeze in every cgroup, but does freezer really count as a controller in this case? There's no freezer css for each cgroup so I guess the better answer is just to report 1 like you suggest. > > > @@ -675,11 +699,19 @@ int proc_cgroupstats_show(struct seq_file *m, voi= d *v) > > * cgroup_mutex contention. > > */ > > > > - for_each_subsys(ss, i) > > + for_each_subsys(ss, i) { > > + int count; > > + > > + if (!cgroup_on_dfl(&ss->root->cgrp) || is_v2_utility_cont= roller(i)) > > + count =3D atomic_read(&ss->root->nr_cgrps); > > I think is_v2_utility_controller(ssid) implies > !cgroup_on_dfl(&ss->root->cgrp). I'd only decide based on the > cgroup_on_dfl() predicate. > > > --- a/kernel/cgroup/cgroup.c > > +++ b/kernel/cgroup/cgroup.c > > @@ -2047,6 +2047,8 @@ void init_cgroup_root(struct cgroup_fs_context *c= tx) > > > > INIT_LIST_HEAD_RCU(&root->root_list); > > atomic_set(&root->nr_cgrps, 1); > > + for (int i =3D 0; i < CGROUP_SUBSYS_COUNT; ++i) > > + atomic_set(&root->nr_css[i], 0); > > Strictly not needed, non-dfl roots are kzalloc'd and dfl root is global > variable (zeroed). > > HTH, > Michal Thanks, removed. I'll resend this with these changes as a PATCH with my SoB= . Best, T.J.