Arch Linuxのパッケージ作成に Zstandard を使用する
Zstarndard とは
Facebook 社が開発した比較的新しい可逆圧縮アルゴリズムです。Cで実装され、今後各OSで広く浸透してくるものと思われます。 性能については以下が詳しいですが、gzip より大きい圧縮率を誇りながら、それでいて圧縮にかかる時間、伸長にかかる時間ともに大幅に短いという優れものです。
最近 Arch Linux においても使用できるようになりましたので、そのインストールや設定の仕方をメモします。
Arch Linux でのインストール
Core パッケージに入ってきていますので、sのまま pacman でインストールできます。
$ sudo pacman -S zstd
主な機能は以下の通り。
圧縮
ファイルを圧縮する。拡張子は zst になる。
$ zstd inputfile
圧縮レベルを使用して圧縮。以下の例は圧縮レベルを11とした。
$ zstd -11 inputfile
出力ファイルの名前を指定して圧縮。
$ zstd inputfile -o outputfile.zst
伸長
ファイルを伸長する。
$ zstd -d inputfile.zst
以下でも同様です。
$ unzstd inputfile.zst
主なオプション
$ zstd --help *** zstd command line interface 64-bits v1.4.4, by Yann Collet *** Usage : zstd [args] [FILE(s)] [-o file] FILE : a filename with no FILE, or when FILE is - , read standard input Arguments : -# : # compression level (1-19, default: 3) -d : decompression -D file: use `file` as Dictionary -o file: result stored into `file` (only if 1 input file) -f : overwrite output without prompting and (de)compress links --rm : remove source file(s) after successful de/compression -k : preserve source file(s) (default) -h/-H : display help/long help and exit Advanced arguments : -V : display Version number and exit -v : verbose mode; specify multiple times to increase verbosity -q : suppress warnings; specify twice to suppress errors too -c : force write to standard output, even if it is the console -l : print information about zstd compressed files --exclude-compressed: only compress files that are not previously compressed --ultra : enable levels beyond 19, up to 22 (requires more memory) --long[=#]: enable long distance matching with given window log (default: 27) --fast[=#]: switch to very fast compression levels (default: 1) --adapt : dynamically adapt compression level to I/O conditions --stream-size=# : optimize compression parameters for streaming input of given number of bytes --size-hint=# optimize compression parameters for streaming input of approximately this size --target-compressed-block-size=# : make compressed block near targeted size -T# : spawns # compression threads (default: 1, 0==# cores) -B# : select size of each job (default: 0==automatic) --rsyncable : compress using a rsync-friendly method (-B sets block size) --no-dictID : don't write dictID into header (dictionary compression) --[no-]check : integrity check (default: enabled) --[no-]compress-literals : force (un)compressed literals -r : operate recursively on directories --output-dir-flat[=directory]: all resulting files stored into `directory`. --format=zstd : compress files to the .zst format (default) --format=gzip : compress files to the .gz format --format=xz : compress files to the .xz format --format=lzma : compress files to the .lzma format --format=lz4 : compress files to the .lz4 format --test : test compressed file integrity --[no-]sparse : sparse mode (default: enabled on file, disabled on stdout) -M# : Set a memory usage limit for decompression --no-progress : do not display the progress bar -- : All arguments after "--" are treated as files Dictionary builder : --train ## : create a dictionary from a training set of files --train-cover[=k=#,d=#,steps=#,split=#,shrink[=#]] : use the cover algorithm with optional args --train-fastcover[=k=#,d=#,f=#,steps=#,split=#,accel=#,shrink[=#]] : use the fast cover algorithm with optional args --train-legacy[=s=#] : use the legacy algorithm with selectivity (default: 9) -o file : `file` is dictionary name (default: dictionary) --maxdict=# : limit dictionary to specified size (default: 112640) --dictID=# : force dictionary ID to specified value (default: random) Benchmark arguments : -b# : benchmark file(s), using # compression level (default: 3) -e# : test all compression levels from -bX to # (default: 1) -i# : minimum evaluation time in seconds (default: 3s) -B# : cut file into independent blocks of size # (default: no block) --priority=rt : set process priority to real-time
makepkg.conf
最新の pacman (執筆時点では 5.2.1-1 )を導入していれば、 makepkg.conf に自動的に Zstandard についての以下のような項目が追加されています。
/etc/makepkg.conf
COMPRESSZST=(zstd -c -z -q -)
もし見当たらない場合は追記してください。
カーネルなど、パッケージ作成時の圧縮伸長に Zstandard をデフォルトにしたい場合は、以下のように変更します。
/etc/makepkg.conf
PKGEXT='.pkg.tar.zst'
以上で、makepkg を実行した際に作成されるパッケージファイルは Zstandard で圧縮されます。