From owner-svn-src-all@freebsd.org Thu Jan 4 22:08:00 2018 Return-Path: Delivered-To: svn-src-all@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 769ACEBB1FD; Thu, 4 Jan 2018 22:08:00 +0000 (UTC) (envelope-from jhb@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 3CFC66391A; Thu, 4 Jan 2018 22:08:00 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w04M7xta003537; Thu, 4 Jan 2018 22:07:59 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w04M7xnC003536; Thu, 4 Jan 2018 22:07:59 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201801042207.w04M7xnC003536@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 4 Jan 2018 22:07:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327562 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 327562 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jan 2018 22:08:00 -0000 Author: jhb Date: Thu Jan 4 22:07:58 2018 New Revision: 327562 URL: https://svnweb.freebsd.org/changeset/base/327562 Log: Always use atomic_fetchadd() when updating per-user accounting values. This avoids re-reading a variable after it has been updated via an atomic op. It is just a cosmetic cleanup as the read value was only used to control a diagnostic printf that should rarely occur (if ever). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D13768 Modified: head/sys/kern/kern_resource.c Modified: head/sys/kern/kern_resource.c ============================================================================== --- head/sys/kern/kern_resource.c Thu Jan 4 21:59:34 2018 (r327561) +++ head/sys/kern/kern_resource.c Thu Jan 4 22:07:58 2018 (r327562) @@ -1384,18 +1384,17 @@ ui_racct_foreach(void (*callback)(struct racct *racct, static inline int chglimit(struct uidinfo *uip, long *limit, int diff, rlim_t max, const char *name) { + long new; /* Don't allow them to exceed max, but allow subtraction. */ + new = atomic_fetchadd_long(limit, (long)diff) + diff; if (diff > 0 && max != 0) { - if (atomic_fetchadd_long(limit, (long)diff) + diff > max) { + if (new < 0 || new > max) { atomic_subtract_long(limit, (long)diff); return (0); } - } else { - atomic_add_long(limit, (long)diff); - if (*limit < 0) - printf("negative %s for uid = %d\n", name, uip->ui_uid); - } + } else if (new < 0) + printf("negative %s for uid = %d\n", name, uip->ui_uid); return (1); }