Spoon wrote On 07/31/07 06:15,:
> [...]
> Consider two buffers A and B.
>
> char A[16];
> char B[1316];
>
> I want to send A+B (A and B concatenated) in a single UDP datagram.
> (I have to do it 500-5000 times per second.)
> [...]
> I could also use scatter-gather I/O with sendmsg().
>
> I'm afraid the kernel (or Ethernet driver) will just end up copying the
> two buffers to concatenate them anyway. Are some Ethernet drivers
> "smart" enough that they don't perform any copy?
Some network stacks may be smart enough to avoid
a copy, some may not. But you can be certain of one
thing: if you copy the data yourself you *will* incur
a copy no matter how smart the rest of the system is.
By using scatter/gather, you at least give the stack
an opportunity to be clever -- it may or may not exploit
the opportunity you give it, but you haven't already
closed the door.
Even if the network stack does copy your buffers
you may win with scatter/gather by copying the data
not zero times, but one less than if you'd copied it
yourself. (For example, a stack that always copies
outbound data from user space to kernel space will
copy even a single contiguous buffer; if its gather
mode just makes those copies from several buffers,
most of the copying you've done is overhead.)
Have you measured the throughput you're actually
getting to see whether it meets your needs? Are you
off by just a few percent, or by a big factor?
--
(E-Mail Removed)