Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

io

unix

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?

like image 230
A.Cho Avatar asked Jun 03 '26 11:06

A.Cho


1 Answers

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.

like image 192
unwind Avatar answered Jun 05 '26 02:06

unwind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!