Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp293183ybv; Wed, 5 Feb 2020 05:45:47 -0800 (PST) X-Google-Smtp-Source: APXvYqwamN+f7CDRkb0Asej4ie8Nk915s26GtUddDd+vpVUYWQAP60vt4ePEFUy0T2tJHg4NCNBD X-Received: by 2002:a9d:7083:: with SMTP id l3mr24835920otj.193.1580910347698; Wed, 05 Feb 2020 05:45:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580910347; cv=none; d=google.com; s=arc-20160816; b=sTWY0P7h6ttecaZH1ENuR6kwqYyRMTP9Zz/ryzOsfZvumKLH2l5lm1Bqtr03Jm37Zj NVhJ0GkXTqgqPVO86p91xvJWAdqRkGel39fuuk/RBwqnCSKGTxuuSJZhROyTtIipe/+x VUpQM9JrU6zxnQdEa3su3lg9svPTdTMCKjyBLsA4fu8voNAgF4u1n7fhiSwd7htpCO6V NP0IVuk95MjVeK3THrkA01iOdkzM6yTXnuWbGBbzvzOJJQ66HsrPuRVDjpR2NRsPGeEA zT1tL68C3yHTjK9hFy5wiKPzSvK3wGyBTu3WvPcJDuOFzxbdtZ2kG9SeKhKe/o9UR1Ux fm7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nm/DPfIQ7KnqDXb4en2a3HogvKQRRYXlFkYL0zi9dZI=; b=GdVlm6vDQRKjETthD0q6XeOI7ltCuk8XvnS4Xlk9ktLhXjNNUeGgrTRojGU2F2thia mMNhJSny2Palj8znXHguaIYAFVcVLX7WINDiYQTMY8kX4N9F4qT3dh0TfGpQt+6ubHol 3+7GT3U7JiaalNyjppVqYTRoA+QPNEv58dec+e4IThmoi3u9ewwZqiSqoLnHYOgKSu7w Qu34Cr8vpqPWi/xm+f4RhFFZmJoGSj/Iv6rU/rQ350I02F8seTitmS1wPFKMBEyan4aC rIE+cEKDChZESlwjc1h/5F/tuTLgIXGCHPVKAre9SqcngP13BUwxqaeyF4kz5VjqT2Zk GsTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6si12955127oti.249.2020.02.05.05.45.34; Wed, 05 Feb 2020 05:45:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728106AbgBENom (ORCPT + 99 others); Wed, 5 Feb 2020 08:44:42 -0500 Received: from mx2.suse.de ([195.135.220.15]:52282 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727104AbgBENom (ORCPT ); Wed, 5 Feb 2020 08:44:42 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5E321AFAC; Wed, 5 Feb 2020 13:44:39 +0000 (UTC) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org Cc: Tejun Heo , Li Zefan , Johannes Weiner , Aleksa Sarai , linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 2/3] cgroup/pids: Make event counters hierarchical Date: Wed, 5 Feb 2020 14:44:25 +0100 Message-Id: <20200205134426.10570-3-mkoutny@suse.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200205134426.10570-1-mkoutny@suse.com> References: <20191128172612.10259-1-mkoutny@suse.com> <20200205134426.10570-1-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pids.events file should honor the hierarchy, so make the events propagate from their origin up to the root on the unified hierarchy. The legacy hierarchy behavior remains the same. Signed-off-by: Michal Koutný --- Documentation/admin-guide/cgroup-v2.rst | 4 ++- kernel/cgroup/pids.c | 44 ++++++++++++++++--------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 38edeb79c2d8..5dda08f268b7 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1819,7 +1819,9 @@ PID Interface Files pids.events A read-only flat-keyed file which exists on non-root cgroups. Unless specified otherwise, a value change in this file generates a file modified - event. The following entries are defined. + event. Fields in this file are hierarchical and the file modified event + can be generated due to an event down the hierarchy. The following + entries are defined. max The number of times the limit of the cgroup was hit. diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c index bbfb2fb56029..5d65b36931cd 100644 --- a/kernel/cgroup/pids.c +++ b/kernel/cgroup/pids.c @@ -223,6 +223,33 @@ static void pids_cancel_attach(struct cgroup_taskset *tset) } } +static void pids_event(struct pids_cgroup *pids_forking, + struct pids_cgroup *pids_over_limit) +{ + struct pids_cgroup *p; + bool limit = false; + + for (p = pids_forking; parent_pids(p); p = parent_pids(p)) { + /* Only log the first time events_limit_imposed is incremented. */ + if (atomic64_inc_return(&p->events_limit_imposed) == 1 && + p == pids_forking) { + pr_info("cgroup: fork rejected by pids controller in "); + pr_cont_cgroup_path(p->css.cgroup); + pr_cont("\n"); + } + + if (p == pids_over_limit) + limit = true; + if (limit) + atomic64_inc(&p->events_limit); + + cgroup_file_notify(&p->events_file); + /* Events are only notified in pids_forking on v1 */ + if (!cgroup_subsys_on_dfl(pids_cgrp_subsys)) + break; + } +} + /* * task_css_check(true) in pids_can_fork() and pids_cancel_fork() relies * on cgroup_threadgroup_change_begin() held by the copy_process(). @@ -237,22 +264,7 @@ static int pids_can_fork(struct task_struct *task) pids = css_pids(css); err = pids_try_charge(pids, 1, &pids_over_limit); if (err) { - /* Backwards compatibility on v1 where events were notified in - * leaves. */ - if (!cgroup_subsys_on_dfl(pids_cgrp_subsys)) - pids_over_limit = pids; - - /* Only log the first time events_limit_imposed is incremented. */ - if (atomic64_inc_return(&pids->events_limit_imposed) == 1) { - pr_info("cgroup: fork rejected by pids controller in "); - pr_cont_cgroup_path(pids->css.cgroup); - pr_cont("\n"); - } - atomic64_inc(&pids_over_limit->events_limit); - - cgroup_file_notify(&pids->events_file); - if (pids_over_limit != pids) - cgroup_file_notify(&pids_over_limit->events_file); + pids_event(pids, pids_over_limit); } return err; } -- 2.24.1