xfs
[Top] [All Lists]

Re: [PATCH] Inode reclaim fixes (was Re: 2.6.31 xfs_fs_destroy_inode: ca

To: Patrick Schreurs <patrick@xxxxxxxxxxxxxxxx>
Subject: Re: [PATCH] Inode reclaim fixes (was Re: 2.6.31 xfs_fs_destroy_inode: cannot reclaim)
From: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Date: Wed, 10 Feb 2010 09:55:08 -0500
Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx>, Dave Chinner <david@xxxxxxxxxxxxx>, Tommy van Leeuwen <tommy@xxxxxxxxxxxxxxxx>, xfs@xxxxxxxxxxx
In-reply-to: <4B72A9D1.8030101@xxxxxxxxxxxxxxxx>
References: <4B3F9F88.9030307@xxxxxxxxxxxxxxxx> <20100107110446.GA13802@xxxxxxxxxxxxxxxx> <4B45CFAC.4000607@xxxxxxxxxxxxxxxx> <20100108113114.GA8654@xxxxxxxxxxxxxxxx> <4B504B03.7050604@xxxxxxxxxxxxxxxx> <4B6706CE.1020207@xxxxxxxxxxxxxxxx> <20100208194226.GD9527@xxxxxxxxxxxxx> <4B712166.9010701@xxxxxxxxxxxxxxxx> <20100209103157.GA5197@xxxxxxxxxxxxx> <4B72A9D1.8030101@xxxxxxxxxxxxxxxx>
User-agent: Mutt/1.5.19 (2009-01-05)
On Wed, Feb 10, 2010 at 01:42:57PM +0100, Patrick Schreurs wrote:
> Thanks for the patch. After having this patch applied we saw *a lot*  
> warnings. They all look like this:

Ok, looks like that is not an issue, so you can discard that patch.

I went down to the radix tree code to look for races in it's tag
handling, but then noticed that we might have an issue with our
usage of the radix-tree API.  Can you try the patch below ontop
of Dave's rollup, and instead of my previous one?

---

From: Christoph Hellwig <hch@xxxxxx>
Subject: xfs: fix locking for inode cache radix tree tag updates

The radix-tree code requires it's users to serialize tag updates against
other updates to the tree.  While XFS protects tag updates against each
other it does not serialize them against updates of the tree contents,
which can lead to tag corruption.  Fix the inode cache to always take
pag_ici_lock in exclusive mode when updating radix tree tags.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>

Index: linux-2.6/fs/xfs/linux-2.6/xfs_sync.c
===================================================================
--- linux-2.6.orig/fs/xfs/linux-2.6/xfs_sync.c  2010-02-10 14:28:46.648004203 
+0100
+++ linux-2.6/fs/xfs/linux-2.6/xfs_sync.c       2010-02-10 14:29:56.657023619 
+0100
@@ -734,12 +734,12 @@ xfs_inode_set_reclaim_tag(
        xfs_mount_t     *mp = ip->i_mount;
        xfs_perag_t     *pag = xfs_get_perag(mp, ip->i_ino);
 
-       read_lock(&pag->pag_ici_lock);
+       write_lock(&pag->pag_ici_lock);
        spin_lock(&ip->i_flags_lock);
        __xfs_inode_set_reclaim_tag(pag, ip);
        __xfs_iflags_set(ip, XFS_IRECLAIMABLE);
        spin_unlock(&ip->i_flags_lock);
-       read_unlock(&pag->pag_ici_lock);
+       write_unlock(&pag->pag_ici_lock);
        xfs_put_perag(mp, pag);
 }
 
Index: linux-2.6/fs/xfs/xfs_iget.c
===================================================================
--- linux-2.6.orig/fs/xfs/xfs_iget.c    2010-02-10 14:30:01.092254586 +0100
+++ linux-2.6/fs/xfs/xfs_iget.c 2010-02-10 14:34:00.199005529 +0100
@@ -228,13 +228,12 @@ xfs_iget_cache_hit(
                xfs_itrace_exit_tag(ip, "xfs_iget.alloc");
 
                /*
-                * We need to set XFS_INEW atomically with clearing the
-                * reclaimable tag so that we do have an indicator of the
-                * inode still being initialized.
+                * We need to set XFS_IRECLAIM to prevent xfs_reclaim_inode
+                * from stomping over us while we recycle the inode.  We can't
+                * clear the radix tree reclaimable tag yet as it requires
+                * pag_ici_lock to be helt exclusive.
                 */
-               ip->i_flags |= XFS_INEW;
-               ip->i_flags &= ~XFS_IRECLAIMABLE;
-               __xfs_inode_clear_reclaim_tag(mp, pag, ip);
+               ip->i_flags |= XFS_IRECLAIM;
 
                spin_unlock(&ip->i_flags_lock);
                read_unlock(&pag->pag_ici_lock);
@@ -253,7 +252,15 @@ xfs_iget_cache_hit(
                        __xfs_inode_set_reclaim_tag(pag, ip);
                        goto out_error;
                }
-               inode->i_state = I_LOCK|I_NEW;
+
+               write_lock(&pag->pag_ici_lock);
+               spin_lock(&ip->i_flags_lock);
+               ip->i_flags &= ~(XFS_IRECLAIMABLE | XFS_IRECLAIM);
+               ip->i_flags |= XFS_INEW;
+               __xfs_inode_clear_reclaim_tag(mp, pag, ip);
+               inode->i_state = I_LOCK | I_NEW;
+               spin_unlock(&ip->i_flags_lock);
+               write_unlock(&pag->pag_ici_lock);
        } else {
                /* If the VFS inode is being torn down, pause and try again. */
                if (!igrab(inode)) {

<Prev in Thread] Current Thread [Next in Thread>