Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set st_nlink in O(1) #34

Closed
overheadhunter opened this issue Mar 26, 2019 · 1 comment
Closed

Set st_nlink in O(1) #34

overheadhunter opened this issue Mar 26, 2019 · 1 comment
Milestone

Comments

@overheadhunter
Copy link
Member

While profiling for issue #33 I noticed, that getattr of directories (which happens frequently, e.g. when the caller wants to know if a file exists or is a directory) takes a lot of time due to nlinks depending on the number of subdirectories:

long nlinks;
try {
attrUtil.copyBasicFileAttributesFromNioToFuse(attrs, stat);
nlinks = 2 + countSubDirs(path);
} catch (IOException e) {
nlinks = 2;
}
stat.st_nlink.set(nlinks);

The run time of countSubDirs vastly depends on the number of items in a directory, which makes getattr of the directory dependend on its size, which can lead to significant slowdowns:

Bildschirmfoto 2019-03-26 um 09 53 04

Other FUSE file systems don't support link count either, such as sshfs, which simply hard-coded st_nlink=1.

Citing Han-Wen Nienhuys:

The st_nlink for dirs is actualy not well defined. But the convention under unix is that it is the number of subdirectories including "." and "..".

[...]

But I think st_nlink == 1 is save in that regard and find will see that st_nlink doesn't follow the unix convention. Any other st_nlink will need "find -noleaf".

While we should try to set st_nlink to the number of subdirectories + 2, it should be ok to hard-code a fixed value in case we can't find an efficient solution to get the number of subdirectories.

@overheadhunter overheadhunter added this to the 1.1.2 milestone Mar 26, 2019
@overheadhunter
Copy link
Member Author

Setting st_nlink = 1 works fine on and FUSE 2.9.7 (tested on Linux 4.15, Mint 19.1) as well as on FUSE for macOS 3.8.2 (tested on High Sierra)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant