From: Kazuya Mio <k-mio@sx.jp.nec.com>
To: linux-ext4@vger.kernel.org, Theodore Tso <tytso@mit.edu>
Subject: [PATCH 1/3] e4defrag: output blocks per extent by -c option
Date: Wed, 30 Sep 2009 16:20:16 +0900 [thread overview]
Message-ID: <4AC306B0.9070308@sx.jp.nec.com> (raw)
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.
Signed-off-by: Kazuya Mio <k-mio@sx.jp.nec.com>
---
e4defrag.c | 61 +++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 41 insertions(+), 20 deletions(-)
diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index 82e3868..ca63229 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -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");
next reply other threads:[~2009-09-30 7:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-30 7:20 Kazuya Mio [this message]
2009-09-30 18:28 ` [PATCH 1/3] e4defrag: output blocks per extent by -c option Greg Freemyer
2009-10-01 8:15 ` Kazuya Mio
2009-10-02 15:28 ` Greg Freemyer
2009-10-06 5:27 ` Kazuya Mio
2009-10-06 18:24 ` Greg Freemyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AC306B0.9070308@sx.jp.nec.com \
--to=k-mio@sx.jp.nec.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.