From owner-svn-src-head@freebsd.org Sat Nov 11 22:39:35 2017 Return-Path: Delivered-To: svn-src-head@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 28802E4E466; Sat, 11 Nov 2017 22:39:35 +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 E9B537137D; Sat, 11 Nov 2017 22:39:34 +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 vABMdXlu053881; Sat, 11 Nov 2017 22:39:33 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vABMdXS2053880; Sat, 11 Nov 2017 22:39:33 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201711112239.vABMdXS2053880@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 11 Nov 2017 22:39:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325726 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 325726 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Nov 2017 22:39:35 -0000 Author: mjg Date: Sat Nov 11 22:39:33 2017 New Revision: 325726 URL: https://svnweb.freebsd.org/changeset/base/325726 Log: Avoid locking and refing in sysctl_kern_proc_args if possible. Turns out the sysctl is called a lot e.g. by pkg-static. Modified: head/sys/kern/kern_proc.c Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Sat Nov 11 21:50:36 2017 (r325725) +++ head/sys/kern/kern_proc.c Sat Nov 11 22:39:33 2017 (r325726) @@ -1909,14 +1909,27 @@ sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS) struct proc *p; struct sbuf sb; int flags, error = 0, error2; + pid_t pid; if (namelen != 1) return (EINVAL); + pid = (pid_t)name[0]; + /* + * If the query is for this process and it is single-threaded, there + * is nobody to modify pargs, thus we can just read. + */ + p = curproc; + if (pid == p->p_pid && p->p_numthreads == 1 && req->newptr == NULL) { + if ((pa = p->p_args) != NULL) + error = SYSCTL_OUT(req, pa->ar_args, pa->ar_length); + return (error); + } + flags = PGET_CANSEE; if (req->newptr != NULL) flags |= PGET_ISCURRENT; - error = pget((pid_t)name[0], flags, &p); + error = pget(pid, flags, &p); if (error) return (error);