From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752744AbcFUEp2 (ORCPT ); Tue, 21 Jun 2016 00:45:28 -0400 Received: from gum.cmpxchg.org ([85.214.110.215]:60726 "EHLO gum.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751462AbcFUEpY (ORCPT ); Tue, 21 Jun 2016 00:45:24 -0400 Date: Tue, 21 Jun 2016 00:44:29 -0400 From: Johannes Weiner To: Kenny Yu Cc: tj@kernel.org, lizefan@huawei.com, cyphar@cyphar.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH] cgroup: Add pids controller event when fork fails because of pid limit Message-ID: <20160621044429.GA19501@cmpxchg.org> References: <1466478562-1997086-1-git-send-email-kennyyu@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1466478562-1997086-1-git-send-email-kennyyu@fb.com> User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 20, 2016 at 08:09:22PM -0700, Kenny Yu wrote: > Summary: > This patch adds more visibility into the pids controller when the controller > rejects a fork request. Whenever fork fails because the limit on the number of > pids in the cgroup is reached, the controller will log this and also notify the > newly added cgroups events file. The `max` key in the events file represents > the number of times fork failed because of the pids controller. > > This change also adds an atomic boolean to prevent logging too much (e.g. a fork > bomb). The message is logged once per cgroup until the next time the pids limit > changes. > > Signed-off-by: Kenny Yu This makes sense to me. Hitting the cgroup PID limit right now is somewhat ominous. A little more visibility would help. Acked-by: Johannes Weiner One comment below, but mostly a matter of preference: > @@ -205,6 +219,17 @@ static void pids_cancel_attach(struct cgroup_taskset *tset) > } > } > > +static void pids_fork_failed_event(struct pids_cgroup *pids) > +{ > + atomic64_inc(&pids->events_limit); > + cgroup_file_notify(&pids->events_file); > + if (!atomic_xchg(&pids->events_limit_logged, 1)) { > + pr_info("cgroup: fork rejected by pids controller in "); > + pr_cont_cgroup_path(task_cgroup(current, pids_cgrp_id)); > + pr_cont("\n"); > + } > +} > + > /* > * task_css_check(true) in pids_can_fork() and pids_cancel_fork() relies > * on threadgroup_change_begin() held by the copy_process(). > @@ -213,10 +238,14 @@ static int pids_can_fork(struct task_struct *task) > { > struct cgroup_subsys_state *css; > struct pids_cgroup *pids; > + int err; > > css = task_css_check(current, pids_cgrp_id, true); > pids = css_pids(css); > - return pids_try_charge(pids, 1); > + err = pids_try_charge(pids, 1); > + if (err) > + pids_fork_failed_event(pids); That function call/name seems somewhat clunky. Maybe it would be better to inline its body directly into pids_try_charge() before return -EAGAIN?