| To: | Christoph Hellwig <hch@xxxxxxxxxxxxx>, Nathan Scott <nathans@xxxxxxx> |
|---|---|
| Subject: | Re: [RFC] Badness in __mutex_unlock_slowpath with XFS stress tests |
| From: | Stephane Doyon <sdoyon@xxxxxxxxx> |
| Date: | Mon, 10 Jul 2006 12:46:23 -0400 (EDT) |
| Cc: | Suzuki <suzuki@xxxxxxxxxx>, linux-fsdevel@xxxxxxxxxxxxxxx, "linux-aio kvack.org" <linux-aio@xxxxxxxxx>, lkml <linux-kernel@xxxxxxxxxxxxxxx>, suparna <suparna@xxxxxxxxxx>, akpm@xxxxxxxx, linux-xfs@xxxxxxxxxxx |
| In-reply-to: | <20060310005020.GF1135@frodo> |
| References: | <440FDF3E.8060400@in.ibm.com> <20060309120306.GA26682@infradead.org> <20060309223042.GC1135@frodo> <20060309224219.GA6709@infradead.org> <20060309231422.GD1135@frodo> <20060310005020.GF1135@frodo> |
| Sender: | xfs-bounce@xxxxxxxxxxx |
Hi, A few months back, a fix was introduced for a mutex double unlock warning related to direct I/O in XFS. I believe that fix has a lock ordering problem that can cause a deadlock. The problem was that __blockdev_direct_IO() would unlock the i_mutex in the READ and DIO_OWN_LOCKING case, and the mutex would be unlocked again in xfs_read() soon after returning from __generic_file_aio_read(). Because there are lots of execution paths down from __generic_file_aio_read() that do not consistently release the i_mutex, the safest fix was deemed to be to reacquire the i_mutex before returning from __blockdev_direct_IO(). At this point however, the reader is holding an xfs ilock, and AFAICT the i_mutex is usually taken BEFORE the xfs ilock. We are seeing a deadlock between a process writing and another process reading the same file, when the reader is using direct I/O. (The writer must apparently be growing the file, using either direct or buffered I/O.) Something like this, on XFS: (dd if=/dev/zero of=f bs=128K count=5000 & ) ; sleep 1 ; dd of=/dev/null if=f iflag=direct bs=128K count=5000 Seen on kernels 2.6.16 and 2.6.17. The deadlock scenario appears to be this: -The reader goes into xfs_read(), takes the i_mutex and then an xfs_ilock XFS_IOLOCK_SHARED, then calls down to __generic_file_aio_read() which eventually goes down to __blockdev_direct_IO(). In there it drops the i_mutex. -The writer goes into xfs_write() and obtains the i_mutex. It then tries to get an xfs_ilock XFS_ILOCK_EXCL and must wait on it since it's held by the reader. -The reader, still in __blockdev_direct_IO(), executes directio_worker() and then tries to reacquire the i_mutex, and must wait on it because the writer has it. And so we have a deadlock. I leave it to the experts to figure out what the right fix for this might be. A workaround might be to not release the i_mutex during __blockdev_direct_IO(). Thanks On Thu, 9 Mar 2006, Christoph Hellwig wrote: On Thu, Mar 09, 2006 at 01:24:38PM +0530, Suzuki wrote:
On Thu, Mar 09, 2006 at 12:47:01PM +0530, Suzuki wrote:Hi all,
On Fri, Mar 10, 2006 at 10:14:22AM +1100, Nathan Scott wrote:On Thu, Mar 09, 2006 at 10:42:19PM +0000, Christoph Hellwig wrote:On Fri, Mar 10, 2006 at 09:30:42AM +1100, Nathan Scott wrote:Not for reads AFAICT - __generic_file_aio_read + own-locking should always have released i_mutex at the end of the direct read - are you thinking of writes or have I missed something? |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: XFS SUPPORT ON WINDOWS PLATFORMS, Eric Sandeen |
|---|---|
| Next by Date: | Re: [PATCH] xfs: remove unused locking flags, Christoph Hellwig |
| Previous by Thread: | Case C622187 (Returned mail: see transcript for details), clarify |
| Next by Thread: | Re: [RFC] Badness in __mutex_unlock_slowpath with XFS stress tests, Nathan Scott |
| Indexes: | [Date] [Thread] [Top] [All Lists] |