Networking is my worst area in operating systems, so forgive me for asking perhaps an incomplete question. I've been reading about this for a few hours, but it's kinda swimming in my head. (To me, I feel like chip design is easy compared to figuring out networking protocols.)
I have some networked services that communicate with each other via sockets. Specifically, the sockets are created with fd = socket(PF_INET, SOCK_STREAM, 0);
, which automatically gets TCP/IP. I need this as the base case, because these services may be running on separate machines.
But for one project, we're trying to squeeze all of them into an underpowered embedded 'appliance', based on an Atom Z530P, so it seems to me that the memory copy overhead is something we could optimize out. I've been reading about that here: data-link-access-and-zero-copy and Linux_packet_mmap and packet_mmap.
For this case, one would create the socket something like this: fd = socket(PF_PACKET, PF_RAW, 0);
. And there's a bunch of other stuff to do, like allocating ring buffers, mmapping them, associating them with the socket, etc. It looks like you're restricted to using sendto
and recvfrom
in order to transmit data. As I understand it, since the socket is local, you don't need a reliable "stream" type socket, so raw sockets is the appropriate interface, and I'm guessing that the ring buffer is used at page granularity, where each packet (or datagram) starts at a page boundary.
Before I spend a huge amount of time trying to investigate this further, I was hoping some helpful individuals might help me with some questions:
Thanks in advance for the help!
Am I over-complicating things and/or optimizing the wrong thing?
Possibly. Using PF_PACKET
sockets is only for specialized stuff. You probably want to look into
What's the simplest or best way to detect that the two processes are on the same machine?
Simply not "forgetting" this information.
Does Linux do any of this automatically, optimizing for processes running on the same machine?
No, you have to do it yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With