Rick Jones wrote:
> Socket buffers in general, and things like net.core.[rw]mem_max
> specifically are not preallocations. They are limits. So, an
> SO_RCVBUF of 256KB is not consuming 256 KB of memory unless there are
> actually data/packets waiting therein.
>
> For the inbound data path, the allocations are actually made by the
> NIC driver when it allocates buffers to post to the NIC for inbound
> DMA. The strategies employed for buffer sizes there will vary from
> NIC to NIC, and will depend on the NIC's programming model.
>
> rick jones
Following code answers few of my questions.
(inline with what Rick told)
http://lxr.linux.no/#linux+v3.8.7/net/core/sock.c#L689
708set_rcvbuf:
709 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
710 /*
711 * We double it on the way in to account for
712 * "struct sk_buff" etc. overhead. Applications
713 * assume that the SO_RCVBUF setting they make will
714 * allow that much actual data to be received on that
715 * socket.
716 *
717 * Applications are unaware that "struct sk_buff" and
718 * other overheads allocate from the receive buffer
719 * during socket buffer allocation.
720 *
721 * And after considering the possible alternatives,
722 * returning the value we actually used in getsockopt
723 * is the most desirable behavior.
724 */
725 sk->sk_rcvbuf = max_t(u32, val * 2, SOCK_MIN_RCVBUF);
726 break;
As my packets are below 100 bytes data, the sk_buff overhead would be
proportionally quite high. Visually looking at sk_buff, for a 32-bit
system, the size of sk_buff appears to be around 200 bytes.
For 100 byte on wire packet, that means only one-third of rcvbuf is
holding packet data. 2/3 is sk_buff overhead.
So for SO_RCVBUF :262142,
262142/3 = 87380 bytes are available for packet data.
87380/100 = 873 is number of packets that can be held in it.
1000 - 873 = 127 drops out of 1000 are expected.
What I got was 170, which is not far from expectation.
Following Chapters/Books were really helpfull.
[1] Understanding Linux Network Internals By Christian Benvenuti
Part III: Transmission and Reception
[2] Essential Linux Device Drivers by Sreekrishnan Venkateswaran
Chapter 15. Network Interface Cards
Thanks all folks here.
- Surinder