bump maxthreads default and on amd64. 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. implement cpu_maxlwp() on amd64 to grow beyond the default when a lot of memory is available, picking 1 lwp per 1MiB of ram, limited to 65535 like the system limit. 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/arch/amd64/amd64/process_machdep.c =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/process_machdep.c,v retrieving revision 1.49 diff -p -u -r1.49 process_machdep.c --- sys/arch/amd64/amd64/process_machdep.c 19 Oct 2020 17:47:37 -0000 1.49 +++ sys/arch/amd64/amd64/process_machdep.c 1 May 2022 04:25:42 -0000 @@ -432,3 +432,16 @@ process_machdep_validfpu(struct proc *p) return 1; } #endif /* __HAVE_PTRACE_MACHDEP */ + +#ifdef __HAVE_CPU_MAXLWP +int +cpu_maxlwp(void) +{ + /* Assume 1 LWP per 1MiB, system max is 65535. */ + const int min_lwps = 4096; + const int max_lwps = 65535; + uint64_t lwps_per = ctob(physmem) / (1024 * 1024); + + return MAX(MIN(max_lwps, lwps_per), min_lwps); +} +#endif /* __HAVE_CPU_MAXLWP */ Index: sys/arch/amd64/include/types.h =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/include/types.h,v retrieving revision 1.71 diff -p -u -r1.71 types.h --- sys/arch/amd64/include/types.h 1 Apr 2021 04:35:45 -0000 1.71 +++ sys/arch/amd64/include/types.h 1 May 2022 04:25:42 -0000 @@ -101,6 +101,7 @@ typedef unsigned char __cpu_simple_lock #define __HAVE_MM_MD_DIRECT_MAPPED_PHYS #define __HAVE_UCAS_FULL #define __HAVE_BUS_SPACE_8 +#define __HAVE_CPU_MAXLWP #ifdef _KERNEL_OPT #define __HAVE_RAS 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 04:25:42 -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 04:25:42 -0000 @@ -239,9 +239,11 @@ 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 #endif -#ifndef __HAVE_CPU_MAXLWP +#ifdef __HAVE_CPU_MAXLWP +int cpu_maxlwp(void); +#else #define cpu_maxlwp() MAXLWP #endif #endif