Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Nov 2017 22:39:33 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325726 - head/sys/kern
Message-ID:  <201711112239.vABMdXS2053880@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 



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