Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 487384 - sys-apps/sysvinit: default inittab causes needlessly slow shutdown / sysvinit has useless sleep(2) after sync()
Summary: sys-apps/sysvinit: default inittab causes needlessly slow shutdown / sysvinit...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-09 06:16 UTC by Patrick Lauer
Modified: 2016-02-01 15:22 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Lauer gentoo-dev 2013-10-09 06:16:29 UTC
So, here's a funny one - a 2 second sleep on shutdown for no apparent reason

Looking through sysvinit source code

src/halt.c ~line 266:

        if (do_sync) {
                sync();
                sleep(2);
        }

do_sync is set by default unless -n is in options

Looking at /etc/inittab:

l0s:0:wait:/sbin/halt -dhp

Not setting -n


So, the interactions is quite stupid:

* mount-ro mounts things as readonly
* mount-ro calls sync anyway

* as far as I can tell (please correct me if wrong) sync is a synchronous system call, thus no need to sleep after it

Comparative timings of a KVM test instance:

Default:
[    2.729372] reboot: Power down

l0s:0:wait:/sbin/halt -dhpn
[    0.707627] reboot: Power down

So, out of the *WHOLE* boot time we waste 2/3ds in a needless sleep!
Comment 1 Patrick Lauer gentoo-dev 2013-10-09 06:29:11 UTC
I guess sysvinit maintainers might be interested too - could be patched in sysvinit easily
Comment 2 Ulrich Müller gentoo-dev 2013-10-09 07:25:52 UTC
(In reply to Patrick Lauer from comment #0)
> * as far as I can tell (please correct me if wrong) sync is a synchronous
> system call, thus no need to sleep after it

This is what IEEE Std 1003.1, 2004 Edition (aka POSIX) says:

   DESCRIPTION
       The sync() function shall cause all information in memory that  updates
       file systems to be scheduled for writing out to all file systems.

       The  writing,  although  scheduled,  is  not  necessarily complete upon
       return from sync().

Linux may be stricter, but isn't OpenRC supposed to be portable?
Comment 3 William Hubbs gentoo-dev 2013-10-09 15:44:27 UTC
Yes, OpenRC is meant to be portable.
Exactly what change are you requesting -- adding -n to the options or
a patch for sysvinit?
Comment 4 Patrick Lauer gentoo-dev 2013-10-10 05:25:56 UTC
I think the sleep(2) is needlessly pessimistic, so changing that might be discussed.

But more importantly, as we already run mount-ro (unless users remove it) there's no reason to do a sync() at this point again, and even less reason to sleep randomly. (So at this point all FSes are readonly, or something went seriously wrong and sync() doesn't help anyway)

Thus I would recommend adding the "-n" to inittab.
Comment 5 Patrick Lauer gentoo-dev 2013-10-11 03:07:12 UTC
Same change for the reboot case (which sleep(1)'s - that is inconsistent!)

-l6r:6:wait:/sbin/reboot -dk
+l6r:6:wait:/sbin/reboot -dkn
Comment 6 William Hubbs gentoo-dev 2013-10-19 00:05:43 UTC
@base-system:
Both changes being proposed here actually apply to the sysvinit package
since it owns /etc/inittab, so I need some insight from the rest of you.

How do you feel about these changes?

William
Comment 7 SpanKY gentoo-dev 2013-12-13 07:42:12 UTC
there's a lot of historical baggage in there woods
Comment 8 Manuel Rüger (RETIRED) gentoo-dev 2015-06-13 10:55:06 UTC
(In reply to SpanKY from comment #7)
> there's a lot of historical baggage in there woods

So it might be the right time to cut down some trees.
Comment 9 William Hubbs gentoo-dev 2016-02-01 15:22:22 UTC
This is fixed in 2.88-r8.
Thanks for the report. :-)