File IO Flashcards
How disk stores data?
Disks are divided into logical blocks called sector and track .
Data is written into blocks denoting sector And track
Usually block is 512 bytes
Standard io( buffered io ) vs direct io
Buffered io
- when data is written it uses kernel space cache to write the data as intermediate. Data will not be written directly into disk .
- Kernel uses write back to write the contents
Each kernel page is of usually 4096 bytes
- When kernel page cache is full , eviction policy is used to evict the least recently data to disk .
Direct IO :
It skips the kernel page and writes directly to disk . Uses O-DIRECT flag. Write will take more time . Some applications uses direct IO .
PostgreSQL uses direct io to write write-ahead-log to make sure there are no failures
Block alignment
In direct io