Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp7025282ybc; Thu, 28 Nov 2019 09:28:22 -0800 (PST) X-Google-Smtp-Source: APXvYqwOKLLV1jhAiA1d4Fr75f3RmhYPx8pW/GOL+DItKMbinktb0Cx5eZJdMTWG6n5alu5TEUWl X-Received: by 2002:a17:906:4c8c:: with SMTP id q12mr56799364eju.256.1574962102463; Thu, 28 Nov 2019 09:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574962102; cv=none; d=google.com; s=arc-20160816; b=oowbnEZkG3NqqD/P0mueWJwBFx/aTJ2cuL2y+zIlNlzegKTrhzOOOkOuj9E8eHLyMY OLlQJOXWtVUyKW5QEhLMYnWhFe3kRPZWmzVlxt0ZjpITcBHd154WO3+v1iQw7xQuynpt vUlIroQNs0XtlXQLBl66RugFzuWKErf6ImmuJeD/aK0SPn5mZwJjBsoUfp6V+mjW1DZl cSAVyHsPRp2LyaNcf8zQikciuNIXahUxDyHOoipnlPDK8QSVblAcNlV8xm8tetTVMLkC O+L+ACaAPewQuNOXOMIpVdk64bx7ukfUEL/5+Ib5WZd66wSxl+E5nYRyvwBCPX+UdvZO GKwQ== 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 :message-id:date:subject:cc:to:from; bh=m41l9Bdw+zniUTKgFhRoz7B44PYD+RRxut/RpPdAI+g=; b=QLn+Wu4wlsgi3ASJ/mCOBa4z2pozHo7Gb6NDdt28niVeT04HDdb0Ef1qHQbnNLnvFQ umc2Wtu6h2mCLnJIiBIWUQAVlLwIa8sc8l5vOxNftBfFUbMkzmz8WiuUaDW9r7+HS4hb FNb52x42CAhTCuFygABfJmU2mAtOOi4PMAgM4B+sI+MVPK2fu9cJ+zCAdaVntz9+KZX6 VdQtn3vnzZALzijcvRPmPIVm9uySzGM3dlAMlH8f1+giVko4xe456+ydx1xsH93GedN3 4X1wH+5bmJMl/8FhvhZJyBT2hpU7hegay8lzDzZhsHuI97HKDSq9Y9W9h5DXDpSICSVw keeA== 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 me8si12408872ejb.382.2019.11.28.09.27.58; Thu, 28 Nov 2019 09:28:22 -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 S1726670AbfK1R00 (ORCPT + 99 others); Thu, 28 Nov 2019 12:26:26 -0500 Received: from mx2.suse.de ([195.135.220.15]:56404 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726594AbfK1R00 (ORCPT ); Thu, 28 Nov 2019 12:26:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6B9A2AE20; Thu, 28 Nov 2019 17:26:24 +0000 (UTC) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org Cc: Tejun Heo , Li Zefan , Johannes Weiner , linux-kernel@vger.kernel.org Subject: [RFC PATCH] cgroup/pids: Make pids.events notifications affine to pids.max Date: Thu, 28 Nov 2019 18:26:12 +0100 Message-Id: <20191128172612.10259-1-mkoutny@suse.com> X-Mailer: git-send-email 2.24.0 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 Currently, when pids.max limit is breached in the hierarchy, the event is counted and reported in the cgroup where the forking task resides. The proper hierarchical behavior is to count and report the event in the cgroup whose limit is being exceeded. Apply this behavior in the default hierarchy. Reasons for RFC: 1) If anyone has adjusted their readings to this behavior, this is a BC break. 2) This solves no reported bug, just a spotted inconsistency. 3) One step further would be to distinguish pids.events and pids.events.local for proper hierarchical counting. (The current behavior wouldn't match neither though.) Signed-off-by: Michal Koutný --- kernel/cgroup/pids.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c index 138059eb730d..5fc34d8b8f60 100644 --- a/kernel/cgroup/pids.c +++ b/kernel/cgroup/pids.c @@ -140,7 +140,7 @@ static void pids_charge(struct pids_cgroup *pids, int num) * the new value to exceed the hierarchical limit. Returns 0 if the charge * succeeded, otherwise -EAGAIN. */ -static int pids_try_charge(struct pids_cgroup *pids, int num) +static int pids_try_charge(struct pids_cgroup *pids, int num, struct pids_cgroup **fail) { struct pids_cgroup *p, *q; @@ -153,8 +153,10 @@ static int pids_try_charge(struct pids_cgroup *pids, int num) * p->limit is %PIDS_MAX then we know that this test will never * fail. */ - if (new > limit) + if (new > limit) { + *fail = p; goto revert; + } } return 0; @@ -217,20 +219,25 @@ static void pids_cancel_attach(struct cgroup_taskset *tset) static int pids_can_fork(struct task_struct *task) { struct cgroup_subsys_state *css; - struct pids_cgroup *pids; + struct pids_cgroup *pids, *pids_over_limit; int err; css = task_css_check(current, pids_cgrp_id, true); pids = css_pids(css); - err = pids_try_charge(pids, 1); + 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 is incremented. */ - if (atomic64_inc_return(&pids->events_limit) == 1) { + if (atomic64_inc_return(&pids_over_limit->events_limit) == 1) { pr_info("cgroup: fork rejected by pids controller in "); - pr_cont_cgroup_path(css->cgroup); + pr_cont_cgroup_path(pids_over_limit->css.cgroup); pr_cont("\n"); } - cgroup_file_notify(&pids->events_file); + cgroup_file_notify(&pids_over_limit->events_file); } return err; } -- 2.24.0