Skip to contentSkip to conversation

Review: Factor some common freelist checks

PATCH David Chinner 2 participants 2 messages Aug 8, 2007 – Aug 9, 2007 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Suggested by Tim - don't duplicate the code used to check the longest available extent on the freelist.

[we've got to clean up this header include mess.]

---
 fs/xfs/dmapi/xfs_dm.c          |    2 +-
 fs/xfs/dmapi/xfs_dm_bhv.c      |    2 +-
 fs/xfs/dmapi/xfs_dm_fsops.c    |    2 +-
 fs/xfs/linux-2.6/xfs_ioctl.c   |    2 +-
 fs/xfs/linux-2.6/xfs_iops.c    |    2 +-
 fs/xfs/linux-2.6/xfs_ksyms.c   |    2 +-
 fs/xfs/linux-2.6/xfs_lrw.c     |    2 +-
 fs/xfs/linux-2.6/xfs_super.c   |    2 +-
 fs/xfs/linux-2.6/xfs_vfs.c     |    2 +-
 fs/xfs/quota/xfs_dquot.c       |    2 +-
 fs/xfs/quota/xfs_dquot_item.c  |    2 +-
 fs/xfs/quota/xfs_qm.c          |    2 +-
 fs/xfs/quota/xfs_qm_bhv.c      |    2 +-
 fs/xfs/quota/xfs_qm_ksyms.c    |    2 +-
 fs/xfs/quota/xfs_qm_stats.c    |    2 +-
 fs/xfs/quota/xfs_qm_syscalls.c |    2 +-
 fs/xfs/quota/xfs_trans_dquot.c |    2 +-
 fs/xfs/xfs_alloc.c             |    7 ++-----
 fs/xfs/xfs_alloc.h             |   19 +++++++++++++++++--
 fs/xfs/xfs_bmap.c              |   12 ++----------
 fs/xfs/xfs_filestream.c        |    9 ++-------
 fs/xfs/xfs_iomap.c             |    2 +-
 22 files changed, 41 insertions(+), 42 deletions(-)
fs/xfs/xfs_alloc.c +2 -5
Index: 2.6.x-xfs-new/fs/xfs/xfs_alloc.c
===================================================================
@@ -1858,15 +1858,12 @@ xfs_alloc_fix_freelist(
 	}
 
 	if (!(flags & XFS_ALLOC_FLAG_FREEING)) {
-		need = XFS_MIN_FREELIST_PAG(pag, mp);
-		delta = need > pag->pagf_flcount ? need - pag->pagf_flcount : 0;
 		/*
 		 * If it looks like there isn't a long enough extent, or enough
 		 * total blocks, reject it.
 		 */
-		longest = (pag->pagf_longest > delta) ?
-			(pag->pagf_longest - delta) :
-			(pag->pagf_flcount > 0 || pag->pagf_longest > 0);
+		need = XFS_MIN_FREELIST_PAG(pag, mp);
+		xfs_alloc_min_freelist(mp, pag, &longest);
 		if ((args->minlen + args->alignment + args->minalignslop - 1) >
 				longest ||
 		    ((int)(pag->pagf_freeblks + pag->pagf_flcount -
fs/xfs/xfs_alloc.h +17 -2
Index: 2.6.x-xfs-new/fs/xfs/xfs_alloc.h
===================================================================
@@ -19,8 +19,6 @@
 #define	__XFS_ALLOC_H__
 
 struct xfs_buf;
-struct xfs_mount;
-struct xfs_perag;
 struct xfs_trans;
 
 /*
@@ -207,6 +205,23 @@ xfs_alloc_clear_busy(xfs_trans_t *tp,
 		xfs_agnumber_t ag,
 		int idx);
 
+/*
+ * Determine the longest free extent available in the AG supplied
+ */
+STATIC_INLINE void
+xfs_alloc_min_freelist(
+	xfs_mount_t	*mp,
+	xfs_perag_t	*pag,
+	xfs_extlen_t	*longest)
+{
+	xfs_extlen_t	need, delta;
+
+	need = XFS_MIN_FREELIST_PAG(pag, mp);
+	delta = need > pag->pagf_flcount ? need - pag->pagf_flcount : 0;
+	*longest = (pag->pagf_longest > delta) ?
+		  (pag->pagf_longest - delta) :
+		  (pag->pagf_flcount > 0 || pag->pagf_longest > 0);
+}
 
 #endif	/* __KERNEL__ */
 
fs/xfs/xfs_bmap.c +2 -10
Index: 2.6.x-xfs-new/fs/xfs/xfs_bmap.c
===================================================================
@@ -2703,9 +2703,6 @@ xfs_bmap_btalloc(
 	xfs_agnumber_t	startag;
 	xfs_alloc_arg_t	args;
 	xfs_extlen_t	blen;
-	xfs_extlen_t	delta;
-	xfs_extlen_t	longest;
-	xfs_extlen_t	need;
 	xfs_extlen_t	nextminlen = 0;
 	xfs_perag_t	*pag;
 	int		nullfb;		/* true if ap->firstblock isn't set */
@@ -2787,13 +2784,8 @@ xfs_bmap_btalloc(
 			 * See xfs_alloc_fix_freelist...
 			 */
 			if (pag->pagf_init) {
-				need = XFS_MIN_FREELIST_PAG(pag, mp);
-				delta = need > pag->pagf_flcount ?
-					need - pag->pagf_flcount : 0;
-				longest = (pag->pagf_longest > delta) ?
-					(pag->pagf_longest - delta) :
-					(pag->pagf_flcount > 0 ||
-					 pag->pagf_longest > 0);
+				xfs_extlen_t	longest;
+				xfs_alloc_min_freelist(mp, pag, &longest);
 				if (blen < longest)
 					blen = longest;
 			} else
fs/xfs/xfs_filestream.c +2 -7
Index: 2.6.x-xfs-new/fs/xfs/xfs_filestream.c
===================================================================
@@ -140,7 +140,7 @@ _xfs_filestream_pick_ag(
 	xfs_extlen_t	minlen)
 {
 	int		err, trylock, nscan;
-	xfs_extlen_t	delta, longest, need, free, minfree, maxfree = 0;
+	xfs_extlen_t	longest, free, minfree, maxfree = 0;
 	xfs_agnumber_t	ag, max_ag = NULLAGNUMBER;
 	struct xfs_perag *pag;
 
@@ -186,12 +186,7 @@ _xfs_filestream_pick_ag(
 			goto next_ag;
 		}
 
-		need = XFS_MIN_FREELIST_PAG(pag, mp);
-		delta = need > pag->pagf_flcount ? need - pag->pagf_flcount : 0;
-		longest = (pag->pagf_longest > delta) ?
-		          (pag->pagf_longest - delta) :
-		          (pag->pagf_flcount > 0 || pag->pagf_longest > 0);
-
+		xfs_alloc_min_freelist(mp, pag, &longest);
 		if (((minlen && longest >= minlen) ||
 		     (!minlen && pag->pagf_freeblks >= minfree)) &&
 		    (!pag->pagf_metadata || !(flags & XFS_PICK_USERDATA) ||
fs/xfs/linux-2.6/xfs_ioctl.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_ioctl.c
===================================================================
@@ -24,9 +24,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/linux-2.6/xfs_iops.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_iops.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/linux-2.6/xfs_lrw.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_lrw.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/linux-2.6/xfs_super.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_super.c
===================================================================
@@ -25,10 +25,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/linux-2.6/xfs_vfs.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_vfs.c
===================================================================
@@ -25,9 +25,9 @@
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
 #include "xfs_imap.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_quota.h"
 
 int
fs/xfs/xfs_iomap.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/xfs_iomap.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/dmapi/xfs_dm.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/dmapi/xfs_dm.c
===================================================================
@@ -26,9 +26,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
fs/xfs/dmapi/xfs_dm_bhv.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/dmapi/xfs_dm_bhv.c
===================================================================
@@ -26,9 +26,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/dmapi/xfs_dm_fsops.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/dmapi/xfs_dm_fsops.c
===================================================================
@@ -26,9 +26,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/linux-2.6/xfs_ksyms.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_ksyms.c
===================================================================
@@ -27,10 +27,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
fs/xfs/quota/xfs_dquot.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_dquot.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_dquot_item.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_dquot_item.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_qm.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm.c
===================================================================
@@ -25,10 +25,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_qm_bhv.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_bhv.c
===================================================================
@@ -25,10 +25,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_qm_ksyms.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_ksyms.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_qm_stats.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_stats.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_qm_syscalls.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_syscalls.c
===================================================================
@@ -27,10 +27,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
fs/xfs/quota/xfs_trans_dquot.c +1 -1
Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_trans_dquot.c
===================================================================
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
#1 lore raw
Quoted 4 lines · David Chinner

Suggested by Tim - don't duplicate the code used to check the longest available extent on the freelist.

[we've got to clean up this header include mess.]

Just move it out of line, it'squite large anyway if you look at all the branches (and there's two more hidden behing XFS_MIN_FREELIST_PAG).

Also I'd suggest returning longest from the function instead of using a pointer to return the value.

in the end we'd have something like:

xfs_extlen_t
xfs_alloc_min_freelist(

	xfs_mount_t	*mp,
	xfs_perag_t	*pag)
{
	xfs_extlen_t	need, delta;

	need = XFS_MIN_FREELIST_PAG(pag, mp);
	if (need > pag->pagf_flcount)
		delta = need - pag->pagf_flcount;
	else
		delta = 0;

	if (pag->pagf_longest > delta)
		return pag->pagf_longest - delta;
	return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
}
Quoted 419 lines
---
 fs/xfs/dmapi/xfs_dm.c          |    2 +-
 fs/xfs/dmapi/xfs_dm_bhv.c      |    2 +-
 fs/xfs/dmapi/xfs_dm_fsops.c    |    2 +-
 fs/xfs/linux-2.6/xfs_ioctl.c   |    2 +-
 fs/xfs/linux-2.6/xfs_iops.c    |    2 +-
 fs/xfs/linux-2.6/xfs_ksyms.c   |    2 +-
 fs/xfs/linux-2.6/xfs_lrw.c     |    2 +-
 fs/xfs/linux-2.6/xfs_super.c   |    2 +-
 fs/xfs/linux-2.6/xfs_vfs.c     |    2 +-
 fs/xfs/quota/xfs_dquot.c       |    2 +-
 fs/xfs/quota/xfs_dquot_item.c  |    2 +-
 fs/xfs/quota/xfs_qm.c          |    2 +-
 fs/xfs/quota/xfs_qm_bhv.c      |    2 +-
 fs/xfs/quota/xfs_qm_ksyms.c    |    2 +-
 fs/xfs/quota/xfs_qm_stats.c    |    2 +-
 fs/xfs/quota/xfs_qm_syscalls.c |    2 +-
 fs/xfs/quota/xfs_trans_dquot.c |    2 +-
 fs/xfs/xfs_alloc.c             |    7 ++-----
 fs/xfs/xfs_alloc.h             |   19 +++++++++++++++++--
 fs/xfs/xfs_bmap.c              |   12 ++----------
 fs/xfs/xfs_filestream.c        |    9 ++-------
 fs/xfs/xfs_iomap.c             |    2 +-
 22 files changed, 41 insertions(+), 42 deletions(-)

Index: 2.6.x-xfs-new/fs/xfs/xfs_alloc.c
===================================================================

fs/xfs/xfs_alloc.c +2 -5
@@ -1858,15 +1858,12 @@ xfs_alloc_fix_freelist(
 	}
 
 	if (!(flags & XFS_ALLOC_FLAG_FREEING)) {
-		need = XFS_MIN_FREELIST_PAG(pag, mp);
-		delta = need > pag->pagf_flcount ? need - pag->pagf_flcount : 0;
 		/*
 		 * If it looks like there isn't a long enough extent, or enough
 		 * total blocks, reject it.
 		 */
-		longest = (pag->pagf_longest > delta) ?
-			(pag->pagf_longest - delta) :
-			(pag->pagf_flcount > 0 || pag->pagf_longest > 0);
+		need = XFS_MIN_FREELIST_PAG(pag, mp);
+		xfs_alloc_min_freelist(mp, pag, &longest);
 		if ((args->minlen + args->alignment + args->minalignslop - 1) >
 				longest ||
 		    ((int)(pag->pagf_freeblks + pag->pagf_flcount -

Index: 2.6.x-xfs-new/fs/xfs/xfs_alloc.h
===================================================================

fs/xfs/xfs_alloc.h +17 -2
@@ -19,8 +19,6 @@
 #define	__XFS_ALLOC_H__
 
 struct xfs_buf;
-struct xfs_mount;
-struct xfs_perag;
 struct xfs_trans;
 
 /*
@@ -207,6 +205,23 @@ xfs_alloc_clear_busy(xfs_trans_t *tp,
 		xfs_agnumber_t ag,
 		int idx);
 
+/*
+ * Determine the longest free extent available in the AG supplied
+ */
+STATIC_INLINE void
+xfs_alloc_min_freelist(
+	xfs_mount_t	*mp,
+	xfs_perag_t	*pag,
+	xfs_extlen_t	*longest)
+{
+	xfs_extlen_t	need, delta;
+
+	need = XFS_MIN_FREELIST_PAG(pag, mp);
+	delta = need > pag->pagf_flcount ? need - pag->pagf_flcount : 0;
+	*longest = (pag->pagf_longest > delta) ?
+		  (pag->pagf_longest - delta) :
+		  (pag->pagf_flcount > 0 || pag->pagf_longest > 0);
+}
 
 #endif	/* __KERNEL__ */
 

Index: 2.6.x-xfs-new/fs/xfs/xfs_bmap.c
===================================================================

fs/xfs/xfs_bmap.c +2 -10
@@ -2703,9 +2703,6 @@ xfs_bmap_btalloc(
 	xfs_agnumber_t	startag;
 	xfs_alloc_arg_t	args;
 	xfs_extlen_t	blen;
-	xfs_extlen_t	delta;
-	xfs_extlen_t	longest;
-	xfs_extlen_t	need;
 	xfs_extlen_t	nextminlen = 0;
 	xfs_perag_t	*pag;
 	int		nullfb;		/* true if ap->firstblock isn't set */
@@ -2787,13 +2784,8 @@ xfs_bmap_btalloc(
 			 * See xfs_alloc_fix_freelist...
 			 */
 			if (pag->pagf_init) {
-				need = XFS_MIN_FREELIST_PAG(pag, mp);
-				delta = need > pag->pagf_flcount ?
-					need - pag->pagf_flcount : 0;
-				longest = (pag->pagf_longest > delta) ?
-					(pag->pagf_longest - delta) :
-					(pag->pagf_flcount > 0 ||
-					 pag->pagf_longest > 0);
+				xfs_extlen_t	longest;
+				xfs_alloc_min_freelist(mp, pag, &longest);
 				if (blen < longest)
 					blen = longest;
 			} else

Index: 2.6.x-xfs-new/fs/xfs/xfs_filestream.c
===================================================================

fs/xfs/xfs_filestream.c +2 -7
@@ -140,7 +140,7 @@ _xfs_filestream_pick_ag(
 	xfs_extlen_t	minlen)
 {
 	int		err, trylock, nscan;
-	xfs_extlen_t	delta, longest, need, free, minfree, maxfree = 0;
+	xfs_extlen_t	longest, free, minfree, maxfree = 0;
 	xfs_agnumber_t	ag, max_ag = NULLAGNUMBER;
 	struct xfs_perag *pag;
 
@@ -186,12 +186,7 @@ _xfs_filestream_pick_ag(
 			goto next_ag;
 		}
 
-		need = XFS_MIN_FREELIST_PAG(pag, mp);
-		delta = need > pag->pagf_flcount ? need - pag->pagf_flcount : 0;
-		longest = (pag->pagf_longest > delta) ?
-		          (pag->pagf_longest - delta) :
-		          (pag->pagf_flcount > 0 || pag->pagf_longest > 0);
-
+		xfs_alloc_min_freelist(mp, pag, &longest);
 		if (((minlen && longest >= minlen) ||
 		     (!minlen && pag->pagf_freeblks >= minfree)) &&
 		    (!pag->pagf_metadata || !(flags & XFS_PICK_USERDATA) ||

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_ioctl.c
===================================================================

fs/xfs/linux-2.6/xfs_ioctl.c +1 -1
@@ -24,9 +24,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_iops.c
===================================================================

fs/xfs/linux-2.6/xfs_iops.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_lrw.c
===================================================================

fs/xfs/linux-2.6/xfs_lrw.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_super.c
===================================================================

fs/xfs/linux-2.6/xfs_super.c +1 -1
@@ -25,10 +25,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_vfs.c
===================================================================

fs/xfs/linux-2.6/xfs_vfs.c +1 -1
@@ -25,9 +25,9 @@
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
 #include "xfs_imap.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_quota.h"
 
 int

Index: 2.6.x-xfs-new/fs/xfs/xfs_iomap.c
===================================================================

fs/xfs/xfs_iomap.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/dmapi/xfs_dm.c
===================================================================

fs/xfs/dmapi/xfs_dm.c +1 -1
@@ -26,9 +26,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/dmapi/xfs_dm_bhv.c
===================================================================

fs/xfs/dmapi/xfs_dm_bhv.c +1 -1
@@ -26,9 +26,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/dmapi/xfs_dm_fsops.c
===================================================================

fs/xfs/dmapi/xfs_dm_fsops.c +1 -1
@@ -26,9 +26,9 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_ksyms.c
===================================================================

fs/xfs/linux-2.6/xfs_ksyms.c +1 -1
@@ -27,10 +27,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_dquot.c
===================================================================

fs/xfs/quota/xfs_dquot.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_dquot_item.c
===================================================================

fs/xfs/quota/xfs_dquot_item.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm.c
===================================================================

fs/xfs/quota/xfs_qm.c +1 -1
@@ -25,10 +25,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_bhv.c
===================================================================

fs/xfs/quota/xfs_qm_bhv.c +1 -1
@@ -25,10 +25,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_ksyms.c
===================================================================

fs/xfs/quota/xfs_qm_ksyms.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_stats.c
===================================================================

fs/xfs/quota/xfs_qm_stats.c +1 -1
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_qm_syscalls.c
===================================================================

fs/xfs/quota/xfs_qm_syscalls.c +1 -1
@@ -27,10 +27,10 @@
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

Index: 2.6.x-xfs-new/fs/xfs/quota/xfs_trans_dquot.c
===================================================================

fs/xfs/quota/xfs_trans_dquot.c +0 -0
@@ -24,10 +24,10 @@
 #include "xfs_sb.h"

fs/xfs/quota/xfs_trans_dquot.c line 33

Quoted 10 lines
fs/xfs/quota/xfs_trans_dquot.c +1 -1
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_alloc.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"

---end quoted text---