bump maxthreads default. bump the default MAXLWP to 4096 from 2048, and adjust the default threads 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. Index: sys/kern/kern_lwp.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_lwp.c,v retrieving revision 1.248 diff -p -u -r1.248 kern_lwp.c --- sys/kern/kern_lwp.c 9 Apr 2022 23:45:36 -0000 1.248 +++ sys/kern/kern_lwp.c 1 May 2022 20:40:22 -0000 @@ -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: sys/kern/kern_proc.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_proc.c,v retrieving revision 1.266 diff -p -u -r1.266 kern_proc.c --- sys/kern/kern_proc.c 7 Apr 2022 19:33:38 -0000 1.266 +++ sys/kern/kern_proc.c 1 May 2022 20:40:22 -0000 @@ -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: sys/sys/lwp.h =================================================================== RCS file: /cvsroot/src/sys/sys/lwp.h,v retrieving revision 1.215 diff -p -u -r1.215 lwp.h --- sys/sys/lwp.h 9 Apr 2022 23:45:37 -0000 1.215 +++ sys/sys/lwp.h 1 May 2022 20:40:22 -0000 @@ -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