Skip to contentSkip to conversation

xfs: Reduce OOM kill problems under heavy load V2

PATCH In review Dave Chinner 2 participants 22 messages Mar 10, 2011 – Apr 4, 2011 XFS filesystem

lore
Share & tools
lore
#1 lore raw

PATCH 1/6 xfs: introduce inode cluster buffer trylocks for xfs_iflush

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

There is an ABBA deadlock between synchronous inode flushing in xfs_reclaim_inode and xfs_icluster_free. xfs_icluster_free locks the buffer, then takes inode ilocks, whilst synchronous reclaim takes the ilock followed by the buffer lock in xfs_iflush().

To avoid this deadlock, separate the inode cluster buffer locking semantics from the synchronous inode flush semantics, allowing callers to attempt to lock the buffer but still issue synchronous IO if it can get the buffer. This requires xfs_iflush() calls that currently use non-blocking semantics to pass SYNC_TRYLOCK rather than 0 as the flags parameter.

This allows xfs_reclaim_inode to avoid the deadlock on the buffer lock and detect the failure so that it can drop the inode ilock and restart the reclaim attempt on the inode. This allows xfs_ifree_cluster to obtain the inode lock, mark the inode stale and release it and hence defuse the deadlock situation. It also has the pleasant side effect of avoiding IO in xfs_reclaim_inode when it tries to next reclaim the inode as it is now marked stale.

---
 fs/xfs/linux-2.6/xfs_super.c |    2 +-
 fs/xfs/linux-2.6/xfs_sync.c  |   30 +++++++++++++++++++++++++++---
 fs/xfs/xfs_inode.c           |    2 +-
 fs/xfs/xfs_inode_item.c      |    6 +++---
 4 files changed, 32 insertions(+), 8 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +1 -1
index 818c4cf..8a70b2a 100644
@@ -1078,7 +1078,7 @@ xfs_fs_write_inode(
 			error = 0;
 			goto out_unlock;
 		}
-		error = xfs_iflush(ip, 0);
+		error = xfs_iflush(ip, SYNC_TRYLOCK);
 	}
 
  out_unlock:
fs/xfs/linux-2.6/xfs_sync.c +27 -3
index 6c10f1d..594cd82 100644
@@ -761,8 +761,10 @@ xfs_reclaim_inode(
 	struct xfs_perag	*pag,
 	int			sync_mode)
 {
-	int	error = 0;
+	int	error;
 
+restart:
+	error = 0;
 	xfs_ilock(ip, XFS_ILOCK_EXCL);
 	if (!xfs_iflock_nowait(ip)) {
 		if (!(sync_mode & SYNC_WAIT))
@@ -788,9 +790,31 @@ xfs_reclaim_inode(
 	if (xfs_inode_clean(ip))
 		goto reclaim;
 
-	/* Now we have an inode that needs flushing */
-	error = xfs_iflush(ip, sync_mode);
+	/*
+	 * Now we have an inode that needs flushing.
+	 *
+	 * We do a nonblocking flush here even if we are doing a SYNC_WAIT
+	 * reclaim as we can deadlock with inode cluster removal.
+	 * xfs_ifree_cluster() can lock the inode buffer before it locks the
+	 * ip->i_lock, and we are doing the exact opposite here. As a result,
+	 * doing a blocking xfs_itobp() to get the cluster buffer will result
+	 * in an ABBA deadlock with xfs_ifree_cluster().
+	 *
+	 * As xfs_ifree_cluser() must gather all inodes that are active in the
+	 * cache to mark them stale, if we hit this case we don't actually want
+	 * to do IO here - we want the inode marked stale so we can simply
+	 * reclaim it. Hence if we get an EAGAIN error on a SYNC_WAIT flush,
+	 * just unlock the inode, back off and try again. Hopefully the next
+	 * pass through will see the stale flag set on the inode.
+	 */
+	error = xfs_iflush(ip, SYNC_TRYLOCK | sync_mode);
 	if (sync_mode & SYNC_WAIT) {
+		if (error == EAGAIN) {
+			xfs_iunlock(ip, XFS_ILOCK_EXCL);
+			/* backoff longer than in xfs_ifree_cluster */
+			delay(2);
+			goto restart;
+		}
 		xfs_iflock(ip);
 		goto reclaim;
 	}
fs/xfs/xfs_inode.c +1 -1
index da871f5..742c833 100644
@@ -2835,7 +2835,7 @@ xfs_iflush(
 	 * Get the buffer containing the on-disk inode.
 	 */
 	error = xfs_itobp(mp, NULL, ip, &dip, &bp,
-				(flags & SYNC_WAIT) ? XBF_LOCK : XBF_TRYLOCK);
+				(flags & SYNC_TRYLOCK) ? XBF_TRYLOCK : XBF_LOCK);
 	if (error || !bp) {
 		xfs_ifunlock(ip);
 		return error;
fs/xfs/xfs_inode_item.c +3 -3
index fd4f398..46cc401 100644
@@ -760,11 +760,11 @@ xfs_inode_item_push(
 	 * Push the inode to it's backing buffer. This will not remove the
 	 * inode from the AIL - a further push will be required to trigger a
 	 * buffer push. However, this allows all the dirty inodes to be pushed
-	 * to the buffer before it is pushed to disk. THe buffer IO completion
-	 * will pull th einode from the AIL, mark it clean and unlock the flush
+	 * to the buffer before it is pushed to disk. The buffer IO completion
+	 * will pull the inode from the AIL, mark it clean and unlock the flush
 	 * lock.
 	 */
-	(void) xfs_iflush(ip, 0);
+	(void) xfs_iflush(ip, SYNC_TRYLOCK);
 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
 }
 
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#0 lore raw

cover xfs: Reduce OOM kill problems under heavy load V2

Chris Mason reported recently that a concurent stress test (basically copying the linux kernel tree 20 times, verifying md5sums and deleting it in a loop concurrently) under low memory conditions was triggering the OOM killer muchmore easily than for btrfs.

Turns out there are two main problems. The first is that unlinked inodes were not being reclaimed fast enough, leading to the OOM being declared when there are large numbers of reclaimable inodes still around. The second was that atime updates due to the verify step were creating large numbers of dirty inodes at the VFS level that were not being written back and hence made reclaimable before the system declared OOM and killed stuff.

The first problem is fixed by making background inode reclaim more frequent and faster, kicking background reclaim from the inode cache shrinker so that when memory is low we always have background inode reclaim in progress, and finally making the shrinker reclaim scan block waiting on inodes to reclaim. This last step throttles memory reclaim to the speed at which we can reclaim inodes, a key step needed to prevent inodes from reclaim declaring OOM while there are still reclaimable inodes around. The background inode reclaim prevents this synchronous flush from finding dirty inodes and block on them in most cases and hence prevents performance regressions in more common workloads due to reclaim stalls.

To enable this new functionality, the xfssyncd thread is replaced with a workqueue and the existing xfssyncd work replaced with a global workqueue. Hence all filesystems will share the same workqueue and we remove allt eh xfssyncd threads from the system. The ENOSPC inode flush is converted to use the workqueue, and optimised to only allow a single flush at a time. This significant speeds up ENOSPC processing under concurrent workloads as it removes all the unnecessary scanning that every single ENOSPC event currently queues to the xfssyncd. Finally, a new reinode reclaim worker is added to the workqueue that runs 5x more frequently that the xfssyncd to do the background inode reclaim scan.

The second problem is could be fixed by making the XFS inode cache shrinker kick the bdi flusher to write back inodes if the bdi flusher is not already active. This, however, causes deadlocks when the bdi-flusher thread needs to be forked under memory pressure, so these patches have been dropped for now.

An addition to the series is to push the AIL when we are under memory stress to speed up the cleaning of dirty metadata. While this does not avoid the problems with VFS level dirty objects, it does ensure we don't keep lots of dirty objects that the VFS knows nothing about pinned in memory when there is a shortage.

By also pushing the AIL doing the periodic syncd work, we ensure that we always clear out dirty objects from the AIL regularly and hence allow the filesytem to idle correctly. Conversion of the xfsaild thread to a workqueue also simplifies the push trigger mechanism for cleaning the AIL and removes the need for a thread per filesystem for this work.

Version 2:
- drop writeback_inodes_sb_nr_if_idle() patch
- no need for work_pending checks before queueing - the queuing already does this atomically.
- remove xfs_syncd_lock as it is not necessary anymore
- simplify inode reclaim trigger
- add AIL pushing patches.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#6 lore raw

PATCH 3/6 xfs: convert ENOSPC inode flushing to use new syncd workqueue

From: Dave Chinner <[email protected]>

On of the problems with the current inode flush at ENOSPC is that we queue a flush per ENOSPC event, regardless of how many are already
queued. Thi can result in hundreds of queued flushes, most of
which simply burn CPU scanned and do no real work. This simply slows down allocation at ENOSPC.

We really only need one active flush at a time, and we can easily implement that via the new xfs_syncd_wq. All we need to do is queue a flush if one is not already active, then block waiting for the currently active flush to complete. The result is that we only ever have a single ENOSPC inode flush active at a time and this greatly reduces the overhead of ENOSPC processing.

On my 2p test machine, this results in tests exercising ENOSPC conditions running significantly faster - 042 halves execution time, 083 drops from 60s to 5s, etc - while not introducing test regressions.

This allows us to remove the old xfssyncd threads and infrastructure as they are no longer used.

---
 fs/xfs/linux-2.6/xfs_super.c |    2 -
 fs/xfs/linux-2.6/xfs_sync.c  |  133 +++++++++++------------------------------
 fs/xfs/xfs_mount.h           |    4 +-
 3 files changed, 37 insertions(+), 102 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +0 -2
index 768894b..1cbee9c 100644
@@ -1480,8 +1480,6 @@ xfs_fs_fill_super(
 	spin_lock_init(&mp->m_sb_lock);
 	mutex_init(&mp->m_growlock);
 	atomic_set(&mp->m_active_trans, 0);
-	INIT_LIST_HEAD(&mp->m_sync_list);
-	spin_lock_init(&mp->m_sync_lock);
 
 	mp->m_super = sb;
 	sb->s_fs_info = mp;
fs/xfs/linux-2.6/xfs_sync.c +36 -97

158 lines not on this page · raw message

fs/xfs/xfs_mount.h +1 -3
index 2c11e62..a0ad90e 100644
@@ -204,9 +204,7 @@ typedef struct xfs_mount {
 #endif
 	struct xfs_mru_cache	*m_filestream;  /* per-mount filestream data */
 	struct delayed_work	m_sync_work;	/* background sync work */
-	struct task_struct	*m_sync_task;	/* generalised sync thread */
-	struct list_head	m_sync_list;	/* sync thread work item list */
-	spinlock_t		m_sync_lock;	/* work item list lock */
+	struct work_struct	m_flush_work;	/* background inode flush */
 	__int64_t		m_update_flags;	/* sb flags we need to update
 						   on the next remount,rw */
 	struct shrinker		m_inode_shrink;	/* inode reclaim shrinker */
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#12 lore raw

PATCH 5/6 xfs: convert the xfsaild threads to a workqueue

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

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.

---
 fs/xfs/linux-2.6/xfs_super.c |  109 ++++++++++-------------------------
 fs/xfs/xfs_trans_ail.c       |  130 ++++++++++++++++++++++++------------------
 fs/xfs/xfs_trans_priv.h      |   11 ++--
 3 files changed, 111 insertions(+), 139 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +32 -77
index 1cbee9c..b0bcfb3 100644
@@ -816,75 +816,6 @@ xfs_setup_devices(
 	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 */
 STATIC struct inode *
 xfs_fs_alloc_inode(
@@ -1772,6 +1703,32 @@ xfs_destroy_zones(void)
 }
 
 STATIC int __init
+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 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
 init_xfs_fs(void)
 {
 	int			error;
@@ -1806,21 +1763,19 @@ init_xfs_fs(void)
 	if (error)
 		goto out_cleanup_procfs;
 
-	xfs_syncd_wq = alloc_workqueue("xfssyncd", WQ_CPU_INTENSIVE, 8);
-	if (!xfs_syncd_wq) {
-		error = -ENOMEM;
+	error = xfs_init_workqueues();
+	if (error)
 		goto out_sysctl_unregister;
-	}
 
 	vfs_initquota();
 
 	error = register_filesystem(&xfs_fs_type);
 	if (error)
-		goto out_destroy_xfs_syncd;
+		goto out_destroy_wq;
 	return 0;
 
-out_destroy_xfs_syncd:
-	destroy_workqueue(xfs_syncd_wq);
+out_destroy_wq:
+	xfs_destroy_workqueues();
 out_sysctl_unregister:
 	xfs_sysctl_unregister();
 out_cleanup_procfs:
@@ -1842,7 +1797,7 @@ exit_xfs_fs(void)
 {
 	vfs_exitquota();
 	unregister_filesystem(&xfs_fs_type);
-	destroy_workqueue(xfs_syncd_wq);
+	xfs_destroy_workqueues();
 	xfs_sysctl_unregister();
 	xfs_cleanup_procfs();
 	xfs_buf_terminate();
fs/xfs/xfs_trans_ail.c +74 -56

220 lines not on this page · raw message

fs/xfs/xfs_trans_priv.h +5 -6
index 35162c2..2410da4 100644
@@ -66,15 +66,19 @@ struct xfs_ail {
 	struct xfs_mount	*xa_mount;
 	struct list_head	xa_ail;
 	uint			xa_gen;
-	struct task_struct	*xa_task;
 	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;
 };
 
 /*
  * 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_log_item **log_items, int nr_items,
 				xfs_lsn_t lsn) __releases(ailp->xa_lock);
@@ -112,11 +116,6 @@ struct xfs_log_item	*xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
 void			xfs_trans_ail_cursor_done(struct xfs_ail *ailp,
 					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
 static inline void
 xfs_trans_ail_copy_lsn(
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#19 lore raw

PATCH 6/6 xfs: push the AIL from memory reclaim and periodic sync

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

When we are short on memory, we want to expedite the cleaning of dirty objects. Hence when we run short on memory, we need to kick the AIL flushing into action to clean as many dirty objects as quickly as possible. To implement this, sample the lsn of the log item at the head of the AIL and use that as the push target for the AIL flush.

Further, we keep items in the AIL that are dirty that are not tracked any other way, so we can get objects sitting in the AIL that don't get written back until the AIL is pushed. Hence to get the filesystem to the idle state, we might need to push the AIL to flush out any remaining dirty objects sitting in the AIL. This requires the same push mechanism as the reclaim push.

This patch rearranges the location of functions in xfs_trans_ail.c to remove the need for forward declarations of those functions and new functions added in this commit.

---
 fs/xfs/linux-2.6/xfs_sync.c |    7 ++-
 fs/xfs/xfs_trans_ail.c      |  206 +++++++++++++++++++++++++------------------
 fs/xfs/xfs_trans_priv.h     |    1 +
 3 files changed, 129 insertions(+), 85 deletions(-)
fs/xfs/linux-2.6/xfs_sync.c +6 -1
index 3f39d83..7ab79671 100644
@@ -22,6 +22,7 @@
 #include "xfs_log.h"
 #include "xfs_inum.h"
 #include "xfs_trans.h"
+#include "xfs_trans_priv.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_mount.h"
@@ -463,6 +464,9 @@ xfs_sync_worker(
 			xfs_log_force(mp, 0);
 		xfs_reclaim_inodes(mp, 0);
 		error = xfs_qm_sync(mp, SYNC_TRYLOCK);
+
+		/* start pushing all the metadata that is currently dirty */
+		xfs_trans_ail_push_all(mp->m_ail);
 	}
 
 	/* queue us up again */
@@ -1017,8 +1021,9 @@ xfs_reclaim_inode_shrink(
 
 	mp = container_of(shrink, struct xfs_mount, m_inode_shrink);
 	if (nr_to_scan) {
-		/* kick background reclaimer */
+		/* kick background reclaimer and push the AIL */
 		xfs_syncd_queue_reclaim(mp);
+		xfs_trans_ail_push_all(mp->m_ail);
 
 		if (!(gfp_mask & __GFP_FS))
 			return -1;
fs/xfs/xfs_trans_ail.c +122 -84

247 lines not on this page · raw message

fs/xfs/xfs_trans_priv.h +1 -0
index 2410da4..dbd93e6 100644
@@ -103,6 +103,7 @@ xfs_trans_ail_delete(
 }
 
 void			xfs_trans_ail_push(struct xfs_ail *, xfs_lsn_t);
+void			xfs_trans_ail_push_all(struct xfs_ail *);
 void			xfs_trans_unlocked_item(struct xfs_ail *,
 					xfs_log_item_t *);
 
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#3 lore raw

PATCH 2/6 xfs: introduce a xfssyncd workqueue

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

All of the work xfssyncd does is background functionality. There is no need for a thread per filesystem to do this work - it can al be managed by a global workqueue now they manage concurrency effectively.

Introduce a new gglobal xfssyncd workqueue, and convert the periodic work to use this new functionality. To do this, use a delayed work construct to schedule the next running of the periodic sync work for the filesystem. When the sync work is complete, queue a new delayed work for the next running of the sync work.

For laptop mode, we wait on completion for the sync works, so ensure that the sync work queuing interface can flush and wait for work to complete to enable the work queue infrastructure to replace the current sequence number and wakeup that is used.

Because the sync work does non-trivial amounts of work, mark the new work queue as CPU intensive.

---
 fs/xfs/linux-2.6/xfs_super.c |   38 +++++++++----------
 fs/xfs/linux-2.6/xfs_sync.c  |   86 ++++++++++++++++++++---------------------
 fs/xfs/linux-2.6/xfs_sync.h  |    2 +
 fs/xfs/xfs_mount.h           |    4 +-
 4 files changed, 63 insertions(+), 67 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +18 -20
index 8a70b2a..768894b 100644
@@ -1191,22 +1191,12 @@ xfs_fs_sync_fs(
 		return -error;
 
 	if (laptop_mode) {
-		int	prev_sync_seq = mp->m_sync_seq;
-
 		/*
 		 * The disk must be active because we're syncing.
 		 * We schedule xfssyncd now (now that the disk is
 		 * active) instead of later (when it might not be).
 		 */
-		wake_up_process(mp->m_sync_task);
-		/*
-		 * We have to wait for the sync iteration to complete.
-		 * If we don't, the disk activity caused by the sync
-		 * will come after the sync is completed, and that
-		 * triggers another sync from laptop mode.
-		 */
-		wait_event(mp->m_wait_single_sync_task,
-				mp->m_sync_seq != prev_sync_seq);
+		flush_delayed_work_sync(&mp->m_sync_work);
 	}
 
 	return 0;
@@ -1492,7 +1482,6 @@ xfs_fs_fill_super(
 	atomic_set(&mp->m_active_trans, 0);
 	INIT_LIST_HEAD(&mp->m_sync_list);
 	spin_lock_init(&mp->m_sync_lock);
-	init_waitqueue_head(&mp->m_wait_single_sync_task);
 
 	mp->m_super = sb;
 	sb->s_fs_info = mp;
@@ -1819,26 +1808,34 @@ init_xfs_fs(void)
 	if (error)
 		goto out_cleanup_procfs;
 
+	xfs_syncd_wq = alloc_workqueue("xfssyncd", WQ_CPU_INTENSIVE, 8);
+	if (!xfs_syncd_wq) {
+		error = -ENOMEM;
+		goto out_sysctl_unregister;
+	}
+
 	vfs_initquota();
 
 	error = register_filesystem(&xfs_fs_type);
 	if (error)
-		goto out_sysctl_unregister;
+		goto out_destroy_xfs_syncd;
 	return 0;
 
- out_sysctl_unregister:
+out_destroy_xfs_syncd:
+	destroy_workqueue(xfs_syncd_wq);
+out_sysctl_unregister:
 	xfs_sysctl_unregister();
- out_cleanup_procfs:
+out_cleanup_procfs:
 	xfs_cleanup_procfs();
- out_buf_terminate:
+out_buf_terminate:
 	xfs_buf_terminate();
- out_filestream_uninit:
+out_filestream_uninit:
 	xfs_filestream_uninit();
- out_mru_cache_uninit:
+out_mru_cache_uninit:
 	xfs_mru_cache_uninit();
- out_destroy_zones:
+out_destroy_zones:
 	xfs_destroy_zones();
- out:
+out:
 	return error;
 }
 
@@ -1847,6 +1844,7 @@ exit_xfs_fs(void)
 {
 	vfs_exitquota();
 	unregister_filesystem(&xfs_fs_type);
+	destroy_workqueue(xfs_syncd_wq);
 	xfs_sysctl_unregister();
 	xfs_cleanup_procfs();
 	xfs_buf_terminate();
fs/xfs/linux-2.6/xfs_sync.c +42 -44

126 lines not on this page · raw message

fs/xfs/linux-2.6/xfs_sync.h +2 -0
index 32ba662..e3a6ad2 100644
@@ -32,6 +32,8 @@ typedef struct xfs_sync_work {
 #define SYNC_WAIT		0x0001	/* wait for i/o to complete */
 #define SYNC_TRYLOCK		0x0002  /* only try to lock inodes */
 
+extern struct workqueue_struct	*xfs_syncd_wq;	/* sync workqueue */
+
 int xfs_syncd_init(struct xfs_mount *mp);
 void xfs_syncd_stop(struct xfs_mount *mp);
 
fs/xfs/xfs_mount.h +1 -3
index a62e897..2c11e62 100644
@@ -203,12 +203,10 @@ typedef struct xfs_mount {
 	struct mutex		m_icsb_mutex;	/* balancer sync lock */
 #endif
 	struct xfs_mru_cache	*m_filestream;  /* per-mount filestream data */
+	struct delayed_work	m_sync_work;	/* background sync work */
 	struct task_struct	*m_sync_task;	/* generalised sync thread */
-	xfs_sync_work_t		m_sync_work;	/* work item for VFS_SYNC */
 	struct list_head	m_sync_list;	/* sync thread work item list */
 	spinlock_t		m_sync_lock;	/* work item list lock */
-	int			m_sync_seq;	/* sync thread generation no. */
-	wait_queue_head_t	m_wait_single_sync_task;
 	__int64_t		m_update_flags;	/* sb flags we need to update
 						   on the next remount,rw */
 	struct shrinker		m_inode_shrink;	/* inode reclaim shrinker */
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#9 lore raw

PATCH 4/6 xfs: introduce background inode reclaim work

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

Background inode reclaim needs to run more frequently that the XFS syncd work is run as 30s is too long between optimal reclaim runs. Add a new periodic work item to the xfs syncd workqueue to run a fast, non-blocking inode reclaim scan.

To make memory reclaim based inode reclaim throttle to inode cleaning but still reclaim inodes efficiently, make it kick the background inode reclaim so that when we are low on memory we are trying to reclaim inodes as efficiently as possible. To contrast this, make the shrinker past do synchronous inode reclaim so that it blocks on inodes under IO. This means that the shrinker will reclaim inodes rather than just skipping over them, but it does not adversely affect the rate of reclaim because most dirty inodes are already under IO due to the background reclaim work the shrinker kicked.

These two modifications solve one of the two OOM killer invocations Chris Mason reported recently when running a stress testing script. The particular workload trigger for the OOM killer invocation is where there are more threads than CPUs all unlinking files in an extremely memory constrained environment. Unlike other solutions, this one does not have a performance impact on performance when memory is not constrained or the number of concurrent threads operating is <= to the number of CPUs.

---
 fs/xfs/linux-2.6/xfs_sync.c |   56 +++++++++++++++++++++++++++++++++++++++++-
 fs/xfs/xfs_mount.h          |    1 +
 2 files changed, 55 insertions(+), 2 deletions(-)
fs/xfs/linux-2.6/xfs_sync.c +54 -2
index 62e1f09..3f39d83 100644
@@ -470,6 +470,44 @@ xfs_sync_worker(
 }
 
 /*
+ * Queue a new inode reclaim pass if there isn't one already in progress.
+ * Wait for completion of the flush if necessary.
+ */
+static void
+xfs_syncd_queue_reclaim(
+	struct xfs_mount        *mp)
+{
+	queue_delayed_work(xfs_syncd_wq, &mp->m_reclaim_work,
+			xfs_syncd_centisecs / 5 * msecs_to_jiffies(10));
+}
+
+/*
+ * This is a fast pass over the inode cache to try to get reclaim moving on as
+ * many inodes as possible in a short period of time. It kicks itself every few
+ * seconds, as well as being kicked by the inode cache shrinker when memory
+ * goes low.
+ */
+STATIC void
+xfs_reclaim_worker(
+	struct work_struct *work)
+{
+	struct xfs_mount *mp = container_of(to_delayed_work(work),
+					struct xfs_mount, m_reclaim_work);
+
+	/* first unpin all the dirty and stale inodes. */
+	xfs_log_force(mp, XFS_LOG_SYNC);
+
+	/*
+	 * now scan as quickly as possible, not getting hung up on locked
+	 * inodes or those that are already flushing.
+	 */
+	xfs_reclaim_inodes(mp, SYNC_TRYLOCK);
+
+	/* queue us up again */
+	xfs_syncd_queue_reclaim(mp);
+}
+
+/*
  * Flush delayed allocate data, attempting to free up reserved space
  * from existing allocations.  At this point a new allocation attempt
  * has failed with ENOSPC and we are in the process of scratching our
@@ -509,7 +547,10 @@ xfs_syncd_init(
 {
 	INIT_WORK(&mp->m_flush_work, xfs_flush_worker);
 	INIT_DELAYED_WORK(&mp->m_sync_work, xfs_sync_worker);
+	INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
+
 	xfs_syncd_queue_sync(mp);
+	xfs_syncd_queue_reclaim(mp);
 
 	return 0;
 }
@@ -519,6 +560,7 @@ xfs_syncd_stop(
 	struct xfs_mount	*mp)
 {
 	cancel_delayed_work_sync(&mp->m_sync_work);
+	cancel_delayed_work_sync(&mp->m_reclaim_work);
 	cancel_work_sync(&mp->m_flush_work);
 }
 
@@ -954,7 +996,13 @@ xfs_reclaim_inodes(
 }
 
 /*
- * Shrinker infrastructure.
+ * Inode cache shrinker.
+ *
+ * When called we make sure that there is a background (fast) inode reclaim in
+ * progress, while we will throttle the speed of reclaim via doiing synchronous
+ * reclaim of inodes. That means if we come across dirty inodes, we wait for
+ * them to be cleaned, which we hope will not be very long due to the
+ * background walker having already kicked the IO off on those dirty inodes.
  */
 static int
 xfs_reclaim_inode_shrink(
@@ -969,10 +1017,14 @@ xfs_reclaim_inode_shrink(
 
 	mp = container_of(shrink, struct xfs_mount, m_inode_shrink);
 	if (nr_to_scan) {
+		/* kick background reclaimer */
+		xfs_syncd_queue_reclaim(mp);
+
 		if (!(gfp_mask & __GFP_FS))
 			return -1;
 
-		xfs_reclaim_inodes_ag(mp, SYNC_TRYLOCK, &nr_to_scan);
+		xfs_reclaim_inodes_ag(mp, SYNC_TRYLOCK | SYNC_WAIT,
+					&nr_to_scan);
 		/* terminate if we don't exhaust the scan */
 		if (nr_to_scan > 0)
 			return -1;
fs/xfs/xfs_mount.h +1 -0
index a0ad90e..19af0ab 100644
@@ -204,6 +204,7 @@ typedef struct xfs_mount {
 #endif
 	struct xfs_mru_cache	*m_filestream;  /* per-mount filestream data */
 	struct delayed_work	m_sync_work;	/* background sync work */
+	struct delayed_work	m_reclaim_work;	/* background inode reclaim */
 	struct work_struct	m_flush_work;	/* background inode flush */
 	__int64_t		m_update_flags;	/* sb flags we need to update
 						   on the next remount,rw */
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] xfs: introduce a xfssyncd workqueue

In reply to Dave Chinner
Quoted 9 lines

- out_sysctl_unregister:

fs/xfs/linux-2.6/xfs_super.c +4 -2
+out_destroy_xfs_syncd:
+	destroy_workqueue(xfs_syncd_wq);
+out_sysctl_unregister:
 	xfs_sysctl_unregister();
- out_cleanup_procfs:
+out_cleanup_procfs:
 	xfs_cleanup_procfs();
- out_buf_terminate:

fs/xfs/linux-2.6/xfs_super.c init_xfs_fs(void) · line 1836

Quoted 10 lines
fs/xfs/linux-2.6/xfs_super.c +4 -3
+out_buf_terminate:
 	xfs_buf_terminate();
- out_filestream_uninit:
+out_filestream_uninit:
 	xfs_filestream_uninit();
- out_mru_cache_uninit:
+out_mru_cache_uninit:
 	xfs_mru_cache_uninit();
- out_destroy_zones:
+out_destroy_zones:

What's the point of these random formatting changes?

Otherwise looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 3/6
#7 lore raw

Re: [PATCH 3/6] xfs: convert ENOSPC inode flushing to use new syncd workqueue

In reply to Dave Chinner

Looks good,

fs/xfs/linux-2.6/xfs_sync.c xfs_sync_worker( · line 503

Quoted 10 lines
fs/xfs/linux-2.6/xfs_sync.c +10 -0
+STATIC void
+xfs_flush_worker(
+	struct work_struct *work)
+{
+	struct xfs_mount *mp = container_of(work,
+					struct xfs_mount, m_flush_work);
+
+	xfs_sync_data(mp, SYNC_TRYLOCK);
+	xfs_sync_data(mp, SYNC_TRYLOCK | SYNC_WAIT);
+	xfs_log_force(mp, XFS_LOG_SYNC);

No actually new in this patch: but what's the point of the log force here? xfs_sync_data just did one before returning.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#10 lore raw

Re: [PATCH 4/6] xfs: introduce background inode reclaim work

In reply to Dave Chinner

Why do we still keep the inode reclaim in the syncer work? If we already have this one doing it I don't think we need it there as well.

Quoted 3 lines

/*
+ * Queue a new inode reclaim pass if there isn't one already in progress.
+ * Wait for completion of the flush if necessary.

No, it doesn't wait ever.

fs/xfs/linux-2.6/xfs_sync.c xfs_sync_worker( · line 481

Quoted 7 lines

+ */

fs/xfs/linux-2.6/xfs_sync.c +6 -0
+static void
+xfs_syncd_queue_reclaim(
+	struct xfs_mount        *mp)
+{
+	queue_delayed_work(xfs_syncd_wq, &mp->m_reclaim_work,
+			xfs_syncd_centisecs / 5 * msecs_to_jiffies(10));

What explanation is there for the magic 5? E.g. why do we neeed to run it exactly 5 times as often as the normal sync work? Should it have it's own tunable? And isn't ever 6 seconds by default a little often on systems trying to saver power, especiall if there aren't any inodes to reclaim? Should we trigger starting this work off having reclaimable inodes tagged in the radix tree?

fs/xfs/linux-2.6/xfs_sync.c xfs_sync_worker( · line 498

Quoted 2 lines
fs/xfs/linux-2.6/xfs_sync.c +2 -0
+	/* first unpin all the dirty and stale inodes. */
+	xfs_log_force(mp, XFS_LOG_SYNC);

So we force out the log every 6 seconds. That's a lot more often than most other filesystem and might have adverse performance impact.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#13 lore raw

Re: [PATCH 5/6] xfs: convert the xfsaild threads to a workqueue

In reply to Dave Chinner

fs/xfs/linux-2.6/xfs_super.c xfs_destroy_zones(void) · line 1725

Quoted 5 lines

STATIC int __init

fs/xfs/linux-2.6/xfs_super.c +3 -0
+xfs_init_workqueues(void)
 
+STATIC void __exit
+xfs_destroy_workqueues(void)

I don't think these helpers are overly useful.

Quoted 4 lines
fs/xfs/xfs_trans_ail.c +2 -0
+	xfs_ail_wq = alloc_workqueue("xfsail", WQ_CPU_INTENSIVE, 8);
 
+}
 

fs/xfs/xfs_trans_ail.c xfsaild_push( · line 399

Quoted 10 lines
fs/xfs/xfs_trans_ail.c +9 -0
 
+static void
+xfs_ail_push_queue(
+	struct xfs_ail		*ailp,
+	xfs_lsn_t		threshold_lsn,
+	int			tout)
+{
+	if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0) {
+		ailp->xa_target = threshold_lsn;
+		queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, tout);

tout is always one in the only caller and thus doesn't need to be passed. But I think you really want a timeout of 0 here to queue it up ASAP (it translates to a direct queue_work() call internally).

Also this function could simply be merged into it's only and relatively simple caller.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#20 lore raw

Re: [PATCH 6/6] xfs: push the AIL from memory reclaim and periodic sync

In reply to Dave Chinner

fs/xfs/xfs_trans_ail.c line 37

Quoted 5 lines
fs/xfs/xfs_trans_ail.c +0 -5
-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 xfs_log_item_t * xfs_ail_min(struct xfs_ail *);
-STATIC xfs_log_item_t * xfs_ail_next(struct xfs_ail *, xfs_log_item_t *);
-

Reordering and cleanup of unrelated existing functions should be in a separate patch.

Quoted 23 lines
fs/xfs/xfs_trans_ail.c +11 -4
@@ -55,16 +93,32 @@ xfs_lsn_t
 xfs_trans_ail_tail(
 	struct xfs_ail	*ailp)
 {
-	xfs_lsn_t	lsn;
+	xfs_lsn_t	lsn = 0;
 	xfs_log_item_t	*lip;
 
 	spin_lock(&ailp->xa_lock);
 	lip = xfs_ail_min(ailp);
-	if (lip == NULL) {
-		lsn = (xfs_lsn_t)0;
-	} else {
+	if (lip)
+		lsn = lip->li_lsn;
+	spin_unlock(&ailp->xa_lock);
+
+	return lsn;
+}
+
+/*
+ * Return the maximum lsn held in the AIL, or zero if the AIl is empty.
+ */

fs/xfs/xfs_trans_ail.c xfs_lsn_t · line 120

Quoted 10 lines
fs/xfs/xfs_trans_ail.c +10 -0
+static xfs_lsn_t
+xfs_ail_max_lsn(
+	struct xfs_ail  *ailp)
+{
+	xfs_lsn_t       lsn = 0;
+	xfs_log_item_t  *lip;
+
+	spin_lock(&ailp->xa_lock);
+	lip = xfs_ail_max(ailp);
+	if (lip)

As this is the counterpart to xfs_trans_ail_tail the naming for both should be similar. I much prefer the descriptive _lsn naming over the random trans in xfs_trans_ail_tail.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw

Re: [PATCH 2/6] xfs: introduce a xfssyncd workqueue

In reply to Christoph Hellwig
Quoted 13 lines · Christoph Hellwig
Quoted 13 lines

- out_sysctl_unregister:

fs/xfs/linux-2.6/xfs_super.c +6 -3
+out_destroy_xfs_syncd:
+	destroy_workqueue(xfs_syncd_wq);
+out_sysctl_unregister:
 	xfs_sysctl_unregister();
- out_cleanup_procfs:
+out_cleanup_procfs:
 	xfs_cleanup_procfs();
- out_buf_terminate:
+out_buf_terminate:
 	xfs_buf_terminate();
- out_filestream_uninit:
+out_filestream_uninit:
Quoted 9 lines

fs/xfs/linux-2.6/xfs_super.c init_xfs_fs(void) · line 1836

Quoted 6 lines
fs/xfs/linux-2.6/xfs_super.c +2 -2
 	xfs_filestream_uninit();
- out_mru_cache_uninit:
+out_mru_cache_uninit:
 	xfs_mru_cache_uninit();
- out_destroy_zones:
+out_destroy_zones:

What's the point of these random formatting changes?

Removed.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#8 lore raw

Re: [PATCH 3/6] xfs: convert ENOSPC inode flushing to use new syncd workqueue

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Looks good,

Quoted 13 lines

fs/xfs/linux-2.6/xfs_sync.c xfs_sync_worker( · line 503

Quoted 10 lines
fs/xfs/linux-2.6/xfs_sync.c +10 -0
+STATIC void
+xfs_flush_worker(
+	struct work_struct *work)
+{
+	struct xfs_mount *mp = container_of(work,
+					struct xfs_mount, m_flush_work);
+
+	xfs_sync_data(mp, SYNC_TRYLOCK);
+	xfs_sync_data(mp, SYNC_TRYLOCK | SYNC_WAIT);
+	xfs_log_force(mp, XFS_LOG_SYNC);

No actually new in this patch: but what's the point of the log force here? xfs_sync_data just did one before returning.

Historical, I think. Removed.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#11 lore raw

Re: [PATCH 4/6] xfs: introduce background inode reclaim work

In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

Why do we still keep the inode reclaim in the syncer work? If we already have this one doing it I don't think we need it there as well.

Ok. Removed.

Quoted 5 lines
Quoted 3 lines

/*
+ * Queue a new inode reclaim pass if there isn't one already in progress.
+ * Wait for completion of the flush if necessary.

No, it doesn't wait ever.

Removed.

Quoted 10 lines

fs/xfs/linux-2.6/xfs_sync.c xfs_sync_worker( · line 481

Quoted 7 lines

+ */

fs/xfs/linux-2.6/xfs_sync.c +6 -0
+static void
+xfs_syncd_queue_reclaim(
+	struct xfs_mount        *mp)
+{
+	queue_delayed_work(xfs_syncd_wq, &mp->m_reclaim_work,
+			xfs_syncd_centisecs / 5 * msecs_to_jiffies(10));

What explanation is there for the magic 5? E.g. why do we neeed to run it exactly 5 times as often as the normal sync work?

It doesn't have to be exactly 5x more frequent, just that it needs to run quite a bit more often than the normal sync work. tens times more often seems like overkill and a lot of overhead given the scan reclaim does, while two times more often isn't sufficient to avoid significant build up of dirty reclaimable inodes that need to be written before they can be reclaimed..

Quoted 2 lines

Should it have it's
own tunable?

Perhaps. I'm not convinced it is necessary, though.

Quoted 4 lines

And isn't ever 6 seconds by default a little often on systems trying to saver power, especiall if there aren't any inodes to reclaim? Should we trigger starting this work off having reclaimable inodes tagged in the radix tree?

Yes, probably should. I'll see if I can do that easily.

Quoted 5 lines

fs/xfs/linux-2.6/xfs_sync.c xfs_sync_worker( · line 498

Quoted 2 lines
fs/xfs/linux-2.6/xfs_sync.c +2 -0
+	/* first unpin all the dirty and stale inodes. */
+	xfs_log_force(mp, XFS_LOG_SYNC);

So we force out the log every 6 seconds. That's a lot more often than most other filesystem and might have adverse performance impact.

I'll remove that and leave it for the sync inode reclaim to force out the log...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#14 lore raw

Re: [PATCH 5/6] xfs: convert the xfsaild threads to a workqueue

In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

fs/xfs/linux-2.6/xfs_super.c xfs_destroy_zones(void) · line 1725

Quoted 5 lines

STATIC int __init

fs/xfs/linux-2.6/xfs_super.c +3 -0
+xfs_init_workqueues(void)
 
+STATIC void __exit
+xfs_destroy_workqueues(void)

I don't think these helpers are overly useful.

I'm thinking of adding a few more workqueues, so I though I'd split them out like zone initialisation at the outset....

Quoted 20 lines
Quoted 5 lines
fs/xfs/xfs_trans_ail.c +2 -0
+	xfs_ail_wq = alloc_workqueue("xfsail", WQ_CPU_INTENSIVE, 8);
 
+}
 

fs/xfs/xfs_trans_ail.c xfsaild_push( · line 399

Quoted 10 lines
fs/xfs/xfs_trans_ail.c +9 -0
 
+static void
+xfs_ail_push_queue(
+	struct xfs_ail		*ailp,
+	xfs_lsn_t		threshold_lsn,
+	int			tout)
+{
+	if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0) {
+		ailp->xa_target = threshold_lsn;
+		queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, tout);

tout is always one in the only caller and thus doesn't need to be passed. But I think you really want a timeout of 0 here to queue it up ASAP (it translates to a direct queue_work() call internally).

Quoted 2 lines

Also this function could simply be merged into it's only and relatively simple caller.

It gets used by a second caller in the next patch that uses a timeout of zero. The idea of adding a delay to a normal push is to rate limit the number of times we do work so we always work on batches rather a few items at a time in multiple executions of the work.

I'll see if it's simpler to just do this work directly in teh callers, though.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#21 lore raw

Re: [PATCH 6/6] xfs: push the AIL from memory reclaim and periodic sync

In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

fs/xfs/xfs_trans_ail.c line 37

Quoted 5 lines
fs/xfs/xfs_trans_ail.c +0 -5
-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 xfs_log_item_t * xfs_ail_min(struct xfs_ail *);
-STATIC xfs_log_item_t * xfs_ail_next(struct xfs_ail *, xfs_log_item_t *);
-

Reordering and cleanup of unrelated existing functions should be in a separate patch.

OK.

Quoted 30 lines
Quoted 30 lines
fs/xfs/xfs_trans_ail.c +17 -4
@@ -55,16 +93,32 @@ xfs_lsn_t
 xfs_trans_ail_tail(
 	struct xfs_ail	*ailp)
 {
-	xfs_lsn_t	lsn;
+	xfs_lsn_t	lsn = 0;
 	xfs_log_item_t	*lip;
 
 	spin_lock(&ailp->xa_lock);
 	lip = xfs_ail_min(ailp);
-	if (lip == NULL) {
-		lsn = (xfs_lsn_t)0;
-	} else {
+	if (lip)
+		lsn = lip->li_lsn;
+	spin_unlock(&ailp->xa_lock);
+
+	return lsn;
+}
+
+/*
+ * Return the maximum lsn held in the AIL, or zero if the AIl is empty.
+ */
+static xfs_lsn_t
+xfs_ail_max_lsn(
+	struct xfs_ail  *ailp)
+{
+	xfs_lsn_t       lsn = 0;
+	xfs_log_item_t  *lip;
Quoted 8 lines

fs/xfs/xfs_trans_ail.c xfs_lsn_t · line 120

Quoted 4 lines
fs/xfs/xfs_trans_ail.c +4 -0
+
+	spin_lock(&ailp->xa_lock);
+	lip = xfs_ail_max(ailp);
+	if (lip)

As this is the counterpart to xfs_trans_ail_tail the naming for both should be similar. I much prefer the descriptive _lsn naming over the random trans in xfs_trans_ail_tail.

Ok, will change.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#15 lore raw

Re: [PATCH 5/6] xfs: convert the xfsaild threads to a workqueue

In reply to Dave Chinner
Quoted 8 lines · Dave Chinner

It gets used by a second caller in the next patch that uses a timeout of zero. The idea of adding a delay to a normal push is to rate limit the number of times we do work so we always work on batches rather a few items at a time in multiple executions of the work.

I'll see if it's simpler to just do this work directly in teh callers, though.

I don't think hiding this delay (uncommented) in the workqueue use is a good idea. xlog_grant_push_ail has all the logics about when to push the AIL, so any batching should be grouped with that logic, and documented there. It in fact already has some comments static that a min/max watermark scheme would be useful.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#16 lore raw

Re: [PATCH 5/6] xfs: convert the xfsaild threads to a workqueue

Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Dave Chinner

It gets used by a second caller in the next patch that uses a timeout of zero. The idea of adding a delay to a normal push is to rate limit the number of times we do work so we always work on batches rather a few items at a time in multiple executions of the work.

Quoted 5 lines
Quoted 2 lines

I'll see if it's simpler to just do this work directly in teh callers, though.

I don't think hiding this delay (uncommented) in the workqueue use is a good idea.

FWIW, we already have an implicit delay for frequent callers when the AIL is busy - the uninterruptible sleep for sleeps of <= 20ms. That was implemented specifically to rate-limit wakeups while the xfsaild was busy pushing. This is essentially a different implementation of the same mechanism.

Quoted 4 lines

xlog_grant_push_ail has all the logics about when to push the AIL, so any batching should be grouped with that logic, and documented there. It in fact already has some comments static that a min/max watermark scheme would be useful.

Yes, it does, but that's a much bigger change that has some potentially nasty problems like ensuring the watermarks are always a sane distance apart which is difficult to do on small logs were a single transaction reservation can easily be larger than 10% of the log. Hence watermarks are a much harder change to validate and tune compared to a simple push wakeup rate-limit...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#17 lore raw

Re: [PATCH 5/6] xfs: convert the xfsaild threads to a workqueue

Quoted 5 lines · Dave Chinner

FWIW, we already have an implicit delay for frequent callers when the AIL is busy - the uninterruptible sleep for sleeps of <= 20ms. That was implemented specifically to rate-limit wakeups while the xfsaild was busy pushing. This is essentially a different implementation of the same mechanism.

In that cases maybe the minum delay of the delayed work should stay at 20ms?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#18 lore raw

Re: [PATCH 5/6] xfs: convert the xfsaild threads to a workqueue

Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Dave Chinner

FWIW, we already have an implicit delay for frequent callers when the AIL is busy - the uninterruptible sleep for sleeps of <= 20ms. That was implemented specifically to rate-limit wakeups while the xfsaild was busy pushing. This is essentially a different implementation of the same mechanism.

In that cases maybe the minum delay of the delayed work should stay at 20ms?

I've been looking at this a little more - I don't think the work_pending() check is sufficient. The pending bit is cleared before the work function is called, so while the work is executing we can queue up another work. That means when the work completes and decides it needs to back off for a short while, it won't back off because new work has been been queued and the pending bit has been set.

Hence I thinkthis needs an external "work running" bit to be set so that the backoff works as expected. That is, when pushing the tail we need to do:

	ailp->xa_target = threshold_lsn;
	if (test_and_set_bit(ailp->pushing))
		queue_delayed_work(work, 0);

When the AIL work function needs to back off for a certain timeout, it just does:

	queue_delayed_work(work, tout);

and when it completes the push, it does:

	clear_bit(ailp->pushing);

So the next tail push requeues the work again. That gets around the need for implicit wakeup rate limiting, allows tail pushing to keep moving the target forwards while the work is running, and doesn't allow tail pushing to impact on a running push.

I'll modify it to do this - it should also simplify the code as well.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs