Skip to contentSkip to conversation

xfs: various 2.6.38 candidate bug fixes

PATCH In review Dave Chinner 2 participants 15 messages Jan 19, 2011 – Jan 24, 2011 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: various 2.6.38 candidate bug fixes

There's the fix for the specualtive allocation regression that arekm and hch reported different symptoms of. Some extsize tweaks to prevent assert failures and btree corruptions. An allocation size fix to prevent wildly inefficient handling of nullfb allocation group scanning (demonstrated by low space scanning or single large preallocation that spans hundreds/thousands of AGs). Finally, another a fix for another delayed logging commit path error handling problem that I noticed by inspection.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw

PATCH 1/5 xfs: speculative delayed allocation uses rounddown_power_of_2 badly

From: Dave Chinner <[email protected]>

rounddown_power_of_2() returns an undefined result when passed a value of zero. The specualtive delayed allocation code is doing this when the inode is zero length. Hence occasionally the preallocation is much, mcuh large than is necessary (e.g. 8GB for a 270 _byte_ file). Ensure we don't even pass a zero value to this function so the result of preallocation is always the desired size.

---
 fs/xfs/xfs_iomap.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
fs/xfs/xfs_iomap.c +6 -1
index 55582bd..8a0f044 100644
@@ -337,7 +337,12 @@ xfs_iomap_prealloc_size(
 		int shift = 0;
 		int64_t freesp;
 
-		alloc_blocks = XFS_B_TO_FSB(mp, ip->i_size);
+		/*
+		 * rounddown_pow_of_two() returns an undefined result
+		 * if we pass in alloc_blocks = 0. Hence the "+ 1" to
+		 * ensure we always pass in a non-zero value.
+		 */
+		alloc_blocks = XFS_B_TO_FSB(mp, ip->i_size) + 1;
 		alloc_blocks = XFS_FILEOFF_MIN(MAXEXTLEN,
 					rounddown_pow_of_two(alloc_blocks));
 
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] xfs: speculative delayed allocation uses rounddown_power_of_2 badly

Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

rounddown_power_of_2() returns an undefined result when passed a value of zero. The specualtive delayed allocation code is doing this when the inode is zero length. Hence occasionally the preallocation is much, mcuh large than is necessary (e.g. 8GB for a 270 _byte_

	^^^^^^^^^ typo

Otherwise looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

PATCH 2/5 xfs: limit extent length for allocation to AG size

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

Delayed allocation extents can be larger than AGs, so when trying to convert a large range we may scan every AG inside xfs_bmap_alloc_nullfb() trying to find an AG with a size larger than an AG. We should stop when we find the first AG with a maximum possible allocation size. This causes excessive CPU usage when there are lots of AGs.

The same problem occurs when doing preallocation of a range larger than an AG.

Fix the problem by limiting real allocation lengths to the maximum that an AG can support. This means if we have empty AGs, we'll stop the search at the first of them. If there are no empty AGs, we'll still scan them all, but that is a different problem....

---
 fs/xfs/xfs_bmap.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
fs/xfs/xfs_bmap.c +14 -7
index 4111cd3..2ad1daf 100644
@@ -2430,7 +2430,7 @@ xfs_bmap_btalloc_nullfb(
 		startag = ag = 0;
 
 	pag = xfs_perag_get(mp, ag);
-	while (*blen < ap->alen) {
+	while (*blen < args->maxlen) {
 		if (!pag->pagf_init) {
 			error = xfs_alloc_pagf_init(mp, args->tp, ag,
 						    XFS_ALLOC_FLAG_TRYLOCK);
@@ -2452,7 +2452,7 @@ xfs_bmap_btalloc_nullfb(
 			notinit = 1;
 
 		if (xfs_inode_is_filestream(ap->ip)) {
-			if (*blen >= ap->alen)
+			if (*blen >= args->maxlen)
 				break;
 
 			if (ap->userdata) {
@@ -2498,14 +2498,14 @@ xfs_bmap_btalloc_nullfb(
 	 * If the best seen length is less than the request
 	 * length, use the best as the minimum.
 	 */
-	else if (*blen < ap->alen)
+	else if (*blen < args->maxlen)
 		args->minlen = *blen;
 	/*
 	 * Otherwise we've seen an extent as big as alen,
 	 * use that as the minimum.
 	 */
 	else
-		args->minlen = ap->alen;
+		args->minlen = args->maxlen;
 
 	/*
 	 * set the failure fallback case to look in the selected
@@ -2573,7 +2573,14 @@ xfs_bmap_btalloc(
 	args.tp = ap->tp;
 	args.mp = mp;
 	args.fsbno = ap->rval;
-	args.maxlen = MIN(ap->alen, mp->m_sb.sb_agblocks);
+
+	/*
+	 * The requested extent can be larger than an AG, so trim the block
+	 * count back to the maximum sized extent in an AG. A typical empty AG
+	 * consumes 1 block for headers, 1 block for each btree root (3) and 4
+	 * blocks for the free list.
+	 */
+	args.maxlen = MIN(ap->alen, mp->m_sb.sb_agblocks - 8);
 	args.firstblock = ap->firstblock;
 	blen = 0;
 	if (nullfb) {
@@ -2621,7 +2628,7 @@ xfs_bmap_btalloc(
 			/*
 			 * Adjust for alignment
 			 */
-			if (blen > args.alignment && blen <= ap->alen)
+			if (blen > args.alignment && blen <= args.maxlen)
 				args.minlen = blen - args.alignment;
 			args.minalignslop = 0;
 		} else {
@@ -2640,7 +2647,7 @@ xfs_bmap_btalloc(
 			 * of minlen+alignment+slop doesn't go up
 			 * between the calls.
 			 */
-			if (blen > mp->m_dalign && blen <= ap->alen)
+			if (blen > mp->m_dalign && blen <= args.maxlen)
 				nextminlen = blen - mp->m_dalign;
 			else
 				nextminlen = args.minlen;
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] xfs: limit extent length for allocation to AG size

fs/xfs/xfs_bmap.c xfs_bmap_btalloc( · line 2583

Quoted 7 lines
fs/xfs/xfs_bmap.c +7 -0
+	/*
+	 * The requested extent can be larger than an AG, so trim the block
+	 * count back to the maximum sized extent in an AG. A typical empty AG
+	 * consumes 1 block for headers, 1 block for each btree root (3) and 4
+	 * blocks for the free list.
+	 */
+	args.maxlen = MIN(ap->alen, mp->m_sb.sb_agblocks - 8);

Maybe add a define for the over head blocks to document it more clearly?

Otherwise looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw

Re: [PATCH 2/5] xfs: limit extent length for allocation to AG size

Quoted 10 lines · Christoph Hellwig

fs/xfs/xfs_bmap.c xfs_bmap_btalloc( · line 2583

Quoted 7 lines
fs/xfs/xfs_bmap.c +7 -0
+	/*
+	 * The requested extent can be larger than an AG, so trim the block
+	 * count back to the maximum sized extent in an AG. A typical empty AG
+	 * consumes 1 block for headers, 1 block for each btree root (3) and 4
+	 * blocks for the free list.
+	 */
+	args.maxlen = MIN(ap->alen, mp->m_sb.sb_agblocks - 8);

Maybe add a define for the over head blocks to document it more clearly?

Will do.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#6 lore raw

PATCH 3/5 xfs: prevent extsize alignment from exceeding maximum extent size

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

When doing delayed allocation, if the allocation size is for a maximally sized extent, extent size alignment can push it over this limit. This results in an assert failure in xfs_bmbt_set_allf() as the extent length is too large to find in the extent record.

Fix this by ensuring that we allow for space that extent size alignment requires (up to 2 * (extsize -1) blocks as we have to handle both head and tail alignment) when limiting the maximum size of the extent.

---
 fs/xfs/xfs_bmap.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
fs/xfs/xfs_bmap.c +11 -0
index 2ad1daf..4901355 100644
@@ -4492,6 +4492,17 @@ xfs_bmapi(
 				/* Figure out the extent size, adjust alen */
 				extsz = xfs_get_extsz_hint(ip);
 				if (extsz) {
+					/*
+					 * make sure we don't exceed a single
+					 * extent length when we align the
+					 * extent by reducing length we are
+					 * going to allocate by the maximum
+					 * amount extent size aligment may
+					 * require.
+					alen = (xfs_extlen_t)XFS_FILBLKS_MIN(
+							len,
+						MAXEXTLEN - (2 * extsz - 1));
+					 */
 					error = xfs_bmap_extsize_align(mp,
 							&got, &prev, extsz,
 							rt, eof,
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#7 lore raw

Re: [PATCH 3/5] xfs: prevent extsize alignment from exceeding maximum extent size

fs/xfs/xfs_bmap.c xfs_bmapi( · line 4505

Quoted 11 lines
fs/xfs/xfs_bmap.c +11 -0
+					/*
+					 * make sure we don't exceed a single
+					 * extent length when we align the
+					 * extent by reducing length we are
+					 * going to allocate by the maximum
+					 * amount extent size aligment may
+					 * require.
+					alen = (xfs_extlen_t)XFS_FILBLKS_MIN(
+							len,
+						MAXEXTLEN - (2 * extsz - 1));
+					 */

This essentially just adds a comment, given that the new code is inside the bracing. Also the xfs_extlen_t cast seems pointless. The C type promotion rules do just fine for going down from a 64bit type to a 32bit one, as long as the results fit into the latter - which they always do here.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#8 lore raw

Re: [PATCH 3/5] xfs: prevent extsize alignment from exceeding maximum extent size

Quoted 9 lines · Christoph Hellwig
Quoted 9 lines
fs/xfs/xfs_bmap.c +9 -0
+					/*
+					 * make sure we don't exceed a single
+					 * extent length when we align the
+					 * extent by reducing length we are
+					 * going to allocate by the maximum
+					 * amount extent size aligment may
+					 * require.
+					alen = (xfs_extlen_t)XFS_FILBLKS_MIN(
+							len,
Quoted 8 lines

fs/xfs/xfs_bmap.c xfs_bmapi( · line 4505

Quoted 2 lines
fs/xfs/xfs_bmap.c +2 -0
+						MAXEXTLEN - (2 * extsz - 1));
+					 */

This essentially just adds a comment, given that the new code is inside the bracing. Also the xfs_extlen_t cast seems pointless. The C type promotion rules do just fine for going down from a 64bit type to a 32bit one, as long as the results fit into the latter - which they always do here.

Argh, forgot to refresh the patch after doing some bug hunting. I'll fix it and retest before I repost it.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#9 lore raw

PATCH 4/5 xfs: limit extsize to size of AGs and/or MAXEXTLEN

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

The extent size hint can be set to larger than an AG. This means that the alignment process can push the range to be allocated outside the bounds of the AG, resulting in assert failures or corrupted bmbt records. Similarly, if the extsize is larger than the maximum extent size supported, the alignment process will produce extents that are too large to fit into the bmbt records, resulting in a different type of assert/corruption failure.

Fix this by limiting extsize at the time іt is set firstly to be less than MAXEXTLEN, then to be a maximum of half the size of the AGs in the filesystem for non-realtime inodes. Realtime inodes do not allocate out of AGs, so don't have to be restricted by the size of AGs.

---
 fs/xfs/linux-2.6/xfs_ioctl.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
fs/xfs/linux-2.6/xfs_ioctl.c +18 -2
index b06ede1..f5e2a19 100644
@@ -985,10 +985,22 @@ xfs_ioctl_setattr(
 
 		/*
 		 * Extent size must be a multiple of the appropriate block
-		 * size, if set at all.
+		 * size, if set at all. It must also be smaller than the
+		 * maximum extent size supported by the filesystem.
+		 *
+		 * Also, for non-realtime files, limit the extent size hint to
+		 * half the size of the AGs in the filesystem so alignment
+		 * doesn't result in extents larger than an AG.
 		 */
 		if (fa->fsx_extsize != 0) {
-			xfs_extlen_t	size;
+			xfs_extlen_t    size;
+			xfs_fsblock_t   extsize_fsb;
+
+			extsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_extsize);
+			if (extsize_fsb > MAXEXTLEN) {
+				code = XFS_ERROR(EINVAL);
+				goto error_return;
+			}
 
 			if (XFS_IS_REALTIME_INODE(ip) ||
 			    ((mask & FSX_XFLAGS) &&
@@ -997,6 +1009,10 @@ xfs_ioctl_setattr(
 				       mp->m_sb.sb_blocklog;
 			} else {
 				size = mp->m_sb.sb_blocksize;
+				if (extsize_fsb > mp->m_sb.sb_agblocks / 2) {
+					code = XFS_ERROR(EINVAL);
+					goto error_return;
+				}
 			}
 
 			if (fa->fsx_extsize % size) {
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 4/5
#10 lore raw

Re: [PATCH 4/5] xfs: limit extsize to size of AGs and/or MAXEXTLEN

fs/xfs/linux-2.6/xfs_ioctl.c xfs_ioctl_setattr( · line 993

Quoted 3 lines · Dave Chinner
fs/xfs/linux-2.6/xfs_ioctl.c +3 -0
+		 * Also, for non-realtime files, limit the extent size hint to
+		 * half the size of the AGs in the filesystem so alignment
+		 * doesn't result in extents larger than an AG.

What do we do about the last AG, which potentionally is smaller than the others?

Otherwise looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#11 lore raw

Re: [PATCH 4/5] xfs: limit extsize to size of AGs and/or MAXEXTLEN

Quoted 7 lines · Christoph Hellwig

fs/xfs/linux-2.6/xfs_ioctl.c xfs_ioctl_setattr( · line 993

Quoted 3 lines · Dave Chinner
fs/xfs/linux-2.6/xfs_ioctl.c +3 -0
+		 * Also, for non-realtime files, limit the extent size hint to
+		 * half the size of the AGs in the filesystem so alignment
+		 * doesn't result in extents larger than an AG.

What do we do about the last AG, which potentionally is smaller than the others?

Not sure - I didn't actually consider that case because I forgot about it.

At first glance it doesn't matter because it won't get selected because the length of the AG is less than the requested size unless it is the best match. If it is the best match, we can't do extsize alignment anyway, so it's the same case as any other allocation without a freespace extent large enough for alignment.

I'll do a bit more analysis, but I think we're OK here.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#12 lore raw

PATCH 5/5 xfs: handle CIl transaction commit failures correctly

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

Failure to commit a transaction into the CIL is not handled correctly. This currently can only happen when racing with a shutdown, so it rare. Handle the error similar to a log vector memory allocation failure, and for both failures clear the PF_TRANS flag from the task correctly.

---
 fs/xfs/xfs_trans.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
fs/xfs/xfs_trans.c +14 -3
index 50753d3..504a804 100644
@@ -1754,15 +1754,26 @@ xfs_trans_commit_cil(
 	 */
 	log_vector = xfs_trans_alloc_log_vecs(tp);
 	if (!log_vector)
-		return ENOMEM;
+		goto out_enomem;
 
 	error = xfs_log_commit_cil(mp, tp, log_vector, commit_lsn, flags);
-	if (error)
-		return error;
+	if (error) {
+		/*
+		 * We will only get an error if no modifications have been
+		 * made to the items in the transaction. Hence treat it
+		  the same as a memory allocation failure.
+		 */
+		goto out_enomem;
+	}
 
 	current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
 	xfs_trans_free(tp);
 	return 0;
+
+out_enomem:
+	/* caller cleans up transaction */
+	current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
+	return ENOMEM;
 }
 
 /*
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#13 lore raw

Re: [PATCH 5/5] xfs: handle CIl transaction commit failures correctly

Quoted 21 lines
fs/xfs/xfs_trans.c +8 -3
index 50753d3..504a804 100644
@@ -1754,15 +1754,26 @@ xfs_trans_commit_cil(
 	 */
 	log_vector = xfs_trans_alloc_log_vecs(tp);
 	if (!log_vector)
-		return ENOMEM;
+		goto out_enomem;
 
 	error = xfs_log_commit_cil(mp, tp, log_vector, commit_lsn, flags);
-	if (error)
-		return error;
+	if (error) {
+		/*
+		 * We will only get an error if no modifications have been
+		 * made to the items in the transaction. Hence treat it
+		  the same as a memory allocation failure.
+		 */
+		goto out_enomem;

fs/xfs/xfs_trans.c xfs_trans_commit_cil( · line 1776

Quoted 10 lines
fs/xfs/xfs_trans.c +6 -0
+	}
 
 	current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
 	xfs_trans_free(tp);
 	return 0;
+
+out_enomem:
+	/* caller cleans up transaction */
+	current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
+	return ENOMEM;

_xfs_trans_commit already restores the process flags for an ENOMEM return, so the failure from xfs_trans_alloc_log_vecs is already handled correctly. If we want to handle the EIO return from xfs_log_commit_cil the same way it just needs to be turned into an ENOMEM. The big questions is if there's any point in having the shutdown check in xfs_trans_commit_cil - we already do one just before applying the trans deltas in _xfs_trans_commit, which is handled correctly and should be sufficient.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#14 lore raw

Re: [PATCH 5/5] xfs: handle CIl transaction commit failures correctly

Quoted 32 lines · Christoph Hellwig
Quoted 21 lines
fs/xfs/xfs_trans.c +8 -3
index 50753d3..504a804 100644
@@ -1754,15 +1754,26 @@ xfs_trans_commit_cil(
 	 */
 	log_vector = xfs_trans_alloc_log_vecs(tp);
 	if (!log_vector)
-		return ENOMEM;
+		goto out_enomem;
 
 	error = xfs_log_commit_cil(mp, tp, log_vector, commit_lsn, flags);
-	if (error)
-		return error;
+	if (error) {
+		/*
+		 * We will only get an error if no modifications have been
+		 * made to the items in the transaction. Hence treat it
+		  the same as a memory allocation failure.
+		 */
+		goto out_enomem;

fs/xfs/xfs_trans.c xfs_trans_commit_cil( · line 1776

Quoted 10 lines
fs/xfs/xfs_trans.c +6 -0
+	}
 
 	current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
 	xfs_trans_free(tp);
 	return 0;
+
+out_enomem:
+	/* caller cleans up transaction */
+	current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
+	return ENOMEM;
Quoted 8 lines

_xfs_trans_commit already restores the process flags for an ENOMEM return, so the failure from xfs_trans_alloc_log_vecs is already handled correctly. If we want to handle the EIO return from xfs_log_commit_cil the same way it just needs to be turned into an ENOMEM. The big questions is if there's any point in having the shutdown check in xfs_trans_commit_cil - we already do one just before applying the trans deltas in _xfs_trans_commit, which is handled correctly and should be sufficient.

True. Removing the shutdown check makes xfs_log_commit_cil() a function that can have a void return. That's probably a better solution, so I'll modify it that way.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs