UDP send and receive in different streams

How independent is UDP handling of send and receive on the same socket in the Linux kernel? In my case, a workflow is used that sends UDP test traffic to (up to) 1000 sockets and receives UDP responses in another workflow. The receiver will be an epoll loop, which also receives hardware sending and receiving timestamps in the socket error queue.

To clarify, when doing syscall sendmsg () does this temporarily block (or generate EAGAIN / EWOULDBLOCK) on the receiver accepting the same socket? (that is, if the transmission and reception occur with an overlap in time). All sockets are set to non-blocking mode.

Another question is granularity of blocking in the kernel - if I send and receive with sendmmsg / recvmmsg, is it a lock for this socket, blocked once on sendmmsg, or once for a UDP datagram in sendmmsg?

UPDATE: I took a look at the source patch for sendmmsg in the Linux kernel, it seems that the main advantage is to avoid the multi-user jump space. If any blocking is completed, it is probably executed inside separate __sys_sendmsg calls: https://lwn.net/Articles/441169/

+5
source share
1 answer

Each system call is thread independent. Thus, since you are not using process core data, both will work independently of each other without disturbing each other.

Another thing that the kernel does is with system calls associated with the same inode (in this case, the virtual node assigned to the socket that you use for communication). To serialize and create atomic calls to the file system, the kernel usually performs an inode lock during the entire system call (this is a system call for reading, writing, or ioctl), which indicates the entire system call (even if you make a unique write call for writing in a million bytes, inode is blocked during the execution of the entire system call)

In the tcp-ip stack, this is done at the socket level and is controlled in your case by special software of the socket class AF_INET . Like udp, sending a packet or receiving does not affect the shared resources that you need to block, but you will have to look at your udp implementation (or socket level) to see if any blocking has been completed, and what is the granularity, Usually a blocking it should be used only during loading / unloading of udp buffers (as a rule, in udp there are no buffers, since the socket and network card driver are sufficient to provide enough buffer resources.

0
source

Source: https://habr.com/ru/post/1264299/


All Articles