What is buffer in Buffered IO?

Hello all,
I have 2 conceptual questions about memory management in driver development. I hope you help me to solve this confusion.

  1. What is the meaning of buffer in buffered IO? Is it just "address space" or "physical pages in RAM". So copying buffer means, just allocating a new address space in the system address space or copying all the data in the RAM?
  2. If it is copying the data in the RAM and at the same time there are 2 versions of same data in the RAM, and it is wasting performance, why just locked pages, like in the Direct IO, and mapped to the system address space?
1 Like

Please read the helpful info on learn.microsoft.com )) or the Windows Internals book.
Buffered I/O means that memory is allocated in the kernel (not just "new address space") and the user data is copied there, then this buffer is passed to you.

If it is copying the data in the RAM and at the same time there are 2 versions of same data in the RAM, and it is wasting performance

Because locking pages has performance cost too. If the size of input/output data is less than a page, buffered I/O makes sense. Also, a usermode process that does not have any locked pages can be completely swapped out of RAM.

2 Likes

Excellent summary from Pavel. Today's CPUs do copies very, very fast, as many as 8 bytes per cycle. Mapping involves manipulating the page tables, finding free virtual space, and allocating new page table entries. That can be expensive.

There's also a more intangible safety aspect. When there is a copy, neither party can impact the other. When both ends are sharing physical pages, that separation is missing.

2 Likes

Another hidden cost of direct I/O is that when you unmap the OS has to invalidate (global) TLB entries. This is going to be much more costly for small, frequent transfers than just logically freeing a block of non-paged pool.

3 Likes