Commit 0bf6a5bd authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: convert the xfsaild threads to a workqueue

Similar to the xfssyncd, the per-filesystem xfsaild threads can be
converted to a global workqueue and run periodically by delayed
works. This makes sense for the AIL pushing because it uses
variable timeouts depending on the work that needs to be done.

By removing the xfsaild, we simplify the AIL pushing code and
remove the need to spread the code to implement the threading
and pushing across multiple files.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarAlex Elder <aelder@sgi.com>
parent a7b339f1
...@@ -816,75 +816,6 @@ xfs_setup_devices( ...@@ -816,75 +816,6 @@ xfs_setup_devices(
return 0; return 0;
} }
/*
* XFS AIL push thread support
*/
void
xfsaild_wakeup(
struct xfs_ail *ailp,
xfs_lsn_t threshold_lsn)
{
/* only ever move the target forwards */
if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0) {
ailp->xa_target = threshold_lsn;
wake_up_process(ailp->xa_task);
}
}
STATIC int
xfsaild(
void *data)
{
struct xfs_ail *ailp = data;
xfs_lsn_t last_pushed_lsn = 0;
long tout = 0; /* milliseconds */
while (!kthread_should_stop()) {
/*
* for short sleeps indicating congestion, don't allow us to
* get woken early. Otherwise all we do is bang on the AIL lock
* without making progress.
*/
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);
/* swsusp */
try_to_freeze();
ASSERT(ailp->xa_mount->m_log);
if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
continue;
tout = xfsaild_push(ailp, &last_pushed_lsn);
}
return 0;
} /* xfsaild */
int
xfsaild_start(
struct xfs_ail *ailp)
{
ailp->xa_target = 0;
ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild/%s",
ailp->xa_mount->m_fsname);
if (IS_ERR(ailp->xa_task))
return -PTR_ERR(ailp->xa_task);
return 0;
}
void
xfsaild_stop(
struct xfs_ail *ailp)
{
kthread_stop(ailp->xa_task);
}
/* Catch misguided souls that try to use this interface on XFS */ /* Catch misguided souls that try to use this interface on XFS */
STATIC struct inode * STATIC struct inode *
xfs_fs_alloc_inode( xfs_fs_alloc_inode(
...@@ -1785,6 +1716,38 @@ xfs_destroy_zones(void) ...@@ -1785,6 +1716,38 @@ xfs_destroy_zones(void)
} }
STATIC int __init
xfs_init_workqueues(void)
{
/*
* max_active is set to 8 to give enough concurency to allow
* multiple work operations on each CPU to run. This allows multiple
* filesystems to be running sync work concurrently, and scales with
* the number of CPUs in the system.
*/
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 0;
out_destroy_syncd:
destroy_workqueue(xfs_syncd_wq);
out:
return -ENOMEM;
}
STATIC void __exit
xfs_destroy_workqueues(void)
{
destroy_workqueue(xfs_ail_wq);
destroy_workqueue(xfs_syncd_wq);
}
STATIC int __init STATIC int __init
init_xfs_fs(void) init_xfs_fs(void)
{ {
...@@ -1800,10 +1763,14 @@ init_xfs_fs(void) ...@@ -1800,10 +1763,14 @@ init_xfs_fs(void)
if (error) if (error)
goto out; goto out;
error = xfs_mru_cache_init(); error = xfs_init_workqueues();
if (error) if (error)
goto out_destroy_zones; goto out_destroy_zones;
error = xfs_mru_cache_init();
if (error)
goto out_destroy_wq;
error = xfs_filestream_init(); error = xfs_filestream_init();
if (error) if (error)
goto out_mru_cache_uninit; goto out_mru_cache_uninit;
...@@ -1820,27 +1787,17 @@ init_xfs_fs(void) ...@@ -1820,27 +1787,17 @@ init_xfs_fs(void)
if (error) if (error)
goto out_cleanup_procfs; goto out_cleanup_procfs;
/* error = xfs_init_workqueues();
* max_active is set to 8 to give enough concurency to allow if (error)
* multiple work operations on each CPU to run. This allows multiple
* filesystems to be running sync work concurrently, and scales with
* the number of CPUs in the system.
*/
xfs_syncd_wq = alloc_workqueue("xfssyncd", WQ_CPU_INTENSIVE, 8);
if (!xfs_syncd_wq) {
error = -ENOMEM;
goto out_sysctl_unregister; goto out_sysctl_unregister;
}
vfs_initquota(); vfs_initquota();
error = register_filesystem(&xfs_fs_type); error = register_filesystem(&xfs_fs_type);
if (error) if (error)
goto out_destroy_xfs_syncd; goto out_sysctl_unregister;
return 0; return 0;
out_destroy_xfs_syncd:
destroy_workqueue(xfs_syncd_wq);
out_sysctl_unregister: out_sysctl_unregister:
xfs_sysctl_unregister(); xfs_sysctl_unregister();
out_cleanup_procfs: out_cleanup_procfs:
...@@ -1851,6 +1808,8 @@ init_xfs_fs(void) ...@@ -1851,6 +1808,8 @@ init_xfs_fs(void)
xfs_filestream_uninit(); xfs_filestream_uninit();
out_mru_cache_uninit: out_mru_cache_uninit:
xfs_mru_cache_uninit(); xfs_mru_cache_uninit();
out_destroy_wq:
xfs_destroy_workqueues();
out_destroy_zones: out_destroy_zones:
xfs_destroy_zones(); xfs_destroy_zones();
out: out:
...@@ -1862,12 +1821,12 @@ exit_xfs_fs(void) ...@@ -1862,12 +1821,12 @@ exit_xfs_fs(void)
{ {
vfs_exitquota(); vfs_exitquota();
unregister_filesystem(&xfs_fs_type); unregister_filesystem(&xfs_fs_type);
destroy_workqueue(xfs_syncd_wq);
xfs_sysctl_unregister(); xfs_sysctl_unregister();
xfs_cleanup_procfs(); xfs_cleanup_procfs();
xfs_buf_terminate(); xfs_buf_terminate();
xfs_filestream_uninit(); xfs_filestream_uninit();
xfs_mru_cache_uninit(); xfs_mru_cache_uninit();
xfs_destroy_workqueues();
xfs_destroy_zones(); xfs_destroy_zones();
} }
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "xfs_trans_priv.h" #include "xfs_trans_priv.h"
#include "xfs_error.h" #include "xfs_error.h"
struct workqueue_struct *xfs_ail_wq; /* AIL workqueue */
STATIC void xfs_ail_splice(struct xfs_ail *, struct list_head *, xfs_lsn_t); STATIC void xfs_ail_splice(struct xfs_ail *, struct list_head *, xfs_lsn_t);
STATIC void xfs_ail_delete(struct xfs_ail *, xfs_log_item_t *); STATIC void xfs_ail_delete(struct xfs_ail *, xfs_log_item_t *);
STATIC xfs_log_item_t * xfs_ail_min(struct xfs_ail *); STATIC xfs_log_item_t * xfs_ail_min(struct xfs_ail *);
...@@ -68,36 +70,6 @@ xfs_trans_ail_tail( ...@@ -68,36 +70,6 @@ xfs_trans_ail_tail(
return lsn; return lsn;
} }
/*
* xfs_trans_push_ail
*
* This routine is called to move the tail of the AIL forward. It does this by
* trying to flush items in the AIL whose lsns are below the given
* threshold_lsn.
*
* the push is run asynchronously in a separate thread, so we return the tail
* of the log right now instead of the tail after the push. This means we will
* either continue right away, or we will sleep waiting on the async thread to
* do its work.
*
* We do this unlocked - we only need to know whether there is anything in the
* AIL at the time we are called. We don't need to access the contents of
* any of the objects, so the lock is not needed.
*/
void
xfs_trans_ail_push(
struct xfs_ail *ailp,
xfs_lsn_t threshold_lsn)
{
xfs_log_item_t *lip;
lip = xfs_ail_min(ailp);
if (lip && !XFS_FORCED_SHUTDOWN(ailp->xa_mount)) {
if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0)
xfsaild_wakeup(ailp, threshold_lsn);
}
}
/* /*
* AIL traversal cursor initialisation. * AIL traversal cursor initialisation.
* *
...@@ -236,16 +208,16 @@ xfs_trans_ail_cursor_first( ...@@ -236,16 +208,16 @@ xfs_trans_ail_cursor_first(
} }
/* /*
* xfsaild_push does the work of pushing on the AIL. Returning a timeout of * xfs_ail_worker does the work of pushing on the AIL. It will requeue itself
* zero indicates that the caller should sleep until woken. * to run at a later time if there is more work to do to complete the push.
*/ */
long STATIC void
xfsaild_push( xfs_ail_worker(
struct xfs_ail *ailp, struct work_struct *work)
xfs_lsn_t *last_lsn)
{ {
long tout = 0; struct xfs_ail *ailp = container_of(to_delayed_work(work),
xfs_lsn_t last_pushed_lsn = *last_lsn; struct xfs_ail, xa_work);
long tout;
xfs_lsn_t target = ailp->xa_target; xfs_lsn_t target = ailp->xa_target;
xfs_lsn_t lsn; xfs_lsn_t lsn;
xfs_log_item_t *lip; xfs_log_item_t *lip;
...@@ -256,15 +228,15 @@ xfsaild_push( ...@@ -256,15 +228,15 @@ xfsaild_push(
spin_lock(&ailp->xa_lock); spin_lock(&ailp->xa_lock);
xfs_trans_ail_cursor_init(ailp, cur); xfs_trans_ail_cursor_init(ailp, cur);
lip = xfs_trans_ail_cursor_first(ailp, cur, *last_lsn); lip = xfs_trans_ail_cursor_first(ailp, cur, ailp->xa_last_pushed_lsn);
if (!lip || XFS_FORCED_SHUTDOWN(mp)) { if (!lip || XFS_FORCED_SHUTDOWN(mp)) {
/* /*
* AIL is empty or our push has reached the end. * AIL is empty or our push has reached the end.
*/ */
xfs_trans_ail_cursor_done(ailp, cur); xfs_trans_ail_cursor_done(ailp, cur);
spin_unlock(&ailp->xa_lock); spin_unlock(&ailp->xa_lock);
*last_lsn = 0; ailp->xa_last_pushed_lsn = 0;
return tout; return;
} }
XFS_STATS_INC(xs_push_ail); XFS_STATS_INC(xs_push_ail);
...@@ -301,13 +273,13 @@ xfsaild_push( ...@@ -301,13 +273,13 @@ xfsaild_push(
case XFS_ITEM_SUCCESS: case XFS_ITEM_SUCCESS:
XFS_STATS_INC(xs_push_ail_success); XFS_STATS_INC(xs_push_ail_success);
IOP_PUSH(lip); IOP_PUSH(lip);
last_pushed_lsn = lsn; ailp->xa_last_pushed_lsn = lsn;
break; break;
case XFS_ITEM_PUSHBUF: case XFS_ITEM_PUSHBUF:
XFS_STATS_INC(xs_push_ail_pushbuf); XFS_STATS_INC(xs_push_ail_pushbuf);
IOP_PUSHBUF(lip); IOP_PUSHBUF(lip);
last_pushed_lsn = lsn; ailp->xa_last_pushed_lsn = lsn;
push_xfsbufd = 1; push_xfsbufd = 1;
break; break;
...@@ -319,7 +291,7 @@ xfsaild_push( ...@@ -319,7 +291,7 @@ xfsaild_push(
case XFS_ITEM_LOCKED: case XFS_ITEM_LOCKED:
XFS_STATS_INC(xs_push_ail_locked); XFS_STATS_INC(xs_push_ail_locked);
last_pushed_lsn = lsn; ailp->xa_last_pushed_lsn = lsn;
stuck++; stuck++;
break; break;
...@@ -374,9 +346,23 @@ xfsaild_push( ...@@ -374,9 +346,23 @@ xfsaild_push(
wake_up_process(mp->m_ddev_targp->bt_task); wake_up_process(mp->m_ddev_targp->bt_task);
} }
/* assume we have more work to do in a short while */
tout = 10;
if (!count) { if (!count) {
/* We're past our target or empty, so idle */ /* We're past our target or empty, so idle */
last_pushed_lsn = 0; ailp->xa_last_pushed_lsn = 0;
/*
* Check for an updated push target before clearing the
* XFS_AIL_PUSHING_BIT. If the target changed, we've got more
* work to do. Wait a bit longer before starting that work.
*/
smp_rmb();
if (ailp->xa_target == target) {
clear_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags);
return;
}
tout = 50;
} else if (XFS_LSN_CMP(lsn, target) >= 0) { } else if (XFS_LSN_CMP(lsn, target) >= 0) {
/* /*
* We reached the target so wait a bit longer for I/O to * We reached the target so wait a bit longer for I/O to
...@@ -384,7 +370,7 @@ xfsaild_push( ...@@ -384,7 +370,7 @@ xfsaild_push(
* start the next scan from the start of the AIL. * start the next scan from the start of the AIL.
*/ */
tout = 50; tout = 50;
last_pushed_lsn = 0; ailp->xa_last_pushed_lsn = 0;
} else if ((stuck * 100) / count > 90) { } else if ((stuck * 100) / count > 90) {
/* /*
* Either there is a lot of contention on the AIL or we * Either there is a lot of contention on the AIL or we
...@@ -396,14 +382,48 @@ xfsaild_push( ...@@ -396,14 +382,48 @@ xfsaild_push(
* continuing from where we were. * continuing from where we were.
*/ */
tout = 20; tout = 20;
} else {
/* more to do, but wait a short while before continuing */
tout = 10;
} }
*last_lsn = last_pushed_lsn;
return tout; /* There is more to do, requeue us. */
queue_delayed_work(xfs_syncd_wq, &ailp->xa_work,
msecs_to_jiffies(tout));
} }
/*
* This routine is called to move the tail of the AIL forward. It does this by
* trying to flush items in the AIL whose lsns are below the given
* threshold_lsn.
*
* The push is run asynchronously in a workqueue, which means the caller needs
* to handle waiting on the async flush for space to become available.
* We don't want to interrupt any push that is in progress, hence we only queue
* work if we set the pushing bit approriately.
*
* We do this unlocked - we only need to know whether there is anything in the
* AIL at the time we are called. We don't need to access the contents of
* any of the objects, so the lock is not needed.
*/
void
xfs_trans_ail_push(
struct xfs_ail *ailp,
xfs_lsn_t threshold_lsn)
{
xfs_log_item_t *lip;
lip = xfs_ail_min(ailp);
if (!lip || XFS_FORCED_SHUTDOWN(ailp->xa_mount) ||
XFS_LSN_CMP(threshold_lsn, ailp->xa_target) <= 0)
return;
/*
* Ensure that the new target is noticed in push code before it clears
* the XFS_AIL_PUSHING_BIT.
*/
smp_wmb();
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);
}
/* /*
* This is to be called when an item is unlocked that may have * This is to be called when an item is unlocked that may have
...@@ -615,7 +635,6 @@ xfs_trans_ail_init( ...@@ -615,7 +635,6 @@ xfs_trans_ail_init(
xfs_mount_t *mp) xfs_mount_t *mp)
{ {
struct xfs_ail *ailp; struct xfs_ail *ailp;
int error;
ailp = kmem_zalloc(sizeof(struct xfs_ail), KM_MAYFAIL); ailp = kmem_zalloc(sizeof(struct xfs_ail), KM_MAYFAIL);
if (!ailp) if (!ailp)
...@@ -624,15 +643,9 @@ xfs_trans_ail_init( ...@@ -624,15 +643,9 @@ xfs_trans_ail_init(
ailp->xa_mount = mp; ailp->xa_mount = mp;
INIT_LIST_HEAD(&ailp->xa_ail); INIT_LIST_HEAD(&ailp->xa_ail);
spin_lock_init(&ailp->xa_lock); spin_lock_init(&ailp->xa_lock);
error = xfsaild_start(ailp); INIT_DELAYED_WORK(&ailp->xa_work, xfs_ail_worker);
if (error)
goto out_free_ailp;
mp->m_ail = ailp; mp->m_ail = ailp;
return 0; return 0;
out_free_ailp:
kmem_free(ailp);
return error;
} }
void void
...@@ -641,7 +654,7 @@ xfs_trans_ail_destroy( ...@@ -641,7 +654,7 @@ xfs_trans_ail_destroy(
{ {
struct xfs_ail *ailp = mp->m_ail; struct xfs_ail *ailp = mp->m_ail;
xfsaild_stop(ailp); cancel_delayed_work_sync(&ailp->xa_work);
kmem_free(ailp); kmem_free(ailp);
} }
......
...@@ -65,16 +65,22 @@ struct xfs_ail_cursor { ...@@ -65,16 +65,22 @@ struct xfs_ail_cursor {
struct xfs_ail { struct xfs_ail {
struct xfs_mount *xa_mount; struct xfs_mount *xa_mount;
struct list_head xa_ail; struct list_head xa_ail;
uint xa_gen;
struct task_struct *xa_task;
xfs_lsn_t xa_target; xfs_lsn_t xa_target;
struct xfs_ail_cursor xa_cursors; struct xfs_ail_cursor xa_cursors;
spinlock_t xa_lock; 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 * From xfs_trans_ail.c
*/ */
extern struct workqueue_struct *xfs_ail_wq; /* AIL workqueue */
void xfs_trans_ail_update_bulk(struct xfs_ail *ailp, void xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
struct xfs_log_item **log_items, int nr_items, struct xfs_log_item **log_items, int nr_items,
xfs_lsn_t lsn) __releases(ailp->xa_lock); xfs_lsn_t lsn) __releases(ailp->xa_lock);
...@@ -112,11 +118,6 @@ struct xfs_log_item *xfs_trans_ail_cursor_next(struct xfs_ail *ailp, ...@@ -112,11 +118,6 @@ struct xfs_log_item *xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
void xfs_trans_ail_cursor_done(struct xfs_ail *ailp, void xfs_trans_ail_cursor_done(struct xfs_ail *ailp,
struct xfs_ail_cursor *cur); struct xfs_ail_cursor *cur);
long xfsaild_push(struct xfs_ail *, xfs_lsn_t *);
void xfsaild_wakeup(struct xfs_ail *, xfs_lsn_t);
int xfsaild_start(struct xfs_ail *);
void xfsaild_stop(struct xfs_ail *);
#if BITS_PER_LONG != 64 #if BITS_PER_LONG != 64
static inline void static inline void
xfs_trans_ail_copy_lsn( xfs_trans_ail_copy_lsn(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment