Skip to content

Commit db2aa7f

Browse files
klonditorvalds
authored andcommitted
initramfs: allow again choice of the embedded initram compression algorithm
Choosing the appropriate compression option when using an embedded initramfs can result in significant size differences in the resulting data. This is caused by avoiding double compression of the initramfs contents. For example on my tests, choosing CONFIG_INITRAMFS_COMPRESSION_NONE when compressing the kernel using XZ) results in up to 500KiB differences (9MiB to 8.5MiB) in the kernel size as the dictionary will not get polluted with uncomprensible data and may reuse kernel data too. Despite embedding an uncompressed initramfs, a user may want to allow for a compressed extra initramfs to be passed using the rd system, for example to boot a recovery system. 9ba4bcb ("initramfs: read CONFIG_RD_ variables for initramfs compression") broke that behavior by making the choice based on CONFIG_RD_* instead of adding CONFIG_INITRAMFS_COMPRESSION_LZ4. Saddly, CONFIG_RD_* is also used to choose the supported RD compression algorithms by the kernel and a user may want to support more than one. This patch also reverts commit 3e4e0f0 ("initramfs: remove "compression mode" choice") restoring back the "compression mode" choice and includes the CONFIG_INITRAMFS_COMPRESSION_LZ4 option which was never added. As a result the following options are added or readed affecting the embedded initramfs compression: INITRAMFS_COMPRESSION_NONE Do no compression INITRAMFS_COMPRESSION_GZIP Compress using gzip INITRAMFS_COMPRESSION_BZIP2 Compress using bzip2 INITRAMFS_COMPRESSION_LZMA Compress using lzma INITRAMFS_COMPRESSION_XZ Compress using xz INITRAMFS_COMPRESSION_LZO Compress using lzo INITRAMFS_COMPRESSION_LZ4 Compress using lz4 These depend on the corresponding CONFIG_RD_* option being set (except NONE which has no dependencies). This patch depends on the previous one (the previous version didn't) to simplify the way in which the algorithm is chosen and keep backwards compatibility with the behaviour introduced by 9ba4bcb ("initramfs: read CONFIG_RD_ variables for initramfs compression"). Link: http://lkml.kernel.org/r/57EAD77B.7090607@klondike.es Signed-off-by: Francisco Blas Izquierdo Riera (klondike) <klondike@klondike.es> Cc: P J P <ppandit@redhat.com> Cc: Paul Bolle <pebolle@tiscali.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 35e669e commit db2aa7f

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

usr/Kconfig

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,125 @@ config RD_LZ4
9999
Support loading of a LZ4 encoded initial ramdisk or cpio buffer
100100
If unsure, say N.
101101

102+
choice
103+
prompt "Built-in initramfs compression mode"
104+
depends on INITRAMFS_SOURCE!=""
105+
optional
106+
help
107+
This option allows you to decide by which algorithm the builtin
108+
initramfs will be compressed. Several compression algorithms are
109+
available, which differ in efficiency, compression and
110+
decompression speed. Compression speed is only relevant
111+
when building a kernel. Decompression speed is relevant at
112+
each boot. Also the memory usage during decompression may become
113+
relevant on memory constrained systems. This is usually based on the
114+
dictionary size of the algorithm with algorithms like XZ and LZMA
115+
featuring large dictionary sizes.
116+
117+
High compression options are mostly useful for users who are
118+
low on RAM, since it reduces the memory consumption during
119+
boot.
120+
121+
Keep in mind that your build system needs to provide the appropriate
122+
compression tool to compress the generated initram cpio file for
123+
embedding.
124+
125+
If in doubt, select 'None'
126+
127+
config INITRAMFS_COMPRESSION_NONE
128+
bool "None"
129+
help
130+
Do not compress the built-in initramfs at all. This may sound wasteful
131+
in space, but, you should be aware that the built-in initramfs will be
132+
compressed at a later stage anyways along with the rest of the kernel,
133+
on those architectures that support this. However, not compressing the
134+
initramfs may lead to slightly higher memory consumption during a
135+
short time at boot, while both the cpio image and the unpacked
136+
filesystem image will be present in memory simultaneously
137+
138+
config INITRAMFS_COMPRESSION_GZIP
139+
bool "Gzip"
140+
depends on RD_GZIP
141+
help
142+
Use the old and well tested gzip compression algorithm. Gzip provides
143+
a good balance between compression ratio and decompression speed and
144+
has a reasonable compression speed. It is also more likely to be
145+
supported by your build system as the gzip tool is present by default
146+
on most distros.
147+
148+
config INITRAMFS_COMPRESSION_BZIP2
149+
bool "Bzip2"
150+
depends on RD_BZIP2
151+
help
152+
It's compression ratio and speed is intermediate. Decompression speed
153+
is slowest among the choices. The initramfs size is about 10% smaller
154+
with bzip2, in comparison to gzip. Bzip2 uses a large amount of
155+
memory. For modern kernels you will need at least 8MB RAM or more for
156+
booting.
157+
158+
If you choose this, keep in mind that you need to have the bzip2 tool
159+
available to be able to compress the initram.
160+
161+
config INITRAMFS_COMPRESSION_LZMA
162+
bool "LZMA"
163+
depends on RD_LZMA
164+
help
165+
This algorithm's compression ratio is best but has a large dictionary
166+
size which might cause issues in memory constrained systems.
167+
Decompression speed is between the other choices. Compression is
168+
slowest. The initramfs size is about 33% smaller with LZMA in
169+
comparison to gzip.
170+
171+
If you choose this, keep in mind that you may need to install the xz
172+
or lzma tools to be able to compress the initram.
173+
174+
config INITRAMFS_COMPRESSION_XZ
175+
bool "XZ"
176+
depends on RD_XZ
177+
help
178+
XZ uses the LZMA2 algorithm and has a large dictionary which may cause
179+
problems on memory constrained systems. The initramfs size is about
180+
30% smaller with XZ in comparison to gzip. Decompression speed is
181+
better than that of bzip2 but worse than gzip and LZO. Compression is
182+
slow.
183+
184+
If you choose this, keep in mind that you may need to install the xz
185+
tool to be able to compress the initram.
186+
187+
config INITRAMFS_COMPRESSION_LZO
188+
bool "LZO"
189+
depends on RD_LZO
190+
help
191+
It's compression ratio is the second poorest amongst the choices. The
192+
kernel size is about 10% bigger than gzip. Despite that, it's
193+
decompression speed is the second fastest and it's compression speed
194+
is quite fast too.
195+
196+
If you choose this, keep in mind that you may need to install the lzop
197+
tool to be able to compress the initram.
198+
199+
config INITRAMFS_COMPRESSION_LZ4
200+
bool "LZ4"
201+
depends on RD_LZ4
202+
help
203+
It's compression ratio is the poorest amongst the choices. The kernel
204+
size is about 15% bigger than gzip; however its decompression speed
205+
is the fastest.
206+
207+
If you choose this, keep in mind that most distros don't provide lz4
208+
by default which could cause a build failure.
209+
210+
endchoice
211+
102212
config INITRAMFS_COMPRESSION
103213
string
214+
default "" if INITRAMFS_COMPRESSION_NONE
215+
default ".gz" if INITRAMFS_COMPRESSION_GZIP
216+
default ".bz2" if INITRAMFS_COMPRESSION_BZIP2
217+
default ".lzma" if INITRAMFS_COMPRESSION_LZMA
218+
default ".xz" if INITRAMFS_COMPRESSION_XZ
219+
default ".lzo" if INITRAMFS_COMPRESSION_LZO
220+
default ".lz4" if INITRAMFS_COMPRESSION_LZ4
104221
default ".gz" if RD_GZIP
105222
default ".lz4" if RD_LZ4
106223
default ".lzo" if RD_LZO

0 commit comments

Comments
 (0)