public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: n.borisov.lkml@gmail.com, linux-xfs@vger.kernel.org
Subject: [PATCH, RFC] xfs: fix multi-AG deadlock in xfs_bunmapi
Date: Tue, 18 Jul 2017 19:25:45 +0200	[thread overview]
Message-ID: <20170718172545.18065-1-hch@lst.de> (raw)

Just like in the allocator we must avoid touching multiple AGs out of
order when freeing blocks, as freeing still locks the AGF and can cause
the same AB-BA deadlocks as in the allocation path.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reported-by: Nikolay Borisov <n.borisov.lkml@gmail.com>
---
 fs/xfs/libxfs/xfs_bmap.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 0a9880777c9c..935adde72a8b 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -5435,6 +5435,7 @@ __xfs_bunmapi(
 	xfs_fsblock_t		sum;
 	xfs_filblks_t		len = *rlen;	/* length to unmap in file */
 	xfs_fileoff_t		max_len;
+	xfs_agnumber_t		prev_agno = NULLAGNUMBER, agno;
 
 	trace_xfs_bunmap(ip, bno, len, flags, _RET_IP_);
 
@@ -5534,6 +5535,17 @@ __xfs_bunmapi(
 		 */
 		del = got;
 		wasdel = isnullstartblock(del.br_startblock);
+
+		/*
+		 * Make sure we don't touch multiple AGF headers out of order
+		 * in a single transaction, as that could cause AB-BA deadlocks.
+		 */
+		if (!wasdel) {
+			agno = XFS_FSB_TO_AGNO(mp, del.br_startblock);
+			if (prev_agno != NULLAGNUMBER && prev_agno > agno)
+				break;
+			prev_agno = agno;
+		}
 		if (got.br_startoff < start) {
 			del.br_startoff = start;
 			del.br_blockcount -= start - got.br_startoff;
-- 
2.11.0


             reply	other threads:[~2017-07-18 17:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 17:25 Christoph Hellwig [this message]
2017-07-18 18:15 ` [PATCH, RFC] xfs: fix multi-AG deadlock in xfs_bunmapi Darrick J. Wong
2017-07-18 18:27   ` Nikolay Borisov
2017-07-18 18:33     ` Darrick J. Wong
2017-07-19  7:36       ` Christoph Hellwig
2017-07-19 13:11 ` Nikolay Borisov
2017-07-19 15:09   ` Nikolay Borisov
2017-07-20  7:47     ` Christoph Hellwig
2017-07-20  7:47       ` Nikolay Borisov
2017-07-20  7:49         ` Christoph Hellwig
2017-07-20  7:51           ` Nikolay Borisov
2017-07-20 14:58           ` Nikolay Borisov
2017-07-21 10:26             ` Christoph Hellwig
2017-07-26 13:04             ` Christoph Hellwig
2017-07-26 13:59               ` Nikolay Borisov
2017-07-28  6:05               ` Nikolay Borisov
2017-07-31 12:09                 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170718172545.18065-1-hch@lst.de \
    --to=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    --cc=n.borisov.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox