Disk IO and OS

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
dillonhao
Posts: 2
Joined: Wed Sep 12, 2007 1:37 am

Disk IO and OS

Post by dillonhao »

we know that the disk read or write couple of fix size (say 64k).
what if i got an io smaller than 64k for example 30k. what will the os do?
Does the os need to read the 64k from the disk first then write the update 64k to the disk?
help me.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Yes. If a process requests a read of less than the block size, the driver needs to read and cache the block, writing back the changed block when you write back to disk.

Cheers,
Adam
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

The blocks cached by the OS do not *need* to be the same size as the clusters on your disk. They can be smaller. But it makes things a bit more complicated if they are different sizes. My OS reads and writes in 32K chunks, for any cluster size larger than 32K.
dillonhao
Posts: 2
Joined: Wed Sep 12, 2007 1:37 am

Post by dillonhao »

AJ wrote:Yes. If a process requests a read of less than the block size, the driver needs to read and cache the block, writing back the changed block when you write back to disk.

Cheers,
Adam
Thank you
then what is the default io size for a disk. Can I change it?
for example i got an aplication io size 30k. i want to change the disk io size to 32k making it more efficient.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

I am not sure I understood your question correctly, but you might want to check out the C standard functions setvbuf() (in <stdio.h>).
Every good solution is obvious once you've found it.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

dillonhao wrote:
AJ wrote:Yes. If a process requests a read of less than the block size, the driver needs to read and cache the block, writing back the changed block when you write back to disk.

Cheers,
Adam
Thank you
then what is the default io size for a disk. Can I change it?
for example i got an aplication io size 30k. i want to change the disk io size to 32k making it more efficient.
Disks, such as hard drives and floppy drives, work in blocks of 512 bytes(normally, of course their are exceptions.) CDs work in blocks on 2048 blocks IIRC. The OS however could have larger block sizes of say 4096 bytes. Also some filesystems have bigger blocks such as 4096 or higher.
Post Reply