From The Linux Programming Interface:
(I've read the related sections. I pasted this sum-up diagram just for illustration.) enter image description here

I know that for direct IO which uses read and write system calls. There is a 2 levels of buffering. read/write buffer + kernel buffer.

When using stdio library calls, which are built on top of direct system IO calls, is

  1. stdio buffer + read/write buffer + kernel buffer, 3 levels of buffering,


  1. stdio and write/read share the same buffer, 2 levels of buffering

stdio calls <---> user buffer <-----> read/write + kernel buffer


(I think it's a 2 levels of buffering, but I want to be sure.)


In the common case there are two levels. A buffer in user space is allocated by the stdio library, and calls to puts/printf/fprintf etc put characters into this buffer. At some stage (e.g. the buffer is fullor a newline is written and the stream is in line buffered mode) the stdio library calls write to ask the kernel to write the buffer. The kernel will usually copy the buffer into a kernel buffer, start whatever is needed to get the data to the destination and return. User space is then free to use the userspace buffer however it wants.

It is possible (but unusual) to have different implementations of stdio which do this differently. sfio has an stdio compatibility layer. Various schemes have been proposed for zero copy etc. The point is that stdio tells you what is the effect, not how it is done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.