You are not logged in.

#1 2013-05-03 18:47:06

ParanoidAndroid
Member
Registered: 2012-10-14
Posts: 114

strip kernel for boot time?

I'm getting a new machine soon (samsung series 9) and I'm currently working on reducing boot time as much as possible. To this end, I'm looking to strip down my kernel and initramfs image (I've already stripped unneeded services, userspace stuff, use lightweight WM, etc). I'm familiar with the kernel build process and I've written a script to automate the better part of it. In the interest of both performance and boot time, I'm trying to figure out how to tailor my kernel to the new machine, and practice the process on my current one. Here are my questions:

1. What are some options I can reasonably remove from menuconfig to make the kernel smaller? (I've already removed non-intel processor features, swap, etc.)

2. Would hardcoding modules into the kernel decrease boot time?

3. how can I tailor my kernel to specific hardware, that is, determine what options/modules to remove? (I already use localmodconfig + modprobed_db)

I've already built a custom kernel, using generic linux kernel 3.8.8 patched with BFS and with stripped-down modules. It actually increased boot time by an average of two seconds (kernel went from 12 sec to 14.x sec). anyone know why? My ultimate goal is to get the kernel as small and efficient as possible, and to get the kernel boot time as low as I can. I've heard rumors of ~2 second kernel boot times on flash media.

Additionally, I would like to speed up my initramfs by removing udev, if I can. I have an encrypted root partition, so an ititramfs is necessary. I've specified all of the hardware modules and fs modules I need, yet somehow it fails to detect the root partition and try to decrypt it... I have heard that the process can be done without udev, but I have no idea how, despite plenty of time on google.

Offline

#2 2013-05-03 19:04:50

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: strip kernel for boot time?

Honestly, I think this is a pretty worthless endevour.  You have to consider that not much is built into the kernel itself anyway.  Most things exist as modules.  So besides, using a tad bit of disk space, you will not really be reducing much of anything.

I also think that the idea of trying to reduce boot time is not really worth the time either.  Especially considering that your new machine will probably fast in itself, and might have a SSD.  At that point, the boot time is going probably be well under 10s, so te amount of time you spend trying to optimize will probably never be regained in saved boot time.

The only thing I think that *might* make your boot time faster is if you compile the necessary modules into the kernel that are required to boot your machine.  Then you can get rid of the initramfs, which could shave off a very very small amount of time.  Though recently, Kay Seivers has shown that with the new possibility of using systemd in the initramfs, boot times with an initramfs can actually be faster than without.

I think that the only good reasons, IMO, to compile your own custom kernel are to gain hardware support, or enable features not present in the stock Arch kernel, or for the learning experience.

Offline

#3 2013-05-03 19:19:51

ParanoidAndroid
Member
Registered: 2012-10-14
Posts: 114

Re: strip kernel for boot time?

The machine does have an SSD. As far as integrating the modules into the kernel, how is that done? I've never managed to figure out how. Additionally, I thought an initramfs was needed, both because my root is encrypted (requiring the encrypt hook) and because grub needs it.

I compiled my kernel to learn, and also because I wanted to enable the Brain Fuck Scheduler, as I subscribe to Kolivas' reasoning on the matter of CPU schedulers. And, seeing as my kernel takes 14 seconds to boot, I thought perhaps I should get that down as far as possible before sticking it on a flash disk. I heard that recompiling a minimal kernel would help. Ideally, the boot process after I enter my password should be less than 2 seconds, and the kernel, as I have observed, takes far more time than userspace to start up. Besides, I'm all about minimalism, and having as minimal a kernel as possible while maintaining functionality appeals to my ideals of efficiency.

While I realize boot time ultimately depends on hardware, my current boot time on a standard laptop HDD is about 25 seconds. If I could get that down to 15 BEFORE I migrate to flash media, if such a thing is even possible, that would be awesome. To that end, if recompiling a stripped kernel doesn't help much, what kernel optimizations (compression type, etc) would help decrease kernel boot time?

Offline

#4 2013-05-03 20:05:26

mich41
Member
Registered: 2012-06-22
Posts: 796

Re: strip kernel for boot time?

My laptop with custom kernel and no initramfs, running on 1.6GHz single-core Celeron and rather old 120GB 5400RPM HDD:

00 - pressed enter in grub menu
01 - screen goes dark - KMS is doing it's magic so grub must have already finished loading the kernel
03 - screen's back online in 1280x800 mode
05 - INIT: version 2.88 booting smile

So it takes 1 second to load the kernel with all drivers built-in (approx. 3 megabytes) and another 4 seconds to initialize everything and start the userspace.

What I did was starting with stock Arch config, going through menuconfig and removing all drivers I'll never need, modularizing things I rarely use (e.g. iptables, many USB devices) and compiling statically all drivers I want to always be loaded (SATA and filesystem are good first candidates smile, but also keyboard, GPU, audio, Ethernet, WiFi, USB, etc.). It took few hours, but I had to do it only once smile

If you do the same and get rid of udev in initramfs you should be able to get to rootfs password prompt in <5 seconds (unless your hardware is even older than mine).

Offline

#5 2013-05-03 20:12:32

ParanoidAndroid
Member
Registered: 2012-10-14
Posts: 114

Re: strip kernel for boot time?

is your root partition encrypted?

Also, could someone please explain and/or point me to an explanation of how to statically compile modules, drivers into the kernel? I've never managed to figure out how to do it, despite copious searchengine queries.

Last edited by ParanoidAndroid (2013-05-03 20:16:39)

Offline

#6 2013-05-03 20:26:21

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: strip kernel for boot time?

I'm pretty sure it's one of the options for certain features when compiling the kernel. You can choose to compile into the kernel, compile as a module, or not compile at all.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#7 2013-05-03 20:44:28

mich41
Member
Registered: 2012-06-22
Posts: 796

Re: strip kernel for boot time?

It's unencrypted, that's why it works without initramfs. You'll need some minimal initramfs to mount encrypted partition. And you need to have SATA/IDE, filesystem and crypto built-in if you want to get rid of modules in initramfs.

SATA and IDE is in Device Drivers -> Serial ATA and Parallel ATA
filesystems are in Filesystems
For crypto you'll likely need Device Drivers -> Multiple devices -> Crypt target and also some algorithms from Cryptographic API


As for the second question:

 .config - Linux/x86 3.9.0 Kernel Configuration
 ──────────────────────────────────────────────────────────────────────────────
  ┌────────────────────── Processor type and features ──────────────────────┐
  │  Arrow keys navigate the menu.  <Enter> selects submenus --->.          │  
  │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes, │  <- read here
  │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </> │  
  │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >       │  
  │ ┌────^(-)─────────────────────────────────────────────────────────────┐ │  
  │ │    <M> Dell laptop support                                          │ │  <- enabled as a module
  │ │    < > CPU microcode loading support                                │ │  <- this could be a module, but is disabled
  │ │    <*> /dev/cpu/*/msr - Model-specific register support             │ │  <- this could be a module, but is compiled statically (built-in) by my choice
  │ │    <*> /dev/cpu/*/cpuid - CPU information support                   │ │  
  │ │    [*] Enable 1GB pages for kernel pagetables                       │ │  <- this can't be modularized, enabled and built-in
  │ │    [ ] Numa Memory Allocation and Scheduler Support                 │ │  <- this can't be modularized, disabled
  │ │        Memory model (Sparse Memory)  --->                           │ │  
  │ │    [*] Sparse Memory virtual memmap                                 │ │  
  │ │    [ ] Allow for memory hot-add                                     │ │  
  │ │    -*- Allow for memory compaction                                  │ │  
  │ └────v(+)─────────────────────────────────────────────────────────────┘ │  
  ├─────────────────────────────────────────────────────────────────────────┤  
  │        <Select>    < Exit >    < Help >    < Save >    < Load >         │  
  └─────────────────────────────────────────────────────────────────────────┘  
                                                                              

Last edited by mich41 (2013-05-03 21:01:44)

Offline

#8 2013-05-03 21:16:10

ParanoidAndroid
Member
Registered: 2012-10-14
Posts: 114

Re: strip kernel for boot time?

I know how to include in the kernel through menuconfig, but when building it still modularizes my drivers. Also, certain drivers don't seem to appear in menuconfig, though I could be mistaken about that. I'm testing a minimal compile right now, went in and chucked out everything I knew I don't need. I'll see what happens.

Also, how can one remove udev from initramfs? as I said, I specified all my needed modules, etc. so far as I know, and yet, based on the errors it throws, I think it might not be detecting my HDD. Mind you, I tried getting rid of udev about a month ago and gave it up as a bad job, so I can't rightly remember the exact nature of the error. Perhaps I'll try again and come back with that particular bit of info.

Offline

#9 2013-05-03 21:51:42

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: strip kernel for boot time?

ParanoidAndroid wrote:

it still modularizes my drivers

So specify for them to be built-in.

See list:

zgrep =m /proc/config.gz

Then use "make menuconfig" with the kernel, press "/" to search for them, and press y to change from "<M>".

If any modules become buggy, then they may need to be *not* built-in, either because the kernel is buggy, or because they need udev rules to run.

Offline

#10 2013-05-03 23:00:10

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 4,645

Re: strip kernel for boot time?

Please read WonderWoofy's post again. Seriously, the amount of time you will gain in boot speed is much less than the time you have spent reading and posting to this thread. And you will have to do it all again every time the kernel gets updated.

Of course, I realize that I have just wasted the time it took me to post this...


How to post. A sincere effort to use modest and proper language and grammar is a sign of respect toward the community.

Offline

#11 2013-05-03 23:35:50

dodo3773
Member
Registered: 2011-03-17
Posts: 801

Re: strip kernel for boot time?

An easy way to increase your kernel boot speed is by switching to lzop compression in  your /etc/mkinitcpio.conf  ( COMPRESSION="lzop" ). Just make sure you have lzo lzop installed so it will boot. I noticed a little bit of a speed increase by doing this.

Offline

#12 2013-05-03 23:39:06

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: strip kernel for boot time?

The compression for an initramfs image which yields the quickest decompression is none at all. Seriously, if you want to rice out your boot time, simply don't compress it.

Getting rid of the initramfs can actually increase boot time.

P.S. For the record, lzop and gzip decompression times are pretty much identical.

Offline

#13 2013-05-04 02:44:21

ParanoidAndroid
Member
Registered: 2012-10-14
Posts: 114

Re: strip kernel for boot time?

I realize a smaller kernel alone won't get me more than a second. I recompiled it so I could patch it with the BFS and to tailor it to my hardware. As I said, a minimalistic system fits with my ideals, and I subscribe to Kolivas' reasoning concerning cpu schedulers.

I read that there are several other patches which can improve performance, particularly with SSDs, something to do with caching. I think it was called sreadahead?

As far as the rest of my boot process goes, I've stripped down userspace services and so on. Based on my tests, it looks like X eats up a significant portion of the startup time. Is there a way to speed up X loading?

and yes falconindy, my initramfs is uncompressed. I figured that bit out yesterday tongue

Offline

#14 2013-05-04 02:53:24

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: strip kernel for boot time?

ParanoidAndroid wrote:

Is there a way to speed up X loading?

See e.g. Ubuntu's 190_cache-xkbcomp_output_for_fast_start_up.patch for xorg-server.

Offline

#15 2013-05-04 08:29:38

Thorsten Reinbold
Member
From: Germany
Registered: 2011-12-06
Posts: 353

Re: strip kernel for boot time?

For a faster boot, building an optimized Kernel is more or less senseless. What you get out isn't worth the work. But (!) I think it is a great way to learn about your System.

Offline

#16 2013-05-04 18:23:52

ParanoidAndroid
Member
Registered: 2012-10-14
Posts: 114

Re: strip kernel for boot time?

I ran tests with the stock arch kernel versus my custom one and found the following:

Custom
boot time kernel: ~14 seconds
boot time usrspace: ~9

Stock
boot time kernel: ~15 seconds
boot time usrspace: ~ 17 seconds

As you all have pointed out, a smaller kernel does not gain much boot performance. It does, as far as I understand it, make the kernel more memory-efficient and resource efficient when unnecessary modules and features are disabled. I am struck, however, by the massive reduction in userspace boot time. This does not appear to be a function of the kernel, so it's likely that it is due to the Brain Fuck Scheduler, which was the main reason I compiled the kernel myself in the first place.

While we're on the subject of boot time, is there a way to hack X (I couldn't find the patch you mentioned anywhere on the page or the web) to make it load faster? perhaps strip down the binary itself/recompile from source with certain options or unneeded features disabled? Also, is there a way to cache files used in the init process in memory, at boot, to decrease boot time? module files, for instance? This is something I picked up off the transcript of a linux conference somewhere. Can't find the link.

Last edited by ParanoidAndroid (2013-05-04 18:24:33)

Offline

#17 2013-06-03 22:44:28

Gryaniy
Member
From: USA,UKRAINE,MEXICO
Registered: 2013-02-15
Posts: 46

Re: strip kernel for boot time?

I know this is an old thread... but I was on a similar situation, on a samsung chronos 7. Here's what I did.

-Profile your hardware-   mkinitcpio -M will give you the modules detected, lsmod will give you the actually loaded modules.
-They're either loaded as modules or within the kernel.
-Run your kernel config before compiling with as many modules as you can from those in the list.
-Remove  or disable crap that you won't be using on your kernel(e.g. bluetooth,vga port, serial ports, ethernet card).
-Compile your kernel.
-Booting the kernel without initrd helps, however in my case I use the 8gb SSD of my hybrid HD as root, hence my kernel won't see it and I need a boot image.(you can ignore this line if you have a pure SSD or HD).Hence I played tweaking boot image instead:
-edit mkinitcpio.conf and load there the modules that were not compiled on the kernel,leave hooks as only "base" without udev or other, as long as these two are enable you don't need them on your image:
systemd-udevd.service  systemd-udev-trigger.service.
once that it is edited run mkinitcpio -c /etc/mkinitcpio.conf g /initrm-custom-name-here.img, then go to your grub.cfg and create a new entry for your kernel calling this new .img.

-make your root partition on your kernel init line RW and remove it from FSTAB.
-Set your other partiotions as "noatime" in FSTAB, this extremely increases performance.
-If you have enough ram(i bet you do)add to fstab a mount point of file system tmpfs for /tmp. (this is loaded in ram).
-Swith to systemd instead of init scripts, and disable all of the unecessary services... you gotta read here and google them.
-Disable the swap partition.. your laptop is powerful enough and has enough memory to live without it.

For me building a custom PF kernel worked better than stock or plain CK.
-Consider deleting your login manager. follow the steps on the archwiki to log automatically into TTY, then add to your batch profile a "startx" line.
-get rid of networkmanager and use WICD and wicd-gtk instead. (this saves a couple of seconds)>

This is what I get with stock kernel.

Startup finished in 1.662s (kernel) + 1.190s (userspace) = 2.853

still a few things to do is to play with target's in SYstemd and try to start services or mount points as early as possible. Again, you have to do your homework here.

I believe that it is also possible to decrease kernel times by not loading all the modules and moving them to /etc/modules-load.d/ instead of. Those will be pulled by a systemd service that can be run in parallel with the others.
Also I believe that some modules can be scripted to be loaded with a "wait" straight from the batch profile, I load my skype 16 seconds after the gui shows up(that's the time it takes for wi-fi to connect.

if there are any tricks that you already found ,share them :-)

Offline

Board footer

Powered by FluxBB