Research on linux kernel compression

kernel image format

(1)vmlinux
vmlinuz is a bootable, compressible kernel image, and vm represents Virtual Memory. It is compiled from the source code of the kernel by the user. In essence, it is a file in elf format with symbol table, which can be used for debugging.
(2)Image
Image is the kernel code that contains only binary data and is processed by objcopy without compression.
(3)zImage
zImage is a kind of compressed image file commonly used in ARM linux. It is composed of vmlinux and decompressed code by gzip compression. The command format is "make zImage"
(4)bzImage
bz represents big zImage, whose format is similar to zImage, but different compression algorithms are used. gzip is used for compression. bzImage has a higher compression ratio and is suitable for large kernel.
(5)uImage
uImage is a special image file for uboot. It is a header information (tag) with a length of 0x40 added before zImage. In the header information, it describes the type, loading position, generation time, size and other information of the image file. In other words, if you start directly from the 0x40 position of uImage, there is no difference between zImage and uImage. The command format is "make" Most Linux image files in this format are stored on NAND.
There is mkimage tool in the tools directory of u-boot, which can be used to make uImage. Refer to Here.
(6)xipImage
Most of the Linux image files in this format are stored in NorFlash, and they do not need to be copied to the memory SDRAM when running. They can run directly in NorFlash

linux compression mode configuration options

In init/Kconfig, you can see the following choices about compression methods. According to the following description, you can briefly know the characteristics of various compression algorithms. For the detailed test of these algorithms, please refer to Here.

choice
        prompt "Kernel compression mode"
        default KERNEL_GZIP
        depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
        help

          The linux kernel is a kind of self-extracting executable.
          Several compression algorithms are available, which differ
          in efficiency, compression and decompression speed.
          Compression speed is only relevant when building a kernel.
          Decompression speed is relevant at each boot.

          If you have any problems with bzip2 or lzma compressed
          kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older
          version of this functionality (bzip2 only), for 2.4, was
          supplied by Christian Ludwig)

          High compression options are mostly useful for users, who
          are low on disk space (embedded systems), but for whom ram
          size matters less.

          If in doubt, select 'gzip'

config KERNEL_GZIP
        bool "Gzip"
        depends on HAVE_KERNEL_GZIP
        help
          The old and tried gzip compression. It provides a good balance
          between compression ratio and decompression speed.

config KERNEL_BZIP2
        bool "Bzip2"
        depends on HAVE_KERNEL_BZIP2
        help
          Its compression ratio and speed is intermediate.
          Decompression speed is slowest among the choices.  The kernel
                    size is about 10% smaller with bzip2, in comparison to gzip.
          Bzip2 uses a large amount of memory. For modern kernels you
          will need at least 8MB RAM or more for booting.

config KERNEL_LZMA
        bool "LZMA"
        depends on HAVE_KERNEL_LZMA
        help
          This compression algorithm's ratio is best.  Decompression speed
          is between gzip and bzip2.  Compression is slowest.
          The kernel size is about 33% smaller with LZMA in comparison to gzip.

config KERNEL_XZ
        bool "XZ"
        depends on HAVE_KERNEL_XZ
        help
          XZ uses the LZMA2 algorithm and instruction set specific
          BCJ filters which can improve compression ratio of executable
          code. The size of the kernel is about 30% smaller with XZ in
          comparison to gzip. On architectures for which there is a BCJ
          filter (i386, x86_64, ARM, IA-64, PowerPC, and SPARC), XZ
          will create a few percent smaller kernel than plain LZMA.

          The speed is about the same as with LZMA: The decompression
          speed of XZ is better than that of bzip2 but worse than gzip
          and LZO. Compression is slow.

config KERNEL_LZO
        bool "LZO"
        depends on HAVE_KERNEL_LZO
        help
          Its compression ratio is the poorest among the choices. The kernel
          size is about 10% bigger than gzip; however its speed
          (both compression and decompression) is the fastest.

config KERNEL_LZ4
        bool "LZ4"
        depends on HAVE_KERNEL_LZ4
        help
          LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding.
          A preliminary version of LZ4 de/compression tool is available at
          <https://code.google.com/p/lz4/>.

          Its compression ratio is worse than LZO. The size of the kernel
          is about 8% bigger than LZO. But the decompression speed is
          faster than LZO.

endchoice

The kernel compression and decompression code is in the directory kernel/arch/arm/boot/compressed. It seems that there is no specific compression algorithm in this document.
More information:
linux kernel image format

Quick Benchmark: Gzip vs Bzip2 vs LZMA vs XZ vs LZ4 vs LZO

Published 30 original articles, won praise 3, visited 5456
Private letter follow

Tags: Linux less encoding Google

Posted on Wed, 26 Feb 2020 21:19:59 -0500 by ondercsn