Messages in this thread | | | Date | Mon, 6 Jun 2005 00:35:28 +0200 | From | Willy Tarreau <> | Subject | Easy trick to reduce kernel footprint |
| |
Hi,
Here's a simple trick for all those who try to squeeze their kernels to the absolute smallest size.
I recently discovered p7zip which comes with the LZMA compression algorithm, which is somewhat better than gzip and bzip2 on most datasets, and I also noticed that this tool provides support for gzip and bzip2 outputs. So I tried to produce some of those standard outputs, and observed a slight gain compared to the default tools. The reason is that we can change the number of passes and the dictionnary size.
So as an experiment, I used it to compress my kernel+initramfs and I could gain about 2% (23 kB) which is not bad at all for embedded systems. Don't ask about the '.' after '-si' in the '7za' command line, it's just that the tool expects a file name, and I didn't managed to fix it, the source is some sort of obfuscated c++ code (who said "pleonasm" ?) ported from windows, but at least it works. Out of curiosity, I also tried both bzip2 and the LZMA algorithm, although that's not fair because the decompressor code would have to be changed to support them.
Size of the 2.6.12-rc4-mm2 vmlinux compiled without the initramfs image :
bash-3.00$ size vmlinux text data bss dec hex filename 1024458 123712 73580 1221750 12a476 vmlinux
Size of the initramfs : -rw-rw-r-- 1 willy users 1014272 2005-05-27 16:31 usr/initramfs_data.cpio
Now the resulting bzImage size with various compression methods
size command 1197277 make 1197275 make cmd_gzip="gzip -9c <\$< >\$@" 1173550 make cmd_gzip="7za a -tgzip -mx9 -mpass=4 -so -si . <\$< >\$@" 1207599 make cmd_gzip="bzip2 -c9 <\$< >\$@" 1051705 make cmd_gzip="rm -f \$@;7za a -t7z -mx9 -md=64m -si \$@ < \$<"
Surprizingly, bzip2 makes a bigger kernel. The gzip implementation in 7za saves 23 kB (2%) on the overall image without touching any code. The LZMA implementation could save 145 kB (12%), but would require a different extraction code (I've already seen patches to bring LZMA support on 2.4).
Note: I don't know who implemented the if_changed macro in the makefile which allows us to pass cmd_gzip here, but it was an excellent idea.
Regards, Willy
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |