linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PATCH: btrfs defrag ioctl, override extent count and size checks compression enabled.
@ 2012-06-05 16:21 Andrew Mahone
  2012-06-15 15:57 ` Josef Bacik
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Mahone @ 2012-06-05 16:21 UTC (permalink / raw)
  To: linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

I noticed a few days ago that btrfs fi defrag -cXXX can not be used to
compress files unless they are fragmented. The attached patch passes
the compression flag to should_defrag_range, where it disables the
adjacent-extent and extent size checks if set. The inline/sparse
extent check is not modified - I assumed it would not be useful to
compress inline extents.

-- 
Andrew Mahone
andrew DOT mahone AT gmail DOT com\

[-- Attachment #2: btrfs_defrag_compress.patch --]
[-- Type: application/octet-stream, Size: 1558 bytes --]

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 1221a39..49f7903 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -812,7 +812,7 @@ static int check_adjacent_extents(struct inode *inode, struct extent_map *em)
 
 static int should_defrag_range(struct inode *inode, u64 start, u64 len,
 			       int thresh, u64 *last_len, u64 *skip,
-			       u64 *defrag_end)
+			       u64 *defrag_end, int compress)
 {
 	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
 	struct extent_map *em = NULL;
@@ -853,7 +853,7 @@ static int should_defrag_range(struct inode *inode, u64 start, u64 len,
 	}
 
 	/* If we have nothing to merge with us, just skip. */
-	if (check_adjacent_extents(inode, em)) {
+	if (!compress && check_adjacent_extents(inode, em)) {
 		ret = 0;
 		goto out;
 	}
@@ -861,7 +861,8 @@ static int should_defrag_range(struct inode *inode, u64 start, u64 len,
 	/*
 	 * we hit a real extent, if it is big don't bother defragging it again
 	 */
-	if ((*last_len == 0 || *last_len >= thresh) && em->len >= thresh)
+	if (!compress &&
+	    (*last_len == 0 || *last_len >= thresh) && em->len >= thresh)
 		ret = 0;
 
 out:
@@ -1143,7 +1144,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 
 		if (!should_defrag_range(inode, (u64)i << PAGE_CACHE_SHIFT,
 					 PAGE_CACHE_SIZE, extent_thresh,
-					 &last_len, &skip, &defrag_end)) {
+					 &last_len, &skip, &defrag_end,
+					 range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) {
 			unsigned long next;
 			/*
 			 * the should_defrag function tells us how much to skip

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

* Re: PATCH: btrfs defrag ioctl, override extent count and size checks compression enabled.
  2012-06-05 16:21 PATCH: btrfs defrag ioctl, override extent count and size checks compression enabled Andrew Mahone
@ 2012-06-15 15:57 ` Josef Bacik
  0 siblings, 0 replies; 2+ messages in thread
From: Josef Bacik @ 2012-06-15 15:57 UTC (permalink / raw)
  To: Andrew Mahone; +Cc: linux-btrfs

On Tue, Jun 05, 2012 at 12:21:40PM -0400, Andrew Mahone wrote:
> I noticed a few days ago that btrfs fi defrag -cXXX can not be used to
> compress files unless they are fragmented. The attached patch passes
> the compression flag to should_defrag_range, where it disables the
> adjacent-extent and extent size checks if set. The inline/sparse
> extent check is not modified - I assumed it would not be useful to
> compress inline extents.
> 

Need a Signed-off-by: line and please inline your patches, don't attach them.
Once you resubmit I'll include in btrfs-next.  Thanks,

Josef

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

end of thread, other threads:[~2012-06-15 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-05 16:21 PATCH: btrfs defrag ioctl, override extent count and size checks compression enabled Andrew Mahone
2012-06-15 15:57 ` Josef Bacik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).