Re: Linux Zero Copy

From: Jamie Lokier (
Date: Thu Aug 14 2003 - 11:52:18 EST

Nagendra Singh Tomar wrote:
> Thanx for ur reply. So this means that this Zero Copy can only be
> used by senders who have to send data from a "file" that supports mmap. I
> just can't fill a buffer in userland and expect it to be sent via Zero
> Copy.

You can fill a buffer in userland and send it with zerocopy. To do
this, mmap() a file using PROT_READ|PROT_WRITE and MAP_FILE|MAP_SHARED.

Then you can write directly to the file's pages in memory, and use
sendfile() to send that data.

You only have to set up a mapping once; after that, for each thing you
want to transmit just choose a region in the mapped memory to prepare
your data in, and call sendfile() to send it.

Ideally, you would use a shared memory file ("man shm_open"), but I
understand that with kernels prior to 2.4.22, that doesn't work with
sendfile(), so you have to use a real file for older kernels than that.

-- Jamie
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at