From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB441C433F5 for ; Wed, 2 Mar 2022 14:44:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBA538D0002; Wed, 2 Mar 2022 09:44:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E43458D0001; Wed, 2 Mar 2022 09:44:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE3DA8D0002; Wed, 2 Mar 2022 09:44:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B86448D0001 for ; Wed, 2 Mar 2022 09:44:21 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 65D6518047608 for ; Wed, 2 Mar 2022 14:44:21 +0000 (UTC) X-FDA: 79199716722.17.C770240 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by imf16.hostedemail.com (Postfix) with ESMTP id 9A669180015 for ; Wed, 2 Mar 2022 14:44:20 +0000 (UTC) Received: from in01.mta.xmission.com ([166.70.13.51]:50778) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nPQDA-00GF8C-Sd; Wed, 02 Mar 2022 07:44:17 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:55716 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nPQD8-005Eiy-SW; Wed, 02 Mar 2022 07:44:16 -0700 From: "Eric W. Biederman" To: Luis Chamberlain Cc: Shakeel Butt , Colin Ian King , NeilBrown , Vasily Averin , Vlastimil Babka , Michal Hocko , Roman Gushchin , Linux MM , netdev@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Tejun Heo , Greg Kroah-Hartman , Eric Dumazet , Kees Cook , Hideaki YOSHIFUJI , David Ahern , linux-kernel@vger.kernel.org, kernel@openvz.org References: <20220301180917.tkibx7zpcz2faoxy@google.com> <87wnhdwg75.fsf@email.froward.int.ebiederm.org> Date: Wed, 02 Mar 2022 08:43:54 -0600 In-Reply-To: (Luis Chamberlain's message of "Tue, 1 Mar 2022 13:25:16 -0800") Message-ID: <87ilswwh1x.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1nPQD8-005Eiy-SW;;;mid=<87ilswwh1x.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19DnP/IlE2D3X8Ono4RyFyPR6RjJvwkeTc= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH RFC] net: memcg accounting for veth devices X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9A669180015 X-Stat-Signature: s9hgos4ktbhcr9jz3ynpzcxjhxupmqzp Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.232 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com X-Rspam-User: X-HE-Tag: 1646232260-76790 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Luis Chamberlain writes: > On Tue, Mar 01, 2022 at 02:50:06PM -0600, Eric W. Biederman wrote: >> I really have not looked at this pids controller. >> >> So I am not certain I understand your example here but I hope I have >> answered your question. > > During experimentation with the above stress-ng test case, I saw tons > of thread just waiting to do exit: You increment the count of concurrent threads after a no return function in do_exit. Since the increment is never reached the count always goes down and eventually the warning prints. > diff --git a/kernel/exit.c b/kernel/exit.c > index 80c4a67d2770..653ca7ebfb58 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -730,11 +730,24 @@ static void check_stack_usage(void) > static inline void check_stack_usage(void) {} > #endif > > +/* Approx more than twice max_threads */ > +#define MAX_EXIT_CONCURRENT (1<<17) > +static atomic_t exit_concurrent_max = ATOMIC_INIT(MAX_EXIT_CONCURRENT); > +static DECLARE_WAIT_QUEUE_HEAD(exit_wq); > + > void __noreturn do_exit(long code) > { > struct task_struct *tsk = current; > int group_dead; > > + if (atomic_dec_if_positive(&exit_concurrent_max) < 0) { > + pr_warn_ratelimited("exit: exit_concurrent_max (%u) close to 0 (max : %u), throttling...", > + atomic_read(&exit_concurrent_max), > + MAX_EXIT_CONCURRENT); > + wait_event(exit_wq, > + atomic_dec_if_positive(&exit_concurrent_max) >= 0); > + } > + > /* > * We can get here from a kernel oops, sometimes with preemption off. > * Start by checking for critical errors. > @@ -881,6 +894,9 @@ void __noreturn do_exit(long code) > > lockdep_free_task(tsk); > do_task_dead(); The function do_task_dead never returns. > + > + atomic_inc(&exit_concurrent_max); > + wake_up(&exit_wq); > } > EXPORT_SYMBOL_GPL(do_exit); > > diff --git a/kernel/ucount.c b/kernel/ucount.c > index 4f5613dac227..980ffaba1ac5 100644 > --- a/kernel/ucount.c > +++ b/kernel/ucount.c > @@ -238,6 +238,8 @@ struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, > long max; > tns = iter->ns; > max = READ_ONCE(tns->ucount_max[type]); > + if (atomic_long_read(&iter->ucount[type]) > max/16) > + cond_resched(); > if (!atomic_long_inc_below(&iter->ucount[type], max)) > goto fail; > } Eric