"Serge E. Hallyn" <serue@xxxxxxxxxx> writes: > Quoting Eric W. Biederman (ebiederm@xxxxxxxxxxxx): >> From: Eric W. Biederman <ebiederm@xxxxxxxxxxxxxxxxxx> >> >> On large directories sysfs_count_nlinks can be a significant >> bottleneck, so keep a count in sysfs_dirent. If we exceed >> the maximum number of directory entries we can store return >> nlink of 1. An nlink of 1 matches what reiserfs does in >> this case, and it let's find and similar utlities know that >> we have a the directory nlink can not be used for optimization >> purposes. >> >> Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxxxxxxxx> >> --- >> fs/sysfs/dir.c | 20 ++++++++++++++++++++ >> fs/sysfs/inode.c | 15 +-------------- >> fs/sysfs/mount.c | 1 + >> fs/sysfs/sysfs.h | 1 + >> 4 files changed, 23 insertions(+), 14 deletions(-) >> >> diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c >> index 5c4703d..1c364be 100644 >> --- a/fs/sysfs/dir.c >> +++ b/fs/sysfs/dir.c >> @@ -359,6 +359,7 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) >> sd->s_name = name; >> sd->s_mode = mode; >> sd->s_flags = type; >> + sd->s_nlink = type == SYSFS_DIR? 2:1; >> >> return sd; >> >> @@ -392,6 +393,23 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, >> mutex_lock(&sysfs_mutex); >> } >> >> +static void sysfs_dir_inc_nlink(struct sysfs_dirent *sd) >> +{ >> + /* If we overflow force nlink to be 1 */ >> + if (sd->s_nlink > 1) { >> + sd->s_nlink++; >> + if (sd->s_nlink == 0) >> + sd->s_nlink = 1; >> + } >> +} > > Now, the original code only ups nlink on parent if child is a dir. > IIUC your code will now inc nlink for files as well. Is any userspace > going to be confused by that? Good point. nlink should only be upped for directories. Eric -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html