Re: [PATCH v1 net-next 4/7] af_unix: Use cached value for SOCK_STREAM in unix_inq_len().

From
Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date
2025-07-06 13:53:23
Reply to
Kuniyuki Iwashima, 2025-07-02
Kuniyuki Iwashima wrote:
Compared to TCP, ioctl(SIOCINQ) for AF_UNIX SOCK_STREAM socket is more
expensive, as unix_inq_len() requires iterating through the receive queue
and accumulating skb->len.

Let's cache the value for SOCK_STREAM to a new field during sendmsg()
and recvmsg().

The field is protected by the receive queue lock.
nit: for updates, but the read is taken without the lock held, hence
the WRITE_ONCE/READ_ONCE accessors.
Note that ioctl(SIOCINQ) for SOCK_DGRAM returns the length of the first
skb in the queue.

SOCK_SEQPACKET still requires iterating through the queue because we do
not touch functions shared with unix_dgram_ops.  But, if really needed,
we can support it by switching __skb_try_recv_datagram() to a custom
version.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Thread (15 messages) 15 messages, 3 authors, last reply 2025-07-09
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help