Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp208798pxb; Tue, 7 Sep 2021 22:28:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzAslwIbHUI/1BoiUMZyAVtukqYaZ6Y/M1WKp+GK7elXiyyZTMpmE5TpwrgAEID89aYB2w X-Received: by 2002:a5d:9693:: with SMTP id m19mr1777951ion.181.1631078884271; Tue, 07 Sep 2021 22:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631078884; cv=none; d=google.com; s=arc-20160816; b=Fq1LKzAhFdoTfbO350oznqBhYENrRtZauywfro1Mfz3YuCe5JX+92lztkJfuC9XI9g HQcwxGkUrxmL9kGk5SiZc1Ylu/Jnb/32NiaFuRBFVAiUQkr3nCz/U4ALwVhEQCedmLfh NKZssrByoBbw+BlGuKVKtIxU9c7zV/Bgdo5MstJrSff5r2lLlHvctj5+noe44PT2L9/z r7Jp7IehExqQhGImPGwVTBH1pef/CWqWollUBxjQzjorMbobcY/iyn5+ofuT/ghqsi6K PGuu33fpDziyG4WEaa+rQdaWLTnUHTwYAna1teMLnGOt+K9EDl61yMo80JoTKzE0c6XN DK+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=4QwjGo86SexE23jmdGh0fNWJgw/M3xzYU7zrtMYZd5A=; b=zTBJ8AH6V05OLu2t0eYr4tct4LcHU2SYfCOvmMJAEn83+GcfznCvFvGw6uiJCQ4u/9 6YW2GUZsbK/jr3L1yJ0h8I8qz5G0z4z5gMPUBynE/Jg7neIfeg/mw3T87Um9DJg3tmMu SqWIF+y0m0mJMLn2NmYwjBPVWqtBGJUZLlmQK/npBc1WVi3X9D5ic9irmUBY7CAULtUw ZTB9cozND1P54oHxVpAXt7jr9iM95YZGGrfdwE7+pAu+UGcdniDtD3D+oTi6K4jzaxD7 81n+pSFRWvaDEf8biQKzE58MDeBzNNQ3QZL4er4fltr2iTqg+17Y9x/YBp1qAlC/2m7T 1eXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X15788MJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h199si1019229iof.50.2021.09.07.22.27.52; Tue, 07 Sep 2021 22:28:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X15788MJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237722AbhIHFZy (ORCPT + 99 others); Wed, 8 Sep 2021 01:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232756AbhIHFZs (ORCPT ); Wed, 8 Sep 2021 01:25:48 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7CAAC061575; Tue, 7 Sep 2021 22:24:40 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id bb10so590944plb.2; Tue, 07 Sep 2021 22:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=4QwjGo86SexE23jmdGh0fNWJgw/M3xzYU7zrtMYZd5A=; b=X15788MJeqt3PwNwegkTci1L+iIKbHbqqgf4ZqPCyulBivyW91J43YAzU6kUQZxJot 2wddoz15H6m653ZYtJtcctX4mMbcR/cW+77QkYEauPkNbpPGAEow0F7gIDoMRvsnPecr AJEuWyL1bGpySI+I+x2JPSJUuxNWA/QrJoH0TVzG5KVBgzZMzIguhB0n/2eAsHDZPKrG S4/2WUjdwwMLDk7F+iK88UttbGbD8n17dxiGeU6Aj1N02YHgSRu3IZYtrdr/chPj44JC YpI00lVRElm3RQi/WCpgeWQPw8A+ve1HVmY3haVQ1NbqjSvsRBeTeQpmbVdmm1mAT5gZ 1Zuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4QwjGo86SexE23jmdGh0fNWJgw/M3xzYU7zrtMYZd5A=; b=0wpN/j+KU4Zm6fd/9UrPo2trHvjRiZJce4qCLJPrCJYE3TPAIIkehhVRoz5iJ+3R6f GLMEGan4r96c/rgloQSU6tbAYhGs81PX4Oylwra1cdpAlcqtZLVhaDqrAY/5DB0AOs7G gTDFKGhjsfIj5kuTbrgvLxuepb1+Z+YwMBzl5PvywZibzR/1qzfJjJpoRA8KIREWGWb4 0g56zzulmFnuMutq/ybHxo+ne62S9boCem+E265LlDAu0HGWSO9ueKc3fb0fsXDGhwwR eoZ5P/e7y9AuAzEFeAFblrjr5MbLX5yc2exu2+IGshikZRGUYTTs77kkgsSqm+JN3yR5 2WgA== X-Gm-Message-State: AOAM532NarGMjzqbuXW9EoIYJAvTG8G+cXyRXoq4dzcXOYAmd2vwvKxu AvwbXaYhdo+I/kK9N6t67Fw= X-Received: by 2002:a17:902:e8ce:b0:132:b140:9540 with SMTP id v14-20020a170902e8ce00b00132b1409540mr1489915plg.28.1631078680353; Tue, 07 Sep 2021 22:24:40 -0700 (PDT) Received: from VM-0-3-centos.localdomain ([101.32.213.191]) by smtp.gmail.com with ESMTPSA id k190sm769674pfd.211.2021.09.07.22.24.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Sep 2021 22:24:40 -0700 (PDT) From: brookxu To: tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org Cc: vipinsh@google.com, mkoutny@suse.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: [RFC PATCH 1/3] misc_cgroup: introduce misc.events and misc_events.local Date: Wed, 8 Sep 2021 13:24:34 +0800 Message-Id: <988f340462a1a3c62b7dc2c64ceb89a4c0a00552.1631077837.git.brookxu@tencent.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chunguang Xu Introduce misc.events and misc.events.local to make it easier for us to understand the pressure of resources. The main idea comes from mem_cgroup. Signed-off-by: Chunguang Xu --- include/linux/misc_cgroup.h | 9 +++++++ kernel/cgroup/misc.c | 50 ++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h index da2367e2ac1e..d29f1743fae9 100644 --- a/include/linux/misc_cgroup.h +++ b/include/linux/misc_cgroup.h @@ -46,6 +46,15 @@ struct misc_res { */ struct misc_cg { struct cgroup_subsys_state css; + + /* misc.events */ + atomic_long_t events[MISC_CG_RES_TYPES]; + struct cgroup_file events_file; + + /* misc.events.local */ + atomic_long_t events_local[MISC_CG_RES_TYPES]; + struct cgroup_file events_local_file; + struct misc_res res[MISC_CG_RES_TYPES]; }; diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c index ec02d963cad1..2a3d14be21e5 100644 --- a/kernel/cgroup/misc.c +++ b/kernel/cgroup/misc.c @@ -140,7 +140,7 @@ static void misc_cg_cancel_charge(enum misc_res_type type, struct misc_cg *cg, int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, unsigned long amount) { - struct misc_cg *i, *j; + struct misc_cg *i, *j, *k; int ret; struct misc_res *res; int new_usage; @@ -171,6 +171,16 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, return 0; err_charge: + if (cgroup_subsys_on_dfl(misc_cgrp_subsys)) { + atomic_long_inc(&i->events_local[type]); + cgroup_file_notify(&i->events_local_file); + + for (k = i; k; k = parent_misc(k)) { + atomic_long_inc(&k->events[type]); + cgroup_file_notify(&k->events_file); + } + } + for (j = cg; j != i; j = parent_misc(j)) misc_cg_cancel_charge(type, j, amount); misc_cg_cancel_charge(type, i, amount); @@ -335,6 +345,32 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v) return 0; } +static int misc_events_show(struct seq_file *sf, void *v) +{ + struct misc_cg *cg = css_misc(seq_css(sf)); + unsigned long count, i; + + for (i = 0; i < MISC_CG_RES_TYPES; i++) { + count = atomic_long_read(&cg->events[i]); + if (READ_ONCE(misc_res_capacity[i]) || count) + seq_printf(sf, "%s %lu\n", misc_res_name[i], count); + } + return 0; +} + +static int misc_events_local_show(struct seq_file *sf, void *v) +{ + struct misc_cg *cg = css_misc(seq_css(sf)); + unsigned long count, i; + + for (i = 0; i < MISC_CG_RES_TYPES; i++) { + count = atomic_long_read(&cg->events_local[i]); + if (READ_ONCE(misc_res_capacity[i]) || count) + seq_printf(sf, "%s %lu\n", misc_res_name[i], count); + } + return 0; +} + /* Misc cgroup interface files */ static struct cftype misc_cg_files[] = { { @@ -353,6 +389,18 @@ static struct cftype misc_cg_files[] = { .seq_show = misc_cg_capacity_show, .flags = CFTYPE_ONLY_ON_ROOT, }, + { + .name = "events", + .flags = CFTYPE_NOT_ON_ROOT, + .file_offset = offsetof(struct misc_cg, events_file), + .seq_show = misc_events_show, + }, + { + .name = "events.local", + .flags = CFTYPE_NOT_ON_ROOT, + .file_offset = offsetof(struct misc_cg, events_local_file), + .seq_show = misc_events_local_show, + }, {} }; -- 2.30.0