aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2007-05-08 03:26:18 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:03 -0400
commitc23fbb6bcb3eb9cdf39a103edadf57bde8ce309c (patch)
treed79ab2278774de2c1a8061aa948ed068902e87b4 /fs
parent2793274298c4423d79701e9a8190f2940bf3c785 (diff)
VFS: delay the dentry name generation on sockets and pipes
1) Introduces a new method in 'struct dentry_operations'. This method called d_dname() might be called from d_path() to build a pathname for special filesystems. It is called without locks. Future patches (if we succeed in having one common dentry for all pipes/sockets) may need to change prototype of this method, but we now use : char *d_dname(struct dentry *dentry, char *buffer, int buflen); 2) Adds a dynamic_dname() helper function that eases d_dname() implementations 3) Defines d_dname method for sockets : No more sprintf() at socket creation. This is delayed up to the moment someone does an access to /proc/pid/fd/... 4) Defines d_dname method for pipes : No more sprintf() at pipe creation. This is delayed up to the moment someone does an access to /proc/pid/fd/... A benchmark consisting of 1.000.000 calls to pipe()/close()/close() gives a *nice* speedup on my Pentium(M) 1.6 Ghz : 3.090 s instead of 3.450 s Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Acked-by: Christoph Hellwig <hch@infradead.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/dcache.c31
-rw-r--r--fs/pipe.c18
2 files changed, 43 insertions, 6 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 268da2e2bc09..2135ab8bb103 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1853,6 +1853,16 @@ char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
1853 struct vfsmount *rootmnt; 1853 struct vfsmount *rootmnt;
1854 struct dentry *root; 1854 struct dentry *root;
1855 1855
1856 /*
1857 * We have various synthetic filesystems that never get mounted. On
1858 * these filesystems dentries are never used for lookup purposes, and
1859 * thus don't need to be hashed. They also don't need a name until a
1860 * user wants to identify the object in /proc/pid/fd/. The little hack
1861 * below allows us to generate a name for these objects on demand:
1862 */
1863 if (dentry->d_op && dentry->d_op->d_dname)
1864 return dentry->d_op->d_dname(dentry, buf, buflen);
1865
1856 read_lock(&current->fs->lock); 1866 read_lock(&current->fs->lock);
1857 rootmnt = mntget(current->fs->rootmnt); 1867 rootmnt = mntget(current->fs->rootmnt);
1858 root = dget(current->fs->root); 1868 root = dget(current->fs->root);
@@ -1866,6 +1876,27 @@ char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
1866} 1876}
1867 1877
1868/* 1878/*
1879 * Helper function for dentry_operations.d_dname() members
1880 */
1881char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen,
1882 const char *fmt, ...)
1883{
1884 va_list args;
1885 char temp[64];
1886 int sz;
1887
1888 va_start(args, fmt);
1889 sz = vsnprintf(temp, sizeof(temp), fmt, args) + 1;
1890 va_end(args);
1891
1892 if (sz > sizeof(temp) || sz > buflen)
1893 return ERR_PTR(-ENAMETOOLONG);
1894
1895 buffer += buflen - sz;
1896 return memcpy(buffer, temp, sz);
1897}
1898
1899/*
1869 * NOTE! The user-level library version returns a 1900 * NOTE! The user-level library version returns a
1870 * character pointer. The kernel system call just 1901 * character pointer. The kernel system call just
1871 * returns the length of the buffer filled (which 1902 * returns the length of the buffer filled (which
diff --git a/fs/pipe.c b/fs/pipe.c
index ebafde7d6aba..3a89592bdf57 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -841,8 +841,18 @@ static int pipefs_delete_dentry(struct dentry *dentry)
841 return 0; 841 return 0;
842} 842}
843 843
844/*
845 * pipefs_dname() is called from d_path().
846 */
847static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
848{
849 return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
850 dentry->d_inode->i_ino);
851}
852
844static struct dentry_operations pipefs_dentry_operations = { 853static struct dentry_operations pipefs_dentry_operations = {
845 .d_delete = pipefs_delete_dentry, 854 .d_delete = pipefs_delete_dentry,
855 .d_dname = pipefs_dname,
846}; 856};
847 857
848static struct inode * get_pipe_inode(void) 858static struct inode * get_pipe_inode(void)
@@ -888,8 +898,7 @@ struct file *create_write_pipe(void)
888 struct inode *inode; 898 struct inode *inode;
889 struct file *f; 899 struct file *f;
890 struct dentry *dentry; 900 struct dentry *dentry;
891 char name[32]; 901 struct qstr name = { .name = "" };
892 struct qstr this;
893 902
894 f = get_empty_filp(); 903 f = get_empty_filp();
895 if (!f) 904 if (!f)
@@ -899,11 +908,8 @@ struct file *create_write_pipe(void)
899 if (!inode) 908 if (!inode)
900 goto err_file; 909 goto err_file;
901 910
902 this.len = sprintf(name, "[%lu]", inode->i_ino);
903 this.name = name;
904 this.hash = 0;
905 err = -ENOMEM; 911 err = -ENOMEM;
906 dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &this); 912 dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &name);
907 if (!dentry) 913 if (!dentry)
908 goto err_inode; 914 goto err_inode;
909 915