public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* xfs_fsr allocation group optimization
@ 2007-06-11  6:51 Johan Andersson
  2007-06-11  7:35 ` Chris Wedgwood
  2007-06-12  1:44 ` David Chinner
  0 siblings, 2 replies; 15+ messages in thread
From: Johan Andersson @ 2007-06-11  6:51 UTC (permalink / raw)
  To: xfs

[-- Attachment #1: Type: text/plain, Size: 1624 bytes --]

Hi!

Last week I discovered that one of our volumes had 87%(!) file
fragmentation. Number of extents per file was in the range of thousands!
Nothing you are used to when it comes to XFS...
The filesystem is 68% full, but was up to 99% full for a short period a
couple of weeks earlier.

The xfs_fsr utility is made for this kind of problem, but after reading
more about xfs_fsr, in particular this:
http://oss.sgi.com/archives/xfs/2003-02/msg00141.html
I was more sceptical.

So I run some tests. And as Chris pointed out, when running xfs_fsr on a
badly fragmented filesystem, it completely destroys the locality of
files.

Then I decided to try to fix this, so I wrote a dirty little proof of
concept hack to xfs_fsr.c (diff against cvs attached) that finds one
name for the inode it defrags, and places the temporary file it's parent
directory. This way, it will restore the broken locality.

This works fine, after running it on the badly fragmented filesystem,
both fragmentation and locality was better than ever!

However, this fix is as I said "dirty". It uses find -inum to find a
filename for an inode. This makes it quite slow. Not much of a problem
for a one-time problem like this, but it's not very nice to put this
into a cron-job. There must be a better way to find the filename. But
I'm not familiar with the internals of XFS, so I thought I ask on this
list:
Does anyone know of a good way to find one filename that points o a
certain inode? I can't use xfs_db ncheck, as the filesystem is mounted.
Or is there a way to tell XFS to place extents in a newly created file
in a certain AG?

/Johan Andersson


[-- Attachment #2: xfs_fsr-agfix.diff --]
[-- Type: text/x-patch, Size: 1522 bytes --]

Index: xfs_fsr.c
===================================================================
RCS file: /cvs/xfs-cmds/xfsdump/fsr/xfs_fsr.c,v
retrieving revision 1.28
diff -u -r1.28 xfs_fsr.c
--- xfs_fsr.c	24 May 2007 03:59:42 -0000	1.28
+++ xfs_fsr.c	11 Jun 2007 06:42:29 -0000
@@ -655,10 +655,12 @@
 	int	ret;
 	__s32	buflenout;
 	xfs_bstat_t buf[GRABSZ];
-	char	fname[64];
+	char	fname[PATH_MAX+1];
 	char	*tname;
+	char    cmd[64];
 	jdm_fshandle_t	*fshandlep;
 	xfs_ino_t	lastino = startino;
+	FILE    *pfname;
 
 	fsrprintf(_("%s start inode=%llu\n"), mntdir,
 		(unsigned long long)startino);
@@ -714,11 +716,20 @@
 				continue;
 			}
 
-			/* Don't know the pathname, so make up something */
-			sprintf(fname, "ino=%lld", (long long)p->bs_ino);
-
-			/* Get a tmp file name */
-			tname = tmp_next(mntdir);
+			/* Find (one) filename that this inode belongs to. */
+			snprintf(cmd, sizeof(cmd), "find %s -xdev -inum %lld -print0", mntdir, (long long)p->bs_ino);
+			pfname = popen(cmd, "r");
+			fgets(fname, sizeof(fname), pfname);
+			pclose(pfname);
+			
+			if (strlen(fname)) {
+			  tname = gettmpname(fname);
+			} else {
+			  /* Don't know the pathname, so make up something */
+			  snprintf(fname, sizeof(fname), "ino=%lld", (long long)p->bs_ino);
+			  /* Get a tmp file name */
+			  tname = tmp_next(mntdir);
+			} 
 
 			ret = fsrfile_common(fname, tname, mntdir, fd, p);
 
@@ -1297,6 +1308,8 @@
 
 	strcat(buf, sbuf);
 
+	fsrprintf(_("gettmpname: fname=%s, buf=%s\n"), fname, buf);
+
 	return(buf);
 }
 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2007-06-15  7:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-11  6:51 xfs_fsr allocation group optimization Johan Andersson
2007-06-11  7:35 ` Chris Wedgwood
2007-06-11  8:43   ` Johan Andersson
2007-06-11  9:01     ` Chris Wedgwood
2007-06-11  9:15       ` Johan Andersson
2007-06-11  9:41         ` Chris Wedgwood
2007-06-11 10:39           ` Johan Andersson
2007-06-11 15:58             ` Chris Wedgwood
2007-06-11 23:07               ` Nathan Scott
2007-06-12  1:38                 ` David Chinner
2007-06-12  1:41         ` David Chinner
2007-06-12  1:44 ` David Chinner
2007-06-15  7:20   ` Timothy Shimmin
2007-06-15  7:24     ` Nathan Scott
2007-06-15  7:40     ` Johan Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox