Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jan 2017 19:41:56 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r312716 - stable/11/sys/kern
Message-ID:  <201701241941.v0OJfuZ4084823@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Tue Jan 24 19:41:55 2017
New Revision: 312716
URL: https://svnweb.freebsd.org/changeset/base/312716

Log:
  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.

Modified:
  stable/11/sys/kern/kern_descrip.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/kern_descrip.c
==============================================================================
--- stable/11/sys/kern/kern_descrip.c	Tue Jan 24 19:40:35 2017	(r312715)
+++ stable/11/sys/kern/kern_descrip.c	Tue Jan 24 19:41:55 2017	(r312716)
@@ -1751,21 +1751,23 @@ falloc_noinstall(struct thread *td, stru
 {
 	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701241941.v0OJfuZ4084823>