[PATCH] resize2fs: fix over-pessimistic heuristic.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In worst case we need one extent per moved block. Number of blocks to
be moved is less or equals to blks_needed.

Signed-off-by: Dmitry Monakhov <dmonakhov@xxxxxxxxxx>
---
 resize/resize2fs.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index f5f1337..8ca53a3 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -2587,11 +2587,17 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags)
 	/*
 	 * We need to reserve a few extra blocks if extents are
 	 * enabled, in case we need to grow the extent tree.  The more
-	 * we shrink the file system, the more space we need.
+	 * we shrink the file system, the more blocks will be moved.
+	 * Worse case is one extent per moved block.
 	 */
 	if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) {
-		blk64_t safe_margin = (ext2fs_blocks_count(fs->super) -
-				       blks_needed)/500;
+		blk64_t safe_margin = ext2fs_blocks_count(fs->super)
+			- blks_needed;
+
+		if (safe_margin > blks_needed)
+			safe_margin = blks_needed;
+		safe_margin /= 500;
+
 #ifdef RESIZE2FS_DEBUG
 		if (flags & RESIZE_DEBUG_MIN_CALC)
 			printf("Extents safety margin: %llu\n", safe_margin);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux