Skip to contentSkip to conversation

buffer caches fixes for Linux 3.5

PATCH In review Christoph Hellwig 3 participants 15 messages Jul 2, 2012 – Jul 13, 2012 XFS filesystem

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 xfs: prevent recursion in xfs_buf_iorequest

If the b_iodone handler is run in calling context in xfs_buf_iorequest we can run into a recursion where xfs_buf_iodone_callbacks keeps calling back into xfs_buf_iorequest because an I/O error happened, which keeps calling back into xfs_buf_iorequest. This chain will usually not take long because the filesystem gets shut down because of log I/O errors, but even over a short time it can cause stack overflows if run on the same context.

As a short term workaround make sure we always call the iodone handler in workqueue context.

---
 fs/xfs/xfs_buf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_buf.c +1 -1
Index: xfs/fs/xfs/xfs_buf.c
===================================================================
@@ -1243,7 +1243,7 @@ xfs_buf_iorequest(
 	 */
 	atomic_set(&bp->b_io_remaining, 1);
 	_xfs_buf_ioapply(bp);
-	_xfs_buf_ioend(bp, 0);
+	_xfs_buf_ioend(bp, 1);
 
 	xfs_buf_rele(bp);
 }

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

Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: prevent recursion in xfs_buf_iorequest

Quoted 11 lines · Christoph Hellwig

If the b_iodone handler is run in calling context in xfs_buf_iorequest we can run into a recursion where xfs_buf_iodone_callbacks keeps calling back into xfs_buf_iorequest because an I/O error happened, which keeps calling back into xfs_buf_iorequest. This chain will usually not take long because the filesystem gets shut down because of log I/O errors, but even over a short time it can cause stack overflows if run on the same context.

As a short term workaround make sure we always call the iodone handler in workqueue context.

Looks fine - final completion from io submission is a rare case so this shouldn't cause issues....

Signature · 7 lines
Dave Chinner
[email protected]

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

PATCH 2/2 xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

In reply to Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

---
 fs/xfs/xfs_buf.c      |   51 +++++++++++++++++++++-----------------------------
 fs/xfs/xfs_buf_item.c |    2 -
 2 files changed, 23 insertions(+), 30 deletions(-)
fs/xfs/xfs_buf_item.c +1 -1
Index: xfs/fs/xfs/xfs_buf_item.c
===================================================================
@@ -954,7 +954,7 @@ xfs_buf_iodone_callbacks(
 
 		if (!XFS_BUF_ISSTALE(bp)) {
 			bp->b_flags |= XBF_WRITE | XBF_ASYNC | XBF_DONE;
-			xfs_bdstrat_cb(bp);
+			xfs_buf_iorequest(bp);
 		} else {
 			xfs_buf_relse(bp);
 		}
fs/xfs/xfs_buf.c +22 -29

69 lines not on this page · raw message

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

Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 4 lines · Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

Makes sense - I have a patch locally that does this as part of a xfs_buf_iorequest(bp, blkno, length) conversion to get rid of XFS_BUF_SETADDR()....

Quoted 1 line
Signature · 7 lines
Dave Chinner
[email protected]

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

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 9 lines · Dave Chinner
Quoted 4 lines · Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

Makes sense - I have a patch locally that does this as part of a xfs_buf_iorequest(bp, blkno, length) conversion to get rid of XFS_BUF_SETADDR()....

Can you send these out ASAP? I have another big batch of buffer error handling changes for 3.6 I'm working on right now.

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

#6 lore raw

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Dave Chinner
Quoted 4 lines · Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

Quoted 5 lines
Quoted 3 lines

Makes sense - I have a patch locally that does this as part of a xfs_buf_iorequest(bp, blkno, length) conversion to get rid of XFS_BUF_SETADDR()....

Can you send these out ASAP?

It's not working yet - I found an issue with logging and writeback of uncached buffers through the AIL (i.e. the superblock). This only works by good fortune right now and requires uncached buffers to carry their block number internally, so I need to rethink and rework the patch.

I think that I will make the superblock buffer a cached buffer once again, but keep the current shortcut to look it up. Doing so will enable me to keep the distinction I created between cached and uncached buffers. It will also solve the AIL flush waiting problem we currently also have with it on freeze/unmount.

Quoted 2 lines

I have another big batch of buffer error handling changes for 3.6 I'm working on right now.

How much does it change? I'm also trying to get all the read verify callback infrastructure changes done for 3.6, and i suspect these may step on each other. I've just about got those patches done - testing and bug fixing is happening at the moment....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 5 lines · Dave Chinner

It's not working yet - I found an issue with logging and writeback of uncached buffers through the AIL (i.e. the superblock). This only works by good fortune right now and requires uncached buffers to carry their block number internally, so I need to rethink and rework the patch.

What is the problem with uncached buffers? I'd hate having to move the superblock buffer away from the uncached scheme.

Quoted 4 lines

How much does it change? I'm also trying to get all the read verify callback infrastructure changes done for 3.6, and i suspect these may step on each other. I've just about got those patches done - testing and bug fixing is happening at the moment....

Basically a lot of impact around all callers of xfsbdstrat (which is going away) and some impact in xfs_buf.c around the higher-level read/write code. I'm not entirely done with the plane I have so other things might get in the way and make it more complicated in the end.

Another thing it depends on is to only start the sync work item later during mount so that the re-read of the superblock after recovery can use normal buffer cache interfaces instead of xfsbdstrat. I have a minimal version of that in my tree but was waiting for your planned large changes in that area.

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

#8 lore raw

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Dave Chinner

It's not working yet - I found an issue with logging and writeback of uncached buffers through the AIL (i.e. the superblock). This only works by good fortune right now and requires uncached buffers to carry their block number internally, so I need to rethink and rework the patch.

What is the problem with uncached buffers? I'd hate having to move the superblock buffer away from the uncached scheme.

I'm not exactly sure yet - I last looked at it before I went on holidays last week. I was getting random ASSERT failures, always on the superblock buffer and always due ot trying to IO to XFS_BUF_DADDR_NULL because it was an uncached buffer. The path to it was always through the AIL flushing, so it was using xfs_buf_iorequest(bp) and getting the null blkno rather than xfs_buf_uncached_iorequest(bp, blkno, len) which supplies the blkno. Like I said, I need to rework is so that either xfs_buf_iorequest(bp) works with uncached buffers, or we don't use uncached buffers in transactions.

IMO, using uncached buffers in transactions is dangerous because concurrent transactions can't find buffers uncached buffers at the same address and so such buffers need higher level synchronisation interfaces (as the superblock has).

I'm happy to leave the superblock as uncached and work around it in some way, but it just seems wrong to me to have one buffer behaves differently to all the cached and other uncached buffers in the system. It doesn't sit well in my mind to do that when the problem simply goes away if we make the superblock a cached buffer again....

Quoted 11 lines
Quoted 4 lines

How much does it change? I'm also trying to get all the read verify callback infrastructure changes done for 3.6, and i suspect these may step on each other. I've just about got those patches done - testing and bug fixing is happening at the moment....

Basically a lot of impact around all callers of xfsbdstrat (which is going away) and some impact in xfs_buf.c around the higher-level read/write code. I'm not entirely done with the plane I have so other things might get in the way and make it more complicated in the end.

Quoted 3 lines

Another thing it depends on is to only start the sync work item later during mount so that the re-read of the superblock after recovery can use normal buffer cache interfaces instead of xfsbdstrat.

Well, we've already got conflicts there, because all of the uncached IO changes I've made remove xfsbdstrat() from those paths....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 10 lines · Dave Chinner

IMO, using uncached buffers in transactions is dangerous because concurrent transactions can't find buffers uncached buffers at the same address and so such buffers need higher level synchronisation interfaces (as the superblock has).

I'm happy to leave the superblock as uncached and work around it in some way, but it just seems wrong to me to have one buffer behaves differently to all the cached and other uncached buffers in the system. It doesn't sit well in my mind to do that when the problem simply goes away if we make the superblock a cached buffer again....

The superblock buffer always has been more special than others, remember the old FS_MANAGED flag before we went for uncached buffers?

If you want to move it back to normal buffers how do you want to look it up, given that IIRC we read it before setting up the perag buffers.

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

#10 lore raw

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

In reply to Christoph Hellwig

Hey Christoph,

Quoted 60 lines · Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

---
 fs/xfs/xfs_buf.c      |   51 +++++++++++++++++++++-----------------------------
 fs/xfs/xfs_buf_item.c |    2 -
 2 files changed, 23 insertions(+), 30 deletions(-)

Index: xfs/fs/xfs/xfs_buf_item.c
===================================================================

fs/xfs/xfs_buf_item.c +1 -1
@@ -954,7 +954,7 @@ xfs_buf_iodone_callbacks(
 
 		if (!XFS_BUF_ISSTALE(bp)) {
 			bp->b_flags |= XBF_WRITE | XBF_ASYNC | XBF_DONE;
-			xfs_bdstrat_cb(bp);
+			xfs_buf_iorequest(bp);
 		} else {
 			xfs_buf_relse(bp);
 		}

Index: xfs/fs/xfs/xfs_buf.c
===================================================================

fs/xfs/xfs_buf.c +0 -21
@@ -989,27 +989,6 @@ xfs_buf_ioerror_alert(
 		(__uint64_t)XFS_BUF_ADDR(bp), func, bp->b_error, bp->b_length);
 }
 
-int
-xfs_bwrite(
-	struct xfs_buf		*bp)
-{
-	int			error;
-
-	ASSERT(xfs_buf_islocked(bp));
-
-	bp->b_flags |= XBF_WRITE;
-	bp->b_flags &= ~(XBF_ASYNC | XBF_READ | _XBF_DELWRI_Q);
-
-	xfs_bdstrat_cb(bp);
-
-	error = xfs_buf_iowait(bp);
-	if (error) {
-		xfs_force_shutdown(bp->b_target->bt_mount,
-				   SHUTDOWN_META_IO_ERROR);
-	}
-	return error;
-}
-
 /*
  * Called when we want to stop a buffer from getting written or read.
  * We attach the EIO error, muck with its flags, and call xfs_buf_ioend
@@ -1079,14 +1058,7 @@ xfs_bioerror_relse(
 	return EIO;
 }

fs/xfs/xfs_buf.c xfs_bioerror_relse( · line 1061

Quoted 10 lines
fs/xfs/xfs_buf.c +1 -8
 
-
-/*
- * All xfs metadata buffers except log state machine buffers
- * get this attached as their b_bdstrat callback function.
- * This is so that we can catch a buffer
- * after prematurely unpinning it to forcibly shutdown the filesystem.
- */
-int
+STATIC int

xfs/fs/xfs/xfs_buf.c:1062: error: static declaration of ‘xfs_bdstrat_cb’ follows non-static declaration xfs/fs/xfs/xfs_buf.h:183: error: previous declaration of ‘xfs_bdstrat_cb’ was here

CONFIG_XFS_DEBUG was not set.

I'm happy to have caught that before pulling this in. Most of the time I am testing with CONFIG_XFS_DEBUG=y. I'll fix it up.

Regards,
Ben

Quoted 32 lines
fs/xfs/xfs_buf.c +21 -0
 xfs_bdstrat_cb(
 	struct xfs_buf	*bp)
 {
@@ -1107,6 +1079,27 @@ xfs_bdstrat_cb(
 	return 0;
 }
 
+int
+xfs_bwrite(
+	struct xfs_buf		*bp)
+{
+	int			error;
+
+	ASSERT(xfs_buf_islocked(bp));
+
+	bp->b_flags |= XBF_WRITE;
+	bp->b_flags &= ~(XBF_ASYNC | XBF_READ | _XBF_DELWRI_Q);
+
+	xfs_bdstrat_cb(bp);
+
+	error = xfs_buf_iowait(bp);
+	if (error) {
+		xfs_force_shutdown(bp->b_target->bt_mount,
+				   SHUTDOWN_META_IO_ERROR);
+	}
+	return error;
+}
+
 /*
  * Wrapper around bdstrat so that we can stop data from going to disk in case
  * we are shutting down the filesystem.  Typically user data goes thru this
Quoted 4 lines

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

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

#11 lore raw

Re: [PATCH 2/2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 7 lines · Ben Myers

xfs/fs/xfs/xfs_buf.c:1062: error: static declaration of ???xfs_bdstrat_cb??? follows non-static declaration xfs/fs/xfs/xfs_buf.h:183: error: previous declaration of ???xfs_bdstrat_cb??? was here

CONFIG_XFS_DEBUG was not set.

I'm happy to have caught that before pulling this in. Most of the time I am testing with CONFIG_XFS_DEBUG=y. I'll fix it up.

The one in the header should just go away, that's why I moved xfs_bwrite.

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

#12 lore raw

PATCH v2 2/2 xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

---
 fs/xfs/xfs_buf.c      |   51 +++++++++++++++++++++-----------------------------
 fs/xfs/xfs_buf.h      |    1 
 fs/xfs/xfs_buf_item.c |    2 -
 3 files changed, 23 insertions(+), 31 deletions(-)
fs/xfs/xfs_buf_item.c +1 -1
Index: xfs/fs/xfs/xfs_buf_item.c
===================================================================
@@ -1101,7 +1101,7 @@ xfs_buf_iodone_callbacks(
 
 		if (!XFS_BUF_ISSTALE(bp)) {
 			bp->b_flags |= XBF_WRITE | XBF_ASYNC | XBF_DONE;
-			xfs_bdstrat_cb(bp);
+			xfs_buf_iorequest(bp);
 		} else {
 			xfs_buf_relse(bp);
 		}
fs/xfs/xfs_buf.c +22 -29

69 lines not on this page · raw message

fs/xfs/xfs_buf.h +0 -1
Index: xfs/fs/xfs/xfs_buf.h
===================================================================
@@ -250,7 +250,6 @@ extern void xfs_buf_unlock(xfs_buf_t *);
 extern int xfs_bwrite(struct xfs_buf *bp);
 
 extern void xfsbdstrat(struct xfs_mount *, struct xfs_buf *);
-extern int xfs_bdstrat_cb(struct xfs_buf *);
 
 extern void xfs_buf_ioend(xfs_buf_t *,	int);
 extern void xfs_buf_ioerror(xfs_buf_t *, int);

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

#13 lore raw

Re: [PATCH 2/2 v2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

Quoted 6 lines · Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

Thanks.

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

Reviewed-by on v2 2/2
#14 lore raw

Re: [PATCH 2/2 v2] xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

xfs_bdstrat_cb only adds a check for a shutdown filesystem over xfs_buf_iorequest, but xfs_buf_iodone_callbacks just checked for a shut down filesystem a little earlier. In addition the shutdown handling in xfs_bdstrat_cb is not very suitable for this caller.

This new version looks good.

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