Mkfifo – Does disk I/O actually occur

fifoio

I have 2 applications:

  • Producer (N instances)
  • Consumer (1 instance)

I currently write out intermediate results from the producers, and then the consumer reads these files from disk and produces a final result.

I would like to minimize this I/O by "streaming" the outputs from the producers directly to the consumer.

I came across named pipes (mkfifo) and a subsequent example here. This looks great, but what I can't determine is how this is actually implemented? Is the FIFO queue just being buffered through a file? If so, that probably wouldn't help me. I would like for the contents to stream "through memory" entirely without utilizing the disk. Maybe this isn't possible across processes?

Best Answer

No disk i/o (except perhaps when navigating through the filesystem to open the fifo file.)

From the Linux fifo(7) man page:

A FIFO special file (a named pipe) is similar to a pipe, except that it is accessed as part of the filesystem. [...] When processes are exchanging data via the FIFO, the kernel passes all data internally without writing it to the filesystem. Thus, the FIFO special file has no contents on the filesystem; the filesystem entry merely serves as a reference point so that processes can access the pipe using a name in the filesystem.

Related Question