xfs: factor out code to find the longest free extent in the AG

Signed-off-by: Dave Chinner <dgc@sgi.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Dave Chinner 2009-03-16 08:29:46 +01:00 коммит произвёл Christoph Hellwig
Родитель cb4c8cc1e9
Коммит 6cc87645e2
4 изменённых файлов: 31 добавлений и 22 удалений

Просмотреть файл

@ -1871,6 +1871,25 @@ xfs_alloc_compute_maxlevels(
mp->m_ag_maxlevels = level; mp->m_ag_maxlevels = level;
} }
/*
* Find the length of the longest extent in an AG.
*/
xfs_extlen_t
xfs_alloc_longest_free_extent(
struct xfs_mount *mp,
struct xfs_perag *pag)
{
xfs_extlen_t need, delta = 0;
need = XFS_MIN_FREELIST_PAG(pag, mp);
if (need > pag->pagf_flcount)
delta = need - pag->pagf_flcount;
if (pag->pagf_longest > delta)
return pag->pagf_longest - delta;
return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
}
/* /*
* Decide whether to use this allocation group for this allocation. * Decide whether to use this allocation group for this allocation.
* If so, fix up the btree freelist's size. * If so, fix up the btree freelist's size.
@ -1923,15 +1942,12 @@ xfs_alloc_fix_freelist(
} }
if (!(flags & XFS_ALLOC_FLAG_FREEING)) { 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 * If it looks like there isn't a long enough extent, or enough
* total blocks, reject it. * total blocks, reject it.
*/ */
longest = (pag->pagf_longest > delta) ? need = XFS_MIN_FREELIST_PAG(pag, mp);
(pag->pagf_longest - delta) : longest = xfs_alloc_longest_free_extent(mp, pag);
(pag->pagf_flcount > 0 || pag->pagf_longest > 0);
if ((args->minlen + args->alignment + args->minalignslop - 1) > if ((args->minlen + args->alignment + args->minalignslop - 1) >
longest || longest ||
((int)(pag->pagf_freeblks + pag->pagf_flcount - ((int)(pag->pagf_freeblks + pag->pagf_flcount -

Просмотреть файл

@ -100,6 +100,12 @@ typedef struct xfs_alloc_arg {
#define XFS_ALLOC_USERDATA 1 /* allocation is for user data*/ #define XFS_ALLOC_USERDATA 1 /* allocation is for user data*/
#define XFS_ALLOC_INITIAL_USER_DATA 2 /* special case start of file */ #define XFS_ALLOC_INITIAL_USER_DATA 2 /* special case start of file */
/*
* Find the length of the longest extent in an AG.
*/
xfs_extlen_t
xfs_alloc_longest_free_extent(struct xfs_mount *mp,
struct xfs_perag *pag);
#ifdef __KERNEL__ #ifdef __KERNEL__

Просмотреть файл

@ -2712,9 +2712,6 @@ xfs_bmap_btalloc(
xfs_agnumber_t startag; xfs_agnumber_t startag;
xfs_alloc_arg_t args; xfs_alloc_arg_t args;
xfs_extlen_t blen; xfs_extlen_t blen;
xfs_extlen_t delta;
xfs_extlen_t longest;
xfs_extlen_t need;
xfs_extlen_t nextminlen = 0; xfs_extlen_t nextminlen = 0;
xfs_perag_t *pag; xfs_perag_t *pag;
int nullfb; /* true if ap->firstblock isn't set */ int nullfb; /* true if ap->firstblock isn't set */
@ -2796,13 +2793,8 @@ xfs_bmap_btalloc(
* See xfs_alloc_fix_freelist... * See xfs_alloc_fix_freelist...
*/ */
if (pag->pagf_init) { if (pag->pagf_init) {
need = XFS_MIN_FREELIST_PAG(pag, mp); xfs_extlen_t longest;
delta = need > pag->pagf_flcount ? longest = xfs_alloc_longest_free_extent(mp, pag);
need - pag->pagf_flcount : 0;
longest = (pag->pagf_longest > delta) ?
(pag->pagf_longest - delta) :
(pag->pagf_flcount > 0 ||
pag->pagf_longest > 0);
if (blen < longest) if (blen < longest)
blen = longest; blen = longest;
} else } else

Просмотреть файл

@ -140,7 +140,7 @@ _xfs_filestream_pick_ag(
xfs_extlen_t minlen) xfs_extlen_t minlen)
{ {
int err, trylock, nscan; 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; xfs_agnumber_t ag, max_ag = NULLAGNUMBER;
struct xfs_perag *pag; struct xfs_perag *pag;
@ -186,12 +186,7 @@ _xfs_filestream_pick_ag(
goto next_ag; goto next_ag;
} }
need = XFS_MIN_FREELIST_PAG(pag, mp); longest = xfs_alloc_longest_free_extent(mp, pag);
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);
if (((minlen && longest >= minlen) || if (((minlen && longest >= minlen) ||
(!minlen && pag->pagf_freeblks >= minfree)) && (!minlen && pag->pagf_freeblks >= minfree)) &&
(!pag->pagf_metadata || !(flags & XFS_PICK_USERDATA) || (!pag->pagf_metadata || !(flags & XFS_PICK_USERDATA) ||