faq.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. XZ Utils FAQ
  2. ============
  3. Q: What do the letters XZ mean?
  4. A: Nothing. They are just two letters, which come from the file format
  5. suffix .xz. The .xz suffix was selected, because it seemed to be
  6. pretty much unused. It has no deeper meaning.
  7. Q: What are LZMA and LZMA2?
  8. A: LZMA stands for Lempel-Ziv-Markov chain-Algorithm. It is the name
  9. of the compression algorithm designed by Igor Pavlov for 7-Zip.
  10. LZMA is based on LZ77 and range encoding.
  11. LZMA2 is an updated version of the original LZMA to fix a couple of
  12. practical issues. In context of XZ Utils, LZMA is called LZMA1 to
  13. emphasize that LZMA is not the same thing as LZMA2. LZMA2 is the
  14. primary compression algorithm in the .xz file format.
  15. Q: There are many LZMA related projects. How does XZ Utils relate to them?
  16. A: 7-Zip and LZMA SDK are the original projects. LZMA SDK is roughly
  17. a subset of the 7-Zip source tree.
  18. p7zip is 7-Zip's command-line tools ported to POSIX-like systems.
  19. LZMA Utils provide a gzip-like lzma tool for POSIX-like systems.
  20. LZMA Utils are based on LZMA SDK. XZ Utils are the successor to
  21. LZMA Utils.
  22. There are several other projects using LZMA. Most are more or less
  23. based on LZMA SDK. See <https://7-zip.org/links.html>.
  24. Q: Why is liblzma named liblzma if its primary file format is .xz?
  25. Shouldn't it be e.g. libxz?
  26. A: When the designing of the .xz format began, the idea was to replace
  27. the .lzma format and use the same .lzma suffix. It would have been
  28. quite OK to reuse the suffix when there were very few .lzma files
  29. around. However, the old .lzma format became popular before the
  30. new format was finished. The new format was renamed to .xz but the
  31. name of liblzma wasn't changed.
  32. Q: Do XZ Utils support the .7z format?
  33. A: No. Use 7-Zip (Windows) or p7zip (POSIX-like systems) to handle .7z
  34. files.
  35. Q: I have many .tar.7z files. Can I convert them to .tar.xz without
  36. spending hours recompressing the data?
  37. A: In the "extra" directory, there is a script named 7z2lzma.bash which
  38. is able to convert some .7z files to the .lzma format (not .xz). It
  39. needs the 7za (or 7z) command from p7zip. The script may silently
  40. produce corrupt output if certain assumptions are not met, so
  41. decompress the resulting .lzma file and compare it against the
  42. original before deleting the original file!
  43. Q: I have many .lzma files. Can I quickly convert them to the .xz format?
  44. A: For now, no. Since XZ Utils supports the .lzma format, it's usually
  45. not too bad to keep the old files in the old format. If you want to
  46. do the conversion anyway, you need to decompress the .lzma files and
  47. then recompress to the .xz format.
  48. Technically, there is a way to make the conversion relatively fast
  49. (roughly twice the time that normal decompression takes). Writing
  50. such a tool would take quite a bit of time though, and would probably
  51. be useful to only a few people. If you really want such a conversion
  52. tool, contact Lasse Collin and offer some money.
  53. Q: I have installed xz, but my tar doesn't recognize .tar.xz files.
  54. How can I extract .tar.xz files?
  55. A: xz -dc foo.tar.xz | tar xf -
  56. Q: Can I recover parts of a broken .xz file (e.g. a corrupted CD-R)?
  57. A: It may be possible if the file consists of multiple blocks, which
  58. typically is not the case if the file was created in single-threaded
  59. mode. There is no recovery program yet.
  60. Q: Is (some part of) XZ Utils patented?
  61. A: Lasse Collin is not aware of any patents that could affect XZ Utils.
  62. However, due to the nature of software patents, it's not possible to
  63. guarantee that XZ Utils isn't affected by any third party patent(s).
  64. Q: Where can I find documentation about the file format and algorithms?
  65. A: The .xz format is documented in xz-file-format.txt. It is a container
  66. format only, and doesn't include descriptions of any non-trivial
  67. filters.
  68. Documenting LZMA and LZMA2 is planned, but for now, there is no other
  69. documentation than the source code. Before you begin, you should know
  70. the basics of LZ77 and range-coding algorithms. LZMA is based on LZ77,
  71. but LZMA is a lot more complex. Range coding is used to compress
  72. the final bitstream like Huffman coding is used in Deflate.
  73. Q: I cannot find BCJ and BCJ2 filters. Don't they exist in liblzma?
  74. A: BCJ filter is called "x86" in liblzma. BCJ2 is not included,
  75. because it requires using more than one encoded output stream.
  76. Q: I need to use a script that runs "xz -9". On a system with 256 MiB
  77. of RAM, xz says that it cannot allocate memory. Can I make the
  78. script work without modifying it?
  79. A: Set a default memory usage limit for compression. You can do it e.g.
  80. in a shell initialization script such as ~/.bashrc or /etc/profile:
  81. XZ_DEFAULTS=--memlimit-compress=150MiB
  82. export XZ_DEFAULTS
  83. xz will then scale the compression settings down so that the given
  84. memory usage limit is not reached. This way xz shouldn't run out
  85. of memory.
  86. Check also that memory-related resource limits are high enough.
  87. On most systems, "ulimit -a" will show the current resource limits.
  88. Q: How do I create files that can be decompressed with XZ Embedded?
  89. A: See the documentation in XZ Embedded. In short, something like
  90. this is a good start:
  91. xz --check=crc32 --lzma2=preset=6e,dict=64KiB
  92. Or if a BCJ filter is needed too, e.g. if compressing
  93. a kernel image for PowerPC:
  94. xz --check=crc32 --powerpc --lzma2=preset=6e,dict=64KiB
  95. Adjust the dictionary size to get a good compromise between
  96. compression ratio and decompressor memory usage. Note that
  97. in single-call decompression mode of XZ Embedded, a big
  98. dictionary doesn't increase memory usage.
  99. Q: How is multi-threaded compression implemented in XZ Utils?
  100. A: The simplest method is splitting the uncompressed data into blocks
  101. and compressing them in parallel independent from each other.
  102. This is currently the only threading method supported in XZ Utils.
  103. Since the blocks are compressed independently, they can also be
  104. decompressed independently. Together with the index feature in .xz,
  105. this allows using threads to create .xz files for random-access
  106. reading. This also makes threaded decompression possible.
  107. The independent blocks method has a couple of disadvantages too. It
  108. will compress worse than a single-block method. Often the difference
  109. is not too big (maybe 1-2 %) but sometimes it can be too big. Also,
  110. the memory usage of the compressor increases linearly when adding
  111. threads.
  112. At least two other threading methods are possible but these haven't
  113. been implemented in XZ Utils:
  114. Match finder parallelization has been in 7-Zip for ages. It doesn't
  115. affect compression ratio or memory usage significantly. Among the
  116. three threading methods, only this is useful when compressing small
  117. files (files that are not significantly bigger than the dictionary).
  118. Unfortunately this method scales only to about two CPU cores.
  119. The third method is pigz-style threading (I use that name, because
  120. pigz <https://www.zlib.net/pigz/> uses that method). It doesn't
  121. affect compression ratio significantly and scales to many cores.
  122. The memory usage scales linearly when threads are added. This isn't
  123. significant with pigz, because Deflate uses only a 32 KiB dictionary,
  124. but with LZMA2 the memory usage will increase dramatically just like
  125. with the independent-blocks method. There is also a constant
  126. computational overhead, which may make pigz-method a bit dull on
  127. dual-core compared to the parallel match finder method, but with more
  128. cores the overhead is not a big deal anymore.
  129. Combining the threading methods will be possible and also useful.
  130. For example, combining match finder parallelization with pigz-style
  131. threading or independent-blocks-threading can cut the memory usage
  132. by 50 %.
  133. Q: I told xz to use many threads but it is using only one or two
  134. processor cores. What is wrong?
  135. A: Since multi-threaded compression is done by splitting the data into
  136. blocks that are compressed individually, if the input file is too
  137. small for the block size, then many threads cannot be used. The
  138. default block size increases when the compression level is
  139. increased. For example, xz -6 uses 8 MiB LZMA2 dictionary and
  140. 24 MiB blocks, and xz -9 uses 64 MiB LZMA dictionary and 192 MiB
  141. blocks. If the input file is 100 MiB, xz -6 can use five threads
  142. of which one will finish quickly as it has only 4 MiB to compress.
  143. However, for the same file, xz -9 can only use one thread.
  144. One can adjust block size with --block-size=SIZE but making the
  145. block size smaller than LZMA2 dictionary is waste of RAM: using
  146. xz -9 with 6 MiB blocks isn't any better than using xz -6 with
  147. 6 MiB blocks. The default settings use a block size bigger than
  148. the LZMA2 dictionary size because this was seen as a reasonable
  149. compromise between RAM usage and compression ratio.
  150. When decompressing, the ability to use threads depends on how the
  151. file was created. If it was created in multi-threaded mode then
  152. it can be decompressed in multi-threaded mode too if there are
  153. multiple blocks in the file.
  154. Q: How do I build a program that needs liblzmadec (lzmadec.h)?
  155. A: liblzmadec is part of LZMA Utils. XZ Utils has liblzma, but no
  156. liblzmadec. The code using liblzmadec should be ported to use
  157. liblzma instead. If you cannot or don't want to do that, download
  158. LZMA Utils from <https://tukaani.org/lzma/>.
  159. Q: The default build of liblzma is too big. How can I make it smaller?
  160. A: Give --enable-small to the configure script. Use also appropriate
  161. --enable or --disable options to include only those filter encoders
  162. and decoders and integrity checks that you actually need. Use
  163. CFLAGS=-Os (with GCC) or equivalent to tell your compiler to optimize
  164. for size. See INSTALL for information about configure options.
  165. If the result is still too big, take a look at XZ Embedded. It is
  166. a separate project, which provides a limited but significantly
  167. smaller XZ decoder implementation than XZ Utils. You can find it
  168. at <https://tukaani.org/xz/embedded.html>.