From patchwork Fri Apr 8 07:51:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 90285 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E4122B6F8F for ; Fri, 8 Apr 2011 18:06:37 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932161Ab1DHIGg (ORCPT ); Fri, 8 Apr 2011 04:06:36 -0400 Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:56158 "EHLO tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932099Ab1DHIGg (ORCPT ); Fri, 8 Apr 2011 04:06:36 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.193]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id p3886XUN019368; Fri, 8 Apr 2011 17:06:33 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id p3886W608368; Fri, 8 Apr 2011 17:06:32 +0900 (JST) Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv3.nec.co.jp (8.13.8/8.13.4) with ESMTP id p3886WLh029676; Fri, 8 Apr 2011 17:06:32 +0900 (JST) Received: from saigo.jp.nec.com ([10.26.220.6] [10.26.220.6]) by mail02.kamome.nec.co.jp with ESMTP id BT-MMP-298629; Fri, 8 Apr 2011 16:52:02 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTP; Fri, 8 Apr 2011 16:51:59 +0900 Message-ID: <4D9EBE99.5060703@sx.jp.nec.com> Date: Fri, 08 Apr 2011 16:51:53 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: ext4 , Theodore Tso Subject: [PATCH 02/11] filefrag: Output fragmentation score Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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) Signed-off-by: Kazuya Mio --- misc/Makefile.in | 4 ++-- misc/filefrag.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/Makefile.in b/misc/Makefile.in index 86ee53f..19eaa43 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -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 $@" diff --git a/misc/filefrag.c b/misc/filefrag.c index d604b6c..a1fab13 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -41,6 +41,7 @@ extern int optind; #include #include #include +#include "e2p/e2p.h" int verbose = 0; int no_bs = 0; /* Don't use the files blocksize, use 1K blocksize */ @@ -267,6 +268,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 @@ -367,6 +369,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; }