On 20.12.18 г. 2:57 ч., Qu Wenruo wrote: > > > On 2018/12/19 下午11:41, devzero@xxxxxx wrote: >> does compress-force really force compression? > > It should. > > The only exception is block size. > > If the file is smaller than the sector size (4K for x86_64), then no > compression no matter whatever the mount options are. What FORCE_COMPRESS does is it ensures that compression is always tried for a file (check code in compress_file_range in the if (pages) branch). However, if btrfs_compress_pages detects compression makes no difference then 'if (pages)' branch is executed since will_compress will not be set and only thing it will be do is not set BTRFS_INODE_NOCOMPRESS. What this all means is that with FORCE_COMPRESS future writes will also be tried to be compressed. For example if you do some non-compressible writes on a file with no FORCE_COMPRESS then BTRFS_INODE_NOCOMPRESS will be set. This means that all future invocation of inode_need_compress for this inode will return false. So if at a later time the io pattern changes to one which is compressible then it wont' be compressed. OTOH with force-compress you will also be compressing those portions of the file which are compressible. IMHO the more pertinent question is : If a file has portions which are not easily compressible does that imply all future writes are also incompressible. IMO no, so I think what will be prudent is remove FORCE_COMPRESS altogether and make the code act as if it's always on. Any opinions? > >> >> for me (found via compsize - see https://github.com/kilobyte/compsize/issues/24 ) it looks it is problably forcing compression check for every block of a file (while compress= makes btrfs skip compression check after first block) and if some block is incompressible, apparently it's being stored uncompressed. > > Any reproducer for this unexpected behavior? > > Thanks, > Qu > >> >> so, the documentation is probably telling misleading information and should be fixed!? >> >> roland >> >> >> >> https://btrfs.wiki.kernel.org/index.php/Compression#What_happens_to_incompressible_files.3F >> >> What happens to incompressible files? >> >> There is a simple decision logic: if the first portion of data being compressed is not smaller than the original, the compression of the file is disabled -- unless the filesystem is mounted with -o compress-force. In that case it'll be compressed always regardless of the compressibility of the file. This is not optimal and subject to optimizations and further development. >> >> >> >
