From owner-svn-src-stable@freebsd.org Tue Jan 24 19:41:57 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3EA67CC064E; Tue, 24 Jan 2017 19:41:57 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0D90711F5; Tue, 24 Jan 2017 19:41:56 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v0OJfulP084824; Tue, 24 Jan 2017 19:41:56 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0OJfuZ4084823; Tue, 24 Jan 2017 19:41:56 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201701241941.v0OJfuZ4084823@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 24 Jan 2017 19:41:56 +0000 (UTC) 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 X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2017 19:41:57 -0000 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);