Linux 中 AF_UNIX 数据报消息的最大大小是多少?
目前我已达到 130688 字节的硬限制。如果我尝试在一条消息中发送较大的内容,则会收到 ENOBUFS
错误。
我已经检查了 net.core.rmem_default
、net.core.wmem_default
、net.core.rmem_max
、net.core。 wmem_max
和 net.unix.max_dgram_qlen
sysctl 选项并增加了它们,但它们没有效果,因为它们处理的是总缓冲区大小而不是消息大小。
我还设置了 SO_SNDBUF
和 SO_RCVBUF
套接字选项,但这与上面有相同的问题。无论如何,默认套接字缓冲区大小是根据默认套接字选项设置的。
我查看了内核源代码,其中 ENOBUFS
在套接字堆栈中返回,但我不清楚它来自哪里。似乎返回此错误的唯一地方与无法分配内存有关。
最大尺寸实际上是 130688 吗?如果不能,可以在不重新编译内核的情况下更改它吗?
Currently I'm hitting a hard limit of 130688 bytes. If I try and send anything larger in one message I get a ENOBUFS
error.
I have checked the net.core.rmem_default
, net.core.wmem_default
, net.core.rmem_max
, net.core.wmem_max
, and net.unix.max_dgram_qlen
sysctl options and increased them all but they have no effect because these deal with the total buffer size not the message size.
I have also set the SO_SNDBUF
and SO_RCVBUF
socket options, but this has the same issue as above. The default socket buffer size are set based on the default socket options anyways.
I've looked at the kernel source where ENOBUFS
is returned in the socket stack, but it wasn't clear to me where it was coming from. The only places that seem to return this error have to do with not being able to allocate memory.
Is the max size actually 130688? If not can this be changed without recompiling the kernel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AF_UNIX SOCK_DATAGRAM/SOCK_SEQPACKET 数据报需要连续的内存。连续的物理内存很难找到,并且分配失败,在内核日志上记录类似的内容:
unix_dgram_sendmsg()
调用sock_alloc_send_skb()
lxr1,它调用sock_alloc_send_pskb()< /code> 其中
data_len
= 0 且header_len
= 数据报大小 lxr2。sock_alloc_send_pskb()
从“正常”skbuff 缓冲区空间分配header_len
,并从分散/聚集页面 lxr3。因此,看起来 AF_UNIX 套接字在当前的 Linux 上不支持分散/聚集。AF_UNIX SOCK_DATAGRAM/SOCK_SEQPACKET datagrams need contiguous memory. Contiguous physical memory is hard to find, and the allocation fails, logging something similar to this on the kernel log:
unix_dgram_sendmsg()
callssock_alloc_send_skb()
lxr1, which callssock_alloc_send_pskb()
withdata_len
= 0 andheader_len
= size of datagram lxr2.sock_alloc_send_pskb()
allocatesheader_len
from "normal" skbuff buffer space, anddata_len
from scatter/gather pages lxr3. So, it looks like AF_UNIX sockets don't support scatter/gather on current Linux.