Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 249a8c11 authored by David Chinner's avatar David Chinner Committed by Lachlan McIlroy
Browse files

[XFS] Move AIL pushing into it's own thread



When many hundreds to thousands of threads all try to do simultaneous
transactions and the log is in a tail-pushing situation (i.e. full), we
can get multiple threads walking the AIL list and contending on the AIL
lock.

The AIL push is, in effect, a simple I/O dispatch algorithm complicated by
the ordering constraints placed on it by the transaction subsystem. It
really does not need multiple threads to push on it - even when only a
single CPU is pushing the AIL, it can push the I/O out far faster that
pretty much any disk subsystem can handle.

So, to avoid contention problems stemming from multiple list walkers, move
the list walk off into another thread and simply provide a "target" to
push to. When a thread requires a push, it sets the target and wakes the
push thread, then goes to sleep waiting for the required amount of space
to become available in the log.

This mechanism should also be a lot fairer under heavy load as the waiters
will queue in arrival order, rather than queuing in "who completed a push
first" order.

Also, by moving the pushing to a separate thread we can do more
effectively overload detection and prevention as we can keep context from
loop iteration to loop iteration. That is, we can push only part of the
list each loop and not have to loop back to the start of the list every
time we run. This should also help by reducing the number of items we try
to lock and/or push items that we cannot move.

Note that this patch is not intended to solve the inefficiencies in the
AIL structure and the associated issues with extremely large list
contents. That needs to be addresses separately; parallel access would
cause problems to any new structure as well, so I'm only aiming to isolate
the structure from unbounded parallelism here.

SGI-PV: 972759
SGI-Modid: xfs-linux-melb:xfs-kern:30371a

Signed-off-by: default avatarDavid Chinner <dgc@sgi.com>
Signed-off-by: default avatarLachlan McIlroy <lachlan@sgi.com>
parent 4576758d
Loading
Loading
Loading
Loading
+59 −0
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@
#include "xfs_vfsops.h"
#include "xfs_vfsops.h"
#include "xfs_version.h"
#include "xfs_version.h"
#include "xfs_log_priv.h"
#include "xfs_log_priv.h"
#include "xfs_trans_priv.h"


#include <linux/namei.h>
#include <linux/namei.h>
#include <linux/init.h>
#include <linux/init.h>
@@ -765,6 +766,64 @@ xfs_blkdev_issue_flush(
	blkdev_issue_flush(buftarg->bt_bdev, NULL);
	blkdev_issue_flush(buftarg->bt_bdev, NULL);
}
}


/*
 * XFS AIL push thread support
 */
void
xfsaild_wakeup(
	xfs_mount_t		*mp,
	xfs_lsn_t		threshold_lsn)
{
	mp->m_ail.xa_target = threshold_lsn;
	wake_up_process(mp->m_ail.xa_task);
}

int
xfsaild(
	void	*data)
{
	xfs_mount_t	*mp = (xfs_mount_t *)data;
	xfs_lsn_t	last_pushed_lsn = 0;
	long		tout = 0;

	while (!kthread_should_stop()) {
		if (tout)
			schedule_timeout_interruptible(msecs_to_jiffies(tout));
		tout = 1000;

		/* swsusp */
		try_to_freeze();

		ASSERT(mp->m_log);
		if (XFS_FORCED_SHUTDOWN(mp))
			continue;

		tout = xfsaild_push(mp, &last_pushed_lsn);
	}

	return 0;
}	/* xfsaild */

int
xfsaild_start(
	xfs_mount_t	*mp)
{
	mp->m_ail.xa_target = 0;
	mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
	if (IS_ERR(mp->m_ail.xa_task))
		return -PTR_ERR(mp->m_ail.xa_task);
	return 0;
}

void
xfsaild_stop(
	xfs_mount_t	*mp)
{
	kthread_stop(mp->m_ail.xa_task);
}



STATIC struct inode *
STATIC struct inode *
xfs_fs_alloc_inode(
xfs_fs_alloc_inode(
	struct super_block	*sb)
	struct super_block	*sb)
+26 −7
Original line number Original line Diff line number Diff line
@@ -498,11 +498,14 @@ xfs_log_reserve(xfs_mount_t *mp,
 * Return error or zero.
 * Return error or zero.
 */
 */
int
int
xfs_log_mount(xfs_mount_t	*mp,
xfs_log_mount(
	xfs_mount_t	*mp,
	xfs_buftarg_t	*log_target,
	xfs_buftarg_t	*log_target,
	xfs_daddr_t	blk_offset,
	xfs_daddr_t	blk_offset,
	int		num_bblks)
	int		num_bblks)
{
{
	int		error;

	if (!(mp->m_flags & XFS_MOUNT_NORECOVERY))
	if (!(mp->m_flags & XFS_MOUNT_NORECOVERY))
		cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname);
		cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname);
	else {
	else {
@@ -514,12 +517,22 @@ xfs_log_mount(xfs_mount_t *mp,


	mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);
	mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);


	/*
	 * Initialize the AIL now we have a log.
	 */
	spin_lock_init(&mp->m_ail_lock);
	error = xfs_trans_ail_init(mp);
	if (error) {
		cmn_err(CE_WARN, "XFS: AIL initialisation failed: error %d", error);
		goto error;
	}

	/*
	/*
	 * skip log recovery on a norecovery mount.  pretend it all
	 * skip log recovery on a norecovery mount.  pretend it all
	 * just worked.
	 * just worked.
	 */
	 */
	if (!(mp->m_flags & XFS_MOUNT_NORECOVERY)) {
	if (!(mp->m_flags & XFS_MOUNT_NORECOVERY)) {
		int		error, readonly = (mp->m_flags & XFS_MOUNT_RDONLY);
		int	readonly = (mp->m_flags & XFS_MOUNT_RDONLY);


		if (readonly)
		if (readonly)
			mp->m_flags &= ~XFS_MOUNT_RDONLY;
			mp->m_flags &= ~XFS_MOUNT_RDONLY;
@@ -530,8 +543,7 @@ xfs_log_mount(xfs_mount_t *mp,
			mp->m_flags |= XFS_MOUNT_RDONLY;
			mp->m_flags |= XFS_MOUNT_RDONLY;
		if (error) {
		if (error) {
			cmn_err(CE_WARN, "XFS: log mount/recovery failed: error %d", error);
			cmn_err(CE_WARN, "XFS: log mount/recovery failed: error %d", error);
			xlog_dealloc_log(mp->m_log);
			goto error;
			return error;
		}
		}
	}
	}


@@ -540,6 +552,9 @@ xfs_log_mount(xfs_mount_t *mp,


	/* End mounting message in xfs_log_mount_finish */
	/* End mounting message in xfs_log_mount_finish */
	return 0;
	return 0;
error:
	xfs_log_unmount_dealloc(mp);
	return error;
}	/* xfs_log_mount */
}	/* xfs_log_mount */


/*
/*
@@ -722,10 +737,14 @@ xfs_log_unmount_write(xfs_mount_t *mp)


/*
/*
 * Deallocate log structures for unmount/relocation.
 * Deallocate log structures for unmount/relocation.
 *
 * We need to stop the aild from running before we destroy
 * and deallocate the log as the aild references the log.
 */
 */
void
void
xfs_log_unmount_dealloc(xfs_mount_t *mp)
xfs_log_unmount_dealloc(xfs_mount_t *mp)
{
{
	xfs_trans_ail_destroy(mp);
	xlog_dealloc_log(mp->m_log);
	xlog_dealloc_log(mp->m_log);
}
}


+0 −6
Original line number Original line Diff line number Diff line
@@ -136,15 +136,9 @@ xfs_mount_init(void)
		mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
		mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
	}
	}


	spin_lock_init(&mp->m_ail_lock);
	spin_lock_init(&mp->m_sb_lock);
	spin_lock_init(&mp->m_sb_lock);
	mutex_init(&mp->m_ilock);
	mutex_init(&mp->m_ilock);
	mutex_init(&mp->m_growlock);
	mutex_init(&mp->m_growlock);
	/*
	 * Initialize the AIL.
	 */
	xfs_trans_ail_init(mp);

	atomic_set(&mp->m_active_trans, 0);
	atomic_set(&mp->m_active_trans, 0);


	return mp;
	return mp;
+8 −2
Original line number Original line Diff line number Diff line
@@ -219,12 +219,18 @@ extern void xfs_icsb_sync_counters_flags(struct xfs_mount *, int);
#define xfs_icsb_sync_counters_flags(mp, flags)	do { } while (0)
#define xfs_icsb_sync_counters_flags(mp, flags)	do { } while (0)
#endif
#endif


typedef struct xfs_ail {
	xfs_ail_entry_t		xa_ail;
	uint			xa_gen;
	struct task_struct	*xa_task;
	xfs_lsn_t		xa_target;
} xfs_ail_t;

typedef struct xfs_mount {
typedef struct xfs_mount {
	struct super_block	*m_super;
	struct super_block	*m_super;
	xfs_tid_t		m_tid;		/* next unused tid for fs */
	xfs_tid_t		m_tid;		/* next unused tid for fs */
	spinlock_t		m_ail_lock;	/* fs AIL mutex */
	spinlock_t		m_ail_lock;	/* fs AIL mutex */
	xfs_ail_entry_t		m_ail;		/* fs active log item list */
	xfs_ail_t		m_ail;		/* fs active log item list */
	uint			m_ail_gen;	/* fs AIL generation count */
	xfs_sb_t		m_sb;		/* copy of fs superblock */
	xfs_sb_t		m_sb;		/* copy of fs superblock */
	spinlock_t		m_sb_lock;	/* sb counter lock */
	spinlock_t		m_sb_lock;	/* sb counter lock */
	struct xfs_buf		*m_sb_bp;	/* buffer for superblock */
	struct xfs_buf		*m_sb_bp;	/* buffer for superblock */
+3 −2
Original line number Original line Diff line number Diff line
@@ -992,8 +992,9 @@ int _xfs_trans_commit(xfs_trans_t *,
				  int *);
				  int *);
#define xfs_trans_commit(tp, flags)	_xfs_trans_commit(tp, flags, NULL)
#define xfs_trans_commit(tp, flags)	_xfs_trans_commit(tp, flags, NULL)
void		xfs_trans_cancel(xfs_trans_t *, int);
void		xfs_trans_cancel(xfs_trans_t *, int);
void		xfs_trans_ail_init(struct xfs_mount *);
int		xfs_trans_ail_init(struct xfs_mount *);
xfs_lsn_t	xfs_trans_push_ail(struct xfs_mount *, xfs_lsn_t);
void		xfs_trans_ail_destroy(struct xfs_mount *);
void		xfs_trans_push_ail(struct xfs_mount *, xfs_lsn_t);
xfs_lsn_t	xfs_trans_tail_ail(struct xfs_mount *);
xfs_lsn_t	xfs_trans_tail_ail(struct xfs_mount *);
void		xfs_trans_unlocked_item(struct xfs_mount *,
void		xfs_trans_unlocked_item(struct xfs_mount *,
					xfs_log_item_t *);
					xfs_log_item_t *);
Loading