From owner-freebsd-hackers@FreeBSD.ORG Thu May 28 21:30:17 2009 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 CE3AE106566B for ; Thu, 28 May 2009 21:30:17 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id BBE718FC0A for ; Thu, 28 May 2009 21:30:17 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id AB6BB1A3C3B; Thu, 28 May 2009 14:30:17 -0700 (PDT) Date: Thu, 28 May 2009 14:30:17 -0700 From: Alfred Perlstein To: Dag-Erling Sm??rgrav Message-ID: <20090528213017.GX67847@elvis.mu.org> References: <4A14F58F.8000801@rawbw.com> <4A1594DA.2010707@rawbw.com> <86ljoig08o.fsf@ds4.des.no> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86ljoig08o.fsf@ds4.des.no> User-Agent: Mutt/1.4.2.3i Cc: Nate Eldredge , yuri@rawbw.com, freebsd-hackers@freebsd.org Subject: Re: Why kernel kills processes that run out of memory instead of just failing memory allocation system calls? 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: Thu, 28 May 2009 21:30:18 -0000 * Dag-Erling Sm??rgrav [090527 06:10] wrote: > Yuri writes: > > I don't have strong opinion for or against "memory overcommit". But I > > can imagine one could argue that fork with intent of exec is a faulty > > scenario that is a relict from the past. It can be replaced by some > > atomic method that would spawn the child without ovecommitting. > > You will very rarely see something like this: > > if ((pid = fork()) == 0) { > execve(path, argv, envp); > _exit(1); > } > > Usually, what you see is closer to this: > > if ((pid = fork()) == 0) { > for (int fd = 3; fd < getdtablesize(); ++fd) > (void)close(fd); > execve(path, argv, envp); > _exit(1); > } I'm probably missing something, but couldn't you iterate in the parent setting the close-on-exec flag then vfork? I guess that wouldn't work for threads AND you'd have to undo it after the fork if you didn't want to retain that behavior? thanks, -Alfred