From nobody@FreeBSD.org  Tue Sep  1 20:09:58 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 36DE41065676
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  1 Sep 2009 20:09:58 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 0CDA58FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  1 Sep 2009 20:09:58 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n81K9veY028673
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 1 Sep 2009 20:09:57 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n81K9vG0028672;
	Tue, 1 Sep 2009 20:09:57 GMT
	(envelope-from nobody)
Message-Id: <200909012009.n81K9vG0028672@www.freebsd.org>
Date: Tue, 1 Sep 2009 20:09:57 GMT
From: alberto villa <villa.alberto@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] start local rc scripts in background
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         138460
>Category:       conf
>Synopsis:       [patch] start local rc scripts in background
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-rc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 01 20:10:04 UTC 2009
>Closed-Date:    Mon Sep 14 22:13:49 UTC 2009
>Last-Modified:  Mon Sep 14 22:13:49 UTC 2009
>Originator:     alberto villa
>Release:        FreeBSD 8-STABLE
>Organization:
>Environment:
FreeBSD echo.hoth 8.0-BETA2 FreeBSD 8.0-BETA2 #11: Sat Aug 15 17:55:03 CEST 2009     root@echo.hoth:/usr/obj/usr/src/sys/TPR60  i386
>Description:
starting every rc script in sequence makes long boot times. the only option to control this is background_dhclient, which can save up to 20 seconds, but local services take more than half the boot time
>How-To-Repeat:

>Fix:
the attached patch (/etc/rc) checks for local scripts which don't have to start BEFORE other scripts: it should be safe to start them in background, unless they depend on other local scripts (this shouldn't happen, but it should be handled anyway)
being able to control the behaviour with a rcvar (something like background_daemons=YES|NO) would be nice, but i wasn't able to get its value (for some reason, it resulted empty if read with load_rc_config 'background_daemons')

a /sbin/rcorder modification would be also needed to handle local scripts which depend on other local scripts... with rcorder listing background able scripts at the end, it would be easy

Patch attached with submission follows:

--- /etc/rc.orig	2009-09-01 15:20:23.231449039 +0200
+++ /etc/rc	2009-09-01 19:01:23.412933856 +0200
@@ -92,7 +92,7 @@
 	esac
 done
 
-unset files local_rc
+unset files late_files local_rc
 
 # Now that disks are mounted, for each dir in $local_startup
 # search for init scripts that use the new rc.d semantics.
@@ -113,7 +113,20 @@
 		;;
 	esac
 
-	run_rc_script ${_rc_elem} ${_boot}
+	case "$_rc_elem" in
+	/etc/rc.d/*)	_skip_late=0 ;;
+	*)	_skip_late=`grep --quiet '# BEFORE:' ${_rc_elem} 2>/dev/null; echo $?` ;;
+	esac
+
+	if [ ${_skip_late} -eq 1 ]; then
+		late_files="$late_files $_rc_elem"
+	else
+		run_rc_script ${_rc_elem} ${_boot}
+	fi
+done
+
+for _rc_elem in `echo ${late_files}`; do
+	run_rc_script ${_rc_elem} ${_boot} &
 done
 
 echo ''


>Release-Note:
>Audit-Trail:

From: Alberto Villa <villa.alberto@gmail.com>
To: bug-followup@freebsd.org,
 villa.alberto@gmail.com
Cc:  
Subject: Re: conf/138460: [patch] start local rc scripts in background
Date: Tue, 1 Sep 2009 22:23:12 +0200

 forgot a note: if implemented in /sbin/rcorder, it would be possible to start 
 in background even some system (non local) rc scripts
 -- 
 Alberto Villa <villa.alberto@gmail.com>
 
 When you dig another out of trouble,
 you've got a place to bury your own.
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Sep 2 09:32:51 UTC 2009 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138460 

From: Doug Barton <dougb@FreeBSD.org>
To: bug-followup@FreeBSD.org, villa.alberto@gmail.com, 
 freebsd-rc@freebsd.org
Cc:  
Subject: Re: conf/138460: [patch] start local rc scripts in background
Date: Wed, 02 Sep 2009 07:36:43 -0700

 I object to this patch on at least 2 grounds. First the lack of BEFORE
 in a script does not mean that it is safe to background it. Some other
 script could easily depend on the service directly via REQUIRE, or
 (unfortunately) there could be indirect dependencies that are not
 properly labeled now because we've never needed to label them.
 Personally I actively discourage the use of BEFORE because I think it
 makes it harder to debug ordering problems although it is occasionally
 necessary.
 
 Second it is actually fairly common for locally installed scripts from
 the ports tree at least to depend on each other, and this is not a bug.
 
 The way to approach this would be to add a flag, probably in rc.conf,
 to indicate that it is safe to background a given service. Then
 rc.subr would have to grow support for this but that shouldn't be too
 hard. If you'd like to follow up in that regard you should send a
 message to freebsd-rc@freebsd.org.
 
 Unless someone else really thinks this is a good idea I plan to close
 this PR.
 
 
 Doug
 
 -- 
 
     This .signature sanitized for your protection
 

From: Adrian Penisoara <ady@freebsd.ady.ro>
To: Doug Barton <dougb@freebsd.org>
Cc: bug-followup@freebsd.org, villa.alberto@gmail.com, freebsd-rc@freebsd.org
Subject: Re: conf/138460: [patch] start local rc scripts in background
Date: Wed, 2 Sep 2009 17:19:50 +0200

 --0015174c35045cf71b047299cca0
 Content-Type: text/plain; charset=ISO-8859-1
 
 Hi,
 On Wed, Sep 2, 2009 at 4:36 PM, Doug Barton <dougb@freebsd.org> wrote:
 
 > I object to this patch on at least 2 grounds. First the lack of BEFORE
 > in a script does not mean that it is safe to background it. Some other
 > script could easily depend on the service directly via REQUIRE, or
 > (unfortunately) there could be indirect dependencies that are not
 > properly labeled now because we've never needed to label them.
 > Personally I actively discourage the use of BEFORE because I think it
 > makes it harder to debug ordering problems although it is occasionally
 > necessary.
 >
 > Second it is actually fairly common for locally installed scripts from
 > the ports tree at least to depend on each other, and this is not a bug.
 >
 > The way to approach this would be to add a flag, probably in rc.conf,
 > to indicate that it is safe to background a given service. Then
 > rc.subr would have to grow support for this but that shouldn't be too
 > hard. If you'd like to follow up in that regard you should send a
 > message to freebsd-rc@freebsd.org.
 >
 > Unless someone else really thinks this is a good idea I plan to close
 > this PR.
 >
 >
   I think this idea has some (great ?) merit -- almost all modern OS'es are
 cutting down on boot times and we should be working on this too.
   It's true that it would take a lot more work than a simple few-lines patch
 to do it right, but it's worth working on it, at least personally I intend
 to work on this at one point [1].
 
 [1]
 https://blueprints.launchpad.net/enterprisebsd/+spec/ebsd-rc.d-startup-fix
 
 Regards,
 Adrian Penisoara
 EnterpriseBSD
 
 --0015174c35045cf71b047299cca0
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 Hi,<div><br></div><div><div class=3D"gmail_quote">On Wed, Sep 2, 2009 at 4:=
 36 PM, Doug Barton <span dir=3D"ltr">&lt;<a href=3D"mailto:dougb@freebsd.or=
 g">dougb@freebsd.org</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_qu=
 ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
 ;">
 I object to this patch on at least 2 grounds. First the lack of BEFORE<br>
 in a script does not mean that it is safe to background it. Some other<br>
 script could easily depend on the service directly via REQUIRE, or<br>
 (unfortunately) there could be indirect dependencies that are not<br>
 properly labeled now because we&#39;ve never needed to label them.<br>
 Personally I actively discourage the use of BEFORE because I think it<br>
 makes it harder to debug ordering problems although it is occasionally<br>
 necessary.<br>
 <br>
 Second it is actually fairly common for locally installed scripts from<br>
 the ports tree at least to depend on each other, and this is not a bug.<br>
 <br>
 The way to approach this would be to add a flag, probably in rc.conf,<br>
 to indicate that it is safe to background a given service. Then<br>
 rc.subr would have to grow support for this but that shouldn&#39;t be too<b=
 r>
 hard. If you&#39;d like to follow up in that regard you should send a<br>
 message to <a href=3D"mailto:freebsd-rc@freebsd.org">freebsd-rc@freebsd.org=
 </a>.<br>
 <br>
 Unless someone else really thinks this is a good idea I plan to close<br>
 this PR.<br>
 <br></blockquote><div><br></div><div>=A0=A0I think this idea has some (grea=
 t ?) merit -- almost all modern OS&#39;es are cutting down on boot times an=
 d we should be working on this too.</div><div>=A0=A0It&#39;s true that it w=
 ould take a lot more work than a simple few-lines patch to do it right, but=
  it&#39;s worth working on it, at least personally I intend to work on this=
  at one point [1].</div>
 <div><br></div><div>[1]=A0<a href=3D"https://blueprints.launchpad.net/enter=
 prisebsd/+spec/ebsd-rc.d-startup-fix">https://blueprints.launchpad.net/ente=
 rprisebsd/+spec/ebsd-rc.d-startup-fix</a></div><div><br></div><div>Regards,=
 </div>
 <div>Adrian Penisoara</div><div>EnterpriseBSD</div></div></div>
 
 --0015174c35045cf71b047299cca0--
State-Changed-From-To: open->closed 
State-Changed-By: dougb 
State-Changed-When: Mon Sep 14 22:13:08 UTC 2009 
State-Changed-Why:  

No support for this idea has arisen on the list, so close the PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138460 
>Unformatted:
