On Fri, Jul 09, 2021 at 08:52:08PM +0000, David Holland wrote: > This was discussed somewhere briefly (probably on chat) a couple weeks > ago, with the conclusion that we should just make the limit something > like twice the maximum number of open files and forget about it. No > real need to add more knobs.
Here is a patch that ties it to maxfiles, with documentation. Tying to open files would be more complex. We could also tie to curproc->p_rlimit[RLIMIT_NOFILE].rlim_cur if that is more relevant. -- Emmanuel Dreyfus m...@netbsd.org
Index: sys/kern/vfs_lockf.c =================================================================== RCS file: /cvsroot/src/sys/kern/vfs_lockf.c,v retrieving revision 1.73 diff -U4 -r1.73 vfs_lockf.c --- sys/kern/vfs_lockf.c 31 Jan 2011 08:25:32 -0000 1.73 +++ sys/kern/vfs_lockf.c 12 Jul 2021 07:51:43 -0000 @@ -122,9 +122,9 @@ * If you're slightly above the limit, we still have to permit an allocation * so that the unlock can succeed. If the unlocking causes too many splits, * however, you're totally cutoff. */ -int maxlocksperuid = 1024; +#define MAXLOCKSPERUID (2 * maxfiles) #ifdef LOCKF_DEBUG /* * Print out a lock. @@ -199,9 +199,9 @@ uip = uid_find(uid); lcnt = atomic_inc_ulong_nv(&uip->ui_lockcnt); if (uid && allowfail && lcnt > - (allowfail == 1 ? maxlocksperuid : (maxlocksperuid * 2))) { + (allowfail == 1 ? MAXLOCKSPERUID : (MAXLOCKSPERUID * 2))) { atomic_dec_ulong(&uip->ui_lockcnt); return NULL; } Index: lib/libc/sys/fcntl.2 =================================================================== RCS file: /cvsroot/src/lib/libc/sys/fcntl.2,v retrieving revision 1.45 diff -U4 -r1.45 fcntl.2 --- lib/libc/sys/fcntl.2 27 Sep 2019 07:20:07 -0000 1.45 +++ lib/libc/sys/fcntl.2 12 Jul 2021 07:51:43 -0000 @@ -548,8 +548,19 @@ .Fa cmd is .Dv F_GETPATH and insufficient memory is available. +.Pp +The argument +.Fa cmd +is +.Dv F_GETLK , +.Dv F_SETLK , +or +.Dv F_SETLKW , +and the file lock limit for the current unprivilegied user +has been reached. It can be modifed using sysctl +.Li kern.maxfiles . .It Bq Er ERANGE The argument .Fa cmd is Index: lib/libc/sys/flock.2 =================================================================== RCS file: /cvsroot/src/lib/libc/sys/flock.2,v retrieving revision 1.22 diff -U4 -r1.22 flock.2 --- lib/libc/sys/flock.2 15 Oct 2011 21:35:50 -0000 1.22 +++ lib/libc/sys/flock.2 12 Jul 2021 07:51:43 -0000 @@ -136,8 +136,12 @@ .Dv LOCK_EX , .Dv LOCK_SH , or .Dv LOCK_UN . +.It Bq Eq ENOMEM +The file lock limit for the current unprivilegied user +has been reached. It can be modifed using sysctl +.Li kern.maxfiles . .It Bq Er EOPNOTSUPP The argument .Fa fd refers to an object other than a file. Index: share/man/man7/sysctl.7 =================================================================== RCS file: /cvsroot/src/share/man/man7/sysctl.7,v retrieving revision 1.151 diff -U4 -r1.151 sysctl.7 --- share/man/man7/sysctl.7 17 Oct 2020 09:20:33 -0000 1.151 +++ share/man/man7/sysctl.7 12 Jul 2021 07:51:43 -0000 @@ -755,8 +755,13 @@ Memory Mapped Files Option is available on this system, otherwise\ 0. .It Li kern.maxfiles ( Dv KERN_MAXFILES ) The maximum number of open files that may be open in the system. +This also controls the maximum file locks per unprivilegied user +enforced by +.Xr fnctl 2 +and +.Xr flock 2 . .It Li kern.maxpartitions ( Dv KERN_MAXPARTITIONS ) The maximum number of partitions allowed per disk. .It Li kern.maxlwp The maximum number of Lightweight Processes (threads) the system allows