From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 5 21:54:34 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 401B21065680 for ; Sun, 5 Aug 2012 21:54:34 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id CD1AB8FC0A for ; Sun, 5 Aug 2012 21:54:33 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id F0C8D1DD5AD; Sun, 5 Aug 2012 23:54:32 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id CB1132847B; Sun, 5 Aug 2012 23:54:32 +0200 (CEST) Date: Sun, 5 Aug 2012 23:54:32 +0200 From: Jilles Tjoelker To: Konstantin Belousov Message-ID: <20120805215432.GA28704@stack.nl> References: <20120730102408.GA19983@stack.nl> <20120730105303.GU2676@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120730105303.GU2676@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org Subject: Re: system() using vfork() or posix_spawn() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Aug 2012 21:54:34 -0000 On Mon, Jul 30, 2012 at 01:53:03PM +0300, Konstantin Belousov wrote: > On Mon, Jul 30, 2012 at 12:24:08PM +0200, Jilles Tjoelker wrote: > > People sometimes use system() from large address spaces where it would > > improve performance greatly to use vfork() instead of fork(). > > A simple approach is to change fork() to vfork(), although I have not > > tried this. It seems safe enough to use sigaction and sigprocmask system > > calls in the vforked process. > > Alternatively, we can have posix_spawn() do the vfork() with signal > > changes. This avoids possible whining from compilers and static > > analyzers about using vfork() in system.c. However, I do not like the > > tricky code for signals and that it adds lines of code. > > This is lightly tested. > It is interesting to note that for some time our vfork(2) no longer > stops the whole forked process (parent), only the forking thread is > waiting for the child exit or exec. I am not sure is this point > important for system(3), but determined code can notice the difference > from the fork->vfork switch. Neither fork nor vfork call thread_single(SINGLE_BOUNDARY), so this is not a difference. Thread singling may be noticeable from a failing execve() (but only in the process doing execve()) and in the rare case of rfork() without RFPROC. -- Jilles Tjoelker