From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 0FEFE5258 for ; Sat, 6 Jul 2024 00:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720227404; cv=none; b=blCkTtfRlt3peD5hZ85JETAHyfPfruiWzSI3oCyDucLqnUTuu3ttHPA9h5dL0yQFe16EVWvnrEhlloBEuwfizHea0dRvgMFWhUQCCYl90nKvuRXxpCR6eCEdoNHu5J/ZFIGr47QdXUG/6rxsggimE8/TWJDHUXjBcE6+iDBGiV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720227404; c=relaxed/simple; bh=hdyPAIau/0lbwqY666TtHYrohV4Hg9om8b+SvUB7ONE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ix2dsGqHlJVUCW2DcOD+8+5rcwfwdxjxtSUrJ/OFa3Fd+mD15bltFQu12JNe9FVt/EtkqB1BatJE7hejd5M259AljZq0Zs9OB9l641BFZcGkK0YQCN9UDTbkQWU2sfhqnK1DQ+SQnYluY56WkPLWUVdeaXgJ2qpEEU0KVRmaITM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d2cgsXBA; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d2cgsXBA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720227402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qgX67LTMOKLJFawZhybZAOqvckQnbxp+1tbcBNs/q8c=; b=d2cgsXBA/808QC0HUeB6v7/ya1g6M6l5Xzxmk7FTazbA1cwlNp4u5j6J+TXNUfdaqCxwg8 F5PjO6HoFksq2r/uEpiKgFEKKJA2joF+rximpuj2r0Nit/XfD4xFwEB51lfTc0zapQc6sc zzCY4x63dK28JVQ0CTkSUbCp2bccpeM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-WeUnhkUUOUC7aXr6k-nYow-1; Fri, 05 Jul 2024 20:56:37 -0400 X-MC-Unique: WeUnhkUUOUC7aXr6k-nYow-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 54888195608A; Sat, 6 Jul 2024 00:56:36 +0000 (UTC) Received: from llong.com (unknown [10.22.8.212]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 774673000184; Sat, 6 Jul 2024 00:56:34 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH-cgroup 1/2] cgroup: Show # of subsystem CSSes in /proc/cgroups Date: Fri, 5 Jul 2024 20:56:21 -0400 Message-Id: <20240706005622.2003606-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 The /proc/cgroups file shows the number of cgroups for each of the subsystems. With cgroup v1, the number of CSSes is the same as the number of cgroups. That is not the case anymore with cgroup v2. The /proc/cgroups file cannot show the actual number of CSSes for the subsystems that are bound to cgroup v2. So if a v2 cgroup subsystem is leaking cgroups (typically memory cgroup), we can't tell by looking at /proc/cgroups which cgroup subsystems may be responsible. This patch adds a css counter in the cgroup_subsys structure to keep track of the number of CSSes for each of the cgroup subsystems. The proc_cgroupstats_show() function is modified to show the number of CSSes instead. This will help us pinpoint which subsystem may be responsible for the increasing number of dying but still allocated cgroups. Signed-off-by: Waiman Long --- include/linux/cgroup-defs.h | 3 +++ kernel/cgroup/cgroup-v1.c | 2 +- kernel/cgroup/cgroup.c | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index b36690ca0d3f..522ab77f0406 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -776,6 +776,9 @@ struct cgroup_subsys { * specifies the mask of subsystems that this one depends on. */ unsigned int depends_on; + + /* Number of CSSes, used only for /proc/cgroups */ + atomic_t nr_csses; }; extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem; diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index b9dbf6bf2779..56c2b030cd00 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -678,7 +678,7 @@ int proc_cgroupstats_show(struct seq_file *m, void *v) for_each_subsys(ss, i) seq_printf(m, "%s\t%d\t%d\t%d\n", ss->legacy_name, ss->root->hierarchy_id, - atomic_read(&ss->root->nr_cgrps), + atomic_read(&ss->nr_csses), cgroup_ssid_enabled(i)); return 0; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index c8e4b62b436a..4a818192950f 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5375,6 +5375,7 @@ static void css_free_rwork_fn(struct work_struct *work) int id = css->id; ss->css_free(css); + atomic_dec(&ss->nr_csses); cgroup_idr_remove(&ss->css_idr, id); cgroup_put(cgrp); @@ -5567,6 +5568,7 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp, if (IS_ERR(css)) return css; + atomic_inc(&ss->nr_csses); init_and_link_css(css, ss, cgrp); err = percpu_ref_init(&css->refcnt, css_release, 0, GFP_KERNEL); @@ -6005,6 +6007,8 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early) /* Create the root cgroup state for this subsystem */ ss->root = &cgrp_dfl_root; css = ss->css_alloc(NULL); + atomic_set(&ss->nr_csses, 1); + /* We don't handle early failures gracefully */ BUG_ON(IS_ERR(css)); init_and_link_css(css, ss, &cgrp_dfl_root.cgrp); -- 2.39.3