tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: AF_UNIX socketpair dgram queue sizes



jschauma%netmeister.org@localhost (Jan Schaumann) writes:

>1) I can write 4 dgrams of size 1 up until 400 bytes
>before my next attempt to write another 1 byte dgram
>fails with ENOBUFS.  This uses 8 512 byte mbufs.
>2) I can write 3 dgrams of size 401 to 856 bytes
>before my next attempt to write another dgram fails
>with ENOBUFS.  This uses 9 512 byte mbufs.
>(If I write 856 bytes, the third datagram will only
>carry 330 bytes for a total of 856 + 856 + 330 = 2042
>bytes, which, when we add the two bytes from the
>SONAME mbuf for each, adds up to 2048, i.e.,
>SNDBUF.)
>3) I can write 2 dgrams of size 857 bytes before my
>next attempt yields ENOBUFS.  This uses 4 mbufs,
>writing 1718 bytes in total.

>My question at this point is: when does my mbuf
>allocation fail? I.e., what is the limit here?

>In (1), I allocated 8 mbufs = 4096 bytes = 2 * SO_RCVBUF.
>In (2), I allocated 9 mbufs = 4608 bytes = 2 * SO_RCVBUF + 512.
>But I ended up writing less data.
>In (3), I allocate 4 mbufs = 2048 bytes = SO_RCVBUF.


There are two limits:

sb_cc counts the valid bytes against sb_hiwat = SO_RCVBUF.
sb_mbcnt counts the mbuf sizes against sb_mbmax = 2 * SO_RCVBUF.

Either limit gives you an amount of free space in the buffer
and the minimum is the limit for the write operation. This
is calculated in sbspace().


If I calculated right you get the following cases:

1)
	after writing 3 datagrams you have:
	1206 bytes written -> 842 bytes free
	3072 bytes of mbufs appended -> 1024 bytes free
	-> you can write another 842 bytes

	next datagram of 400 + 2 bytes fits and you have:
	1608 bytes written -> 440 bytes free
	4096 bytes of mbufs appended -> 0 bytes free
	-> next write will fail

	The same happens also when you just write 1 byte datagrams
	as sb_mbcnt will be the same.

2)
	after writing 2 datagrams you have:
	1716 bytes written -> 332 bytes free
	3072 bytes of mbufs appended -> 1024 bytes free
	-> you can write another 332 bytes

	next datagram of 330 + 2 bytes fits and you have
	2048 bytes written -> 0 bytes free
	4096 bytes of mbufs appended -> 0 bytes free
	-> next write will fail

3)
	after writing 1 datagram you have:
	859 bytes written -> 1189 bytes free
	2560 bytes of mbufs appended -> 1536 bytes free
	-> you can write another 1189 bytes

	next datagram of 857 + 2 bytes fits and you have:
	1718 bytes written -> 330 bytes free
	5120 bytes of mbufs appended -> 0 bytes free
	-> next write will fail



Home | Main Index | Thread Index | Old Index