Tuesday, 31 October 2017

io - Cost of disc I/O read versus write



Is writing to a disc more costly operation then reading from a disk. For example - writing a 1 GB file of records as compared to reading the whole file.



Answer



At the drive level, a read sector operation would take about the same (or a bit longer) time as a write sector operation. For a read sector, the command has to arrive over the drive interface (e.g. SATA), the command decoded, seek issued, scan Address Marks and record IDs until sector is found, read sector data into a buffer, validate the sector using ECC (error correction code), and then finally send out the sector data. (Note that there is a widespread misconception that sector data can be transferred directly from the read head to the interface. Absolutely false: the sector data is always fully buffered, and is always transmitted at full interface speed only after the entire sector has been read and validated.) If read-ahead is performed and cached, then a subsequent sequential read will not have the seek and rotational delays. For a write sector, the command and sector data has to arrive over the drive interface, the command decoded, seek issued, scan Address Marks and record IDs until sector is found, write out sector with ECC, and the host is notified of completion.


At the OS or filesystem level, writes are more complex when a new file is being created. Reading a or rewriting an existing disk file only requires lookup of where the data sectors (or clusters) are located. Writing a new file or appending to a file will require first allocating sectors/clusters from the free list, assigning those sectors/clusters to the file (directory entry update?), and then writing the data out. Note that the disk allocation table(s) will typically be updated (i.e. written to disk) as soon as possible, maybe even before the file data, in order to maintain filesystem integrity. If you've ever noticed/heard a lot of disk seeks while creating a file, you can assume the heads were moving between the allocation table and the new file.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...