filefrag: Output fragmentation score
PATCH RESEND 2/11 filefrag: Output fragmentation score
This patch adds the fragmentation score to the output of filefrag. The threshold that shows whether a fragment is good or not comes from "blocksize * 8 - 2048". "blocksize * 8 - 2048" is the maximum number of contiguous blocks which we can get from empty blockgroup containing some metadata blocks.
For example, filefrag shows fragmentation score as follows:
# filefrag /mnt/mp1/testfile /mnt/mp1/testfile: 4 extents found Fragmentation score: 33 (found a little bit fragmentation)
--- misc/Makefile.in | 4 ++-- misc/filefrag.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-)
misc/Makefile.in +2 -2
@@ -306,9 +306,9 @@ e2freefrag: $(E2FREEFRAG_OBJS) $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -o e2freefrag $(E2FREEFRAG_OBJS) $(LIBS) -filefrag: $(FILEFRAG_OBJS) +filefrag: $(FILEFRAG_OBJS) $(DEPLIBS_E2P) $(E) " LD $@" - $(Q) $(CC) $(ALL_LDFLAGS) -o filefrag $(FILEFRAG_OBJS) + $(Q) $(CC) $(ALL_LDFLAGS) -o filefrag $(FILEFRAG_OBJS) $(DEPLIBS_E2P) filefrag.profiled: $(PROFILED_FILEFRAG_OBJS) $(E) " LD $@"
misc/filefrag.c +28 -0
@@ -41,6 +41,7 @@ extern int optind;#include <linux/fd.h> #include <ext2fs/ext2_types.h> #include <ext2fs/fiemap.h> +#include "e2p/e2p.h" int verbose =0 ;int no_bs =0 ;/* Don't use the files blocksize, use 1K blocksize */
@@ -279,6 +280,7 @@ static void frag_report(const char *filename)int is_ext2 =0 ;static int once =1 ;unsigned int flags; +int score;int rc;#ifdef HAVE_OPEN64
@@ -379,6 +381,32 @@ static void frag_report(const char *filename) (expected>1) ? "s" : ""); else fputc('\n', stdout); + +if (!xattr_map) { +/* +* Get the fragmentation score. +* NOTE: 2048 means the maximum block region of mballoc. +*/ + score =get_fragment_score (fd, + (fsinfo.f_bsize *8 -2048 ) * fsinfo.f_bsize); + +/* +* Print fragmentation score with some comments +* 0-30 no problem, 31-55 a little bit fragmented, +* 56- needs defrag +*/ +if (score <0 ) + ; +else if (score <=30 ) +printf ("Fragmentation score: %d (no problem)\n" , score); +else if (score <=55 ) +printf ("Fragmentation score: %d " +"(found a little bit fragmentation)\n" , score); +else +printf ("Fragmentation score: %d " +"(need to do e4defrag command)\n" , score); + } +close (fd); once =0 ; }
Quoted 11 lines · Kazuya Mio
This patch adds the fragmentation score to the output of filefrag. The threshold that shows whether a fragment is good or not comes from "blocksize * 8 - 2048". "blocksize * 8 - 2048" is the maximum number of contiguous blocks which we can get from empty blockgroup containing some metadata blocks.
For example, filefrag shows fragmentation score as follows:
# filefrag /mnt/mp1/testfile /mnt/mp1/testfile: 4 extents found Fragmentation score: 33 (found a little bit fragmentation)
It would probably be just as clear, and a lot more compact to keep only a single line per file:
# filefrag /mnt/mp1/testfile /mnt/mp1/testfile: 4 extents found, 33% fragmented
or similar like "..., fragmentation score 33/100" if we don't like to use percent.
Quoted 79 lines
Signed-off-by Kazuya Mio <[email protected]>---
misc/Makefile.in | 4 ++--misc/filefrag.c| 28 ++++++++++++++++++++++++++++2 files changed, 30 insertions(+), 2 deletions(-)misc/Makefile.in +2
-2@@ -306,9 +306,9 @@ e2freefrag: $(E2FREEFRAG_OBJS) $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -o e2freefrag $(E2FREEFRAG_OBJS) $(LIBS) -filefrag: $(FILEFRAG_OBJS) +filefrag: $(FILEFRAG_OBJS) $(DEPLIBS_E2P) $(E) " LD $@" - $(Q) $(CC) $(ALL_LDFLAGS) -o filefrag $(FILEFRAG_OBJS) + $(Q) $(CC) $(ALL_LDFLAGS) -o filefrag $(FILEFRAG_OBJS) $(DEPLIBS_E2P) filefrag.profiled: $(PROFILED_FILEFRAG_OBJS) $(E) " LD $@"misc/filefrag.c +1
-0@@ -41,6 +41,7 @@ extern int optind;#include <linux/fd.h> #include <ext2fs/ext2_types.h> #include <ext2fs/fiemap.h> +#include "e2p/e2p.h" int verbose =0 ;int
no_bs= 0; /* Don't use the files blocksize, use 1K blocksize */misc/filefrag.c +27
-1@@ -279,6 +280,7 @@ static void frag_report(const char *filename)int is_ext2 =0 ;static int once =1 ;unsigned int flags; +int score;int rc;#ifdef HAVE_OPEN64 @@ -379,6 +381,32 @@ static void frag_report(const char *filename) (expected>1) ? "s" : ""); else fputc('\n', stdout); + +if (!xattr_map) { +/* +* Get the fragmentation score. +* NOTE: 2048 means the maximum block region of mballoc. +*/ + score =get_fragment_score (fd, + (fsinfo.f_bsize *8 -2048 ) * fsinfo.f_bsize); + +/* +* Print fragmentation score with some comments +* 0-30 no problem, 31-55 a little bit fragmented, +* 56- needs defrag +*/ +if (score <0 ) + ; +else if (score <=30 ) +printf ("Fragmentation score: %d (no problem)\n" , score); +else if (score <=55 ) +printf ("Fragmentation score: %d " +"(found a little bit fragmentation)\n" , score); +else +printf ("Fragmentation score: %d " +"(need to do e4defrag command)\n" , score); + } +close (fd); once =0 ; } --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