Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

More and more tar archives use the xz format based on LZMA2 for compression instead of the traditional bzip2(bz2) compression. In fact kernel.org made a late "Good-bye bzip2" announcement, 27th Dec. 2013, indicating kernel sources would from this point on be released in both tar.gz and tar.xz format - and on the main page of the website what's directly offered is in tar.xz.

Are there any specific reasons explaining why this is happening and what is the relevance of gzip in this context?

share|improve this question

4 Answers 4

up vote 80 down vote accepted

For distributing archives over the Internet, the following things are generally a priority:

  1. Compression ratio (i.e., how small the compressor makes the data);
  2. Decompression time (CPU requirements);
  3. Decompression memory requirements; and
  4. Compatibility (how wide-spread the decompression program is)

Compression memory & CPU requirements aren't very important, because you can use a large fast machine for that, and you only have to do it once.

Compared to bzip2, xz has a better compression ratio and lower (better) decompression time. It, however, requires more memory to decompress[1] and is somewhat less widespread.

So, both gzip and xz format archives are posted, allowing you to pick:

  • Need to decompress on a machine with very limited memory (<128 MB): gzip. Given, not very likely when talking about kernel sources.
  • Need to decompress minimal tools available: gzip
  • Want to save download time and/or bandwidth: xz

There isn't really a realistic combination of factors that'd get you to pick bzip2. So its being phased out.

I looked at compression comparisons in a blog post. I didn't attempt to replicate the results, and I suspect some of it has changed (mostly, I expect xz has improved, as its the newest.)

(There are some specific scenarios where a good bzip2 implementation may be preferable to xz: bzip2 can compresses a file with lots of zeros and genome DNA sequences better than xz; it still possible to recover data after the point of corruption in bzip2 files whereas this is not possible for xz; bzip2 decompression can be parallelized.[2] However none of these are relevant for kernel distribution)


1: This depends on how you count. E.g., in archive size, xz -3 is around bzip -9. Then xz uses less memory to decompress. But xz -9 uses much more than bzip -9.

2: Re: F21 System Wide Change: lbzip2 as default bzip2 implementation

share|improve this answer
    
Any comment on the topic of fault tolerance or is that something that's always implemented completely outside of compression algorithms? –  Amphiteóth Jan 8 at 1:00
1  
@illuminÉ resiliency can't be provided without sacrificing compression ratio. It's an orthogonal problem, and while tools like Parchive exist, for distributing the kernel TCP's error handling does the job just as well. –  Tobu Jan 8 at 8:58
2  
@illuminÉ Fault tolerance (assuming you mean something similar to par2) isn't normally a concern with distributing archives over the Internet. Downloads are assumed reliable enough (and you can just redownload if it was corrupted). Cryptographic hashes and signatures are often used, and they detect corruption as well as tampering. There are compressors that give greater fault tolerance, though at the cost of compression ratio. No one seems to find the tradeoff worth it for HTTP or FTP downloads. –  derobert Jan 8 at 17:02

First of all, this question is not directly related to tar. Tar just creates an uncompressed archive, the compression is then applied later on.

Gzip is known to be relatively fast when compared to LZMA2 and bzip2. If speed matters, gzip (especially the multithreaded implementation pigz) is often a good compromise between compression speed and compression ratio. Although there are alternatives if speed is an issue (e.g. LZ4).

However, if a high compression ratio is desired LZMA2 beats bzip2 in almost every aspect. The compression speed is often slower, but it decompresses much faster and provides a much better compression ratio at the cost of higher memory usage.

There is not much reason to use bzip2 any more, except of backwards compatibility. Furthermore, LZMA2 was desiged with multithreading in mind and many implementations by default make use of multicore CPUs (unfortunately xz on Linux does not do this, yet). This makes sense since the clock speeds won't increase any more but the number of cores will.

There are multithreaded bzip2 implementations (e.g. pbzip), but they are often not installed by default. Also note that multithreaded bzip2 only really pay off while compressing whereas decompression uses a single thread if the file was compress using a single threaded bzip2, in contrast to LZMA2. Parallel bzip2 variants can only leverage multicore CPUs if the file was compressed using a parallel bzip2 version, which is often not the case.

share|improve this answer
3  
Well some tars grok a z option. –  tchrist Jan 7 at 1:19
    
"speed" makes for a muddled answer, you should refer to compression speed or decompression speed. Neither pixz, pbzip2 or pigz are installed by default (or used by tar without the -I flag), but pixz and pbzip2 speed up compression and decompression and pigz is just for compression. –  Tobu Jan 8 at 8:33
    
@Tobu xz will be multithreaded by default so no pixz installation will be required in the future. On some platforms xz threading is supported already. Whereas bzip2 will unlikely ever be multithreaded since the format wasn't designed with multithreading in mind. Furthermore, pbzip2 only speeds up decompression if the file has been compressed using pbzip2 which is often not the case. –  Marco Jan 8 at 12:07

Short answer : xz is more efficient in terms of compression ratio. So it saves disk space and optimizes the transfer through the network.
You can see this Quick Benchmark so as to discover the difference by practical tests.

share|improve this answer

xz is what they are using for the kernel so we're seeing many other packages move to that compression. bzip2 just didnt see the widespread use that .gz did.

gz is still the fastest (even xz can't compete) but while gz archives can be >4GB the size reported is wrong when the archive is over 4GB (2^32). You'll have to decompress it to know how big it will be when decompressed (you can decompress to stdout and count it if you need to). So an archive that is bigger than 4GB that you want to give out and want the downloaders to know how big it will be when de-compressed should probably not be stored in .gz format.

In my experience I'm still just using gzip in most instances and go to .xz for those times that I need the better compression or want to know a large tar.?z's size when uncompressed (w/o uncompressing it to know). Basically if I want better compression, its xz, if I want speed, its gz. So I agree... bye bzip2.

share|improve this answer
    
gzip is not by any means the fastest compression algorithm available; LZOP beats it by leaps and bounds. –  Charles Duffy Nov 2 at 22:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.