-
Notifications
You must be signed in to change notification settings - Fork 153
WIP: Add Multithreading Support #293
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
base: master
Are you sure you want to change the base?
Conversation
| /// nothing. | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub trait Filesystem { | ||
| pub trait Filesystem: Clone { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the random drive-by comment. In my opinion, it would be better to require Send + Sync instead of Clone, and change the trait methods to take non-mutable self. Then it's up to the user how they handle mutability, if they need it. Cloning + mutability is a massive footgun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback!
I need to figure out exactly what you're referring to and understand it, but that does make sense and does seem better. Something fun to do this weekend!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a type is Send, it can be safely moved between threads.
if a type is Sync, it can be safely shared between threads.
see https://doc.rust-lang.org/nomicon/send-and-sync.html?highlight=Send#send-and-sync
| struct SimpleFS { | ||
| data_dir: String, | ||
| next_file_handle: AtomicU64, | ||
| next_file_handle: Arc<AtomicU64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, Arc<AtomicU64> is a totally reasonable way to handle mutability, here - but this example could have easily used a normal u64 before these changes and still derived Clone, leading to coinciding file handles.
|
Do mind explaining why you picked the multithreading programming model rather than async/await programming model? |
Because that would be a major refactor of the code base, and to do it properly everything would need to be rewritten |
|
@volfco I created a similar multithreading solution but instead of making a whole new session object for each worker, I just created a new channel object for each worker, and one session holds an array of channels. The entire session goes into an arc, rather than each of its mutable fields. Then the run function becomes an associated function that takes Arc rather than a traditional method that takes Self (Of course, just putting the Filesystem in an Arc would have accomplished the same thing. So maybe I over-engineered it? Oh well). This worked for me because at the same time, I was also changing the method signatures of Filesystem to take |
|
@rarensu I'm not currently working in this space and on this project. At this point, I'm waiting for more robust Rust support for the kernel and then I'll reimplement my idea as a kernel module. Even with multi-threading, the overhead was still quite high. Maybe I'll revisit this eventually |
Add Multithreading Support to fuser.
This implementation modifies
BackgroundSessionto accept a thread quantity. If this number is two or more, then n - 1 background workers will be created. There will always be a primary worker created, hence n - 1.Session::workeris called to clone the Session, which in turn callsChannel::worker. This method accepts the Mount object, and using.session_fdto return the Session FD,fuse_fd_cloneis invoked to clone the file descriptor and run the needed ioctl call to setup the session.I can't take all the credit, as the main piece of code in channel.rs is from the Datenlord project where they are doing a native async_fuse library.
The code in question is from here: https://github.com/datenlord/datenlord/blob/d90fd43732373451207e56e9b9cd7eef9e7b53e1/src/async_fuse/fuse/session.rs#L73
Additional References:
TODO