Alex Rivera | Logout

communicating between processes with shared-memory results zero-copy?

Asked 2011-02-26T23:31:59.623
10

I am writing a network daemon, on Linux with kernel 2.6, which has one producer process and N of consumer processes, which does not make any change on the data, and does not create any response back to the producer.

Whenever the producer process produces a data object, of which the length varies from few 10 bytes to few 10 K-bytes, it has to pass the data object into one available consumer process.

First time, I considered to use a named/unnamed PIPE. However, they would be memory-copy overhead.

  1. producer's user-space buffer --copy--> kernel-space PIPE buffer
  2. kernel-space PIPE buffer --copy--> consumer's user-space buffer

Since the program may work with a large-number of peers with low latency, the copy-overhead could be harmful. Thus, I decided to use POSIX shared-memory with mmap().

I am just wondering if sharing data between processes using POSIX shared-memory with mmap() does not result any memory-copy, unlike PIPE.

Also, is there any other way to share data between processes, but results zero-copy? The program will be run on Linux with a recent version of kernel and may not have to have a cross-platform ability.

I decided not to spawn/run a thread for each consumer/produce, but a process due to design issues.

Thanks for reply.

Edit
Report

1 Answer

2

Shared-memory should not introduce any copies (cache coherency excepted), and you can directly access the memory so you may be able to avoid copies in your code.

answered 2011-02-26T23:53:32.423

Your Answer