aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/inode.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 05ea293d5f32..46a3e120b196 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -717,6 +717,43 @@ repeat:
717 return NULL; 717 return NULL;
718} 718}
719 719
720/*
721 * Each cpu owns a range of LAST_INO_BATCH numbers.
722 * 'shared_last_ino' is dirtied only once out of LAST_INO_BATCH allocations,
723 * to renew the exhausted range.
724 *
725 * This does not significantly increase overflow rate because every CPU can
726 * consume at most LAST_INO_BATCH-1 unused inode numbers. So there is
727 * NR_CPUS*(LAST_INO_BATCH-1) wastage. At 4096 and 1024, this is ~0.1% of the
728 * 2^32 range, and is a worst-case. Even a 50% wastage would only increase
729 * overflow rate by 2x, which does not seem too significant.
730 *
731 * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
732 * error if st_ino won't fit in target struct field. Use 32bit counter
733 * here to attempt to avoid that.
734 */
735#define LAST_INO_BATCH 1024
736static DEFINE_PER_CPU(unsigned int, last_ino);
737
738static unsigned int get_next_ino(void)
739{
740 unsigned int *p = &get_cpu_var(last_ino);
741 unsigned int res = *p;
742
743#ifdef CONFIG_SMP
744 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
745 static atomic_t shared_last_ino;
746 int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
747
748 res = next - LAST_INO_BATCH;
749 }
750#endif
751
752 *p = ++res;
753 put_cpu_var(last_ino);
754 return res;
755}
756
720/** 757/**
721 * new_inode - obtain an inode 758 * new_inode - obtain an inode
722 * @sb: superblock 759 * @sb: superblock
@@ -731,12 +768,6 @@ repeat:
731 */ 768 */
732struct inode *new_inode(struct super_block *sb) 769struct inode *new_inode(struct super_block *sb)
733{ 770{
734 /*
735 * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
736 * error if st_ino won't fit in target struct field. Use 32bit counter
737 * here to attempt to avoid that.
738 */
739 static unsigned int last_ino;
740 struct inode *inode; 771 struct inode *inode;
741 772
742 spin_lock_prefetch(&inode_lock); 773 spin_lock_prefetch(&inode_lock);
@@ -745,7 +776,7 @@ struct inode *new_inode(struct super_block *sb)
745 if (inode) { 776 if (inode) {
746 spin_lock(&inode_lock); 777 spin_lock(&inode_lock);
747 __inode_sb_list_add(inode); 778 __inode_sb_list_add(inode);
748 inode->i_ino = ++last_ino; 779 inode->i_ino = get_next_ino();
749 inode->i_state = 0; 780 inode->i_state = 0;
750 spin_unlock(&inode_lock); 781 spin_unlock(&inode_lock);
751 } 782 }