All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Ignore unfragmented file checks in defrag when compression enabled
@ 2012-06-18 17:27 Andrew Mahone
  2012-06-18 17:27 ` [PATCH] btrfs: ignore " Andrew Mahone
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Mahone @ 2012-06-18 17:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Andrew Mahone

I noticed that btrfs fi defrag -c<method> can't be used to compress files
unless they are fragmented. This patch corrects the problem, by informing
should_defrag_range if compression is enabled, and skipping tests for extent
and adjacent extents if it is.

Andrew Mahone (1):
  btrfs: ignore unfragmented file checks in defrag when compression
    enabled

 fs/btrfs/ioctl.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

-- 
1.7.10.2


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

* [PATCH] btrfs: ignore unfragmented file checks in defrag when compression enabled
  2012-06-18 17:27 [PATCH] Ignore unfragmented file checks in defrag when compression enabled Andrew Mahone
@ 2012-06-18 17:27 ` Andrew Mahone
  2012-06-19 15:01   ` Josef Bacik
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Mahone @ 2012-06-18 17:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Andrew Mahone

Inform should_defrag_range if BTRFS_DEFRAG_RANGE_COMPRESS is set. If so, skip
checks for adjacent extents and extent size when deciding whether to defrag,
as these can prevent an uncompressed and unfragmented file from being
compressed as requested.

Signed-off-by: Andrew Mahone <andrew.mahone@gmail.com>
---
 fs/btrfs/ioctl.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 24b776c..ac48d7f 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
-- 
1.7.10.2


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

* Re: [PATCH] btrfs: ignore unfragmented file checks in defrag when compression enabled
  2012-06-18 17:27 ` [PATCH] btrfs: ignore " Andrew Mahone
@ 2012-06-19 15:01   ` Josef Bacik
  2012-06-20  1:08     ` [PATCH] btrfs: ignore unfragmented file checks in defrag when compression enabled - rebased Andrew Mahone
  0 siblings, 1 reply; 4+ messages in thread
From: Josef Bacik @ 2012-06-19 15:01 UTC (permalink / raw)
  To: Andrew Mahone; +Cc: linux-btrfs

On Mon, Jun 18, 2012 at 01:27:37PM -0400, Andrew Mahone wrote:
> Inform should_defrag_range if BTRFS_DEFRAG_RANGE_COMPRESS is set. If so, skip
> checks for adjacent extents and extent size when deciding whether to defrag,
> as these can prevent an uncompressed and unfragmented file from being
> compressed as requested.
> 
> Signed-off-by: Andrew Mahone <andrew.mahone@gmail.com>

This patch does not apply cleanly at all, please rebase onto btrfs-next and
resend.  Thanks,

Josef

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

* [PATCH] btrfs: ignore unfragmented file checks in defrag when compression enabled - rebased
  2012-06-19 15:01   ` Josef Bacik
@ 2012-06-20  1:08     ` Andrew Mahone
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Mahone @ 2012-06-20  1:08 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Josef Bacik, Andrew Mahone

Rebased on btrfs-next and retested.

Inform should_defrag_range if BTRFS_DEFRAG_RANGE_COMPRESS is set. If so, skip
checks for adjacent extents and extent size when deciding whether to defrag,
as these can prevent an uncompressed and unfragmented file from being
compressed as requested.

Signed-off-by: Andrew Mahone <andrew.mahone@gmail.com>
---
 fs/btrfs/ioctl.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0e92e57..9ec23b9 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -832,7 +832,8 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em)
 }
 
 static int should_defrag_range(struct inode *inode, u64 start, int thresh,
-			       u64 *last_len, u64 *skip, u64 *defrag_end)
+			       u64 *last_len, u64 *skip, u64 *defrag_end,
+			       int compress)
 {
 	struct extent_map *em;
 	int ret = 1;
@@ -863,7 +864,7 @@ static int should_defrag_range(struct inode *inode, u64 start, int thresh,
 	 * we hit a real extent, if it is big or the next extent is not a
 	 * real extent, don't bother defragging it
 	 */
-	if ((*last_len == 0 || *last_len >= thresh) &&
+	if (!compress && (*last_len == 0 || *last_len >= thresh) &&
 	    (em->len >= thresh || !next_mergeable))
 		ret = 0;
 out:
@@ -1145,7 +1146,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 
 		if (!should_defrag_range(inode, (u64)i << PAGE_CACHE_SHIFT,
 					 extent_thresh, &last_len, &skip,
-					 &defrag_end)) {
+					 &defrag_end, range->flags &
+					 BTRFS_DEFRAG_RANGE_COMPRESS)) {
 			unsigned long next;
 			/*
 			 * the should_defrag function tells us how much to skip
-- 
1.7.10.4


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

end of thread, other threads:[~2012-06-20  1:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-18 17:27 [PATCH] Ignore unfragmented file checks in defrag when compression enabled Andrew Mahone
2012-06-18 17:27 ` [PATCH] btrfs: ignore " Andrew Mahone
2012-06-19 15:01   ` Josef Bacik
2012-06-20  1:08     ` [PATCH] btrfs: ignore unfragmented file checks in defrag when compression enabled - rebased Andrew Mahone

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.