-
Notifications
You must be signed in to change notification settings - Fork 332
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
High cpu usage after viewing a CryFS FUSE filesystem #1543
Comments
I'm able to replicate this, 10% cpu usage if I ever touch the mountdir directory It seems that this channel is somehow getting flooded with a ridiculous number of directories When I make a global variable to add one to a counter every time we reach line 384 and print it when the program ends I get a number in the thousands if I open lf in the mountdir for even a few seconds versus 6 if I open any other directory Edit: also adding even a 5 millsecond delay takes my cpu usage from 10% to 0.8%. The time is actually being spent in app.ui.draw on line 418 Edit pt2: I think I see why this is happening. When a dir is received on dirchan, we call app.nav.checkdir . Then checkDir goes down a codepath where it creates a newDir and passes it into that channel. So it loops on itself. I'm unsure what checkDir is doing and what the purpose of that go func is so I'm hesistant proposing a solution |
If the directory has been modified, the load timestamp is updated, so theoretically it should not cause an infinite loop: You might want to check the modified time of the directory and the load timestamp to investigate further. |
The modified time of a mounted cryfs directory always seems to be the current time. This is without any processes (other than cryfs) touching it Just a thought, the number of Blocks from os.Stat.Sys() on the mounted directory always shows 0, I can't find any other directories that work like this on my system. Perhaps we can use that as a sign to early return/ |
That makes sense, if the modified time is constantly updating (to the current time), then the directory will constantly be reloaded. I think it would be acceptable to add some check similar to below to perform an early
Thank you for looking into the root cause. |
So it turns out the root cause comes from |
I think it's possible that we can try this approach, though I would still be inclined to keep the block count = 0 check. I'm not exactly keen on this kind of solution, but I think having users run into this high CPU usage situation is much worse. cc @gokcehan |
Just a thought Maybe whether we run this check could be a boolean option of some sort? I think it'll be a very small minority of users that are using CryFS so this check can only cause unintended behavior for the overwhelming majority of users, and is an extra comparison operation they don't need. |
@joelim-work Unfortunately, I can't think of a good solution for this either. I think I'm ok with using the @Michael-Gallo 's new Boolean option might also be a good idea, I'm not sure. But if we are thinking of a new option, how about a more general option to be able to disable |
The project only has 1.9k stars on Github ( https://github.com/cryfs/cryfs ) , and I also have never heard of it prior to reading this issue, and fundamentally I would say the bug is on their end. So yea I'm going to agree we probably shouldn't have a file system specific fix here in this case. Since the issue is fundamentally |
After spending some more time to investigate the issue, I'm not actually sure whether it's necessary for the According to the commit history, it looks like it was added in 3e36500 to fix issue #338. But the root cause appears to be the fact that directories were loaded asynchronously (via |
Good catch @joelim-work , thanks for digging through the history, and thanks @Michael-Gallo for submitting the patch. The only case I can think of is that maybe this can now be triggered if an option is changed dynamically without the config file while a directory is being loaded. Unfortunately, I did not have a chance to give it a try yet myself. In any case, we can consider those as niche cases, so I think I'm ok with the patch as it is. |
I did some testing with the new changes, it looks like a race condition is possible again if &lf -remote "send $id set hidden"
I still think it's a niche scenario though. Maybe a more proper fix might be to have |
This is now fixed by #1607 |
CryFS is a program to encrypt a folder of files and view them in a FUSE mounted directory.
After lf even glances at a CryFS directory, it will start using about 14.5% cpu on my 8 thread machine, sometimes dropping down to ~3% usage for a while before going back up. Obviously CryFS has to use some cpu to create the file tree, but this is finished quite early on as shown by the cryfs process, and the problem persists even when navigating far away from the cryfs dir.
btop
also shows the process's thread count going up over time. One day i woke up to find it using over 1000 threads, which actually seemed to lag my system.Pressing F1 to open help in the pager temporarily halts all cpu usage, and goes back up on quit. Any ideas?
The text was updated successfully, but these errors were encountered: