Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Speed up kernel loading time at boot.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Wed Jan 27, 2016 1:03 pm    Post subject: Speed up kernel loading time at boot. Reply with quote

So I have been trying to speed up boot times (really more for show than any functional purpose) and I have hit a point where I can't seem to get it a lot lower. However, running systemd-analyze (I am a gnome user) I noted what feels to be a strangely long kernel load time:

Startup finished in 2.975s (firmware) + 296ms (loader) + 8.273s (kernel) + 3.110s (userspace) = 14.656s

Facts to know about this:
1) A lot of things are compiled into my kernel rather than added as modules. (Like the GPU/DRM driver)
2) I am using an SSD
3) This is a UEFI setup
4) I have previously gotten around 4 seconds with this drive in a slower computer with an arch linux install, given that was a lighter desktop environment (and lightdm vs gdm), I don't expect that here, but I feel like I should be able to get down to 10 seconds total.

I have a very simple setup, with a efi partition (vfat), my rootfs as ext4 with 'noatime' mount option, and a swap partition.
The kernel is stored in the efi partition, and I have heard that the fat filesystem can be rather slow. Is there a way to speed up fat?
Back to top
View user's profile Send private message
Keruskerfuerst
Advocate
Advocate


Joined: 01 Feb 2006
Posts: 2289
Location: near Augsburg, Germany

PostPosted: Wed Jan 27, 2016 3:31 pm    Post subject: Reply with quote

You can add relatime to the mont options.
Rest of the setup?
Like Systemd
And emerge --info?
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Thu Jan 28, 2016 3:08 am    Post subject: System setup Reply with quote

So my system setup uses the default gnome/systemd profile. I use the open source radeon driver for my gpu (fglrx causes a lot of issues with gnome), and a lot of things, including it, are compiled in my kernel rather than included as modules. There isn't a compelling reason for this. The computer is an HP pavilion g6-2235 us with a 2.7 GHz AMD a-6 APU and 12GB ram. I run apparmor, I know that my main source of the userspace boot time component is a bash script that loads a couple of apparmor profiles and launches preload. (A lot of gentoo packages don't come with systemd compatible initscripts). I also have sys-apps/systemd-readahead-216 installed.

I will try the relatime option.

My fstab:
Code:

cat /etc/fstab
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed); notail increases performance of ReiserFS (at the expense of storage
# efficiency).  It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>         <mountpoint>   <type>      <opts>      <dump/pass>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/sda1          /boot                vfat          noauto,noatime   1 2
/dev/sda2          /                      ext4          noatime             0 1
/dev/sda3          none                swap         sw                     0 0
/dev/cdrom        /mnt/cdrom      auto          noauto,ro           0 0
#/dev/fd0          /mnt/floppy      auto          noauto                0 0



Output of emerge --info
Code:

Portage 2.2.26 (python 3.4.3-final-0, default/linux/amd64/13.0/desktop/gnome/systemd, gcc-4.9.3, glibc-2.21-r1, 4.1.12-gentoo x86_64)
=================================================================
System uname: Linux-4.1.12-gentoo-x86_64-AMD_A6-4400M_APU_with_Radeon-tm-_HD_Graphics-with-gentoo-2.2
KiB Mem:    11760564 total,   9408800 free
KiB Swap:   12026876 total,  12026876 free
Timestamp of repository gentoo: Tue, 26 Jan 2016 11:00:01 +0000
sh bash 4.3_p42-r1
ld GNU ld (Gentoo 2.25.1 p1.1) 2.25.1
app-shells/bash:          4.3_p42-r1::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.10-r1::gentoo, 3.4.3-r1::gentoo
dev-util/cmake:           3.3.1-r1::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.19.1::gentoo
sys-apps/sandbox:         2.10-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.25.1-r1::gentoo
sys-devel/gcc:            4.9.3::gentoo
sys-devel/gcc-config:     1.7.3::gentoo
sys-devel/libtool:        2.4.6::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 4.3::gentoo (virtual/os-headers)
sys-libs/glibc:           2.21-r1::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

pentoo
    location: /var/lib/layman/pentoo
    masters: gentoo
    priority: 50

steam-overlay
    location: /var/lib/layman/steam-overlay
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=native"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -march=native"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi aes alsa amd64 avx bash-completion berkdb branding bzip2 cairo cdda cdr cli colord cracklib crypt cups cxx dbus dri dts dvd dvdr eds emboss encode evo exif fam firefox flac fma3 fma4 fortran gdbm gif glamor gnome gnome-keyring gnome-online-accounts gpm gstreamer gtk iconv injection introspection ipv6 jpeg lcms ldap libnotify libsecret mad mmx mmxext mng modules mp3 mp4 mpeg multilib nautilus ncurses networkmanager nls nptl ogg openal opengl openmp pam pango pcre pdf png policykit popcnt ppds pulseaudio qt3support readline scanner sdl seccomp session spell sse sse2 sse3 sse4_1 sse4_2 sse4a ssl ssse3 startup-notification steamruntime svg systemd tcpd tiff tk tracker truetype udev udisks unicode upower usb vdpau vorbis wifi wxwidgets x264 xattr xcb xml xop xv xvid zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx fma3 fma4 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 xop" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON


Finally, My kernel config.
http://pastebin.com/ETJ4ZQNU
Back to top
View user's profile Send private message
Keruskerfuerst
Advocate
Advocate


Joined: 01 Feb 2006
Posts: 2289
Location: near Augsburg, Germany

PostPosted: Thu Jan 28, 2016 6:35 am    Post subject: Reply with quote

The content of /boot ?

In my opinion the vfat partition is not nessecary. It should be ext4.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3137

PostPosted: Thu Jan 28, 2016 9:32 pm    Post subject: Reply with quote

For UEFI it is necessary, but you only need kernel and optional initramfs there. It's a total of ~10MB. Doesn't matter how slow vfat is, it's still only 10MB split into only 2 files.

Whatever you do to speedup boot, you're not gonna beat resuming from suspend. If you want to do something really for show, you might consider hibernation. With SSD loading RAM from disk will probably be much faster than going through the boot process.
So, hibernate your system once, do some magic to protect the resulting file, and then you can power on almost instantly. You'd have to rebuild the hibernation file after updating your system though.
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Fri Jan 29, 2016 2:09 am    Post subject: Hibernation Reply with quote

I suppose hibernation probably is my best bet actually.
If anyone thinks up anything though, I would be interested to hear.
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Fri Jan 29, 2016 2:30 am    Post subject: Hibernation Reply with quote

After some tests, it turns out, I am wrong there. Contrary to what we might expect, my system boots faster from a clean state than it does from hibernate.
Hibernate appears to significantly increase the loading time.
Code:
Startup finished in 2.990s (firmware) + 309ms (loader) + 15.134s (kernel) + 5.347s (userspace) = 23.782s


I used the "resume=UUID=<UUID>" kernel parameter to enable hibernate, so it is loading by UUID.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Mon Feb 01, 2016 6:50 pm    Post subject: Reply with quote

`dmesg -H` might show you what's taking a long time in the kernel. Look for the numbers on the left.
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Sat Feb 06, 2016 11:30 pm    Post subject: dmesg -H Reply with quote

Quote:
`dmesg -H` might show you what's taking a long time in the kernel. Look for the numbers on the left.


I took the time to analyze the output and found a few notable lengths

Code:

Line 241: [  +1.211437] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
Line 432: [  +2.497504] pnp: PnP ACPI: found 6 devices
Line 658: [  +1.000149] Switched to clocksource tsc
Line 660: [  +1.811252] switching from power state:
Line 682: [  +1.114340] cfg80211: Calling CRDA to update world regulatory domain
Line 683: [  +2.228016] Console: switching to colour frame buffer device 170x48
Line 881: [  +2.411653] fuse init (API version 7.23)


Then systemd appears to start at about line 884, so everything after that I will discount.

For context, the complete output of dmesg -H can be found here: http://pastebin.com/2BY8EWET[/code]
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sun Feb 07, 2016 10:12 am    Post subject: Reply with quote

Seems to spend a pretty long time doing plug-and-play device setup... is this a genkernel config?
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 472
Location: Brisbane, Australia

PostPosted: Sun Feb 07, 2016 12:09 pm    Post subject: Reply with quote

Had a similar problem 2 days ago after installing Gentoo on a new HP laptop with genkernel, openrc , grub-static, Xfce.

Very long boot time compared to Gentoo installed with identiacal configuartion on an identical laptop in November 2015. The only difference was using install-amd64-minimal-20160204.iso and stage3-amd64-20160204.tar.bz2 instead of the November 2015 versions and that the resulting compressed initramfs is about 32Mbyte versus about 3Mbyte for the November 2015 version.

After various rebuilds and a test install in VirtualBox also resulting in a 32Mbyte compressed initramfs, I copied the kernel, initramfs to /boot/*.bak, deleted kernel and initramfs files, renamed the *.bak files and rebooted. The result was nearly the same boot speed as the November 2015 laptop.

I belive the slow booting was caused by fragmentation of kernel and/or initramfs files.

EDIT:
Corrected "kernel" to "initramfs".


Last edited by C5ace on Mon Feb 08, 2016 1:35 am; edited 1 time in total
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Sun Feb 07, 2016 5:47 pm    Post subject: Reply with quote

@Ant P. This is not a genkernel config, the config is linked to pastbin in my second post. I don't know a lot about plug and play, it was enabled by default, and I left it that way.
@C5ace This is not a file fragmentation issue. I have an SSD so it should have no effect if present. My kernel is 5.6M.
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Sun Feb 07, 2016 6:49 pm    Post subject: Kernel Compression Reply with quote

So I was able to cut 4 seconds by switching my kernel compression mode to LZ4.
Also did some userspace optimization to reduce a small overhead there. (Mostly just rewriting blocking scripts so that they forked)

Code:
Startup finished in 2.999s (firmware) + 308ms (loader) + 6.071s (kernel) + 868ms (userspace) = 10.248s


Is there a way to have no kernel compression? For that matter, I use genkernel for my initramfs, and it does an .xz compressed image, but the kernel supports other types. Can I reduce compression there?
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Sun Feb 07, 2016 7:00 pm    Post subject: Reply with quote

C5ace wrote:
Had a similar problem 2 days ago after installing Gentoo on a new HP laptop with genkernel, openrc , grub-static, Xfce.

Very long boot time compared to Gentoo installed with identiacal configuartion on an identical laptop in November 2015. The only difference was using install-amd64-minimal-20160204.iso and stage3-amd64-20160204.tar.bz2 instead of the November 2015 versions and that the resulting compressed kernel is about 32Mbyte versus about 3Mbyte for the November 2015 version.

After various rebuilds and a test install in VirtualBox also resulting in a 32Mbyte compressed kernel, I copied the kernel, initramfs to /boot/*.bak, deleted kernel and initramfs files, renamed the *.bak files and rebooted. The result was nearly the same boot speed as the November 2015 laptop.

I belive the slow booting was caused by fragmentation of kernel and/or initramfs files.


32 Mb compressed kernel ? Mine are never more than 3 Mb, I can imagine with lots of modules in it will be 5-6 Mb, but 32 ??
Back to top
View user's profile Send private message
HystericalLich
n00b
n00b


Joined: 05 Oct 2015
Posts: 12
Location: United States

PostPosted: Sun Feb 07, 2016 7:43 pm    Post subject: Compressions Reply with quote

I did some research, and messed around with kernel compression as well as initramfs compression, trying all supported options.
What I found was that on my ssd, LZ4 got the best kernel loading time.
As for the initramfs, it seemed to load fastest with .xz for some reason (disk I/O?), but then I realized by accident my system doesn't even need one. Although there isn't a notable boot time increase between an .xz compressed initramfs and no initramfs, strangely. Note that an LZ4 initramfs was not supported by genkernel, so I did not test it.
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 472
Location: Brisbane, Australia

PostPosted: Mon Feb 08, 2016 1:39 am    Post subject: Reply with quote

dmpogo wrote:
C5ace wrote:
Had a similar problem 2 days ago after installing Gentoo on a new HP laptop with genkernel, openrc , grub-static, Xfce.

Very long boot time compared to Gentoo installed with identiacal configuartion on an identical laptop in November 2015. The only difference was using install-amd64-minimal-20160204.iso and stage3-amd64-20160204.tar.bz2 instead of the November 2015 versions and that the resulting compressed kernel is about 32Mbyte versus about 3Mbyte for the November 2015 version.

After various rebuilds and a test install in VirtualBox also resulting in a 32Mbyte compressed kernel, I copied the kernel, initramfs to /boot/*.bak, deleted kernel and initramfs files, renamed the *.bak files and rebooted. The result was nearly the same boot speed as the November 2015 laptop.

I belive the slow booting was caused by fragmentation of kernel and/or initramfs files.


32 Mb compressed kernel ? Mine are never more than 3 Mb, I can imagine with lots of modules in it will be 5-6 Mb, but 32 ??


Sorry, made a mistake. Mixed up "kernel" and "initramfs". The "initramfs" file is 32Mbyte in the last installation vs about 3Mbytes in the November 2015. Can't figure out what causes the bloat.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum