summaryrefslogtreecommitdiffstats
path: root/fs/sysfs/dir.c
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2011-07-22 01:59:22 +0200
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-23 02:43:30 +0200
commit7f9838fd01833ffb30177d964983076924344c9e (patch)
tree95487aa8962c0baaed05375f739a4a16a566a388 /fs/sysfs/dir.c
parentdocs/sysfs: Specify ABI documentation requirements (diff)
downloadlinux-7f9838fd01833ffb30177d964983076924344c9e.tar.xz
linux-7f9838fd01833ffb30177d964983076924344c9e.zip
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/dir.c')
-rw-r--r--fs/sysfs/dir.c6
1 files changed, 6 insertions, 0 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)
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
* readdir to properly restart without having to add a
* cursor into the s_dir.children list.
@@ -73,6 +76,9 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
{
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;
pos = &(*pos)->s_sibling) {
if (*pos == sd) {