Skip to contentSkip to conversation

x86/boot: Support uncompressed kernel

PATCH Superseded Chao Peng 8 participants 12 messages Mar 23, 2017 – Mar 28, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Peng

author
#0 lore raw

PATCH 1/1 x86/boot: Support uncompressed kernel

Compressed kernel has its own drawback: uncompressing takes time. Even though the time is short enough to ignore for most cases but for cases that time is critical this is still a big number. In our on-going optimization for kernel boot time, the measured overall kernel boot time is ~90ms while the uncompressing takes ~50ms with gzip.

The patch adds a 'CONFIG_KERNEL_RAW' configure choice so the built binary can have no uncompressing at all. The experiment shows:

    kernel               kernel size    time in decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms
---
 arch/x86/boot/compressed/Makefile |  3 +++
 arch/x86/boot/compressed/misc.c   | 14 ++++++++++++++
 init/Kconfig                      |  7 +++++++
 scripts/Makefile.lib              |  8 ++++++++
 4 files changed, 32 insertions(+)
arch/x86/boot/compressed/Makefile +3 -0
index f9ce75d..fc0e1c0 100644
@@ -73,6 +73,8 @@ $(obj)/vmlinux.relocs: vmlinux FORCE
 vmlinux.bin.all-y := $(obj)/vmlinux.bin
 vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
 
+$(obj)/vmlinux.bin.raw: $(vmlinux.bin.all-y) FORCE
+	$(call if_changed,raw)
 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,gzip)
 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
@@ -86,6 +88,7 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,lz4)
 
+suffix-$(CONFIG_KERNEL_RAW)	:= raw
 suffix-$(CONFIG_KERNEL_GZIP)	:= gz
 suffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
 suffix-$(CONFIG_KERNEL_LZMA)	:= lzma
arch/x86/boot/compressed/misc.c +14 -0
index 79dac17..fb3cd43 100644
@@ -123,6 +123,20 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#ifdef CONFIG_KERNEL_RAW
+#include <linux/decompress/mm.h>
+static int __decompress(unsigned char *buf, long len,
+			long (*fill)(void*, unsigned long),
+			long (*flush)(void*, unsigned long),
+			unsigned char *outbuf, long olen,
+			long *pos,
+			void (*error)(char *x))
+{
+	memcpy(outbuf, buf, olen);
+	return 0;
+}
+#endif
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
init/Kconfig +7 -0
index 2232080..1db2ea2 100644
@@ -137,6 +137,13 @@ choice
 
 	  If in doubt, select 'gzip'
 
+config KERNEL_RAW
+	bool "RAW"
+	help
+	  No compression. It creates much bigger kernel and uses much more
+	  space (disk/memory) than other choices. It can be useful when
+	  decompression speed is the most concern while space is not a problem.
+
 config KERNEL_GZIP
 	bool "Gzip"
 	depends on HAVE_KERNEL_GZIP
scripts/Makefile.lib +8 -0
index 2edbcad..384128d 100644
@@ -344,6 +344,14 @@ cmd_lz4 = (cat $(filter-out FORCE,$^) | \
 	lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
 	(rm -f $@ ; false)
 
+# RAW
+# ---------------------------------------------------------------------------
+quiet_cmd_raw = RAW     $@
+cmd_raw = (cat $(filter-out FORCE,$^) && \
+	$(call size_append, $(filter-out FORCE,$^))) > $@ || \
+	(rm -f $@ ; false)
+
+
 # U-Boot mkimage
 # ---------------------------------------------------------------------------
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Chao Peng

Compressed kernel has its own drawback: uncompressing takes time. Even though the time is short enough to ignore for most cases but for cases that time is critical this is still a big number. In our on-going optimization for kernel boot time, the measured overall kernel boot time is ~90ms while the uncompressing takes ~50ms with gzip.

Quoted 6 lines

The patch adds a 'CONFIG_KERNEL_RAW' configure choice so the built binary can have no uncompressing at all. The experiment shows:

    kernel               kernel size    time in decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms

How about the time difference for bootloader to read kernel from flash/disk/network to ram?

Thanks

Yinghai

#2 lore raw
Quoted 10 lines · Yinghai Lu
Quoted 9 lines · Chao Peng

Compressed kernel has its own drawback: uncompressing takes time. Even though the time is short enough to ignore for most cases but for cases that time is critical this is still a big number. In our on-going optimization for kernel boot time, the measured overall kernel boot time is ~90ms while the uncompressing takes ~50ms with gzip.

The patch adds a 'CONFIG_KERNEL_RAW' configure choice so the built binary can have no uncompressing at all. The experiment shows:

Quoted 6 lines
Quoted 3 lines
    kernel               kernel size    time in decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms

How about the time difference for bootloader to read kernel from flash/disk/network to ram?

there are also faster de-compressors than gzip out there. LZ4, for instance. LZ4, as far as I remember, can be quite fast, like ~10 times faster than gzip. have you tested it?

	-ss
author
#3 lore raw
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

The patch adds a 'CONFIG_KERNEL_RAW' configure choice so the built binary
can have no uncompressing at all. The experiment shows:

    kernel               kernel size    time in decompress_kernel compressed (gzip)    3.3M           53ms uncompressed         14M            3ms

How about the time difference for bootloader to read kernel from flash/disk/network to ram?

The loading time for bootloader can be longer as size increased, but that depends on which media it uses. For our usecase, it's not a big problem. As we run the kernel in virtual machine and lunch thousands of instances in the same physical machine so only the first instance needs to read from the file and later we just copy the memory. The thing that really matters for us is how fast we can boot for majority of the instances.

Quoted 6 lines

there are also faster de-compressors than gzip out there. LZ4, for instance.
LZ4, as far as I remember, can be quite fast, like ~10 times faster than gzip.
have you tested it?

Exactly, LZ4 is the fastest. It takes 16ms to complete the decompression. Still sounds a little longer when compared to uncompressed kernel.

Chao

#11 lore raw
In reply to Chao Peng
Quoted 72 lines · Chao Peng

Compressed kernel has its own drawback: uncompressing takes time. Even though the time is short enough to ignore for most cases but for cases that time is critical this is still a big number. In our on-going optimization for kernel boot time, the measured overall kernel boot time is ~90ms while the uncompressing takes ~50ms with gzip.

The patch adds a 'CONFIG_KERNEL_RAW' configure choice so the built binary can have no uncompressing at all. The experiment shows:

    kernel               kernel size    time in decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms
---
 arch/x86/boot/compressed/Makefile |  3 +++
 arch/x86/boot/compressed/misc.c   | 14 ++++++++++++++
 init/Kconfig                      |  7 +++++++
 scripts/Makefile.lib              |  8 ++++++++
 4 files changed, 32 insertions(+)
arch/x86/boot/compressed/Makefile +3 -0
index f9ce75d..fc0e1c0 100644
@@ -73,6 +73,8 @@ $(obj)/vmlinux.relocs: vmlinux FORCE
 vmlinux.bin.all-y := $(obj)/vmlinux.bin
 vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
 
+$(obj)/vmlinux.bin.raw: $(vmlinux.bin.all-y) FORCE
+	$(call if_changed,raw)
 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,gzip)
 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
@@ -86,6 +88,7 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,lz4)
 
+suffix-$(CONFIG_KERNEL_RAW)	:= raw
 suffix-$(CONFIG_KERNEL_GZIP)	:= gz
 suffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
 suffix-$(CONFIG_KERNEL_LZMA)	:= lzma
arch/x86/boot/compressed/misc.c +14 -0
index 79dac17..fb3cd43 100644
@@ -123,6 +123,20 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#ifdef CONFIG_KERNEL_RAW
+#include <linux/decompress/mm.h>
+static int __decompress(unsigned char *buf, long len,
+			long (*fill)(void*, unsigned long),
+			long (*flush)(void*, unsigned long),
+			unsigned char *outbuf, long olen,
+			long *pos,
+			void (*error)(char *x))
+{
+	memcpy(outbuf, buf, olen);
+	return 0;
+}
+#endif
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
init/Kconfig +0 -0
index 2232080..1db2ea2 100644

init/Kconfig choice · line 145

Quoted 9 lines
init/Kconfig +6 -0
@@ -137,6 +137,13 @@ choice
 
 	  If in doubt, select 'gzip'
 
+config KERNEL_RAW
+	bool "RAW"
+	help
+	  No compression. It creates much bigger kernel and uses much more
+	  space (disk/memory) than other choices. It can be useful when
+	  decompression speed is the most concern while space is not a problem.

This needs to depend on a HAVE_KERNEL_RAW config that is selected by the architectures that implement this target (x86).

Michal

#4 lore raw
In reply to Chao Peng
Quoted 8 lines · Chao Peng
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

    kernel               kernel size    time in decompress_kernel compressed (gzip)    3.3M           53ms uncompressed         14M            3ms

Exactly, LZ4 is the fastest. It takes 16ms to complete the decompression. Still sounds a little longer when compared to uncompressed kernel.

Are we seriously talking here about one-time improvement of 13ms boot time?

Quoted 1 line

Chao

Sebastian

author
#5 lore raw
Quoted 11 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Chao Peng
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

    kernel               kernel size    time in
decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms

Quoted 6 lines
Quoted 3 lines

Exactly, LZ4 is the fastest. It takes 16ms to complete the decompression. Still sounds a little longer when compared to uncompressed kernel.

Are we seriously talking here about one-time improvement of 13ms boot time?

The usage model for us is to lunch kernel in virtual machine and there will be thousands of instances lunched and shutdowned/re-lunched frequently, so every single million-second helps. And 13ms means 20% improvement to our existing optimization (the other part besides decompression is optimized to ~40ms).

Chao

Quoted 5 lines
Quoted 3 lines

Chao

Sebastian

#6 lore raw
In reply to Sebastian Andrzej Siewior

Dne 27.3.2017 v 09:58 Sebastian Andrzej Siewior napsal(a):

Quoted 6 lines · Chao Peng
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
    kernel               kernel size    time in decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms
Quoted 6 lines
Quoted 3 lines

Exactly, LZ4 is the fastest. It takes 16ms to complete the decompression. Still sounds a little longer when compared to uncompressed kernel.

Are we seriously talking here about one-time improvement of 13ms boot time?

If the use case is launching new VM instances continuously, then compressing the kernel image is about as useful as compressing /bin/bash.

Michal

#7 lore raw
Quoted 11 lines · Michal Marek

Dne 27.3.2017 v 09:58 Sebastian Andrzej Siewior napsal(a):

Quoted 10 lines · Chao Peng
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
    kernel               kernel size    time in decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms

Exactly, LZ4 is the fastest. It takes 16ms to complete the decompression. Still sounds a little longer when compared to uncompressed kernel.

Quoted 5 lines
Quoted 2 lines

Are we seriously talking here about one-time improvement of 13ms boot time?

If the use case is launching new VM instances continuously, then compressing the kernel image is about as useful as compressing /bin/bash.

I guess the next step would be to use CONFIG_XIP_KERNEL on x86, which requires an uncompressed kernel but has the additional advantage of sharing the read-only sections of the kernel image across virtual machines, resulting in better RAM and cache usage.

Arnd

author
#8 lore raw
Quoted 22 lines · Arnd Bergmann
Quoted 21 lines · Michal Marek

Dne 27.3.2017 v 09:58 Sebastian Andrzej Siewior napsal(a):

Quoted 18 lines · Chao Peng
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

    kernel               kernel size    time in
decompress_kernel
    compressed (gzip)    3.3M           53ms
    uncompressed         14M            3ms

Exactly, LZ4 is the fastest. It takes 16ms to complete the decompression. Still sounds a little longer when compared to uncompressed kernel.

Are we seriously talking here about one-time improvement of 13ms boot time?

Quoted 8 lines
Quoted 3 lines

If the use case is launching new VM instances continuously, then compressing the kernel image is about as useful as compressing /bin/bash.

I guess the next step would be to use CONFIG_XIP_KERNEL on x86, which requires an uncompressed kernel but has the additional advantage of sharing the read-only sections of the kernel image across virtual machines, resulting in better RAM and cache usage.

That is something we wanna look into :)

Chao

#9 lore raw
Quoted 8 lines · Chao Peng
Quoted 5 lines

I guess the next step would be to use CONFIG_XIP_KERNEL on x86, which requires an uncompressed kernel but has the additional advantage of sharing the read-only sections of the kernel image across virtual machines, resulting in better RAM and cache usage.

That is something we wanna look into :)

It is, but that is a second order thing... especially since the x86 kernel makes heavy use of self-patching at the moment. What would be more significant, though, would be to avoid the memcpy() and instead decode the uncompressed kernel in-place.

-hpa

#10 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Chao Peng
Quoted 5 lines

I guess the next step would be to use CONFIG_XIP_KERNEL on x86, which requires an uncompressed kernel but has the additional advantage of sharing the read-only sections of the kernel image across virtual machines, resulting in better RAM and cache usage.

Quoted 8 lines
Quoted 2 lines

That is something we wanna look into :)

It is, but that is a second order thing... especially since the x86 kernel makes heavy use of self-patching at the moment. What would be more significant, though, would be to avoid the memcpy() and instead decode the uncompressed kernel in-place.

Having looked at this code recently, I'd rather fix it differently:
use the streaming decompression API and integrate it with the ELF parsing code so we can decompress directly into the actual load location. Also, the parse_elf() code needs some serious improved documentation and robustification. It's absurdly fragile right now.