diff options
author | mjg <mjg@FreeBSD.org> | 2017-01-24 19:41:55 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2017-01-24 19:41:55 +0000 |
commit | b809b50b2fe2482b6f5b035699874ceb8ca6836a (patch) | |
tree | 98813d57acdda4b78d035f7079fd457c2d519cd8 | |
parent | 47820ab33d86fb3a9c47bcde22119b42f17b1722 (diff) | |
download | FreeBSD-src-b809b50b2fe2482b6f5b035699874ceb8ca6836a.zip FreeBSD-src-b809b50b2fe2482b6f5b035699874ceb8ca6836a.tar.gz |
MFC r311004:
fd: access openfiles once in falloc_noinstall
This is similar to what's done with nprocs.
Note this is only a band aid.
-rw-r--r-- | sys/kern/kern_descrip.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index a27a19d..cd1ba6f 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1751,21 +1751,23 @@ falloc_noinstall(struct thread *td, struct file **resultfp) { struct file *fp; int maxuserfiles = maxfiles - (maxfiles / 20); + int openfiles_new; static struct timeval lastfail; static int curfail; KASSERT(resultfp != NULL, ("%s: resultfp == NULL", __func__)); - if ((openfiles >= maxuserfiles && + openfiles_new = atomic_fetchadd_int(&openfiles, 1) + 1; + if ((openfiles_new >= maxuserfiles && priv_check(td, PRIV_MAXFILES) != 0) || - openfiles >= maxfiles) { + openfiles_new >= maxfiles) { + atomic_subtract_int(&openfiles, 1); if (ppsratecheck(&lastfail, &curfail, 1)) { printf("kern.maxfiles limit exceeded by uid %i, (%s) " "please see tuning(7).\n", td->td_ucred->cr_ruid, td->td_proc->p_comm); } return (ENFILE); } - atomic_add_int(&openfiles, 1); fp = uma_zalloc(file_zone, M_WAITOK | M_ZERO); refcount_init(&fp->f_count, 1); fp->f_cred = crhold(td->td_ucred); |