aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2011-07-21 19:59:22 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-22 20:43:30 -0400
commit7f9838fd01833ffb30177d964983076924344c9e (patch)
tree95487aa8962c0baaed05375f739a4a16a566a388 /fs/sysfs
parent86028619b9f653a30f5aa0d331fdedd899a1eea5 (diff)
sysfs: count subdirectories
sysfs: count subdirectories This patch introduces a subdirectory counter for each sysfs directory. Without the patch, sysfs_refresh_inode would walk all entries of the directory to calculate the number of subdirectories. This patch improves time of "ls -la /sys/block" when there are 10000 block devices from 9 seconds to 0.19 seconds. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/dir.c6
-rw-r--r--fs/sysfs/inode.c14
-rw-r--r--fs/sysfs/sysfs.h2
3 files changed, 9 insertions, 13 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index ea9120a830d8..7d240e6b7176 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -47,6 +47,9 @@ static void sysfs_link_sibling(struct sysfs_dirent *sd)
47 47
48 BUG_ON(sd->s_sibling); 48 BUG_ON(sd->s_sibling);
49 49
50 if (sysfs_type(sd) == SYSFS_DIR)
51 parent_sd->s_dir.subdirs++;
52
50 /* Store directory entries in order by ino. This allows 53 /* Store directory entries in order by ino. This allows
51 * readdir to properly restart without having to add a 54 * readdir to properly restart without having to add a
52 * cursor into the s_dir.children list. 55 * cursor into the s_dir.children list.
@@ -73,6 +76,9 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
73{ 76{
74 struct sysfs_dirent **pos; 77 struct sysfs_dirent **pos;
75 78
79 if (sysfs_type(sd) == SYSFS_DIR)
80 sd->s_parent->s_dir.subdirs--;
81
76 for (pos = &sd->s_parent->s_dir.children; *pos; 82 for (pos = &sd->s_parent->s_dir.children; *pos;
77 pos = &(*pos)->s_sibling) { 83 pos = &(*pos)->s_sibling) {
78 if (*pos == sd) { 84 if (*pos == sd) {
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index e3f091a81c72..1ee18c81df78 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -202,18 +202,6 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
202 inode->i_ctime = iattr->ia_ctime; 202 inode->i_ctime = iattr->ia_ctime;
203} 203}
204 204
205static int sysfs_count_nlink(struct sysfs_dirent *sd)
206{
207 struct sysfs_dirent *child;
208 int nr = 0;
209
210 for (child = sd->s_dir.children; child; child = child->s_sibling)
211 if (sysfs_type(child) == SYSFS_DIR)
212 nr++;
213
214 return nr + 2;
215}
216
217static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) 205static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode)
218{ 206{
219 struct sysfs_inode_attrs *iattrs = sd->s_iattr; 207 struct sysfs_inode_attrs *iattrs = sd->s_iattr;
@@ -230,7 +218,7 @@ static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode)
230 } 218 }
231 219
232 if (sysfs_type(sd) == SYSFS_DIR) 220 if (sysfs_type(sd) == SYSFS_DIR)
233 inode->i_nlink = sysfs_count_nlink(sd); 221 inode->i_nlink = sd->s_dir.subdirs + 2;
234} 222}
235 223
236int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 224int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 845ab3ad229d..6348e2c753f6 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -19,6 +19,8 @@ struct sysfs_elem_dir {
19 struct kobject *kobj; 19 struct kobject *kobj;
20 /* children list starts here and goes through sd->s_sibling */ 20 /* children list starts here and goes through sd->s_sibling */
21 struct sysfs_dirent *children; 21 struct sysfs_dirent *children;
22
23 unsigned long subdirs;
22}; 24};
23 25
24struct sysfs_elem_symlink { 26struct sysfs_elem_symlink {