public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode()
@ 2012-02-16 22:01 Alex Elder
  2012-02-17  2:45 ` Dave Chinner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alex Elder @ 2012-02-16 22:01 UTC (permalink / raw)
  To: xfs

At the end of xfs_reclaim_inode(), the inode is locked in order to
we wait for a possible concurrent lookup to complete before the
inode is freed.  This synchronization step was taking both the ILOCK
and the IOLOCK, but the latter was causing lockdep to produce
reports of the possibility of deadlock.

It turns out that there's no need to acquire the IOLOCK at this
point anyway.  It may have been required in some earlier version of
the code, but there should be no need to take the IOLOCK in
xfs_iget(), so there's no (longer) any need to get it here for
synchronization.  Add an assertion in xfs_iget() as a reminder
of this assumption.

Dave Chinner diagnosed this on IRC, and Christoph Hellwig suggested
no longer including the IOLOCK.  I just put together the patch.

Signed-off-by: Alex Elder <elder@dreamhost.com>
---
 fs/xfs/xfs_iget.c |    9 +++++++++
 fs/xfs/xfs_sync.c |   10 ++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c
index 0fa98b1..39d51d9 100644
--- a/fs/xfs/xfs_iget.c
+++ b/fs/xfs/xfs_iget.c
@@ -421,6 +421,15 @@ xfs_iget(
 	xfs_perag_t	*pag;
 	xfs_agino_t	agino;
 
+	/*
+	 * xfs_reclaim_inode() uses the ILOCK to ensure an inode
+	 * doesn't get freed while it's being referenced during a
+	 * radix tree traversal here.  It assumes this function
+	 * aqcuires only the ILOCK (and therefore it has no need to
+	 * involve the IOLOCK in this synchronization).
+	 */
+	ASSERT((lock_flags & (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED)) == 0);
+
 	/* reject inode numbers outside existing AGs */
 	if (!ino || XFS_INO_TO_AGNO(mp, ino) >= mp->m_sb.sb_agcount)
 		return EINVAL;
diff --git a/fs/xfs/xfs_sync.c b/fs/xfs/xfs_sync.c
index f0994aedc..61c6986 100644
--- a/fs/xfs/xfs_sync.c
+++ b/fs/xfs/xfs_sync.c
@@ -918,17 +918,15 @@ reclaim:
 	 * can reference the inodes in the cache without taking references.
 	 *
 	 * We make that OK here by ensuring that we wait until the inode is
-	 * unlocked after the lookup before we go ahead and free it.  We get
-	 * both the ilock and the iolock because the code may need to drop the
-	 * ilock one but will still hold the iolock.
+	 * unlocked after the lookup before we go ahead and free it.
 	 */
-	xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
 	xfs_qm_dqdetach(ip);
-	xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
 	xfs_inode_free(ip);
-	return error;
 
+	return error;
 }
 
 /*
-- 
1.7.5.4



_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode()
  2012-02-16 22:01 [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode() Alex Elder
@ 2012-02-17  2:45 ` Dave Chinner
  2012-02-17 19:13 ` Christoph Hellwig
  2012-02-25 19:50 ` Ben Myers
  2 siblings, 0 replies; 4+ messages in thread
From: Dave Chinner @ 2012-02-17  2:45 UTC (permalink / raw)
  To: Alex Elder; +Cc: xfs

On Thu, Feb 16, 2012 at 04:01:00PM -0600, Alex Elder wrote:
> At the end of xfs_reclaim_inode(), the inode is locked in order to
> we wait for a possible concurrent lookup to complete before the
> inode is freed.  This synchronization step was taking both the ILOCK
> and the IOLOCK, but the latter was causing lockdep to produce
> reports of the possibility of deadlock.
> 
> It turns out that there's no need to acquire the IOLOCK at this
> point anyway.  It may have been required in some earlier version of
> the code, but there should be no need to take the IOLOCK in
> xfs_iget(), so there's no (longer) any need to get it here for
> synchronization.  Add an assertion in xfs_iget() as a reminder
> of this assumption.
> 
> Dave Chinner diagnosed this on IRC, and Christoph Hellwig suggested
> no longer including the IOLOCK.  I just put together the patch.
> 
> Signed-off-by: Alex Elder <elder@dreamhost.com>

The code and comments is almost identical to the patch I've been
testing over the past day, so consider it

Reviewed-by: Dave Chinner <dchinner@redhat.com>
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode()
  2012-02-16 22:01 [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode() Alex Elder
  2012-02-17  2:45 ` Dave Chinner
@ 2012-02-17 19:13 ` Christoph Hellwig
  2012-02-25 19:50 ` Ben Myers
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2012-02-17 19:13 UTC (permalink / raw)
  To: Alex Elder; +Cc: xfs

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode()
  2012-02-16 22:01 [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode() Alex Elder
  2012-02-17  2:45 ` Dave Chinner
  2012-02-17 19:13 ` Christoph Hellwig
@ 2012-02-25 19:50 ` Ben Myers
  2 siblings, 0 replies; 4+ messages in thread
From: Ben Myers @ 2012-02-25 19:50 UTC (permalink / raw)
  To: Alex Elder; +Cc: xfs

On Thu, Feb 16, 2012 at 04:01:00PM -0600, Alex Elder wrote:
> At the end of xfs_reclaim_inode(), the inode is locked in order to
> we wait for a possible concurrent lookup to complete before the
> inode is freed.  This synchronization step was taking both the ILOCK
> and the IOLOCK, but the latter was causing lockdep to produce
> reports of the possibility of deadlock.
> 
> It turns out that there's no need to acquire the IOLOCK at this
> point anyway.  It may have been required in some earlier version of
> the code, but there should be no need to take the IOLOCK in
> xfs_iget(), so there's no (longer) any need to get it here for
> synchronization.  Add an assertion in xfs_iget() as a reminder
> of this assumption.
> 
> Dave Chinner diagnosed this on IRC, and Christoph Hellwig suggested
> no longer including the IOLOCK.  I just put together the patch.
> 
> Signed-off-by: Alex Elder <elder@dreamhost.com>

Looks good.

Reviewed-by: Ben Myers <bpm@sgi.com>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-25 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-16 22:01 [PATCH] xfs: only take the ILOCK in xfs_reclaim_inode() Alex Elder
2012-02-17  2:45 ` Dave Chinner
2012-02-17 19:13 ` Christoph Hellwig
2012-02-25 19:50 ` Ben Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox