Skip to contentSkip to conversation

btrfs: allow defrag compress to override NOCOMPRESS attribute

PATCH In review David Sterba 4 participants 6 messages Jul 13, 2017 – Jul 17, 2017 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 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
index 5d3c6ac960fd..ea2f02ec0394 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · David Sterba

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.

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
---
  fs/btrfs/inode.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +4 -2
index 5d3c6ac960fd..ea2f02ec0394 100644
@@ -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;
  }
#2 lore raw
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 attribute

Quoted 1 line · David Sterba

Currently, the BTRFS_INODE_NOCOMPRESS will prevent any compression

on

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

#3 lore raw
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.

#4 lore raw
In reply to Anand Jain
Quoted 14 lines · Anand Jain
Quoted 13 lines · David Sterba

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.

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.

#5 lore raw
Quoted 15 lines · David Sterba
Quoted 14 lines · Anand Jain
Quoted 13 lines · David Sterba

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.

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.