btrfs: allow defrag compress to override NOCOMPRESS attribute
David Sterba
maintainerPATCH 1/1 btrfs: allow defrag compress to override NOCOMPRESS attribute
Currently, the BTRFS_INODE_NOCOMPRESS will prevent any compression on a given file, except when the mount is force-compress. As users have reported on IRC, this will also prevent compression when requested by defrag (btrfs fi defrag -c file).
The nocompress flag is set automatically by filesystem when the ratios are bad and the user would have to manually drop the bit in order to make defrag -c work. This is not good from the usability perspective.
This patch will raise priority for the defrag -c over nocompress, ie. any file with NOCOMPRESS bit set will get defragmented. The bit will remain untouched.
Alternate option was to also drop the nocompress bit and keep the decision logic as is, but I think this is not the right solution.
--- fs/btrfs/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +4 -2
@@ -399,12 +399,14 @@ static inline int inode_need_compress(struct inode *inode)/* force compress */ if (btrfs_test_opt (fs_info,FORCE_COMPRESS ))return 1 ; +/* force compress when called from defrag */ +if (BTRFS_I (inode)->force_compress) +return 1 ;/* bad compression ratios */ if (BTRFS_I (inode)->flags &BTRFS_INODE_NOCOMPRESS )return 0 ;if (btrfs_test_opt (fs_info,COMPRESS ) || -BTRFS_I (inode)->flags &BTRFS_INODE_COMPRESS || -BTRFS_I (inode)->force_compress) +BTRFS_I (inode)->flags &BTRFS_INODE_COMPRESS )return 1 ;return 0 ; }
Signature · 1 line
2.13.0
Quoted 9 lines · David Sterba
Currently, the
BTRFS_INODE_NOCOMPRESSwill prevent any compression on a given file, except when the mount is force-compress. As users have reported on IRC, this will also prevent compression when requested by defrag (btrfs fi defrag -c file).The nocompress flag is set automatically by filesystem when the ratios are bad and the user would have to manually drop the bit in order to make defrag -c work. This is not good from the usability perspective.
Quoted 6 lines
This patch will raise priority for the defrag -c over nocompress, ie. any file with NOCOMPRESS bit set will get defragmented. The bit will remain untouched.
Alternate option was to also drop the nocompress bit and keep the decision logic as is, but I think this is not the right solution.
Now the compression set through property will act same as '-o compress-force'. Before this patch is was like '-o compress'. I am ok to fix that patch with a new patch.
Thanks, Anand
Quoted 27 lines
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/btrfs/inode.c +4
-2@@ -399,12 +399,14 @@ static inline int inode_need_compress(struct inode *inode)/* force compress */ if (btrfs_test_opt (fs_info,FORCE_COMPRESS ))return 1 ; +/* force compress when called from defrag */ +if (BTRFS_I (inode)->force_compress) +return 1 ;/* bad compression ratios */ if (BTRFS_I (inode)->flags &BTRFS_INODE_NOCOMPRESS )return 0 ;if (btrfs_test_opt (fs_info,COMPRESS ) || -BTRFS_I (inode)->flags &BTRFS_INODE_COMPRESS || -BTRFS_I (inode)->force_compress) +BTRFS_I (inode)->flags &BTRFS_INODE_COMPRESS )return 1 ;return 0 ; }
Quoted 24 lines
-----Original Message-----
From: [email protected] [mailto:linux-btrfs- [email protected]] On Behalf Of Anand Jain
Sent: Saturday, 15 July 2017 2:53 PM
To: David Sterba <[email protected]>; [email protected]
Subject: Re: [PATCH] btrfs: allow defrag compress to override NOCOMPRESS attributeQuoted 1 line · David Sterba
Currently, the
BTRFS_INODE_NOCOMPRESSwill prevent any compressionon
Quoted 12 lines
a given file, except when the mount is force-compress. As users have reported on IRC, this will also prevent compression when requested by defrag (btrfs fi defrag -c file).
The nocompress flag is set automatically by filesystem when the ratios are bad and the user would have to manually drop the bit in order to make defrag -c work. This is not good from the usability perspective.
This patch will raise priority for the defrag -c over nocompress, ie. any file with NOCOMPRESS bit set will get defragmented. The bit will remain untouched.
Quoted 7 lines
Quoted 2 lines
Alternate option was to also drop the nocompress bit and keep the decision logic as is, but I think this is not the right solution.
Now the compression set through property will act same as '-o compress- force'. Before this patch is was like '-o compress'.
I am ok to fix that patch with a new patch.
While we are at it, would it be possible to add an option to remove compression? Ie. btrfs fi defrag -c none file Currently this doesn't seem to exist.
Thanks,
Paul. ���{.n�+�������+%�����ݶ��w��{.n�+����{���k~���^n�r���z���h����&���z��z�ޗ�+��+zf���h���~����i��������z_��j:+v���)ߣ�m
Quoted 14 lines · Anand Jain
Quoted 13 lines · David Sterba
Currently, the
BTRFS_INODE_NOCOMPRESSwill prevent any compression on a given file, except when the mount is force-compress. As users have reported on IRC, this will also prevent compression when requested by defrag (btrfs fi defrag -c file).The nocompress flag is set automatically by filesystem when the ratios are bad and the user would have to manually drop the bit in order to make defrag -c work. This is not good from the usability perspective.
This patch will raise priority for the defrag -c over nocompress, ie. any file with NOCOMPRESS bit set will get defragmented. The bit will remain untouched.
Quoted 6 lines
Quoted 2 lines
Alternate option was to also drop the nocompress bit and keep the decision logic as is, but I think this is not the right solution.
Now the compression set through property will act same as '-o compress-force'. Before this patch is was like '-o compress'.
Right, I missed that. Yet I'm not sure, we actually might want this semantics for the per-file compression option. The mount option 'compress' applies to the whole filesystem so the semantics "try to compress and if it's not a gain, stop and mark the file nocompress".
The per-file compression option is user's intent to compress the file, so the nocompress fallback logic goes against that.
Quoted 1 line
I am ok to fix that patch with a new patch.
Feel free to send the patch, although I think we don't want it, we still can have a discussion. This should help to clarify the semantics of compression behaviour further.
Quoted 15 lines · David Sterba
Quoted 14 lines · Anand Jain
Quoted 13 lines · David Sterba
Currently, the
BTRFS_INODE_NOCOMPRESSwill prevent any compression on a given file, except when the mount is force-compress. As users have reported on IRC, this will also prevent compression when requested by defrag (btrfs fi defrag -c file).The nocompress flag is set automatically by filesystem when the ratios are bad and the user would have to manually drop the bit in order to make defrag -c work. This is not good from the usability perspective.
This patch will raise priority for the defrag -c over nocompress, ie. any file with NOCOMPRESS bit set will get defragmented. The bit will remain untouched.
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Alternate option was to also drop the nocompress bit and keep the decision logic as is, but I think this is not the right solution.
Now the compression set through property will act same as '-o compress-force'. Before this patch is was like '-o compress'.
Actually we'll need to split btrfs_inode::force_compress as defrag will reset it to 0 at the end, which needs to be fixed so it does not conflict with the properties.
Quoted 7 lines · Paul Jones
Quoted 3 lines
Now the compression set through property will act same as '-o compress- force'. Before this patch is was like '-o compress'.
I am ok to fix that patch with a new patch.While we are at it, would it be possible to add an option to remove compression? Ie. btrfs fi defrag -c none file Currently this doesn't seem to exist.
Short answer: yes. As we're going to touch the ioctl and commandline interface for zstd anyway.