Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vsock: avoid timeout for non-blocking accept() with empty backlog

A common pattern in epoll network servers is to eagerly accept all
pending connections from the non-blocking listening socket after
epoll_wait indicates the socket is ready by calling accept in a loop
until EAGAIN is returned indicating that the backlog is empty.

Scheduling a timeout for a non-blocking accept with an empty backlog
meant AF_VSOCK sockets used by epoll network servers incurred hundreds
of microseconds of additional latency per accept loop compared to
AF_INET or AF_UNIX sockets.

Signed-off-by: Laurence Rowe <laurencerowe@gmail.com>
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://patch.msgid.link/20260402204918.130395-1-laurencerowe@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Laurence Rowe and committed by
Jakub Kicinski
98f28d8d c8eee00c

+6 -9
+6 -9
net/vmw_vsock/af_vsock.c
··· 1864 1864 * created upon connection establishment. 1865 1865 */ 1866 1866 timeout = sock_rcvtimeo(listener, arg->flags & O_NONBLOCK); 1867 - prepare_to_wait(sk_sleep(listener), &wait, TASK_INTERRUPTIBLE); 1868 1867 1869 1868 while ((connected = vsock_dequeue_accept(listener)) == NULL && 1870 - listener->sk_err == 0) { 1869 + listener->sk_err == 0 && timeout != 0) { 1870 + prepare_to_wait(sk_sleep(listener), &wait, TASK_INTERRUPTIBLE); 1871 1871 release_sock(listener); 1872 1872 timeout = schedule_timeout(timeout); 1873 1873 finish_wait(sk_sleep(listener), &wait); ··· 1876 1876 if (signal_pending(current)) { 1877 1877 err = sock_intr_errno(timeout); 1878 1878 goto out; 1879 - } else if (timeout == 0) { 1880 - err = -EAGAIN; 1881 - goto out; 1882 1879 } 1883 - 1884 - prepare_to_wait(sk_sleep(listener), &wait, TASK_INTERRUPTIBLE); 1885 1880 } 1886 - finish_wait(sk_sleep(listener), &wait); 1887 1881 1888 - if (listener->sk_err) 1882 + if (listener->sk_err) { 1889 1883 err = -listener->sk_err; 1884 + } else if (!connected) { 1885 + err = -EAGAIN; 1886 + } 1890 1887 1891 1888 if (connected) { 1892 1889 sk_acceptq_removed(listener);