[PATCH 10/21] fs: Stop abusing find_inode_fast in iunique

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Dave Chinner
Date: Wednesday, October 20, 2010 - 5:49 pm

From: Christoph Hellwig <hch@lst.de>

Stop abusing find_inode_fast for iunique and opencode the inode hash walk.
Introduce a new iunique_lock to protect the iunique counters once inode_lock
is removed.

Based on a patch originally from Nick Piggin.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 fs/inode.c |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index cfcafee..77ff091 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -913,6 +913,27 @@ static struct inode *get_new_inode_fast(struct super_block *sb,
 	return inode;
 }
 
+/*
+ * search the inode cache for a matching inode number.
+ * If we find one, then the inode number we are trying to
+ * allocate is not unique and so we should not use it.
+ *
+ * Returns 1 if the inode number is unique, 0 if it is not.
+ */
+static int test_inode_iunique(struct super_block *sb, unsigned long ino)
+{
+	struct hlist_head *b = inode_hashtable + hash(sb, ino);
+	struct hlist_node *node;
+	struct inode *inode;
+
+	hlist_for_each_entry(inode, node, b, i_hash) {
+		if (inode->i_ino == ino && inode->i_sb == sb)
+			return 0;
+	}
+
+	return 1;
+}
+
 /**
  *	iunique - get a unique inode number
  *	@sb: superblock
@@ -934,19 +955,18 @@ ino_t iunique(struct super_block *sb, ino_t max_reserved)
 	 * error if st_ino won't fit in target struct field. Use 32bit counter
 	 * here to attempt to avoid that.
 	 */
+	static DEFINE_SPINLOCK(iunique_lock);
 	static unsigned int counter;
-	struct inode *inode;
-	struct hlist_head *head;
 	ino_t res;
 
 	spin_lock(&inode_lock);
+	spin_lock(&iunique_lock);
 	do {
 		if (counter <= max_reserved)
 			counter = max_reserved + 1;
 		res = counter++;
-		head = inode_hashtable + hash(sb, res);
-		inode = find_inode_fast(sb, head, res);
-	} while (inode != NULL);
+	} while (!test_inode_iunique(sb, res));
+	spin_unlock(&iunique_lock);
 	spin_unlock(&inode_lock);
 
 	return res;
-- 
1.7.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Inode Lock Scalability V6, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 04/21] fs: Implement lazy LRU updates for inodes, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 05/21] fs: inode split IO and LRU lists, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 06/21] fs: Clean up inode reference counting, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 08/21] fs: rework icount to be a locked variable, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 10/21] fs: Stop abusing find_inode_fast in iunique, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 13/21] fs: Introduce per-bucket inode hash locks, Dave Chinner, (Wed Oct 20, 5:49 pm)
[PATCH 19/21] fs: icache remove inode_lock, Dave Chinner, (Wed Oct 20, 5:49 pm)
Re: [PATCH 06/21] fs: Clean up inode reference counting, Christoph Hellwig, (Wed Oct 20, 6:41 pm)
Re: Inode Lock Scalability V7 (was V6), Dave Chinner, (Wed Oct 20, 10:04 pm)
Re: [PATCH 04/21] fs: Implement lazy LRU updates for inodes, Christoph Hellwig, (Thu Oct 21, 5:22 am)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 6:20 am)
Re: Inode Lock Scalability V7 (was V6), Dave Chinner, (Thu Oct 21, 4:52 pm)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 5:45 pm)
Re: Inode Lock Scalability V7 (was V6), Al Viro, (Thu Oct 21, 7:20 pm)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 7:41 pm)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 7:48 pm)
Re: Inode Lock Scalability V7 (was V6), Al Viro, (Thu Oct 21, 8:07 pm)
Re: Inode Lock Scalability V7 (was V6), Al Viro, (Thu Oct 21, 8:12 pm)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 9:46 pm)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 9:48 pm)
Re: Inode Lock Scalability V7 (was V6), Nick Piggin, (Thu Oct 21, 10:01 pm)