Documentation/staging/lzo.rst

Source file repositories/reference/linux-study-clean/Documentation/staging/lzo.rst

File Facts

System
Linux kernel
Corpus path
Documentation/staging/lzo.rst
Extension
.rst
Size
9585 bytes
Lines
203
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!length) {
               length = ((1 << #bits) - 1)
               length += 255*(number of zero bytes)
               length += first-non-zero-byte
       }
       length += constant (generally 2 or 3)

  For references to the dictionary, distances are relative to the output
  pointer. Distances are encoded using very few bits belonging to certain
  ranges, resulting in multiple copy instructions using different encodings.
  Certain encodings involve one extra byte, others involve two extra bytes
  forming a little-endian 16-bit quantity (marked LE16 below).

  After any instruction except the large literal copy, 0, 1, 2 or 3 literals
  are copied before starting the next instruction. The number of literals that
  were copied may change the meaning and behaviour of the next instruction. In
  practice, only one instruction needs to know whether 0, less than 4, or more
  literals were copied. This is the information stored in the <state> variable
  in this implementation. This number of immediate literals to be copied is
  generally encoded in the last two bits of the instruction but may also be
  taken from the last two bits of an extra operand (eg: distance).

  End of stream is declared when a block copy of distance 0 is seen. Only one
  instruction may encode this distance (0001HLLL), it takes one LE16 operand
  for the distance, thus requiring 3 bytes.

  .. important::

     In the code some length checks are missing because certain instructions
     are called under the assumption that a certain number of bytes follow
     because it has already been guaranteed before parsing the instructions.
     They just have to "refill" this credit if they consume extra bytes. This
     is an implementation design choice independent of the algorithm or
     encoding.

Versions

0: Original version
1: LZO-RLE

Version 1 of LZO implements an extension to encode runs of zeros using run
length encoding. This improves speed for data with many zeros, which is a
common case for zram. This modifies the bitstream in a backwards compatible way
(v1 can correctly decompress v0 compressed data, but v0 cannot read v1 data).

For maximum compatibility, both versions are available under different names
(lzo and lzo-rle). Differences in the encoding are noted in this document with
e.g.: version 1 only.

Byte sequences
==============

  First byte encoding::

      0..16   : follow regular instruction encoding, see below. It is worth
                noting that code 16 will represent a block copy from the
                dictionary which is empty, and that it will always be
                invalid at this place.

      17      : bitstream version. If the first byte is 17, and compressed
                stream length is at least 5 bytes (length of shortest possible
                versioned bitstream), the next byte gives the bitstream version
                (version 1 only).
                Otherwise, the bitstream version is 0.

      18..21  : copy 0..3 literals
                state = (byte - 17) = 0..3  [ copy <state> literals ]
                skip byte

      22..255 : copy literal string

Annotation

Implementation Notes