Repository navigation
Single worker during init - #1326
Conversation
e69311d to
e9f106a
Compare
ec0d76c to
e27c78e
Compare
e27c78e to
400834e
Compare
This is to prevent startup races. For example it is hard for threads to know the buffer size the kernel usage. In the past kernel buffer size always was max 1MB, but in the mean time this might be more, depending on system tunings. I thought I had fixed all races, but the report in issue libfuse#1296 proves otherwise. Closes: libfuse#1296 Signed-off-by: Bernd Schubert <[email protected]>
400834e to
8a6cbbf
Compare
|
@joannekoong @szmi Any chance you could review? I'm also going to add a commit on top later this week to avoid buffer re-allocation when reading /dev/fuse, but have |
| mt->numavail--; | ||
| if (mt->numavail == 0 && mt->numworker < mt->max_threads) | ||
| if (mt->numavail == 0 && mt->numworker < mt->max_threads && | ||
| likely(se->got_init)) |
There was a problem hiding this comment.
Does se->got_init = 1 also need to be moved in _do_init() to be set after (instead of before) the
if (se->op.init) {
...
se->op.init(se->userdata, &se->conn);
}
call?
There was a problem hiding this comment.
Let me add this into a different commit. I would like to back port the 1st commit in this series to 3.17.x, as I think it is rather safe. Setting se->op.init later has the slight risk to change behavior, as it is check in send_notify_iov() - isn't there at least slight risk that application call notify from their ->init method?
Technically moving got_init is not needed in this commit, although I didn't mention it in the commit message. New worker threads are created by fuse_do_work - it will only read got_init after returning from fuse_session_process_buf_internal - returns after completely handling FUSE_INIT.
| se->bufsize = FUSE_DEFAULT_MAX_PAGES_PER_REQ * getpagesize() + | ||
| FUSE_BUFFER_HEADER_SIZE; |
There was a problem hiding this comment.
Does this run into issues later when the init processing is handled (in particular when this line gets hit se->conn.max_write = MIN(se->conn.max_write, bufsize - FUSE_BUFFER_HEADER_SIZE);)? I think in most of the cases, when we reach that line, bufsize is se->bufsize, which means se->conn.max_write would be truncated too short?
There was a problem hiding this comment.
Good point!
The line before has
if (buf_reallocable)
bufsize = UINT_MAX;
Which is true for all internal libfuse users. And buf_reallocable is also set to false when FUSE_MAX_PAGES is not set - technically setting it to false is actually not correct - we just don't need a larger buffer in that case.
My generic issue with fuse_session_receive_buf, i.e. external callers is, how do these callers actually know the needed buffer size? struct fuse_session is internal - these callers have no knowledge which buffer size has to be used? At best we can add an assumption into the code that when called through fuse_session_receive_buf that it is an external caller and that this caller has set a buffer size of 1MB - i.e. traditional libfuse3 behavior?
There was a problem hiding this comment.
I removed this commit for now, will added in a different PR
8a6cbbf to
6f0a8f1
Compare
32b80b6 to
ffaee98
Compare
A previous commit added single thread behavior as long as se->got_init is not set, especially as buffer allocation should be done after got_init only. Technically it should not make a difference in current libfuse design, as more worker threads are only allocated after the FUSE_INIT handler is completely done. That might at some point change, though. In general it is cleaner to set se->got_init, when the init handler is done. Done as separate commit, as this introduces a slight risk to break something - backport to older version should be done carefully. Signed-off-by: Bernd Schubert <[email protected]>
ffaee98 to
8f7fae1
Compare
No description provided.