[PATCH 5/5] xfs: modify the logic to comply with AF rules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Shida Zhang <zhangshida@xxxxxxxxxx>

AF rules:
Lower AF will never go to higher AF for its alloction if they
have other choices.

So unlike previous iterating over the entire [0, agcount),
now iterate one AF, i.e. [curr_af, next_af), at a time.

Signed-off-by: Shida Zhang <zhangshida@xxxxxxxxxx>
---
 fs/xfs/libxfs/xfs_alloc.c | 20 +++++++++++++++++++-
 fs/xfs/libxfs/xfs_bmap.c  | 13 +++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 04f64cf9777e..c3321f24a4f9 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -3707,12 +3707,30 @@ xfs_alloc_vextent_iterate_ags(
 	xfs_agnumber_t		restart_agno = minimum_agno;
 	xfs_agnumber_t		agno;
 	int			error = 0;
+	xfs_agnumber_t		start_af = args->curr_af;
+	xfs_agnumber_t		end_af = args->next_af - 1;
+
 
 	if (alloc_flags & XFS_ALLOC_FLAG_TRYLOCK)
 		restart_agno = 0;
 restart:
+	/* if start_agno is not in current AF range, make it be. */
+	if ((start_agno < start_af) || (start_agno > end_af))
+		start_agno = start_af;
+
+	/* Only iterate the cross region between current allocation field and
+	 * [restart_agno, start_agno].
+	 */
+	restart_agno = max(start_af, restart_agno);
+	start_agno = min(end_af, start_agno);
+
+	WARN_ON_ONCE((args->next_af <= 0) || (args->next_af > mp->m_sb.sb_agcount));
+	WARN_ON_ONCE((args->curr_af < 0) || (args->curr_af >= mp->m_sb.sb_agcount));
+	WARN_ON_ONCE(restart_agno > start_agno);
+	WARN_ON_ONCE(restart_agno < start_af);
+	WARN_ON_ONCE(start_agno > end_af);
 	for_each_perag_wrap_range(mp, start_agno, restart_agno,
-			mp->m_sb.sb_agcount, agno, args->pag) {
+			args->next_af, agno, args->pag) {
 		args->agno = agno;
 		error = xfs_alloc_vextent_prepare_ag(args, alloc_flags);
 		if (error)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index b55b8670730c..799cd75cd150 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3326,6 +3326,8 @@ xfs_bmap_btalloc_select_lengths(
 	struct xfs_perag	*pag;
 	xfs_agnumber_t		agno, startag;
 	int			error = 0;
+	xfs_agnumber_t		start_af = args->curr_af;
+	xfs_agnumber_t		end_af = args->next_af - 1;
 
 	if (ap->tp->t_flags & XFS_TRANS_LOWMODE) {
 		args->total = ap->minlen;
@@ -3338,8 +3340,14 @@ xfs_bmap_btalloc_select_lengths(
 	if (startag == NULLAGNUMBER)
 		startag = 0;
 
+	/* if startag is not in current AF range, make it be. */
+	if ((startag < start_af) || (startag > end_af))
+		startag = start_af;
+
 	*blen = 0;
-	for_each_perag_wrap(mp, startag, agno, pag) {
+	WARN_ON_ONCE((args->next_af <= 0) || (args->next_af > mp->m_sb.sb_agcount));
+	WARN_ON_ONCE((args->curr_af < 0) || (args->curr_af >= mp->m_sb.sb_agcount));
+	for_each_perag_af_wrap(mp, startag, agno, pag, start_af, args->next_af) {
 		error = xfs_bmap_longest_free_extent(pag, args->tp, blen);
 		if (error && error != -EAGAIN)
 			break;
@@ -3807,7 +3815,8 @@ xfs_bmap_btalloc(
 			xfs_inode_is_filestream(ap->ip))
 		error = xfs_bmap_btalloc_filestreams(ap, &args, stripe_align);
 	else
-		error = xfs_bmap_btalloc_best_length(ap, &args, stripe_align);
+		error = xfs_bmap_btalloc_best_length_iterate_afs(ap, &args,
+							 stripe_align);
 	if (error)
 		return error;
 
-- 
2.33.0





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux