Search code examples
linuxlinux-kernelnetwork-programmingraw-sockets

Why is the RX ring of a Linux raw socket limited to 4GB in size?


Background

I'm trying to mmap() the RX ring buffer of a raw socket in my 64-bit Linux application. My ring consists of 4096 blocks of size 1MB each for a total of 4GB. (Note there can be many frames in each 1MB block. See this doc for background if you're curious.)

Problem

Unfortunately, there appears to be a 4GB limit on the size of the RX ring buffer when configuring it using setsockopt() with option PACKET_RX_RING. The implication for me is that I cannot increase either my block size or my ring size any further. My application would benefit from an increase though.

This limit is at least enforced in modern versions of the Linux kernel. See the source here.

(Note that there is no issue mmap()ing larger than 4GB. I originally stumbled into this question.)

Question

Why is there a limit of 4GB for the RX ring buffer? If it's a bug when migrating this part of the kernel from 32-bit, that would be cool and might be straightforward to patch. But, if there's a more fundamental reason, I'm curious to know what that may be.


Solution

  • This was a bug. I submitted a patch to fix this (now merged): https://github.com/torvalds/linux/commit/fc62814d690cf62189854464f4bd07457d5e9e50