October 21, 2024
Chicago 12, Melborne City, USA
C#

minimum write size with O_DIRECT


I am writing a custom database engine for Linux 2.6.X kernels in C and I need to know what is the minimum write size of a write() system call for a file opened with O_DIRECT flag? In the docs it says that since linux 2.6 kernel versions you can use 512 byte block. But, what if my hard disk uses 8K blocks? Will it return EINVAL error on write in this case? I heard disks with 512 byte sector are becoming obsolete and the new disks use 8K sector, so I need to be sure my app doesn’t crash when the user tries it on such disk.
In case of it is possible to use 512 byte writes on a disk with 8k sectors, what happens when I write , say 2 blocks of 512 bytes , does the linux kernel reads the 8k sector from disk, replaces the 1k block I told it to write and then writes back to disk the 8k sector? This would be real slow!

Also, there is another question I have regarding this issue, does the minimum write size varies if I use raw device or a ext3 filesystem when opening file?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video