Module Name: src Committed By: mrg Date: Sat May 7 19:44:40 UTC 2022
Modified Files: src/sys/kern: kern_lwp.c kern_proc.c src/sys/sys: lwp.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.248 -r1.249 src/sys/kern/kern_lwp.c cvs rdiff -u -r1.266 -r1.267 src/sys/kern/kern_proc.c cvs rdiff -u -r1.215 -r1.216 src/sys/sys/lwp.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_lwp.c diff -u src/sys/kern/kern_lwp.c:1.248 src/sys/kern/kern_lwp.c:1.249 --- src/sys/kern/kern_lwp.c:1.248 Sat Apr 9 23:45:36 2022 +++ src/sys/kern/kern_lwp.c Sat May 7 19:44:40 2022 @@ -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 @@ struct lwp lwp0 __aligned(MIN_LWP_ALIGNM .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 @@ sysctl_kern_maxlwp(SYSCTLFN_ARGS) 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 @@ lwpinit(void) 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(); } Index: src/sys/kern/kern_proc.c diff -u src/sys/kern/kern_proc.c:1.266 src/sys/kern/kern_proc.c:1.267 --- src/sys/kern/kern_proc.c:1.266 Thu Apr 7 19:33:38 2022 +++ src/sys/kern/kern_proc.c Sat May 7 19:44:40 2022 @@ -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 @@ proc0_init(void) 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; Index: src/sys/sys/lwp.h diff -u src/sys/sys/lwp.h:1.215 src/sys/sys/lwp.h:1.216 --- src/sys/sys/lwp.h:1.215 Sat Apr 9 23:45:37 2022 +++ src/sys/sys/lwp.h Sat May 7 19:44:40 2022 @@ -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 struct lwplist alllwp; /* List o 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