A.Cho
A.Cho

Reputation: 593

Why do unbuffered read()/write() operations use buffer cache?

Basically on UNIX, read() and write() functions are unbuffered I/O,

and there are Standard I/O, which is buffered I/O.

But, read() and write() functions use buffer cache which is in kernel before doing real I/O(I/O to real device), and real I/O happens using buffer cache. It's using buffer.

I heard unbuffered I/O means I/O happens on char-by-char to real device.

Then, why read() and write() functions are unbuffered I/O, even though it is using buffer cache?

Upvotes: 3

Views: 961

Answers (2)

Alexander Ekzhanov
Alexander Ekzhanov

Reputation: 162

"(Un)buffered" in the manual refers to user-space buffering. Kernel space buffering depends on implementation, usually most devices are buffered (disk, sockets, USB etc.) except hardware ports (GPIO).

Upvotes: 1

unwind
unwind

Reputation: 400079

Basically the term "buffering" here means "a place where data is stored when going to/from the kernel", i.e. to avoid doing one system call for each I/O call, the buffered functions use a buffer between.

What the kernel does with the data is not something the standard library can do much about.

It would be possible to do a 1:1 mapping of read/write calls at the standard library's level (i.e. fread() and friends) to read()/write() calls on the underlying file descriptor; the term buffering is telling you that is not what you can expect.

Upvotes: 3

Related Questions