Documentation/translations/zh_CN/staging/xz.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/staging/xz.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/staging/xz.rst- Extension
.rst- Size
- 5033 bytes
- Lines
- 101
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/staging/xz.rst
:翻译:
李睿 Rui Li <me@lirui.org>
===================
Linux中的XZ数据压缩
===================
介绍
====
XZ是一种通用的数据压缩格式,其具有高压缩率和相对快的解压速度。主要的压缩算法(
过滤器)是LZMA2。额外的过滤器可以被用来进一步提高压缩率,比如用来提高可执行数据
压缩率的Branch/Call/Jump (BCJ)过滤器。
XZ解压器在Linux中被称作XZ Embedded。它支持LZMA2过滤器和可选的BCJ过滤器,并支持
CRC32完整性校验。你可以在XZ Embedded的主页<https://tukaani.org/xz/embedded.html>
中找到最新版本和关于在Linux内核之外使用源码的信息。
对于用户空间来说,XZ Utils提供了类似于zlib的压缩库和类似于gzip的命令行工具。
XZ Utils可以从<https://tukaani.org/xz/>下载。
内核中的XZ相关组件
==================
xz_dec模块为XZ解压器提供了单次调用(缓冲区到缓冲区)和多次调用(有状态)的
API。xz_dec模块的用法记录在include/linux/xz.h中。
xz_dec_test模块用于测试xz_dec。除非你想魔改XZ解压器,否则xz_dec_test是
没有用的。xz_dec_test会动态分配一个字符设备主设备号,你可以从用户空间向它
写入.xz文件,解压的输出会被丢弃。关注dmesg可以找到xz_dec_test输出的诊断信息。
详细内容请查看xz_dec_test的源码。
为了解压内核镜像、初始ram文件系统和初始ram磁盘,lib/decompress_unxz.c实现
了一个包装函数。它的API与其他 decompress_*.c 文件相同,那些API定义在
include/linux/decompress/generic.h中。
scripts/xz_wrap.sh是一个XZ Utils中的xz命令行工具包装器。这个包装器会
设置合适的压缩选项来压缩内核镜像。
在内核的makefiles中,提供了使用$(call if_needed)的两个命令。内核镜像应该
使用$(call if_needed,xzkern)来压缩,它会使用BCJ过滤器和一个大LZMA2字典。
它还会附加一个四字节的包含源文件大小的预告,这会在启动代码中被用到。其他文件
应该使用$(call if_needed,xzmisc)来压缩,它会使用1 MiB的LZMA2字典并禁用
BCJ过滤器。
关于压缩选项的说明
==================
因为XZ Embedded只支持没有完整性校验的数据流或者CRC32,请确保你在编码未来将被
内核解码的文件时没有使用其他完整性校验方式。使用liblzma时,你需要使用LZMA_CHECK_NONE
或LZMA_CHECK_CRC32。使用xz命令行工具时,使用--check=none或--check=crc32。
除非有其他环节会验证解压数据的完整性,否则强烈使用CRC32。双重验证可能会浪费
CPU周期。请注意头部总是会包含用于解压器验证的CRC32,你只能修改或禁用解压后数据
的完整性校验方式。
在用户中间中,LZMA2通常使用几兆字节大小的字典。解码器需要在RAM中放置字典,
因此大字典不能被用于那些意在被内核解码的文件。1 MiB在内核中大概是可接受的最大
字典大小(可能对初始ram文件系统也适用)。XZ Utils中的预设值可能并不适合创建
内核文件,所以请别犹豫使用自定义设置。比如::
xz --check=crc32 --lzma2=dict=512KiB inputfile
使用上面字典大小的一个例外是在单一调用模式下使用解码器。解压内核自身就是一个例
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.