[PATCH: 2.6.20-rc4-mm1] JFS: Avoid deadlock introduced by explicitI/O plugging

From: Dave Kleikamp
Date: Wed Jan 17 2007 - 17:56:16 EST


Jens,
Can you please take a look at this patch, and if you think it's sane,
add it to your explicit i/o plugging patchset? Would it make sense in
any of these paths to use io_schedule() instead of schedule()?

I hadn't looked at your patchset until I discovered that jfs was easy to
hang in the -mm kernel. I think jfs may be able to add explicit
plugging and unplugging in a couple of places, but I'd like to fix the
hang right away and take my time with any later patches.

Thanks,
Shaggy

JFS: Avoid deadlock introduced by explicit I/O plugging

jfs is pretty easy to deadlock with Jens' explicit i/o plugging patchset.
Just try building a kernel.

The problem occurs when a synchronous transaction initiates some I/O, then
waits in lmGroupCommit for the transaction to be committed to the journal.
This requires action by the commit thread, which ends up waiting on a page
to complete writeback. The commit thread did not initiate the I/O, so it
cannot unplug the io queue, and deadlock occurs.

The fix is for the first thread to call blk_replug_current_nested() before
going to sleep. This patch also adds the call to a couple other places that
look like they need it.

Signed-off-by: Dave Kleikamp <shaggy@xxxxxxxxxxxxxxxxxx>

diff -Nurp linux-2.6.20-rc4-mm1/fs/jfs/jfs_lock.h linux/fs/jfs/jfs_lock.h
--- linux-2.6.20-rc4-mm1/fs/jfs/jfs_lock.h 2006-11-29 15:57:37.000000000 -0600
+++ linux/fs/jfs/jfs_lock.h 2007-01-17 15:30:19.000000000 -0600
@@ -22,6 +22,7 @@
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/sched.h>
+#include <linux/blkdev.h>

/*
* jfs_lock.h
@@ -42,6 +43,7 @@ do { \
if (cond) \
break; \
unlock_cmd; \
+ blk_replug_current_nested(); \
schedule(); \
lock_cmd; \
} \
diff -Nurp linux-2.6.20-rc4-mm1/fs/jfs/jfs_metapage.c linux/fs/jfs/jfs_metapage.c
--- linux-2.6.20-rc4-mm1/fs/jfs/jfs_metapage.c 2007-01-12 09:50:45.000000000 -0600
+++ linux/fs/jfs/jfs_metapage.c 2007-01-17 15:28:46.000000000 -0600
@@ -23,6 +23,7 @@
#include <linux/init.h>
#include <linux/buffer_head.h>
#include <linux/mempool.h>
+#include <linux/blkdev.h>
#include "jfs_incore.h"
#include "jfs_superblock.h"
#include "jfs_filsys.h"
@@ -56,6 +57,7 @@ static inline void __lock_metapage(struc
set_current_state(TASK_UNINTERRUPTIBLE);
if (metapage_locked(mp)) {
unlock_page(mp->page);
+ blk_replug_current_nested();
schedule();
lock_page(mp->page);
}
diff -Nurp linux-2.6.20-rc4-mm1/fs/jfs/jfs_txnmgr.c linux/fs/jfs/jfs_txnmgr.c
--- linux-2.6.20-rc4-mm1/fs/jfs/jfs_txnmgr.c 2007-01-12 09:50:45.000000000 -0600
+++ linux/fs/jfs/jfs_txnmgr.c 2007-01-17 15:29:04.000000000 -0600
@@ -50,6 +50,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kthread.h>
+#include <linux/blkdev.h>
#include "jfs_incore.h"
#include "jfs_inode.h"
#include "jfs_filsys.h"
@@ -135,6 +136,7 @@ static inline void TXN_SLEEP_DROP_LOCK(w
add_wait_queue(event, &wait);
set_current_state(TASK_UNINTERRUPTIBLE);
TXN_UNLOCK();
+ blk_replug_current_nested();
schedule();
current->state = TASK_RUNNING;
remove_wait_queue(event, &wait);

--
David Kleikamp
IBM Linux Technology Center

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/