Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys bump maxthreads default.



details:   https://anonhg.NetBSD.org/src/rev/913bff5a8a14
branches:  trunk
changeset: 365992:913bff5a8a14
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat May 07 19:44:40 2022 +0000

description:
bump maxthreads default.

bump the default MAXLWP to 4096 from 2048, and adjust the default
limits seen to be 2048 cur / 4096 max.  remove the linkage to
maxuprc entirely.

remove cpu_maxlwp() that isn't implemented anywhere.  instead,
grow the maxlwp for larger memory systems, picking 1 lwp per 1MiB
of ram, limited to 65535 like the system limit.

remove some magic numbers.


i've been having weird firefox issues for a few months now and
it turns out i was having pthread_create() failures and since
bumping the defaults i've had none of the recent issues.

diffstat:

 sys/kern/kern_lwp.c  |  19 ++++++++++++++-----
 sys/kern/kern_proc.c |   6 +++---
 sys/sys/lwp.h        |   8 ++++----
 3 files changed, 21 insertions(+), 12 deletions(-)

diffs (105 lines):

diff -r 3870210b5583 -r 913bff5a8a14 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Sat May 07 17:49:47 2022 +0000
+++ b/sys/kern/kern_lwp.c       Sat May 07 19:44:40 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lwp.c,v 1.248 2022/04/09 23:45:36 riastradh Exp $ */
+/*     $NetBSD: kern_lwp.c,v 1.249 2022/05/07 19:44:40 mrg Exp $       */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@@ -217,7 +217,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.248 2022/04/09 23:45:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.249 2022/05/07 19:44:40 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -294,6 +294,15 @@
        .l_fd = &filedesc0,
 };
 
+static int
+lwp_maxlwp(void)
+{
+       /* Assume 1 LWP per 1MiB. */
+       uint64_t lwps_per = ctob(physmem) / (1024 * 1024);
+
+       return MAX(MIN(MAXMAXLWP, lwps_per), MAXLWP);
+}
+
 static int sysctl_kern_maxlwp(SYSCTLFN_PROTO);
 
 /*
@@ -313,9 +322,9 @@
        if (error || newp == NULL)
                return error;
 
-       if (nmaxlwp < 0 || nmaxlwp >= 65536)
+       if (nmaxlwp < 0 || nmaxlwp >= MAXMAXLWP)
                return EINVAL;
-       if (nmaxlwp > cpu_maxlwp())
+       if (nmaxlwp > lwp_maxlwp())
                return EINVAL;
        maxlwp = nmaxlwp;
 
@@ -350,7 +359,7 @@
        lwp_cache = pool_cache_init(sizeof(lwp_t), MIN_LWP_ALIGNMENT, 0,
            PR_PSERIALIZE, "lwppl", NULL, IPL_NONE, lwp_ctor, lwp_dtor, NULL);
 
-       maxlwp = cpu_maxlwp();
+       maxlwp = lwp_maxlwp();
        sysctl_kern_lwp_setup();
 }
 
diff -r 3870210b5583 -r 913bff5a8a14 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c      Sat May 07 17:49:47 2022 +0000
+++ b/sys/kern/kern_proc.c      Sat May 07 19:44:40 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_proc.c,v 1.266 2022/04/07 19:33:38 andvar Exp $   */
+/*     $NetBSD: kern_proc.c,v 1.267 2022/05/07 19:44:40 mrg Exp $      */
 
 /*-
  * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.266 2022/04/07 19:33:38 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.267 2022/05/07 19:44:40 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kstack.h"
@@ -539,7 +539,7 @@
        rlim[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
 
        rlim[RLIMIT_NTHR].rlim_max = maxlwp;
-       rlim[RLIMIT_NTHR].rlim_cur = maxlwp < maxuprc ? maxlwp : maxuprc;
+       rlim[RLIMIT_NTHR].rlim_cur = maxlwp / 2;
 
        /* Note that default core name has zero length. */
        limit0.pl_corename = defcorename;
diff -r 3870210b5583 -r 913bff5a8a14 sys/sys/lwp.h
--- a/sys/sys/lwp.h     Sat May 07 17:49:47 2022 +0000
+++ b/sys/sys/lwp.h     Sat May 07 19:44:40 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lwp.h,v 1.215 2022/04/09 23:45:37 riastradh Exp $      */
+/*     $NetBSD: lwp.h,v 1.216 2022/05/07 19:44:40 mrg Exp $    */
 
 /*
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010, 2019, 2020
@@ -239,10 +239,10 @@
 extern lwp_t           lwp0;           /* LWP for proc0. */
 extern int             maxlwp __read_mostly;   /* max number of lwps */
 #ifndef MAXLWP
-#define        MAXLWP          2048
+#define        MAXLWP          4096            /* default max */
 #endif
-#ifndef        __HAVE_CPU_MAXLWP
-#define        cpu_maxlwp()    MAXLWP
+#ifndef MAXMAXLWP
+#define MAXMAXLWP      65535           /* absolute max */
 #endif
 #endif
 



Home | Main Index | Thread Index | Old Index