Skip to contentSkip to conversation

e4defrag: output blocks per extent by -c option

PATCH Superseded Kazuya Mio 2 participants 6 messages Sep 30, 2009 – Oct 6, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kazuya Mio

author
#0 lore raw

PATCH 1/3 e4defrag: output blocks per extent by -c option

e4defrag with -c option outputs "ratio" that means the levels of fragmentation. However, it's difficult for users to understand, so we will use blocks per extent instead of ratio.

Before:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best          ratio
/mnt/mp1/file                                   14/1             0.01%
 Total/best extents                             14/1
 Fragmentation ratio                            0.01%
 Fragmentation score                            0.10

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

After:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best        blk/ext
/mnt/mp1/file                                   14/1              7142
 Total/best extents                             14/1
 Average blocks per extent                      7142
 Fragmentation score                            0

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

---

 e4defrag.c |   61 +++++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 20 deletions(-)
misc/e4defrag.c +41 -20
index 82e3868..ca63229 100644
@@ -160,6 +160,7 @@ struct move_extent {
 struct frag_statistic_ino {
 	int now_count;	/* the file's extents count of before defrag */
 	int best_count; /* the best file's extents count */
+	__u64 blk_per_ext;	/* blocks per extent */
 	float ratio;	/* the ratio of fragmentation */
 	char msg_buffer[PATH_MAX + 1];	/* pathname of the file */
 };
@@ -1212,6 +1213,7 @@ static int file_statistic(const char *file, const struct stat64 *buf,
 	int	ret;
 	int	now_ext_count, best_ext_count = 0, physical_ext_count;
 	int	i, j;
+	__u64	blk_per_ext = 0;
 	float	ratio = 0.0;
 	ext4_fsblk_t	blk_count = 0;
 	char	msg_buffer[PATH_MAX + 24];
@@ -1312,12 +1314,13 @@ static int file_statistic(const char *file, const struct stat64 *buf,
 	now_ext_count = get_logical_count(logical_list_head);
 
 	if (current_uid == ROOT_UID) {
-		/* Calculate fragment ratio  */
+		/* Calculate the blocks per extent  */
 		blk_count =
 				SECTOR_TO_BLOCK(buf->st_blocks, block_size);
 
 		best_ext_count = get_best_count(blk_count);
 
+		blk_per_ext = blk_count / now_ext_count;
 		ratio = (float)(physical_ext_count - best_ext_count) * 100 /
 							blk_count;
 
@@ -1346,16 +1349,16 @@ static int file_statistic(const char *file, const struct stat64 *buf,
 
 		} else {
 			printf("%-40s%10s/%-10s%9s\n",
-					"<File>", "now", "best", "ratio");
+					"<File>", "now", "best", "blk/ext");
 			if (current_uid == ROOT_UID) {
 				if (strlen(file) > 40)
-					printf("%s\n%50d/%-10d%8.2f%%\n",
+					printf("%s\n%50d/%-10d%9llu\n",
 						file, now_ext_count,
-						best_ext_count, ratio);
+						best_ext_count, blk_per_ext);
 				else
-					printf("%-40s%10d/%-10d%8.2f%%\n",
+					printf("%-40s%10d/%-10d%9llu\n",
 						file, now_ext_count,
-						best_ext_count, ratio);
+						best_ext_count, blk_per_ext);
 			} else {
 				if (strlen(file) > 40)
 					printf("%s\n%50d/%-10s%7s\n",
@@ -1378,14 +1381,14 @@ static int file_statistic(const char *file, const struct stat64 *buf,
 		if (current_uid == ROOT_UID) {
 			if (strlen(msg_buffer) > 40)
 				printf("\033[79;0H\033[K%s\n"
-						"%50d/%-10d%8.2f%%\n",
+						"%50d/%-10d%9llu\n",
 						msg_buffer, now_ext_count,
-						best_ext_count, ratio);
+						best_ext_count, blk_per_ext);
 			else
 				printf("\033[79;0H\033[K%-40s"
-						"%10d/%-10d%8.2f%%\n",
+						"%10d/%-10d%9llu\n",
 						msg_buffer, now_ext_count,
-						best_ext_count, ratio);
+						best_ext_count, blk_per_ext);
 		} else {
 			if (strlen(msg_buffer) > 40)
 				printf("\033[79;0H\033[K%s\n%50d/%-10s%7s\n",
@@ -1401,8 +1404,20 @@ static int file_statistic(const char *file, const struct stat64 *buf,
 	for (i = 0; i < SHOW_FRAG_FILES; i++) {
 		if (ratio >= frag_rank[i].ratio) {
 			for (j = SHOW_FRAG_FILES - 1; j > i; j--) {
-				memcpy(&frag_rank[j], &frag_rank[j - 1],
+				memset(&frag_rank[j], 0,
 					sizeof(struct frag_statistic_ino));
+				strncpy(frag_rank[j].msg_buffer,
+					frag_rank[j - 1].msg_buffer,
+					strnlen(frag_rank[j - 1].msg_buffer,
+					PATH_MAX));
+				frag_rank[j].now_count =
+					frag_rank[j - 1].now_count;
+				frag_rank[j].best_count =
+					frag_rank[j - 1].best_count;
+				frag_rank[j].blk_per_ext =
+					frag_rank[j - 1].blk_per_ext;
+				frag_rank[j].ratio =
+					frag_rank[j - 1].ratio;
 			}
 			memset(&frag_rank[i], 0,
 					sizeof(struct frag_statistic_ino));
@@ -1410,6 +1425,7 @@ static int file_statistic(const char *file, const struct stat64 *buf,
 						strnlen(file, PATH_MAX));
 			frag_rank[i].now_count = now_ext_count;
 			frag_rank[i].best_count = best_ext_count;
+			frag_rank[i].blk_per_ext = blk_per_ext;
 			frag_rank[i].ratio = ratio;
 			break;
 		}
@@ -1992,7 +2008,7 @@ int main(int argc, char *argv[])
 			if (mode_flag & STATISTIC) {
 				if (mode_flag & DETAIL)
 					printf("%-40s%10s/%-10s%9s\n",
-					"<File>", "now", "best", "ratio");
+					"<File>", "now", "best", "blk/ext");
 
 				if (!(mode_flag & DETAIL) &&
 						current_uid != ROOT_UID) {
@@ -2009,24 +2025,26 @@ int main(int argc, char *argv[])
 						printf("\n");
 					printf("%-40s%10s/%-10s%9s\n",
 						"<Fragmented files>", "now",
-						"best", "ratio");
+						"best", "blk/ext");
 					for (j = 0; j < SHOW_FRAG_FILES; j++) {
 						if (strlen(frag_rank[j].
 							msg_buffer) > 37) {
 							printf("%d. %s\n%50d/"
-							"%-10d%8.2f%%\n", j + 1,
+							"%-10d%9llu\n", j + 1,
 							frag_rank[j].msg_buffer,
 							frag_rank[j].now_count,
 							frag_rank[j].best_count,
-							frag_rank[j].ratio);
+							frag_rank[j].
+								blk_per_ext);
 						} else if (strlen(frag_rank[j].
 							msg_buffer) > 0) {
 							printf("%d. %-37s%10d/"
-							"%-10d%8.2f%%\n", j + 1,
+							"%-10d%9llu\n", j + 1,
 							frag_rank[j].msg_buffer,
 							frag_rank[j].now_count,
 							frag_rank[j].best_count,
-							frag_rank[j].ratio);
+							frag_rank[j].
+								blk_per_ext);
 						} else
 							break;
 					}
@@ -2109,16 +2127,19 @@ int main(int argc, char *argv[])
 			} else {
 				float files_ratio = 0.0;
 				float score = 0.0;
+				__u64 blk_per_ext = files_block_count /
+						extents_before_defrag;
+
 				files_ratio = (float)(extents_before_defrag -
 						extents_after_defrag) *
 						100 / files_block_count;
 				score = CALC_SCORE(files_ratio);
 				printf("\n Total/best extents\t\t\t\t%d/%d\n"
-					" Fragmentation ratio\t\t\t\t%.2f%%\n"
-					" Fragmentation score\t\t\t\t%.2f\n",
+					" Average blocks per extent\t\t\t%llu\n"
+					" Fragmentation score\t\t\t\t%.0f\n",
 						extents_before_defrag,
 						extents_after_defrag,
-						files_ratio, score);
+						blk_per_ext, score);
 				printf(" [0-30 no problem:"
 					" 31-55 a little bit fragmented:"
 					" 55- needs defrag]\n");
#1 lore raw

2009/9/30 Kazuya Mio <[email protected]>:

Quoted 21 lines

e4defrag with -c option outputs "ratio" that means the levels of fragmentation. However, it's difficult for users to understand, so we will use blocks per extent instead of ratio.

Before:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best          ratio
/mnt/mp1/file                                   14/1             0.01%

 Total/best extents                             14/1 Fragmentation ratio                            0.01% Fragmentation score                            0.10 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

After:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best        blk/ext
/mnt/mp1/file                                   14/1              7142
Quoted 6 lines

 Total/best extents                             14/1 Average blocks per extent                      7142 Fragmentation score                            0
 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

RFC

If we are going go that far (which I like), how about adding the avg extent size in bytes. (ie. 7142 * blocksize I assume).

Also a note about the max blocks / extent might be good.

ie. Add a more or less hard coded line
Ext4 max blocks per extent 32,768 (128MiB)

Otherwise your typical user won't know what perfect is.

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

author
#2 lore raw

2009/10/01 3:28, Greg Freemyer wrote::

Quoted 31 lines

2009/9/30 Kazuya Mio <[email protected]>:

Quoted 21 lines

e4defrag with -c option outputs "ratio" that means the levels of fragmentation. However, it's difficult for users to understand, so we will use blocks per extent instead of ratio.

Before:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best          ratio
/mnt/mp1/file                                   14/1             0.01%
 Total/best extents                             14/1
 Fragmentation ratio                            0.01%
 Fragmentation score                            0.10

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

After:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best        blk/ext
/mnt/mp1/file                                   14/1              7142
Quoted 6 lines
 Total/best extents                             14/1
 Average blocks per extent                      7142
 Fragmentation score                            0

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

RFC

Quoted 7 lines

If we are going go that far (which I like), how about adding the avg extent size in bytes. (ie. 7142 * blocksize I assume).

Also a note about the max blocks / extent might be good.

ie. Add a more or less hard coded line
Ext4 max blocks per extent 32,768 (128MiB)

Your ideas sound good. How about the following output image?

# e4defrag -c /mnt/mp1/file
<File>                                         now/best         KB/ext
/mnt/mp1/file                                   14/1              4000
 Total/best extents                             14/1
 Min bytes per extent                           1024 KB
 Max bytes per extent                           20489 KB
 Average bytes per extent                       4000 KB
 Fragmentation score                            0

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

Regards,

Kazuya Mio

#3 lore raw

2009/10/1 Kazuya Mio <[email protected]>:

Quoted 55 lines

2009/10/01 3:28, Greg Freemyer wrote::

Quoted 31 lines

2009/9/30 Kazuya Mio <[email protected]>:

Quoted 21 lines

e4defrag with -c option outputs "ratio" that means the levels of fragmentation. However, it's difficult for users to understand, so we will use blocks per extent instead of ratio.

Before:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best          ratio
/mnt/mp1/file                                   14/1             0.01%

 Total/best extents                             14/1 Fragmentation ratio                            0.01% Fragmentation score                            0.10 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

After:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best        blk/ext
/mnt/mp1/file                                   14/1              7142
Quoted 6 lines

 Total/best extents                             14/1 Average blocks per extent                      7142 Fragmentation score                            0
 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

RFC

Quoted 7 lines

If we are going go that far (which I like), how about adding the avg extent size in bytes.  (ie. 7142 * blocksize I assume).

Also a note about the max blocks / extent might be good.

ie. Add a more or less hard coded line
Ext4 max blocks per extent     32,768  (128MiB)

Your ideas sound good. How about the following output image?

# e4defrag -c /mnt/mp1/file
<File>                                         now/best         KB/ext
/mnt/mp1/file                                   14/1              4000

 Total/best extents                             14/1
 Min bytes per extent                           1024 KB Max bytes per extent                           20489 KB Average bytes per extent                       4000 KB Fragmentation score                            0
 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

Quoted 3 lines

Regards,

Kazuya Mio

I was thinking more of the theoretical max bytes per extent, not the largest extent found in the actual file.

I say this because most users of e4defrag won't know what perfection is, so they won't know if and when they have come close if they don't know what the ultimate goal is.

Specifically, think of a admin hosting a few virtual machines where the virtual disks are ext4 files. They could easily be 100's of GB so they may think even 128MB / extent can be improved on, even though they have already achieved the theoretical max.

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

author
#4 lore raw

2009/10/03 0:28, Greg Freemyer wrote::

Quoted 65 lines

2009/10/1 Kazuya Mio <[email protected]>:

Quoted 49 lines

2009/10/01 3:28, Greg Freemyer wrote::

Quoted 30 lines

2009/9/30 Kazuya Mio <[email protected]>:

Quoted 21 lines

e4defrag with -c option outputs "ratio" that means the levels of fragmentation. However, it's difficult for users to understand, so we will use blocks per extent instead of ratio.

Before:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best          ratio
/mnt/mp1/file                                   14/1             0.01%
 Total/best extents                             14/1
 Fragmentation ratio                            0.01%
 Fragmentation score                            0.10

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

After:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best        blk/ext
/mnt/mp1/file                                   14/1              7142
Quoted 6 lines
 Total/best extents                             14/1
 Average blocks per extent                      7142
 Fragmentation score                            0

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

RFC

Quoted 7 lines

If we are going go that far (which I like), how about adding the avg extent size in bytes. (ie. 7142 * blocksize I assume).

Also a note about the max blocks / extent might be good.

ie. Add a more or less hard coded line
Ext4 max blocks per extent 32,768 (128MiB)

Your ideas sound good. How about the following output image?

# e4defrag -c /mnt/mp1/file
<File>                                         now/best         KB/ext
/mnt/mp1/file                                   14/1              4000
 Total/best extents                             14/1
 Min bytes per extent                           1024 KB
 Max bytes per extent                           20489 KB
 Average bytes per extent                       4000 KB
 Fragmentation score                            0
Quoted 7 lines

[0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

Regards,

Kazuya Mio

I was thinking more of the theoretical max bytes per extent, not the largest extent found in the actual file.

I say this because most users of e4defrag won't know what perfection is, so they won't know if and when they have come close if they don't know what the ultimate goal is.

Quoted 6 lines

Specifically, think of a admin hosting a few virtual machines where the virtual disks are ext4 files. They could easily be 100's of GB so they may think even 128MB / extent can be improved on, even though they have already achieved the theoretical max.

Greg

I see. But I think e4defrag doesn't always need to print logical max bytes per extent. So, I will add it to e4defrag man page instead of standard output. What do you think?

Regards,

Kazuya Mio

#5 lore raw

2009/10/6 Kazuya Mio <[email protected]>:

Quoted 73 lines

2009/10/03 0:28, Greg Freemyer wrote::

Quoted 65 lines

2009/10/1 Kazuya Mio <[email protected]>:

Quoted 53 lines

2009/10/01 3:28, Greg Freemyer wrote::

Quoted 30 lines

2009/9/30 Kazuya Mio <[email protected]>:

Quoted 21 lines

e4defrag with -c option outputs "ratio" that means the levels of fragmentation. However, it's difficult for users to understand, so we will use blocks per extent instead of ratio.

Before:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best          ratio
/mnt/mp1/file                                   14/1             0.01%

 Total/best extents                             14/1 Fragmentation ratio                            0.01% Fragmentation score                            0.10 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

After:

# e4defrag -c /mnt/mp1/file
<File>                                         now/best        blk/ext
/mnt/mp1/file                                   14/1              7142
Quoted 6 lines

 Total/best extents                             14/1 Average blocks per extent                      7142 Fragmentation score                            0
 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

RFC

Quoted 7 lines

If we are going go that far (which I like), how about adding the avg extent size in bytes.  (ie. 7142 * blocksize I assume).

Also a note about the max blocks / extent might be good.

ie. Add a more or less hard coded line
Ext4 max blocks per extent     32,768  (128MiB)

Your ideas sound good. How about the following output image?

# e4defrag -c /mnt/mp1/file
<File>                                         now/best         KB/ext
/mnt/mp1/file                                   14/1              4000

 Total/best extents                             14/1
 Min bytes per extent                           1024 KB Max bytes per extent                           20489 KB Average bytes per extent                       4000 KB Fragmentation score                            0
 [0-30 no problem: 31-55 a little bit fragmented: 55- needs defrag] This file(/mnt/mp1/file) does not need defragmentation. Done.

Quoted 3 lines

Regards,

Kazuya Mio

I was thinking more of the theoretical max bytes per extent, not the largest extent found in the actual file.

I say this because most users of e4defrag won't know what perfection is, so they won't know if and when they have come close if they don't know what the ultimate goal is.

Quoted 6 lines

Specifically, think of a admin hosting a few virtual machines where the virtual disks are ext4 files.  They could easily be 100's of GB so they may think even 128MB / extent can be improved on, even though they have already achieved the theoretical max.

Greg

Quoted 7 lines

I see. But I think e4defrag doesn't always need to print logical max bytes per extent. So, I will add it to e4defrag man page instead of standard output. What do you think?

Regards,

Kazuya Mio

I had not thought about the man page for some reason, but it would satisfy my concern.

Greg

Signature · 14 lines
Greg Freemyer
Head of EDD Tape Extraction and Processing team
Litigation Triage Solutions Specialist
http://www.linkedin.com/in/gregfreemyer
Preservation and Forensic processing of Exchange Repositories White Paper -
<http://www.norcrossgroup.com/forms/whitepapers/tng_whitepaper_fpe.html>

The Norcross Group
The Intersection of Evidence & Technology
http://www.norcrossgroup.com
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html