mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: stable-review@vger.kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	greg@kroah.com, Christoph Hellwig <hch@lst.de>
Subject: [20/27] xfs: revert to using a kthread for AIL pushing
Date: Sun, 23 Oct 2011 08:24:48 +0200	[thread overview]
Message-ID: <20111023062540.374050289@pistachio.kroah.org> (raw)
In-Reply-To: <20111023062833.GA8126@kroah.com>

3.0-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Christoph Hellwig <hch@infradead.org>

commit 0030807c66f058230bcb20d2573bcaf28852e804 upstream

Currently we have a few issues with the way the workqueue code is used to
implement AIL pushing:

 - it accidentally uses the same workqueue as the syncer action, and thus
   can be prevented from running if there are enough sync actions active
   in the system.
 - it doesn't use the HIGHPRI flag to queue at the head of the queue of
   work items

At this point I'm not confident enough in getting all the workqueue flags and
tweaks right to provide a perfectly reliable execution context for AIL
pushing, which is the most important piece in XFS to make forward progress
when the log fills.

Revert back to use a kthread per filesystem which fixes all the above issues
at the cost of having a task struct and stack around for each mounted
filesystem.  In addition this also gives us much better ways to diagnose
any issues involving hung AIL pushing and removes a small amount of code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reported-by: Stefan Priebe <s.priebe@profihost.ag>
Tested-by: Stefan Priebe <s.priebe@profihost.ag>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/xfs/linux-2.6/xfs_linux.h |    2 +
 fs/xfs/linux-2.6/xfs_super.c |   13 -------
 fs/xfs/xfs_trans_ail.c       |   73 ++++++++++++++++++++++++-------------------
 fs/xfs/xfs_trans_priv.h      |    8 ----
 4 files changed, 45 insertions(+), 51 deletions(-)

--- a/fs/xfs/linux-2.6/xfs_linux.h
+++ b/fs/xfs/linux-2.6/xfs_linux.h
@@ -70,6 +70,8 @@
 #include <linux/ctype.h>
 #include <linux/writeback.h>
 #include <linux/capability.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
 #include <linux/list_sort.h>
 
 #include <asm/page.h>
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -1660,24 +1660,13 @@ xfs_init_workqueues(void)
 	 */
 	xfs_syncd_wq = alloc_workqueue("xfssyncd", WQ_CPU_INTENSIVE, 8);
 	if (!xfs_syncd_wq)
-		goto out;
-
-	xfs_ail_wq = alloc_workqueue("xfsail", WQ_CPU_INTENSIVE, 8);
-	if (!xfs_ail_wq)
-		goto out_destroy_syncd;
-
+		return -ENOMEM;
 	return 0;
-
-out_destroy_syncd:
-	destroy_workqueue(xfs_syncd_wq);
-out:
-	return -ENOMEM;
 }
 
 STATIC void
 xfs_destroy_workqueues(void)
 {
-	destroy_workqueue(xfs_ail_wq);
 	destroy_workqueue(xfs_syncd_wq);
 }
 
--- a/fs/xfs/xfs_trans_ail.c
+++ b/fs/xfs/xfs_trans_ail.c
@@ -28,8 +28,6 @@
 #include "xfs_trans_priv.h"
 #include "xfs_error.h"
 
-struct workqueue_struct	*xfs_ail_wq;	/* AIL workqueue */
-
 #ifdef DEBUG
 /*
  * Check that the list is sorted as it should be.
@@ -406,16 +404,10 @@ xfs_ail_delete(
 	xfs_trans_ail_cursor_clear(ailp, lip);
 }
 
-/*
- * xfs_ail_worker does the work of pushing on the AIL. It will requeue itself
- * to run at a later time if there is more work to do to complete the push.
- */
-STATIC void
-xfs_ail_worker(
-	struct work_struct	*work)
+static long
+xfsaild_push(
+	struct xfs_ail		*ailp)
 {
-	struct xfs_ail		*ailp = container_of(to_delayed_work(work),
-					struct xfs_ail, xa_work);
 	xfs_mount_t		*mp = ailp->xa_mount;
 	struct xfs_ail_cursor	*cur = &ailp->xa_cursors;
 	xfs_log_item_t		*lip;
@@ -556,20 +548,6 @@ out_done:
 		/* We're past our target or empty, so idle */
 		ailp->xa_last_pushed_lsn = 0;
 
-		/*
-		 * We clear the XFS_AIL_PUSHING_BIT first before checking
-		 * whether the target has changed. If the target has changed,
-		 * this pushes the requeue race directly onto the result of the
-		 * atomic test/set bit, so we are guaranteed that either the
-		 * the pusher that changed the target or ourselves will requeue
-		 * the work (but not both).
-		 */
-		clear_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags);
-		smp_rmb();
-		if (XFS_LSN_CMP(ailp->xa_target, target) == 0 ||
-		    test_and_set_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags))
-			return;
-
 		tout = 50;
 	} else if (XFS_LSN_CMP(lsn, target) >= 0) {
 		/*
@@ -592,9 +570,30 @@ out_done:
 		tout = 20;
 	}
 
-	/* There is more to do, requeue us.  */
-	queue_delayed_work(xfs_syncd_wq, &ailp->xa_work,
-					msecs_to_jiffies(tout));
+	return tout;
+}
+
+static int
+xfsaild(
+	void		*data)
+{
+	struct xfs_ail	*ailp = data;
+	long		tout = 0;	/* milliseconds */
+
+	while (!kthread_should_stop()) {
+		if (tout && tout <= 20)
+			__set_current_state(TASK_KILLABLE);
+		else
+			__set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(tout ?
+				 msecs_to_jiffies(tout) : MAX_SCHEDULE_TIMEOUT);
+
+		try_to_freeze();
+
+		tout = xfsaild_push(ailp);
+	}
+
+	return 0;
 }
 
 /*
@@ -629,8 +628,9 @@ xfs_ail_push(
 	 */
 	smp_wmb();
 	xfs_trans_ail_copy_lsn(ailp, &ailp->xa_target, &threshold_lsn);
-	if (!test_and_set_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags))
-		queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, 0);
+	smp_wmb();
+
+	wake_up_process(ailp->xa_task);
 }
 
 /*
@@ -865,9 +865,18 @@ xfs_trans_ail_init(
 	ailp->xa_mount = mp;
 	INIT_LIST_HEAD(&ailp->xa_ail);
 	spin_lock_init(&ailp->xa_lock);
-	INIT_DELAYED_WORK(&ailp->xa_work, xfs_ail_worker);
+
+	ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild/%s",
+			ailp->xa_mount->m_fsname);
+	if (IS_ERR(ailp->xa_task))
+		goto out_free_ailp;
+
 	mp->m_ail = ailp;
 	return 0;
+
+out_free_ailp:
+	kmem_free(ailp);
+	return ENOMEM;
 }
 
 void
@@ -876,6 +885,6 @@ xfs_trans_ail_destroy(
 {
 	struct xfs_ail	*ailp = mp->m_ail;
 
-	cancel_delayed_work_sync(&ailp->xa_work);
+	kthread_stop(ailp->xa_task);
 	kmem_free(ailp);
 }
--- a/fs/xfs/xfs_trans_priv.h
+++ b/fs/xfs/xfs_trans_priv.h
@@ -64,23 +64,17 @@ struct xfs_ail_cursor {
  */
 struct xfs_ail {
 	struct xfs_mount	*xa_mount;
+	struct task_struct	*xa_task;
 	struct list_head	xa_ail;
 	xfs_lsn_t		xa_target;
 	struct xfs_ail_cursor	xa_cursors;
 	spinlock_t		xa_lock;
-	struct delayed_work	xa_work;
 	xfs_lsn_t		xa_last_pushed_lsn;
-	unsigned long		xa_flags;
 };
 
-#define XFS_AIL_PUSHING_BIT	0
-
 /*
  * From xfs_trans_ail.c
  */
-
-extern struct workqueue_struct	*xfs_ail_wq;	/* AIL workqueue */
-
 void	xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
 				struct xfs_ail_cursor *cur,
 				struct xfs_log_item **log_items, int nr_items,



  parent reply	other threads:[~2011-10-23  6:38 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-23  6:28 [00/27] 3.0.8-stable review Greg KH
2011-10-23  6:24 ` [01/27] ARM: 7113/1: mm: Align bank start to MAX_ORDER_NR_PAGES Greg KH
2011-10-23  6:24 ` [02/27] ARM: 7117/1: perf: fix HW_CACHE_* events on Cortex-A9 Greg KH
2011-10-23  6:24 ` [03/27] HID: usbhid: Add support for SiGma Micro chip Greg KH
2011-10-23  6:24 ` [04/27] hwmon: (w83627ehf) Properly report thermal diode sensors Greg KH
2011-10-23  6:24 ` [05/27] Avoid using variable-length arrays in kernel/sys.c Greg KH
2011-10-23  6:24 ` [06/27] drm/radeon/kms/atom: fix handling of FB scratch indices Greg KH
2011-10-23  6:24 ` [07/27] cputimer: Cure lock inversion Greg KH
2011-10-23  6:24 ` [08/27] fuse: fix memory leak Greg KH
2011-10-23  6:24 ` [09/27] Platform: fix samsung-laptop DMI identification for N150/N210/220/N230 Greg KH
2011-10-23  6:24 ` [10/27] HID: magicmouse: ignore ivalid report id while switching modes, v2 Greg KH
2011-10-23  6:24 ` [11/27] [media] uvcvideo: Fix crash when linking entities Greg KH
2011-10-23  6:24 ` [12/27] hfsplus: ensure bio requests are not smaller than the hardware sectors Greg KH
2011-10-23  6:24 ` [13/27] drm/ttm: ensure ttm for new node is bound before calling move_notify() Greg KH
2011-10-23  6:24 ` [14/27] drm/ttm: unbind ttm before destroying node in accel move cleanup Greg KH
2011-10-23  6:24 ` [15/27] CIFS: Fix ERR_PTR dereference in cifs_get_root Greg KH
2011-10-23  6:24 ` [16/27] xfs: start periodic workers later Greg KH
2011-10-23  6:24 ` [17/27] xfs: use a cursor for bulk AIL insertion Greg KH
2011-10-23  6:24 ` [18/27] xfs: do not update xa_last_pushed_lsn for locked items Greg KH
2011-10-23  6:24 ` [19/27] xfs: force the log if we encounter pinned buffers in .iop_pushbuf Greg KH
2011-10-23  6:24 ` Greg KH [this message]
2011-10-23  6:24 ` [21/27] firewire: sbp2: fix panic after rmmod with slow targets Greg KH
2011-10-23  6:24 ` [22/27] VFS: Fix automount for negative autofs dentries Greg KH
2011-10-23  7:35   ` Linus Torvalds
2011-10-23  8:36     ` Greg KH
2011-10-23 21:09       ` Miklos Szeredi
2011-10-24 14:22         ` Greg KH
2011-10-23 11:59     ` Ian Kent
2011-11-01 15:51     ` David Howells
2011-10-23 11:41   ` Ian Kent
2011-10-23 11:48     ` Greg KH
2011-10-23 12:07       ` Ian Kent
2011-10-23  6:24 ` [23/27] mm: fix race between mremap and removing migration entry Greg KH
2011-10-23  6:24 ` [24/27] x25: Prevent skb overreads when checking call user data Greg KH
2011-10-23  6:24 ` [25/27] crypto: ghash - Avoid null pointer dereference if no key is set Greg KH
2011-10-23  6:24 ` [26/27] ALSA: HDA: conexant support for Lenovo T520/W520 Greg KH
2011-10-23  6:24 ` [27/27] ALSA: hda - Add position_fix quirk for Dell Inspiron 1010 Greg KH

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=20111023062540.374050289@pistachio.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable-review@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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

all inboxes | Powered by JetHome®