[patch-2.3.99-pre6-5] do_close() optimization

From: Tigran Aivazian (tigran@veritas.com)
Date: Sat Apr 22 2000 - 11:04:51 EST


Hi Linus,

If we add a new inline called __put_unused_fd() which assumes the caller
took the files->file_lock spinlock then we save calls to write_lock() and
write_unlock() in the normal (critical) code path of do_close(fd, 1).

Apart from this simple optimization, this patch also helps in my function
force_closefd() which does something similar to do_close() but not
exactly.

Regards,
Tigran

diff -urN linux/fs/open.c close/fs/open.c
--- linux/fs/open.c Sat Apr 22 10:30:24 2000
+++ close/fs/open.c Sat Apr 22 16:53:32 2000
@@ -756,12 +756,18 @@
         return error;
 }
 
-inline void put_unused_fd(unsigned int fd)
+inline void __put_unused_fd(unsigned int fd)
 {
- write_lock(&current->files->file_lock);
         FD_CLR(fd, current->files->open_fds);
         if (fd < current->files->next_fd)
                 current->files->next_fd = fd;
+}
+
+
+inline void put_unused_fd(unsigned int fd)
+{
+ write_lock(&current->files->file_lock);
+ __put_unused_fd(fd);
         write_unlock(&current->files->file_lock);
 }
 
@@ -852,9 +858,9 @@
         if (!filp)
                 goto out_unlock;
         FD_CLR(fd, files->close_on_exec);
- write_unlock(&files->file_lock);
         if (release)
- put_unused_fd(fd);
+ __put_unused_fd(fd);
+ write_unlock(&files->file_lock);
         lock_kernel();
         error = filp_close(filp, files);
         unlock_kernel();
diff -urN linux/include/linux/fs.h close/include/linux/fs.h
--- linux/include/linux/fs.h Sat Apr 22 10:30:25 2000
+++ close/include/linux/fs.h Sat Apr 22 16:53:58 2000
@@ -848,7 +848,8 @@
 extern int do_close(unsigned int, int); /* yes, it's really unsigned */
 extern int do_truncate(struct dentry *, loff_t start);
 extern int get_unused_fd(void);
-extern void put_unused_fd(unsigned int);
+extern void __put_unused_fd(unsigned int); /* locked by the caller */
+extern void put_unused_fd(unsigned int); /* locked internally */
 
 extern struct file *filp_open(const char *, int, int);
 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 23 2000 - 21:00:20 EST