Looking at the Linux kernel Git repository, it appears that neither PF_INET
sockets nor PF_INET6
sockets support memory-mapped access, so if by
My application only requires the use of the standard linux UDP socket interface. I wish to use packet_mmap purely for efficiency - right now syscalls are eating over 50% of my CPU cycles.
you mean you want to use memory-mapped access for a normal UDP or TCP socket, unfortunately, you can't. The same applies to raw IP sockets.
PF_PACKET
sockets do support memory-mapped access, but they require elevated privileges, regardless of whether you're using memory-mapped access or not. They are not a replacement for PF_INET
or PF_INET6
sockets; they are a mechanism for reading and writing link-layer packets, so if you want to run normal Internet applications atop them, good luck:
- you'll have to reimplement IP and whatever transport protocol you're using (UDP, TCP, etc.) yourself;
- you'll somehow have to keep the kernel's IP and transport protocol stack from processing those packets;
and you really don't want to try doing that.
(Note that by "elevated privileges" I don't necessarily mean "root privileges"; CAP_NET_RAW
privileges should suffice. However, as I note, if you're trying to replace regular socket access, you don't want to use PF_PACKET
sockets.)