Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the CPU read from the disk?

I'm a bit confused about the whole idea of IO; I want to know how the CPU reads from the disk (a SATA disk for example) ?

When the program with read()/write() is complied with a reference to a specific file and when the CPU encounters this reference, does it read from the disk directly (via memory mapped IO ports)? Or does it write to the RAM and then writes back to disk?

like image 480
user1339237 Avatar asked Apr 17 '12 16:04

user1339237


1 Answers

I'd suggest reading: http://www.makelinux.net/books/ulk3/understandlk-CHP-13-SECT-1 With a supplement of: http://en.wikipedia.org/wiki/Direct_memory_access

With regards to buffering in RAM: most programming languages and operating systems buffer at least part of I/O operations (read and write) to memory. This is usually done asynchronously: i.e. a buffer is created, filled, and then processed. For a read, the CPU would (working with the disk controller) create IO instructions to fetch data and a place to put it in memory, fill that space, and then present its contents to the program making the request. For a write request, this would be queuing write operations and their associated data and then sending them off to the IO controller and eventually the disk to be executed. Buffering can happen in multiple places: on the CPU's caches, in RAM, (sometimes) on the disk controller, or on the hard disk itself. How much buffering is done, and exactly how the abstract sequence of operations I've mentioned is handled, differs depending on your hardware architecture, OS, and task.

like image 94
Zac B Avatar answered Sep 20 '22 15:09

Zac B