Linux中AF_UNIX数据报消息的最大大小是多少? [英] What is the max size of AF_UNIX datagram message in Linux?

查看:228
本文介绍了Linux中AF_UNIX数据报消息的最大大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的硬限制是130688字节。如果我尝试在一条消息中发送更大的内容,则会收到ENOBUFS错误。

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.

我已经检查了net.core.rmem_default,net.core.wmem_default,net.core .rmem_max,net.core.wmem_max和net.unix.max_dgram_qlen sysctl选项并全部增加了,但它们没有效果,因为它们处理的是缓冲区的总大小而不是消息的大小。

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.

我还设置了SO_SNDBUF和SO_RCVBUF套接字选项,但这与上面的问题相同。无论如何,默认套接字缓冲区的大小都是根据_default套接字选项设置的。

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.

我看了内核源代码,在套接字堆栈中返回了ENOBUFS,我不清楚它的来源。似乎返回此错误的唯一地方与无法分配内存有关。

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.

最大大小实际上是130688吗?

Is the max size actually 130688? If not can this be changed without recompiling the kernel?

推荐答案

AF_UNIX SOCK_DATAGRAM / SOCK_SEQPACKET数据报需要连续的内存。很难找到连续的物理内存,并且分配失败,在内核日志中记录与此类似的内容:

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:

udgc: page allocation failure. order:7, mode:0x44d0
[...snip...]
DMA: 185*4kB 69*8kB 34*16kB 27*32kB 11*64kB 1*128kB 1*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 3788kB
Normal: 13*4kB 6*8kB 100*16kB 62*32kB 24*64kB 10*128kB 0*256kB 1*512kB 0*1024kB 0*2048kB 0*4096kB = 7012kB
[...snip...]

unix_dgram_sendmsg()调用 sock_alloc_send_skb() lxr1 ,它调用 sock_alloc_send_pskb() data_len = 0和 header_len =数据报的大小 lxr2 sock_alloc_send_pskb()从普通 skbuff缓冲区空间分配 header_len data_len 从分散/收集页面 lxr3 。因此,AF_UNIX套接字在当前Linux上似乎不支持分散/聚集。

unix_dgram_sendmsg() calls sock_alloc_send_skb() lxr1, which calls sock_alloc_send_pskb() with data_len = 0 and header_len = size of datagram lxr2. sock_alloc_send_pskb() allocates header_len from "normal" skbuff buffer space, and data_len from scatter/gather pages lxr3. So, it looks like AF_UNIX sockets don't support scatter/gather on current Linux.

这篇关于Linux中AF_UNIX数据报消息的最大大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆