Jump to content
  • Consider using compress-force instead of compress for Btrfs compression


    JSE
    • Annoyance

    The current unraid default when you enable compression on btrfs in 6.12 is compress=zstd. (can be confirmed with mtab). However, this is generally not recommended by most in the btrfs community.

     

    Instead, compress-force should be used instead. The reason is, with compress, if the first 64KiB of a file is not compressible, Btrfs will not even attempt to compress the rest of the data. Compress-force meanwhile will attempt to compress the entire file, even if the first 64KiB isn't compressible (which can definitely be the case for many files). 

     

    Using compress-force wont have any noticeable impact on performance, and in no case will it use more disk space. ZSTD compression is blazing fast, and any data that isn't compressible will be discarded anyway.

     

    Doing this will significantly increase compression ratios. Benchmarks a few years ago show default level 3 compresion, which Unraid is using will achieve over 800MiB/s on a Xeon E3 1650, so only on NVMEs would it potentially be a bottleneck. That's a rather old CPU as well, newer CPUs will be even faster.




    User Feedback

    Recommended Comments

    Don't have a strong opinion one way or the other, from previous searches I see some recommendations to use compress, others to use compress-force, I believe Arch Linux also defaults to compress=zstd:3, I have two file systems that I am considering compressing (the other ones have mostly media files so compression doesn't really help), one is used for docker containers, the other for my VMs, did some tests using those files since it's the ones I'm interested in how they perform, test was done copying all the files from both filesystems (around 2k small files from the containers and some larger ones and 5 larger vdisks) from one NVMe device (formatted xfs) to another, CPU in this test server is a quad core Skylake Xeon (E3-1220 v5), cp speed is based on the uncompressed size:


     

                                 time     used space      cp speed
    uncompressed              7m57.281s     311GB        651.61MB/s
    compress=zstd:3           7m41.138s     306GB        674.42MB/s
    compress-force=zstd:3    13m43.869s     163GB        377.49MB/s

     

    While this shows that like you mentioned some files (most in this case) will not get compressed with just the compress option, it also shows that the performance is clearly affected with compress-force, of course for the actual use case, i.e., docker/VMs speed doesn't really get near the copy speeds, so possibly not a big impact, curiously, and since I'm also considering converting these to zfs, also tested zfs uncompressed and compressed and with zfs the performance is much better with compression enabled, better than the uncompressed speed, with a compression ratio just a little lower than btrfs compress-force, but it uses lz4, not zstd, so differences are expected.

     

    Anyway it's just one data point, and it does look like just compress might skip a lot of compressible files, but performance suffers, I guess the best setting depends on your priority, space or speed.

    Link to comment
    4 hours ago, JorgeB said:

    Don't have a strong opinion one way or the other, from previous searches I see some recommendations to use compress, others to use compress-force, I believe Arch Linux also defaults to compress=zstd:3, I have two file systems that I am considering compressing (the other ones have mostly media files so compression doesn't really help), one is used for docker containers, the other for my VMs, did some tests using those files since it's the ones I'm interested in how they perform, test was done copying all the files from both filesystems (around 2k small files from the containers and some larger ones and 5 larger vdisks) from one NVMe device (formatted xfs) to another, CPU in this test server is a quad core Skylake Xeon (E3-1220 v5), cp speed is based on the uncompressed size:


     

                                 time     used space      cp speed
    uncompressed              7m57.281s     311GB        651.61MB/s
    compress=zstd:3           7m41.138s     306GB        674.42MB/s
    compress-force=zstd:3    13m43.869s     163GB        377.49MB/s

     

    While this shows that like you mentioned some files (most in this case) will not get compressed with just the compress option, it also shows that the performance is clearly affected with compress-force, of course for the actual use case, i.e., docker/VMs speed doesn't really get near the copy speeds, so possibly not a big impact, curiously, and since I'm also considering converting these to zfs, also tested zfs uncompressed and compressed and with zfs the performance is much better with compression enabled, better than the uncompressed speed, with a compression ratio just a little lower than btrfs compress-force, but it uses lz4, not zstd, so differences are expected.

     

    Anyway it's just one data point, and it does look like just compress might skip a lot of compressible files, but performance suffers, I guess the best setting depends on your priority, space or speed.

    The reason the compress option instead of compress-force was faster is *because* it straight up just didn't compress your files for the most part ;) . You might as well not use compression with the compress mount option, as the algorithm is known to be poor. Many files can have headers or first portions not compressible, yet the file straight up gets skipped based on the first 64KiB.

     

    Keep in mind, filesystem fragmentation can also play a part in these benchmarks. I'm not certain how fragmented it was, particularly free space. If you did a full balance in particular, free space would be less fragmented and that could improve performance of compress-force. The referenced benchmark was performed on a ramdisk to eliminate that bottleneck.

     

    At any rate, the fact ZFS is faster is just yet another example of the downsides of btrfs in my opinion. ZFS is always going to be faster. However, in my opinion, if people want compression, it's a given it will have CPU overhead. The point is to trade CPU for disk space, so in my opinion, this just further shows how the force option should be used.

     

    I've actually been doing this on UnRAID manually via a remount script with user scripts. I was hopeful the built in compress option would allow me to eliminate that.

     

    Most in the btrfs community recommend it over the standard compress option, especially with zstd compression. Like everything btrfs, the official documentation can be outdated.

    Edited by JSE
    Link to comment
    10 hours ago, JSE said:

    Keep in mind, filesystem fragmentation can also play a part in these benchmarks.

    It should not affect these tests since the files are being copied from a new xfs filesystem to a new btrfs/zfs filesystem.

     

    10 hours ago, JSE said:

    At any rate, the fact ZFS is faster is just yet another example of the downsides of btrfs in my opinion. ZFS is always going to be faster. However, in my opinion, if people want compression, it's a given it will have CPU overhead. The point is to trade CPU for disk space, so in my opinion, this just further shows how the force option should be used.

     

    Yeah, but zfs with compression with this data is faster that zfs/btrs without compression, these were the results of the same test with zfs:


     

                            time      used space        cp speed
    uncompressed zfs      8m37.722s      320GB         618.09MB/s
    compressed zfs        5m08.942s      185GB        1035.80MB/s

     

     

    Link to comment
    1 hour ago, JorgeB said:

    It should not affect these tests since the files are being copied from a new xfs filesystem to a new btrfs/zfs filesystem.

    Hmmm interesting, then it should also have been faster tbh.

     

    1 hour ago, JorgeB said:

    Yeah, but zfs with compression with this data is faster that zfs/btrs without compression

    What I meant by that is ZFS is just a better fs when it comes to performance. ZFS' ARC caching alone is a big difference. Btrfs has a lot of performance downsides.

     

    That said, many people do see performance upsides with Btrfs transparent compression and compress-force, since often the CPU is capable of compressing data faster and the block device is the bottleneck. I wonder if a lower compression level would help. If you could try :2 or :1, you might see much better performance.

     

    I'm not personally asking for adding compression level support in this release, it seems to be planned for later. I would just prefer compress would be switched out for compress-force so that compression can actually work :)

    Link to comment
    10 minutes ago, JSE said:

    I would just prefer compress would be switched out for compress-force so that compression can actually work

    Yeah, it would be nice to see more tests with different data but I'm inclined to agree, looks like just compress might not actually do much, LT plans to add compression levels later, so possibly this can be changed at that time, or have both options with compress-force as the default.

    Link to comment

    I think it would be nice to have it swapped out for compress-force now, before the next stable release. The current option should just straight up be forgot about imo. It's kinda useless. 

    Link to comment


    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.
    Note: Your post will require moderator approval before it will be visible.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Restore formatting

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


  • Status Definitions

     

    Open = Under consideration.

     

    Solved = The issue has been resolved.

     

    Solved version = The issue has been resolved in the indicated release version.

     

    Closed = Feedback or opinion better posted on our forum for discussion. Also for reports we cannot reproduce or need more information. In this case just add a comment and we will review it again.

     

    Retest = Please retest in latest release.


    Priority Definitions

     

    Minor = Something not working correctly.

     

    Urgent = Server crash, data loss, or other showstopper.

     

    Annoyance = Doesn't affect functionality but should be fixed.

     

    Other = Announcement or other non-issue.

×
×
  • Create New...