Need info about FreeBSD and interrupted system calls for MySQL code

Dan Nelson dnelson at allantgroup.com
Thu Apr 29 19:49:35 UTC 2010


In the last episode (Apr 29), Joerg Bruehe said:
> For some long, unknown time, the MySQL code contains a variable
> "net_retry_count" which is by default set to 10 (ten) for all platforms,
> but to 1000000 (1 million) for FreeBSD (during configure phase).
> 
> The source code comment about this variable reads
>        If a read on a communication port is interrupted, retry this many
>        times before giving up.
> 
> The documentation (manual) has this sentence in addition:
>        This value should be set quite high on FreeBSD because internal
>        interrupts are sent to all threads.
> 
> I read that as
> "On FreeBSD, a thread may receive many more interrupts than on other
> platforms, so an operation which may take some time (like network I/O)
> may be interrupted much more often than on other platforms, and hence
> the retry count should be higher."
> 
> I trust that this comment was valid at the time it was written -
> is it still true for current versions of FreeBSD, or did things change?

I'm pretty sure this is a holdover from when FreeBSD only had a user
pthreads package (libc_r).  libc calls that would normally block got
converted into non-blocking versions and a select() loop would execute
threads as the events they were waiting on occurred.  Incoming signals would
cause all threads waiting on read() to return EINTR.  If you have other
threads doing work and sending/receiving signals, this can add up to a lot
of extra EINTR's.

FreeBSD 5.0 (released in 2003) was the first version to have kernel-based
pthread support, so the original reason for raising net_retry_count has long
since disappeared.

A related question might be, though:  Should that variable even exist? 
EINTR isn't technically a failure, and most programs that read from sockets
simply wrap their read()s in a loop that retries when EINTR is received. 
Only mysql actually counts the number of times through the loop.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list