提交 7f9838fd 编写于 作者: M Mikulas Patocka 提交者: Greg Kroah-Hartman

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: NMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 86028619
...@@ -47,6 +47,9 @@ static void sysfs_link_sibling(struct sysfs_dirent *sd) ...@@ -47,6 +47,9 @@ static void sysfs_link_sibling(struct sysfs_dirent *sd)
BUG_ON(sd->s_sibling); BUG_ON(sd->s_sibling);
if (sysfs_type(sd) == SYSFS_DIR)
parent_sd->s_dir.subdirs++;
/* Store directory entries in order by ino. This allows /* Store directory entries in order by ino. This allows
* readdir to properly restart without having to add a * readdir to properly restart without having to add a
* cursor into the s_dir.children list. * cursor into the s_dir.children list.
...@@ -73,6 +76,9 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd) ...@@ -73,6 +76,9 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
{ {
struct sysfs_dirent **pos; struct sysfs_dirent **pos;
if (sysfs_type(sd) == SYSFS_DIR)
sd->s_parent->s_dir.subdirs--;
for (pos = &sd->s_parent->s_dir.children; *pos; for (pos = &sd->s_parent->s_dir.children; *pos;
pos = &(*pos)->s_sibling) { pos = &(*pos)->s_sibling) {
if (*pos == sd) { if (*pos == sd) {
......
...@@ -202,18 +202,6 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr) ...@@ -202,18 +202,6 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
inode->i_ctime = iattr->ia_ctime; inode->i_ctime = iattr->ia_ctime;
} }
static int sysfs_count_nlink(struct sysfs_dirent *sd)
{
struct sysfs_dirent *child;
int nr = 0;
for (child = sd->s_dir.children; child; child = child->s_sibling)
if (sysfs_type(child) == SYSFS_DIR)
nr++;
return nr + 2;
}
static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode)
{ {
struct sysfs_inode_attrs *iattrs = sd->s_iattr; 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,7 +218,7 @@ static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode)
} }
if (sysfs_type(sd) == SYSFS_DIR) if (sysfs_type(sd) == SYSFS_DIR)
inode->i_nlink = sysfs_count_nlink(sd); inode->i_nlink = sd->s_dir.subdirs + 2;
} }
int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
......
...@@ -19,6 +19,8 @@ struct sysfs_elem_dir { ...@@ -19,6 +19,8 @@ struct sysfs_elem_dir {
struct kobject *kobj; struct kobject *kobj;
/* children list starts here and goes through sd->s_sibling */ /* children list starts here and goes through sd->s_sibling */
struct sysfs_dirent *children; struct sysfs_dirent *children;
unsigned long subdirs;
}; };
struct sysfs_elem_symlink { struct sysfs_elem_symlink {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册