From: mvs Date: Tue, 20 Aug 2024 13:29:25 +0000 (+0000) Subject: Unlock KERN_MAXFILES. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1b92846ddd7e1fa8b6e00bead79e839717a05c0a;p=openbsd Unlock KERN_MAXFILES. `maxfiles' is atomically accessed integer which is lockless and read-only accessed in file descriptors layer. lim_startup() called during kernel bootstrap, no need to atomic_load_int() within. ok mpi --- diff --git a/sys/conf/param.c b/sys/conf/param.c index 39bf00676d8..cce0eea4f21 100644 --- a/sys/conf/param.c +++ b/sys/conf/param.c @@ -1,4 +1,4 @@ -/* $OpenBSD: param.c,v 1.51 2024/08/20 07:48:23 mvs Exp $ */ +/* $OpenBSD: param.c,v 1.52 2024/08/20 13:29:25 mvs Exp $ */ /* $NetBSD: param.c,v 1.16 1996/03/12 03:08:40 mrg Exp $ */ /* @@ -74,7 +74,7 @@ int utc_offset = 0; int initialvnodes = NVNODE; int maxprocess = NPROCESS; /* [a] */ int maxthread = 2 * NPROCESS; /* [a] */ -int maxfiles = 5 * (NPROCESS + MAXUSERS) + 80; +int maxfiles = 5 * (NPROCESS + MAXUSERS) + 80; /* [a] */ long nmbclust = NMBCLUSTERS; #ifndef BUFCACHEPERCENT diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 84216d168d8..44f2925df88 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.208 2024/06/22 10:22:29 jsg Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.209 2024/08/20 13:29:25 mvs Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -362,7 +362,7 @@ restart: return (0); } if ((u_int)new >= lim_cur(RLIMIT_NOFILE) || - (u_int)new >= maxfiles) { + (u_int)new >= atomic_load_int(&maxfiles)) { FRELE(fp, p); return (EBADF); } @@ -424,7 +424,7 @@ restart: case F_DUPFD_CLOEXEC: newmin = (long)SCARG(uap, arg); if ((u_int)newmin >= lim_cur(RLIMIT_NOFILE) || - (u_int)newmin >= maxfiles) { + (u_int)newmin >= atomic_load_int(&maxfiles)) { error = EINVAL; break; } @@ -877,7 +877,7 @@ fdalloc(struct proc *p, int want, int *result) * expanding the ofile array. */ restart: - lim = min((int)lim_cur(RLIMIT_NOFILE), maxfiles); + lim = min((int)lim_cur(RLIMIT_NOFILE), atomic_load_int(&maxfiles)); last = min(fdp->fd_nfiles, lim); if ((i = want) < fdp->fd_freefile) i = fdp->fd_freefile; @@ -1037,7 +1037,7 @@ fnew(struct proc *p) int nfiles; nfiles = atomic_inc_int_nv(&numfiles); - if (nfiles > maxfiles) { + if (nfiles > atomic_load_int(&maxfiles)) { atomic_dec_int(&numfiles); tablefull("file"); return (NULL); diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 2afc6287f21..70c2b515034 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_resource.c,v 1.87 2024/08/20 07:48:23 mvs Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.88 2024/08/20 13:29:25 mvs Exp $ */ /* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */ /*- @@ -275,7 +275,7 @@ dosetrlimit(struct proc *p, u_int which, struct rlimit *limp) maxlim = maxsmap; break; case RLIMIT_NOFILE: - maxlim = maxfiles; + maxlim = atomic_load_int(&maxfiles); break; case RLIMIT_NPROC: maxlim = atomic_load_int(&maxprocess); diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 698548fbcf8..7df7f058385 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.441 2024/08/20 07:48:23 mvs Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.442 2024/08/20 13:29:25 mvs Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -555,6 +555,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, } case KERN_OSREV: case KERN_MAXPROC: + case KERN_MAXFILES: case KERN_NFILES: case KERN_TTYCOUNT: case KERN_ARGMAX: