LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: 聚焦深空

gzip bzip2 lzma xz 7z 讨论(xz 推荐贴)

[复制链接]
发表于 2009-7-21 21:41:12 | 显示全部楼层
以往内核映像都是以 bzip2 压缩的,更旧的内核则采用 gzip,现在新内核新支援了 lzma 方式,今天试验了一下,在使用完全相同的 config 下得出来的结果如下:
  1. d00m3d@BlackMesa:~$ cd /boot
  2. d00m3d@BlackMesa:/boot$ ll
  3. total 12881
  4. -rw-rw-r-- 1 root root  932596 Dec 19  2008 System.map-2.6.28-rc9
  5. -rw-r--r-- 1 root root 1231585 Feb 21 15:21 System.map-2.6.28.7
  6. -rw-rw-r-- 1 root root  981943 Jul 21 09:29 System.map-2.6.30.2
  7. -rw-r--r-- 1 root root 2510080 Feb 21 15:21 clfskernel-2.6.28.7
  8. -rw-rw-r-- 1 root root   54701 Dec 19  2008 config-2.6.28-rc9
  9. -rw-r--r-- 1 root root   52457 Feb 21 15:21 config-2.6.28.7
  10. -rw-rw-r-- 1 root root   56734 Jul 21 09:29 config-2.6.30.2
  11. drwxr-xr-x 2 root root    1024 Jan 17  2009 grub
  12. -rw-rw-r-- 1 root root 2573296 Dec 19  2008 lfskernel-2.6.28-rc9
  13. -rw-rw-r-- 1 root root [color="Red"]2535120 [/color]Jul 21 09:30 [color="Red"]lfskernel-2.6.30.2[/color]
  14. -rw-rw-r-- 1 root root [color="Red"]2181120 [/color]Jul 21 12:09 [color="Red"]lfskernel-lzma-2.6.30.2[/color]
  15. drwx------ 2 root root   12288 Jan 17  2009 lost+found
  16. d00m3d@BlackMesa:/boot$ cat /proc/version
  17. Linux version 2.6.30.2 (d00m3d@BlackMesa) (gcc version 4.4.1 20090707 (prerelease) (GCC) ) #1 SMP PREEMPT Tue Jul 21 11:57:37 HKT 2009
  18. d00m3d@BlackMesa:/boot$
复制代码


采用 lzma 方式的内核映像会细一点,这是常识。其实我原意是想比较启动速度的区别,我的理论是:

1. 内核解压应该是内核本身支援的,因为系统起动时根分区尚未挂载,不可能调用系统的解压软件来解压内核自身的映像文件(我没有查看内核源码,应该没有猜错吧?)

2. lzma 解压速度比 bzip2 快,如果内核本身能解压,那麽起动的时间应能缩短,反正加载到内存後运行上是没有区别的

可是不论是 bzip2 还是 lzma,解压速度实在太快了,无法实时测得,我的系统没有 bootchart,哪位兄弟可以帮忙证实一下?

若然属实,那麽在编译内核时选用 lzma,既能将内核映像缩细,又能将起动时间减少,代价只不过是编译(压缩)时间长一点点而矣,何乐而不为之?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-7-22 13:11:03 | 显示全部楼层
一般的机器没必要启用内核压缩选项。
一般情况,livecd liveusb 也没必要这么做。

资源受限系统,比如现在的手机,才有必要启用内核压缩选项。

启用内核压缩选项,启动时,加载压缩的内核,解压,清理,正常引导。
不启用内核压缩选项,启动时,加载内核,正常引导。
所以重点在于是加载速度、解压速度,也就是存储介质读取物理速度、cpu处理速度的比较。

个人感觉,普通机器启用内核压缩选项,启动过程要比不启用时用时稍长,有时间不妨具体测试一下。
回复 支持 反对

使用道具 举报

发表于 2009-7-22 19:11:37 | 显示全部楼层
深空兄,这个选项好像是 2.6.30 以後新加的,旧版内核并没有此选项,见附图。

如果我没有记错的话,昔日我们 2.4 的时代要 make zImage 来用 gzip 方式压缩,又或者用 make bzImage 来指定用 bzip2 方式压缩,到了 2.6 的年代就只用 make 让系统自动编译出 bzImage 出来,但内核编译一直是默认使用 bzip2 的,你真的肯定你的内核未被压缩过?

现在 2.6.30 新加了压缩选项,默认依然是 bzip2,但它是 mandatory 的,非要你从 gzip/bzip/lzma 当中选一个,也就是你不能选择不压缩的。。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-7-22 21:24:21 | 显示全部楼层
吼吼,x86 机器,linux-2.6.30 果然没法去掉压缩选项。
找了之前的 linux-2.6.25.7,没有可选的压缩选择设置,一样只有 make bzImage。

如果没记错,很久以前用 make bzImage 生成压缩版内核是为了配合 1.44M 的可启动软盘、及可启动光盘,当时 x86 机器 内核大小启动过程还受 实模式 640K 限制,当时还有不压缩的编译方式。

久而久之,x86 环境下,用 make bzImage 编译内核成为习惯性动作,make Image,make zImage 消失了都没注意。

不过这是平台相关的,arm 下仍有非压缩的内核可选。
摘录 linux-2.6.30 内核编译命令 make arch=arm help , make arch=x86 help 如下:
  1. Architecture specific targets (arm):
  2. * zImage        - Compressed kernel image (arch/arm/boot/zImage)
  3.   Image         - Uncompressed kernel image (arch/arm/boot/Image)
  4. * xipImage      - XIP kernel image, if configured (arch/arm/boot/xipImage)
  5.   uImage        - U-Boot wrapped zImage
  6.   bootpImage    - Combined zImage and initial RAM disk
  7.                   (supply initrd image via make variable INITRD=<path>)
  8.   install       - Install uncompressed kernel
  9.   zinstall      - Install compressed kernel
  10.                   Install using (your) ~/bin/installkernel or
  11.                   (distribution) /sbin/installkernel or
  12.                   install to $(INSTALL_PATH) and run lilo
复制代码
  1. Architecture specific targets (x86):
  2. * bzImage      - Compressed kernel image (arch/x86/boot/bzImage)
  3.   install      - Install kernel using
  4.                   (your) ~/bin/installkernel or
  5.                   (distribution) /sbin/installkernel or
  6.                   install to $(INSTALL_PATH) and run lilo
  7.   fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
  8.   fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
  9.   fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)
  10.   isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)
  11.                   bzdisk/fdimage*/isoimage also accept:
  12.                   FDARGS="..."  arguments for the booted kernel
  13.                   FDINITRD=file initrd for the booted kernel
复制代码

回到前面毁灭兄的问题,现在只有压缩的内核可选,x86 环境下,应该还是 gzip 压缩的内核启动快些,解压最快,只是体积不占优势。
回复 支持 反对

使用道具 举报

发表于 2009-7-22 23:53:37 | 显示全部楼层
据我所知,在2.6.27之后的kernel全部都有压缩技术(开始学习kernel)
可以尝试更改压缩包的命令然后编译kernel会发现最后出现error

而在其目录下也会有些文件压缩前的文件(很抱歉,暂时机子没kernel源代码,没法给列表)
回复 支持 反对

使用道具 举报

发表于 2009-7-23 02:29:35 | 显示全部楼层
nonplus 兄,压缩技术远在 2.4 年代已经采用了
回复 支持 反对

使用道具 举报

发表于 2009-7-23 02:33:55 | 显示全部楼层
Post by 聚焦深空;2008584
吼吼,x86 机器,linux-2.6.30 果然没法去掉压缩选项。
找了之前的 linux-2.6.25.7,没有可选的压缩选择设置,一样只有 make bzImage。

如果没记错,很久以前用 make bzImage 生成压缩版内核是为了配合 1.44M 的可启动软盘、及可启动光盘,当时 x86 机器 内核大小启动过程还受 实模式 640K 限制,当时还有不压缩的编译方式。

久而久之,x86 环境下,用 make bzImage 编译内核成为习惯性动作,make Image,make zImage 消失了都没注意。

不过这是平台相关的,arm 下仍有非压缩的内核可选。
摘录 linux-2.6.30 内核编译命令 make arch=arm help , make arch=x86 help 如下:
  1. Architecture specific targets (arm):
  2. * zImage        - Compressed kernel image (arch/arm/boot/zImage)
  3.   Image         - Uncompressed kernel image (arch/arm/boot/Image)
  4. * xipImage      - XIP kernel image, if configured (arch/arm/boot/xipImage)
  5.   uImage        - U-Boot wrapped zImage
  6.   bootpImage    - Combined zImage and initial RAM disk
  7.                   (supply initrd image via make variable INITRD=<path>)
  8.   install       - Install uncompressed kernel
  9.   zinstall      - Install compressed kernel
  10.                   Install using (your) ~/bin/installkernel or
  11.                   (distribution) /sbin/installkernel or
  12.                   install to $(INSTALL_PATH) and run lilo
复制代码

  1. Architecture specific targets (x86):
  2. * bzImage      - Compressed kernel image (arch/x86/boot/bzImage)
  3.   install      - Install kernel using
  4.                   (your) ~/bin/installkernel or
  5.                   (distribution) /sbin/installkernel or
  6.                   install to $(INSTALL_PATH) and run lilo
  7.   fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
  8.   fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
  9.   fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)
  10.   isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)
  11.                   bzdisk/fdimage*/isoimage also accept:
  12.                   FDARGS="..."  arguments for the booted kernel
  13.                   FDINITRD=file initrd for the booted kernel
复制代码


回到前面毁灭兄的问题,现在只有压缩的内核可选,x86 环境下,应该还是 gzip 压缩的内核启动快些,解压最快,只是体积不占优势。

我一直在 x86 环境下操作,真的忽略了其他平台,考虑真的不够全面,谢谢深空兄提示
回复 支持 反对

使用道具 举报

发表于 2009-7-23 07:36:40 | 显示全部楼层
额,我是2.6.27kernel那时才开始玩linux的说 : )

---------------------------------------------------------------------
错了,是2.6.23那时开始玩,开始接触kernel是2.6.27
回复 支持 反对

使用道具 举报

发表于 2009-7-23 13:09:15 | 显示全部楼层
  1. d00m3d@BlackMesa:~$ cd /boot
  2. d00m3d@BlackMesa:/boot$ ll
  3. total 15472
  4. -rw-rw-r-- 1 root root  932596 Dec 19  2008 System.map-2.6.28-rc9
  5. -rw-r--r-- 1 root root 1231585 Feb 21 15:21 System.map-2.6.28.7
  6. -rw-rw-r-- 1 root root  981943 Jul 21 09:29 System.map-2.6.30.2
  7. -rw-r--r-- 1 root root 2510080 Feb 21 15:21 clfskernel-2.6.28.7
  8. -rw-rw-r-- 1 root root   54701 Dec 19  2008 config-2.6.28-rc9
  9. -rw-r--r-- 1 root root   52457 Feb 21 15:21 config-2.6.28.7
  10. -rw-rw-r-- 1 root root   56734 Jul 21 09:29 config-2.6.30.2
  11. drwxr-xr-x 2 root root    1024 Jan 17  2009 grub
  12. -rw-rw-r-- 1 root root 2573296 Dec 19  2008 lfskernel-2.6.28-rc9
  13. -rw-rw-r-- 1 root root [color="Red"]2535120 [/color]Jul 21 09:30 [color="Red"]lfskernel-2.6.30.2[/color]
  14. -rw-rw-r-- 1 root root [color="Blue"]2640320 [/color]Jul 23 09:30 [color="Blue"]lfskernel-gzip-2.6.30.2[/color]
  15. -rw-rw-r-- 1 root root [color="Red"]2181120 [/color]Jul 21 12:09 [color="Red"]lfskernel-lzma-2.6.30.2[/color]
  16. drwx------ 2 root root   12288 Jan 17  2009 lost+found
  17. d00m3d@BlackMesa:/boot$
复制代码

今天把 gzip 的内核也弄出来对比一下,size 比 bzip2 不是输很多,只差 100k 左右

由於没法直接对比解压时间,只好简接对比系统的起动时间,由 grub menu 选择开始至显示 login prompt 为止,当中有少许人手反应时间的误差,采用不同的压缩方式结果如下:

Boot time:
bzip2 - 14.14s
gzip - 13.66s
lzma - 13.95s

差别相当少,都在一秒钟内。

对我来说,我会从今起,采用 lzma :)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-7-25 13:38:33 | 显示全部楼层
好吧,反正 x86 下都要压缩,没得选,偶也换 lzma 好啦。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表