]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] open writecount scalability cleanup
authorIngo Molnar <mingo@elte.hu>
Tue, 10 Feb 2004 23:54:06 +0000 (15:54 -0800)
committerLinus Torvalds <torvalds@home.osdl.org>
Tue, 10 Feb 2004 23:54:06 +0000 (15:54 -0800)
This is an obvious scalability improvement for write()s.  We used a
global lock to protect the inode writecount (updated on every open for
writing) - this just makes it use the existing inode->i_lock instead.

Compiles & boots fine on x86 SMP.

fs/namei.c

index 5302c5ed75c4285c64cceab8141ccbf06f6b9077..8553bce3a9702bef804dc3f2be177828e7979152 100644 (file)
@@ -237,30 +237,34 @@ int permission(struct inode * inode,int mask, struct nameidata *nd)
  * except for the cases where we don't hold i_writecount yet. Then we need to
  * use {get,deny}_write_access() - these functions check the sign and refuse
  * to do the change if sign is wrong. Exclusion between them is provided by
- * spinlock (arbitration_lock) and I'll rip the second arsehole to the first
- * who will try to move it in struct inode - just leave it here.
+ * the inode->i_lock spinlock.
  */
-static spinlock_t arbitration_lock = SPIN_LOCK_UNLOCKED;
+
 int get_write_access(struct inode * inode)
 {
-       spin_lock(&arbitration_lock);
+       spin_lock(&inode->i_lock);
        if (atomic_read(&inode->i_writecount) < 0) {
-               spin_unlock(&arbitration_lock);
+               spin_unlock(&inode->i_lock);
                return -ETXTBSY;
        }
        atomic_inc(&inode->i_writecount);
-       spin_unlock(&arbitration_lock);
+       spin_unlock(&inode->i_lock);
+
        return 0;
 }
+
 int deny_write_access(struct file * file)
 {
-       spin_lock(&arbitration_lock);
-       if (atomic_read(&file->f_dentry->d_inode->i_writecount) > 0) {
-               spin_unlock(&arbitration_lock);
+       struct inode *inode = file->f_dentry->d_inode;
+
+       spin_lock(&inode->i_lock);
+       if (atomic_read(&inode->i_writecount) > 0) {
+               spin_unlock(&inode->i_lock);
                return -ETXTBSY;
        }
-       atomic_dec(&file->f_dentry->d_inode->i_writecount);
-       spin_unlock(&arbitration_lock);
+       atomic_dec(&inode->i_writecount);
+       spin_unlock(&inode->i_lock);
+
        return 0;
 }