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

查看:22
本文介绍了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_defaultnet.core.wmem_defaultnet.core.rmem_maxnet.core.wmem_maxnet.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_SNDBUFSO_RCVBUF 套接字选项,但这与上面的问题相同.无论如何,默认套接字缓冲区大小是根据默认套接字选项设置的.

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,它使用 data_len = 0 和 header_len<调用 sock_alloc_send_pskb()/code> = 数据报的大小 lxr2.sock_alloc_send_pskb() 从普通"skbuff 缓冲区空间分配header_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天全站免登陆