User Details
- User Since
- Jul 2 2021, 4:03 PM (228 w, 5 d)
Today
The Makefile needs to be updated to install mmap.c.
Bump.
Yesterday
Mon, Nov 17
This is an initial quick review, as I haven't had a chance to properly test it yet.
Sat, Nov 15
Thu, Nov 13
Wed, Nov 12
Address kib's comments.
Clean up. Finalized on my part.
Do what I explained in the last message. stress2 has finished after 30 minutes
without panicking. I've yet to test chn_read() though.
After some pen and paper debugging, it seems that my current approach does solve most cases, but there is still one case that can reproduce the panic, albeit quite rare. You need to run stress2 usually for about ~20 minutes with enough workload to hit the race. Suppose the following scenario: the buffer has a size of 4 bytes, and we have two threads: (A) and (B).
In the first iteration, thread (A) wants to write 2 bytes, while the buffer is empty, BUT the pointer (sndbuf_getfreeptr()) is at the end (i.e., buf[3]). In the first iteration of the loop, because of the way we calculate t, we'll end up writing only 1 byte, so after sz -= t, sz will be 1, and so we'll need one more iteration in the inner loop, to write the remaining 1 byte. Now we're at the end of the first loop, thread (A) unlocks the channel, it has written 1 byte, it needs to write 1 more, and the buffer is left with 3 empty slots. Now thread (B) picks up the lock, and it wants to write 3 (or more) bytes. Eventually it writes the 3 bytes, and it leaves the buffer with 0 free slots. By the time thread (A) picks up the lock again, and continues with the second iteration of the inner loop, it will try to write the last byte, but sndbuf_acquire() will panic because there is no free space anymore. I'm pretty sure this is what is going on.
I can actually fix those last comments myself, no need to waste your time for this. Just let me know if tests worked fine on your machine. :-)
Tue, Nov 11
All of my inline comments are mostly grammar/typo fixes. If you tested the most recent code (especially simple.c) with the most recent changes, then we'll be good to go. I'll commit this once you address the last comments. Thanks a lot for this! :-)