About Compression

From eLinux.org
Revision as of 16:17, 14 November 2008 by FransMeulenbroeks (Talk | contribs) (creation)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

WORK IN PROGRESS, PLEASE DO NOT TOUCH

About Compression

Introduction

This page discussed compression in relation to boot and load time.
First we explain the effects of compression on the system in general.
Next we discuss where compression may be applied.
After that we will discuss the alternatives and go into detail whether they are worthwhile or not.

Effects of compression (general discussion)

Space impact

Generally compression will cause that less space is needed. Typically a piece of data that is compressed becomes smaller. Note though that this is not always the case. If you compress something which is already compressed there is probably nothing to gain, and in most cases you'll loose a little bit, because the compressor itself adds info for decompression. Compressing audio or video files (like mp3, DivX or jpeg files) also will yield little space reduction as these data files are internally already highly compressed.

The amount of compression also depends on the compression algorithm and the options that are applied.

Performance impact

Of course compression also has a performance impact. At first sight it may seem that the impact is negative, as additional time is needed to compress/decompress the data. However experiments may yield otherwise.
Consider the following situation. You have a 2 MB linux kernel. Compression will reduce that kernel to 1 MB. Now suppose you store the kernel in flash which has a read speed of 20 MB/s. In case of an uncompressed kernel, 100 ms will be needed to read the kernel from flash to RAM. However if the kernel is compressed, the actual I/O activity will only take 50 ms. So if decompressing 1MB takes less than 50 ms (decompression speed > 40 MB/s) you gain some time.

So whether or not compression affects your performance positive or negative depends on factors like read speed and decompression speed.

Of course it is not as simple as this. If reading is done through DMA and your system is CPU constrained compression will cause performance degradation. This is because reading using DMA is almost free as far as the CPU is concerned, and the decompression additionally loads the CPU (which was already the bottlenect).

Where compression may be applied

There are a number of places where compression can be applied in Linux:

  • If you use an initramfs in the kernel by default this initramfs is compressed.
  • The kernel itself often is also compressed. (hint: if your kernel name is vmlinuz or bzImage it is most likely a compressed kernel, if your kernel name is vmlinux it is probably not compressed; if you want to make sure: file is your friend here.
  • The filesystem itself can also apply compression. This is often the case with flash file systems. Notably SquashFS, CRAMFS and JFFS2 use filesystem compression.
  • Compression of executables, application data and the like. This is outside the scope of this page and not covered.

Initramfs compression

TODO

Kernel compression

TODO

Filesystem compression

TODO