[PATCH 15/18] fs: introduce a per-cpu last_ino allocator

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Dave Chinner
Date: Thursday, October 7, 2010 - 10:21 pm

From: Eric Dumazet <eric.dumazet@gmail.com>

new_inode() dirties a contended cache line to get increasing
inode numbers. This limits performance on workloads that cause
significant parallel inode allocation.

Solve this problem by using a per_cpu variable fed by the shared
last_ino in batches of 1024 allocations.  This reduces contention on
the shared last_ino, and give same spreading ino numbers than before
(i.e. same wraparound after 2^32 allocations).

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 fs/inode.c |   45 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index d3bd08a..13e1325 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -870,6 +870,43 @@ void inode_add_to_lists(struct super_block *sb, struct inode *inode)
 }
 EXPORT_SYMBOL_GPL(inode_add_to_lists);
 
+/*
+ * Each cpu owns a range of LAST_INO_BATCH numbers.
+ * 'shared_last_ino' is dirtied only once out of LAST_INO_BATCH allocations,
+ * to renew the exhausted range.
+ *
+ * This does not significantly increase overflow rate because every CPU can
+ * consume at most LAST_INO_BATCH-1 unused inode numbers. So there is
+ * NR_CPUS*(LAST_INO_BATCH-1) wastage. At 4096 and 1024, this is ~0.1% of the
+ * 2^32 range, and is a worst-case. Even a 50% wastage would only increase
+ * overflow rate by 2x, which does not seem too significant.
+ *
+ * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
+ * error if st_ino won't fit in target struct field. Use 32bit counter
+ * here to attempt to avoid that.
+ */
+#define LAST_INO_BATCH 1024
+static DEFINE_PER_CPU(unsigned int, last_ino);
+
+static unsigned int last_ino_get(void)
+{
+	unsigned int *p = &get_cpu_var(last_ino);
+	unsigned int res = *p;
+
+#ifdef CONFIG_SMP
+	if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
+		static atomic_t shared_last_ino;
+		int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
+
+		res = next - LAST_INO_BATCH;
+	}
+#endif
+
+	*p = ++res;
+	put_cpu_var(last_ino);
+	return res;
+}
+
 /**
  *	new_inode 	- obtain an inode
  *	@sb: superblock
@@ -884,12 +921,6 @@ EXPORT_SYMBOL_GPL(inode_add_to_lists);
  */
 struct inode *new_inode(struct super_block *sb)
 {
-	/*
-	 * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
-	 * error if st_ino won't fit in target struct field. Use 32bit counter
-	 * here to attempt to avoid that.
-	 */
-	static unsigned int last_ino;
 	struct inode *inode;
 
 	spin_lock_prefetch(&inode_lock);
@@ -897,7 +928,7 @@ struct inode *new_inode(struct super_block *sb)
 	inode = alloc_inode(sb);
 	if (inode) {
 		spin_lock(&inode_lock);
-		inode->i_ino = ++last_ino;
+		inode->i_ino = last_ino_get();
 		inode->i_state = 0;
 		__inode_add_to_lists(sb, NULL, inode);
 		spin_unlock(&inode_lock);
-- 
1.7.1

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

Messages in current thread:
fs: Inode cache scalability V2, Dave Chinner, (Thu Oct 7, 10:21 pm)
[PATCH 01/18] kernel: add bl_list, Dave Chinner, (Thu Oct 7, 10:21 pm)
[PATCH 03/18] fs: keep inode with backing-dev, Dave Chinner, (Thu Oct 7, 10:21 pm)
[PATCH 05/18] fs: inode split IO and LRU lists, Dave Chinner, (Thu Oct 7, 10:21 pm)
[PATCH 11/18] fs: Introduce per-bucket inode hash locks, Dave Chinner, (Thu Oct 7, 10:21 pm)
[PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Dave Chinner, (Thu Oct 7, 10:21 pm)
[PATCH 17/18] fs: icache remove inode_lock, Dave Chinner, (Thu Oct 7, 10:21 pm)
Re: [PATCH 02/18] fs: Convert nr_inodes and nr_unused to p ..., Christoph Hellwig, (Fri Oct 8, 12:01 am)
Re: [PATCH 03/18] fs: keep inode with backing-dev, Christoph Hellwig, (Fri Oct 8, 12:01 am)
Re: [PATCH 04/18] fs: Implement lazy LRU updates for inodes., Christoph Hellwig, (Fri Oct 8, 12:08 am)
Re: [PATCH 05/18] fs: inode split IO and LRU lists, Christoph Hellwig, (Fri Oct 8, 12:14 am)
Re: [PATCH 06/18] fs: Clean up inode reference counting, Christoph Hellwig, (Fri Oct 8, 12:20 am)
Re: [PATCH 07/18] exofs: use iput() for inode reference co ..., Christoph Hellwig, (Fri Oct 8, 12:21 am)
Re: [PATCH 08/18] fs: add inode reference coutn read accessor, Christoph Hellwig, (Fri Oct 8, 12:24 am)
Re: [PATCH 03/18] fs: keep inode with backing-dev, Dave Chinner, (Fri Oct 8, 12:27 am)
Re: [PATCH 09/18] fs: rework icount to be a locked variable, Christoph Hellwig, (Fri Oct 8, 12:27 am)
Re: [PATCH 10/18] fs: Factor inode hash operations into fu ..., Christoph Hellwig, (Fri Oct 8, 12:29 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Fri Oct 8, 12:33 am)
Re: [PATCH 12/18] fs: add a per-superblock lock for the in ..., Christoph Hellwig, (Fri Oct 8, 12:35 am)
Re: [PATCH 05/18] fs: inode split IO and LRU lists, Dave Chinner, (Fri Oct 8, 12:38 am)
Re: [PATCH 13/18] fs: split locking of inode writeback and ..., Christoph Hellwig, (Fri Oct 8, 12:42 am)
Re: [PATCH 06/18] fs: Clean up inode reference counting, Dave Chinner, (Fri Oct 8, 12:46 am)
Re: [PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Christoph Hellwig, (Fri Oct 8, 12:53 am)
Re: [PATCH 16/18] fs: Make iunique independent of inode_lock, Christoph Hellwig, (Fri Oct 8, 12:55 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Dave Chinner, (Fri Oct 8, 1:09 am)
Re: [PATCH 06/18] fs: Clean up inode reference counting, Christoph Hellwig, (Fri Oct 8, 1:15 am)
Re: [PATCH 09/18] fs: rework icount to be a locked variable, Christoph Hellwig, (Fri Oct 8, 1:17 am)
Re: [PATCH 01/18] kernel: add bl_list, Andi Kleen, (Fri Oct 8, 1:18 am)
Re: [PATCH 16/18] fs: Make iunique independent of inode_lock, Christoph Hellwig, (Fri Oct 8, 1:19 am)
Re: [PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Christoph Hellwig, (Fri Oct 8, 1:44 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Fri Oct 8, 2:51 am)
Re: [PATCH 05/18] fs: inode split IO and LRU lists, Dave Chinner, (Fri Oct 8, 2:58 am)
Re: [PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Christoph Hellwig, (Fri Oct 8, 3:03 am)
Re: [PATCH 01/18] kernel: add bl_list, Dave Chinner, (Fri Oct 8, 3:33 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Fri Oct 8, 6:43 am)
Re: [PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Christoph Hellwig, (Fri Oct 8, 6:48 am)
Re: [PATCH 09/18] fs: rework icount to be a locked variable, Christoph Hellwig, (Fri Oct 8, 6:53 am)
Re: [PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Christoph Hellwig, (Fri Oct 8, 12:10 pm)
[PATCH 19/18] fs: split __inode_add_to_list, Christoph Hellwig, (Sat Oct 9, 1:08 am)
[PATCH 20/18] fs: do not assign default i_ino in new_inode, Christoph Hellwig, (Sat Oct 9, 4:18 am)
Re: [PATCH 19/18] fs: split __inode_add_to_list, Dave Chinner, (Tue Oct 12, 3:47 am)
Re: [PATCH 19/18] fs: split __inode_add_to_list, Christoph Hellwig, (Tue Oct 12, 4:31 am)
Re: [PATCH 19/18] fs: split __inode_add_to_list, Dave Chinner, (Tue Oct 12, 5:05 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Wed Oct 13, 12:20 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Wed Oct 13, 12:27 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Eric Dumazet, (Wed Oct 13, 3:42 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Christoph Hellwig, (Wed Oct 13, 4:25 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Christoph Hellwig, (Wed Oct 13, 4:28 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Wed Oct 13, 5:03 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Wed Oct 13, 5:07 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Christoph Hellwig, (Wed Oct 13, 5:20 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Wed Oct 13, 5:25 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Dave Chinner, (Wed Oct 13, 4:23 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Thu Oct 14, 2:06 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Thu Oct 14, 2:13 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Christoph Hellwig, (Thu Oct 14, 7:41 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Thu Oct 14, 5:14 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Dave Chinner, (Thu Oct 14, 8:13 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Thu Oct 14, 9:04 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Thu Oct 14, 11:41 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Dave Chinner, (Fri Oct 15, 3:59 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Dave Chinner, (Fri Oct 15, 4:33 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 6:03 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 6:14 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 6:29 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 7:11 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 8:38 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 10:33 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Christoph Hellwig, (Fri Oct 15, 10:52 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 11:02 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 11:14 am)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 1:50 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 1:56 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Fri Oct 15, 7:09 pm)
Re: [PATCH 17/18] fs: icache remove inode_lock, Nick Piggin, (Sat Oct 16, 12:57 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Sat Oct 16, 9:16 am)
Re: [PATCH 13/18] fs: split locking of inode writeback and ..., Christoph Hellwig, (Sat Oct 16, 9:20 am)
Re: [PATCH 15/18] fs: introduce a per-cpu last_ino allocator, Christoph Hellwig, (Sat Oct 16, 9:22 am)
Re: [PATCH 07/18] exofs: use iput() for inode reference co ..., Christoph Hellwig, (Sat Oct 16, 9:29 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Sat Oct 16, 5:45 pm)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Mon Oct 18, 9:21 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Christoph Hellwig, (Tue Oct 19, 9:50 am)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Thomas Gleixner, (Sun Oct 24, 9:41 pm)
Re: [PATCH 11/18] fs: Introduce per-bucket inode hash locks, Thomas Gleixner, (Mon Oct 25, 12:04 am)