From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Subject: [PATCH 6/6] [XFS] introduce a per-ag inode iterator
Date: Sun, 15 Mar 2009 22:46:43 +1100 [thread overview]
Message-ID: <1237117603-26071-7-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1237117603-26071-1-git-send-email-david@fromorbit.com>
Given that we walk across the per-ag inode lists so
often, it makes sense to introduce an iterator for this.
Break the operations on each inode into two operations -
a lookup validation step to confirm the inode is good to
be used and an execution step that performs the operation
on the inode.
Convert the sync and reclaim code to use this new iterator.
At some point the quota sync needs to be converted as well.
Signed-off-by: Dave Chinner <david@fromorbit.com>
---
fs/xfs/linux-2.6/xfs_sync.c | 320 ++++++++++++++++++++-----------------------
1 files changed, 149 insertions(+), 171 deletions(-)
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c
index f9c2a56..45dfff9 100644
--- a/fs/xfs/linux-2.6/xfs_sync.c
+++ b/fs/xfs/linux-2.6/xfs_sync.c
@@ -48,6 +48,132 @@
#include <linux/kthread.h>
#include <linux/freezer.h>
+
+STATIC xfs_inode_t *
+xfs_inode_ag_lookup(
+ xfs_mount_t *mp,
+ xfs_perag_t *pag,
+ int (*lookup)(xfs_mount_t *mp, xfs_inode_t *ip),
+ uint32_t *first_index,
+ int tag)
+{
+ int nr_found;
+ xfs_inode_t *ip;
+ int error = -ENOENT;
+
+ /*
+ * use a gang lookup to find the next inode in the tree
+ * as the tree is sparse and a gang lookup walks to find
+ * the number of objects requested.
+ */
+ read_lock(&pag->pag_ici_lock);
+ if (tag == -1) {
+ nr_found = radix_tree_gang_lookup(&pag->pag_ici_root,
+ (void**)&ip, *first_index, 1);
+ } else {
+ nr_found = radix_tree_gang_lookup_tag(&pag->pag_ici_root,
+ (void**)&ip, *first_index, 1, tag);
+ }
+ if (!nr_found)
+ goto unlock;
+
+ /*
+ * Update the index for the next lookup. Catch overflows
+ * into the next AG range which can occur if we have inodes
+ * in the last block of the AG and we are currently
+ * pointing to the last inode.
+ */
+ *first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1);
+ if (*first_index < XFS_INO_TO_AGINO(mp, ip->i_ino))
+ goto unlock;
+
+
+ error = lookup(mp, ip);
+ read_unlock(&pag->pag_ici_lock);
+ if (error)
+ return ERR_PTR(error);
+ return ip;
+
+unlock:
+ read_unlock(&pag->pag_ici_lock);
+ return NULL;
+}
+
+STATIC int
+xfs_inode_ag_walk(
+ xfs_mount_t *mp,
+ xfs_agnumber_t ag,
+ int (*lookup)(xfs_mount_t *mp, xfs_inode_t *ip),
+ int (*execute)(xfs_inode_t *ip, int flags),
+ int flags,
+ int tag)
+{
+ xfs_perag_t *pag = &mp->m_perag[ag];
+ uint32_t first_index;
+ int last_error = 0;
+ int skipped;
+
+restart:
+ skipped = 0;
+ first_index = 0;
+ do {
+ int error = 0;
+ xfs_inode_t *ip;
+
+ ip = xfs_inode_ag_lookup(mp, pag, lookup, &first_index, tag);
+ if (!ip)
+ break;
+ if (IS_ERR(ip))
+ continue;
+
+ error = execute(ip, flags);
+ if (error == EAGAIN) {
+ skipped++;
+ continue;
+ }
+ if (error)
+ last_error = error;
+ /*
+ * bail out if the filesystem is corrupted.
+ */
+ if (error == EFSCORRUPTED)
+ break;
+
+ } while (1);
+
+ if (skipped) {
+ delay(1);
+ goto restart;
+ }
+
+ xfs_put_perag(mp, pag);
+ return last_error;
+}
+
+STATIC int
+xfs_inode_ag_iterator(
+ xfs_mount_t *mp,
+ int (*lookup)(xfs_mount_t *mp, xfs_inode_t *ip),
+ int (*execute)(xfs_inode_t *ip, int flags),
+ int flags,
+ int tag)
+{
+ int error = 0;
+ int last_error = 0;
+ xfs_agnumber_t ag;
+
+ for (ag = 0; ag < mp->m_sb.sb_agcount; ag++) {
+ if (!mp->m_perag[ag].pag_ici_init)
+ continue;
+ error = xfs_inode_ag_walk(mp, ag, lookup, execute, flags, tag);
+ if (error)
+ last_error = error;
+ if (error == EFSCORRUPTED)
+ break;
+ }
+ return XFS_ERROR(last_error);
+}
+
static int
xfs_sync_inode_data(
struct xfs_inode *ip,
@@ -76,6 +202,7 @@ xfs_sync_inode_data(
if (flags & SYNC_IOWAIT)
xfs_ioend_wait(ip);
+ IRELE(ip);
return error;
}
@@ -91,7 +218,7 @@ xfs_sync_inode_flush(
* the inode flush clustering code inside xfs_iflush
*/
if (xfs_inode_clean(ip))
- return 0;
+ goto out_rele;
/*
* We make this non-blocking if the inode is contended,
@@ -107,7 +234,7 @@ xfs_sync_inode_flush(
error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
} else {
if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
- goto out;
+ goto out_rele;
if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
goto out_unlock;
@@ -116,7 +243,8 @@ xfs_sync_inode_flush(
out_unlock:
xfs_iunlock(ip, XFS_ILOCK_SHARED);
-out:
+out_rele:
+ IRELE(ip);
return error;
}
@@ -151,115 +279,32 @@ error:
return error;
}
-/*
- * Sync all the inodes in the given AG according to the
- * direction given by the flags.
- */
-STATIC int
-xfs_sync_inodes_ag(
- xfs_mount_t *mp,
- int ag,
- int flags)
-{
- xfs_perag_t *pag = &mp->m_perag[ag];
- int nr_found;
- uint32_t first_index = 0;
- int error = 0;
- int last_error = 0;
-
- do {
- xfs_inode_t *ip = NULL;
-
- /*
- * use a gang lookup to find the next inode in the tree
- * as the tree is sparse and a gang lookup walks to find
- * the number of objects requested.
- */
- read_lock(&pag->pag_ici_lock);
- nr_found = radix_tree_gang_lookup(&pag->pag_ici_root,
- (void**)&ip, first_index, 1);
-
- if (!nr_found) {
- read_unlock(&pag->pag_ici_lock);
- break;
- }
-
- /*
- * Update the index for the next lookup. Catch overflows
- * into the next AG range which can occur if we have inodes
- * in the last block of the AG and we are currently
- * pointing to the last inode.
- */
- first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1);
- if (first_index < XFS_INO_TO_AGINO(mp, ip->i_ino)) {
- read_unlock(&pag->pag_ici_lock);
- break;
- }
-
- error = xfs_sync_inode_valid(mp, ip);
- if (error) {
- read_unlock(&pag->pag_ici_lock);
- if (error == EFSCORRUPTED)
- return 0;
- continue;
- }
-
- /*
- * If we have to flush data or wait for I/O completion
- * we need to hold the iolock.
- */
- if (flags & SYNC_DELWRI)
- error = xfs_sync_inode_data(ip, flags);
-
- if (flags & SYNC_ATTR)
- error = xfs_sync_inode_flush(ip, flags);
-
- IRELE(ip);
-
- if (error)
- last_error = error;
- /*
- * bail out if the filesystem is corrupted.
- */
- if (error == EFSCORRUPTED)
- return XFS_ERROR(error);
-
- } while (nr_found);
-
- return last_error;
-}
-
int
xfs_sync_inodes(
xfs_mount_t *mp,
int flags)
{
- int error;
- int last_error;
- int i;
+ int error = 0;
int lflags = XFS_LOG_FORCE;
if (mp->m_flags & XFS_MOUNT_RDONLY)
return 0;
- error = 0;
- last_error = 0;
if (flags & SYNC_WAIT)
lflags |= XFS_LOG_SYNC;
- for (i = 0; i < mp->m_sb.sb_agcount; i++) {
- if (!mp->m_perag[i].pag_ici_init)
- continue;
- error = xfs_sync_inodes_ag(mp, i, flags);
- if (error)
- last_error = error;
- if (error == EFSCORRUPTED)
- break;
- }
if (flags & SYNC_DELWRI)
+ error = xfs_inode_ag_iterator(mp, xfs_sync_inode_valid,
+ xfs_sync_inode_data, flags, -1);
+
+ if (flags & SYNC_ATTR)
+ error = xfs_inode_ag_iterator(mp, xfs_sync_inode_valid,
+ xfs_sync_inode_flush, flags, -1);
+
+ if (!error && (flags & SYNC_DELWRI))
xfs_log_force(mp, 0, lflags);
- return XFS_ERROR(last_error);
+ return XFS_ERROR(error);
}
STATIC int
@@ -724,72 +769,12 @@ xfs_reclaim_inode_valid(
return 0;
}
-STATIC void
-xfs_reclaim_inodes_ag(
- xfs_mount_t *mp,
- int ag,
- int mode)
+static int
+xfs_reclaim_inode_now(
+ xfs_inode_t *ip,
+ int flags)
{
- xfs_inode_t *ip = NULL;
- xfs_perag_t *pag = &mp->m_perag[ag];
- int nr_found;
- uint32_t first_index;
- int skipped;
-
-restart:
- first_index = 0;
- skipped = 0;
- do {
- int error;
-
- /*
- * use a gang lookup to find the next inode in the tree
- * as the tree is sparse and a gang lookup walks to find
- * the number of objects requested.
- */
- read_lock(&pag->pag_ici_lock);
- nr_found = radix_tree_gang_lookup_tag(&pag->pag_ici_root,
- (void**)&ip, first_index, 1,
- XFS_ICI_RECLAIM_TAG);
-
- if (!nr_found) {
- read_unlock(&pag->pag_ici_lock);
- break;
- }
-
- /*
- * Update the index for the next lookup. Catch overflows
- * into the next AG range which can occur if we have inodes
- * in the last block of the AG and we are currently
- * pointing to the last inode.
- */
- first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1);
- if (first_index < XFS_INO_TO_AGINO(mp, ip->i_ino)) {
- read_unlock(&pag->pag_ici_lock);
- break;
- }
-
- error = xfs_reclaim_inode_valid(mp, ip);
- if (error) {
- read_unlock(&pag->pag_ici_lock);
- continue;
- }
- read_unlock(&pag->pag_ici_lock);
-
- /*
- * hmmm - this is an inode already in reclaim. Do
- * we even bother catching it here?
- */
- if (xfs_reclaim_inode(ip, 0, mode))
- skipped++;
- } while (nr_found);
-
- if (skipped) {
- delay(1);
- goto restart;
- }
- return;
-
+ return xfs_reclaim_inode(ip, 0, flags);
}
int
@@ -797,14 +782,7 @@ xfs_reclaim_inodes(
xfs_mount_t *mp,
int mode)
{
- int i;
-
- for (i = 0; i < mp->m_sb.sb_agcount; i++) {
- if (!mp->m_perag[i].pag_ici_init)
- continue;
- xfs_reclaim_inodes_ag(mp, i, mode);
- }
- return 0;
+ return xfs_inode_ag_iterator(mp, xfs_reclaim_inode_valid,
+ xfs_reclaim_inode_now, mode,
+ XFS_ICI_RECLAIM_TAG);
}
-
-
--
1.6.2
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2009-03-15 19:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-15 11:46 [PATCH 0/6] [XFS] introduce a AG inode tree walker Dave Chinner
2009-03-15 11:46 ` [PATCH 1/6] [XFS] Split inode data writeback from inode sync Dave Chinner
2009-03-16 10:10 ` Christoph Hellwig
2009-03-16 10:47 ` Dave Chinner
2009-03-15 11:46 ` [PATCH 2/6] [XFS] Use xfs_inode_flush() in xfs_sync_inodes_ag() Dave Chinner
2009-03-15 11:46 ` [PATCH 3/6] [XFS] Factor out inode validation for sync Dave Chinner
2009-03-15 11:46 ` [PATCH 4/6] [XFS] Factor out inode validation for reclaim Dave Chinner
2009-03-15 11:46 ` [PATCH 5/6] [XFS] Remove unused parameter from xfs_reclaim_inodes Dave Chinner
2009-03-15 11:46 ` Dave Chinner [this message]
2009-03-16 7:53 ` [PATCH 0/6] [XFS] introduce a AG inode tree walker Christoph Hellwig
2009-03-16 9:40 ` Dave Chinner
2009-03-16 10:01 ` Christoph Hellwig
2009-03-16 10:35 ` Dave Chinner
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=1237117603-26071-7-git-send-email-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=xfs@oss.sgi.com \
/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