Re: svn commit: r325726 - head/sys/kern

2018-01-01 Thread Jilles Tjoelker
On Thu, Dec 28, 2017 at 05:25:25PM +0100, Jilles Tjoelker wrote:
> On Thu, Dec 28, 2017 at 12:40:31PM +, Antoine Brodin wrote:
> > On Sat, Nov 11, 2017 at 10:39 PM, Mateusz Guzik  wrote:
> > > 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

> > There is a regression after this commit: x11-toolkits/gnustep-gui no
> > longer builds.
> > You can find a failure log at
> > http://pb2.nyi.freebsd.org/data/111i386-default-PR224618/2017-12-28_12h28m51s/logs/errors/gnustep-gui-0.25.1_3.log
> > The failure seems to be from lang/gnustep-base:

> >   /* get the argument vectors */
> >   vectors = kvm_getargv(kptr, proc_ptr, 0);

> It looks like the new fast path only works properly if p->p_args is not
> NULL. If p->p_args is NULL, this usually means that the arguments are
> longer than ps_arg_cache_limit and must be retrieved from (pageable)
> process memory and not wired p->p_args->ar_args. It is possible to
> duplicate that piece of code as well but that is probably not worth it.

I created a review that fixes the problem, but I am not completely sure
that it preserves the original intent of the optimization:
https://reviews.freebsd.org/D13729

-- 
Jilles Tjoelker
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r325726 - head/sys/kern

2017-12-28 Thread Jilles Tjoelker
On Thu, Dec 28, 2017 at 12:40:31PM +, Antoine Brodin wrote:
> On Sat, Nov 11, 2017 at 10:39 PM, Mateusz Guzik  wrote:
> > 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

> There is a regression after this commit: x11-toolkits/gnustep-gui no
> longer builds.
> You can find a failure log at
> http://pb2.nyi.freebsd.org/data/111i386-default-PR224618/2017-12-28_12h28m51s/logs/errors/gnustep-gui-0.25.1_3.log
> The failure seems to be from lang/gnustep-base:

>   /* get the argument vectors */
>   vectors = kvm_getargv(kptr, proc_ptr, 0);

It looks like the new fast path only works properly if p->p_args is not
NULL. If p->p_args is NULL, this usually means that the arguments are
longer than ps_arg_cache_limit and must be retrieved from (pageable)
process memory and not wired p->p_args->ar_args. It is possible to
duplicate that piece of code as well but that is probably not worth it.

A simple reproducer is

sh -c 'n=$(sysctl -n kern.ps_arg_cache_limit);
exec ps -p "$$" -o "args=$(printf "%0${n}d" 0)"'

On head, the second line is [ps] indicating that KERN_PROC_ARGS did not
return the expected string. On stable/10 and stable/11, the second line
is a truncated version of the command line like
ps -p 86963 -o args=00

A prerequisite for this reproducer is that kern.ps_arg_cache_limit is
not set so high that it is impractical to exceed it but not {ARG_MAX}.

-- 
Jilles Tjoelker
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r325726 - head/sys/kern

2017-12-28 Thread Antoine Brodin
On Sat, Nov 11, 2017 at 10:39 PM, Mateusz Guzik  wrote:
> 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

Hi,

There is a regression after this commit: x11-toolkits/gnustep-gui no
longer builds.
You can find a failure log at
http://pb2.nyi.freebsd.org/data/111i386-default-PR224618/2017-12-28_12h28m51s/logs/errors/gnustep-gui-0.25.1_3.log
The failure seems to be from lang/gnustep-base:

  /* get the argument vectors */
  vectors = kvm_getargv(kptr, proc_ptr, 0);

Cheers,

Antoine
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r325726 - head/sys/kern

2017-11-11 Thread Mateusz Guzik
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, );
+   error = pget(pid, flags, );
if (error)
return (error);
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"