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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D96BC433EF for ; Wed, 2 Mar 2022 14:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243188AbiCBOpF (ORCPT ); Wed, 2 Mar 2022 09:45:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243187AbiCBOpE (ORCPT ); Wed, 2 Mar 2022 09:45:04 -0500 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4680366AD5; Wed, 2 Mar 2022 06:44:20 -0800 (PST) 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) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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