Merge to Fedora kernel-2.6.6-1.422
[linux-2.6.git] / fs / inode.c
index 1f847ba..7e1d502 100644 (file)
@@ -98,13 +98,36 @@ struct inodes_stat_t inodes_stat;
 
 static kmem_cache_t * inode_cachep;
 
+static void prune_icache(int nr_to_scan);
+
+
+#define INODE_UNUSED_THRESHOLD 15000
+#define PRUNE_BATCH_COUNT 32
+
+void try_to_clip_inodes(void)
+{
+       unsigned long count = 0; 
+       /* if there are a LOT of unused inodes in cache, better shrink a few first */
+       
+       /* check lockless first to not take the lock always here; racing occasionally isn't a big deal */
+       if (inodes_stat.nr_unused > INODE_UNUSED_THRESHOLD) {
+               spin_lock(&inode_lock);
+               if (inodes_stat.nr_unused > INODE_UNUSED_THRESHOLD)
+                       count = inodes_stat.nr_unused - INODE_UNUSED_THRESHOLD;
+               spin_unlock(&inode_lock);
+               if (count)
+                       prune_icache(count);
+       }
+}
+
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
        static struct address_space_operations empty_aops;
        static struct inode_operations empty_iops;
        static struct file_operations empty_fops;
        struct inode *inode;
-
+       
        if (sb->s_op->alloc_inode)
                inode = sb->s_op->alloc_inode(sb);
        else