By: Howard Chu (hyc.delete@this.symas.com),
Room: Moderated Discussions
Linus Torvalds (torvalds.delete@this.linux-foundation.org) on January 4, 2020 12:31 pm wrote:
> Btw, locking can be simple too. If you do a lot of work, and the locking is something "occasional",
> you can use things like just passing a token over a pipe (or even a network connection) as your locking
> mechanism. Yes, the individual locking events end up being somewhat expensive, and it doesn't work
> very well at all for what is one very common case - no locking really needed at all because there's
> really only one active thread, but it can actually be a very simple and effective model.
>
> It turns out people get even that simple model wrong (passing tokens around in a pipe
> is exactly what the GNU make "jobserver" code does as a kind of "counting semaphore"
> implementation), and we found a bug in that user-space jobserver locking just last
> month because it got exposed when we tried to make the kernel more efficient.
Got a link to a bug report for gmake? Has it been fixed yet?
Fwiw, I invented that jobserver code back in 1991 while I was working at JPL,
and back then there was no consistent shared memory API in Unix, but pipe()
existed everywhere. And the default pipe buffer size was 4096 bytes, so it
even worked fine on our 1024 node Connection Machine. (I recall a gmake
bug report where it deadlocked on a system with more than 4096 CPUs, a few years
back.) Overall, not a bad thing for a concept to have survived for the past 29
years across multiple POSIX OSs.
http://highlandsun.com/hyc/#Make
> Btw, locking can be simple too. If you do a lot of work, and the locking is something "occasional",
> you can use things like just passing a token over a pipe (or even a network connection) as your locking
> mechanism. Yes, the individual locking events end up being somewhat expensive, and it doesn't work
> very well at all for what is one very common case - no locking really needed at all because there's
> really only one active thread, but it can actually be a very simple and effective model.
>
> It turns out people get even that simple model wrong (passing tokens around in a pipe
> is exactly what the GNU make "jobserver" code does as a kind of "counting semaphore"
> implementation), and we found a bug in that user-space jobserver locking just last
> month because it got exposed when we tried to make the kernel more efficient.
Got a link to a bug report for gmake? Has it been fixed yet?
Fwiw, I invented that jobserver code back in 1991 while I was working at JPL,
and back then there was no consistent shared memory API in Unix, but pipe()
existed everywhere. And the default pipe buffer size was 4096 bytes, so it
even worked fine on our 1024 node Connection Machine. (I recall a gmake
bug report where it deadlocked on a system with more than 4096 CPUs, a few years
back.) Overall, not a bad thing for a concept to have survived for the past 29
years across multiple POSIX OSs.
http://highlandsun.com/hyc/#Make


