Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* Question about btrfs compression
@ 2024-05-23 18:32 Sijie Lan
  2024-05-28 16:06 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Sijie Lan @ 2024-05-23 18:32 UTC (permalink / raw)
  To: linux-btrfs, wqu

As described in
https://archive.kernel.org/oldwiki/btrfs.wiki.kernel.org/index.php/Compression.html.
"The compression processes ranges of a file of maximum size 128 KiB
and compresses each 4 KiB (or page-sized) block separately. Accessing
a byte in the middle of the given 128 KiB range requires to decompress
the whole range. This is not optimal and is subject to optimizations
and further development."

Since Btrfs compresses each 4KiB block of data separately. My question
is that when randomly accessing some of the bytes in the entire
compressed chunk, decompressing some of the bytes in the entire chunk
seems to be much more efficient than decompressing the entire range
(128 KiB), but the current method still decompresses the entire 128KiB
chunk when accessing some of the bytes in the chunk (e.g., 4KiB). So
why is it not optimized for this, is it a basic implementation
difficulty or something else?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question about btrfs compression
  2024-05-23 18:32 Question about btrfs compression Sijie Lan
@ 2024-05-28 16:06 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2024-05-28 16:06 UTC (permalink / raw)
  To: Sijie Lan; +Cc: linux-btrfs, wqu

On Fri, May 24, 2024 at 02:32:38AM +0800, Sijie Lan wrote:
> As described in
> https://archive.kernel.org/oldwiki/btrfs.wiki.kernel.org/index.php/Compression.html.
> "The compression processes ranges of a file of maximum size 128 KiB
> and compresses each 4 KiB (or page-sized) block separately. Accessing
> a byte in the middle of the given 128 KiB range requires to decompress
> the whole range. This is not optimal and is subject to optimizations
> and further development."
> 
> Since Btrfs compresses each 4KiB block of data separately. My question
> is that when randomly accessing some of the bytes in the entire
> compressed chunk, decompressing some of the bytes in the entire chunk
> seems to be much more efficient than decompressing the entire range
> (128 KiB), but the current method still decompresses the entire 128KiB
> chunk when accessing some of the bytes in the chunk (e.g., 4KiB). So
> why is it not optimized for this, is it a basic implementation
> difficulty or something else?

Technically it's possible. I'm not sure if this would be that noticeable
because page cache readahead reads more memory around what is accessed
so the requested range could be bigger once it ends up in the
decompression.

Assuming we're reading 4k page, we'd need to support seeking into the
compressed stream.  This depends on the used compression algorithm,
we'd need somehow let each decompression to start from there.

For LZO the chunking is done manually, as it needs a contiguous buffer
and referes to previous data directly. We could skip the segments,
though I'm not sure if we store the compressed size (ie. the amount to
skip).

Zstd or zlib keep the state separately and there's no outer container so
we'd need API support for that, returning offset in compressed stream
for a given uncompressed offset in the result. I'm not familiar with the
formats but to make this work the internal segments would have to track
the compressed size and would be able to go over them without
decompression.

The last thing is probably the interface for btrfs compression to fill
just the given range.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-28 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 18:32 Question about btrfs compression Sijie Lan
2024-05-28 16:06 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox