Linux sector write size?

Don´t be shy, Linux is fun! =)
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Linux sector write size?

Post by ayu »

As far as I know, the default size of a sector in ext4/3 is 512 byte.
So that when the system writes to disc it writes per 512 bytes (thus writing to a file each 512 byte in a C program makes it faster).

But my question is, can the sector size vary?
Or is it common that it does?
And can I detect the sector size somehow if I want to hand that to my application?
"The best place to hide a tree, is in a forest"

User avatar
lilrofl
Siliconoclast
Siliconoclast
Posts: 1363
Joined: 28 Jan 2009, 17:00
15
Location: California, USA
Contact:

Re: Linux sector write size?

Post by lilrofl »

The sector size was traditionally 512 bytes, but with new Advanced Sector Formatting can be as large as 4kb. I know the Western Digital Green uses the new formatting, so the transition has begun already.

I'm not sure how to detect the sector size, but it has to be possible as programs to partition hard drives will need to be aware of the technology, and support the legacy 512 sector size.

From what I understand ASF is not real common yet, but that will be short lived.
knuffeltjes voor mijn knuffel
[img]http://i911.photobucket.com/albums/ac320/stuphsack/Sig.jpg[/img]

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: Linux sector write size?

Post by bad_brain »

yep, actually there are 2 types of sector sizes, the one set by the filesystem (in ext4 it's 4kb actually), and the one set by the physical drive (512 byte or 4kb). in ext you can theoretically set any sector size you want to, that's one of the new features compared to ext3, but afaik that's still experimental.
if you have a spare HDD where it wouldn't matter if you break it you can play around with hdparm:
http://sourceforge.net/projects/hdparm/" onclick="window.open(this.href);return false;
it should also be in the repositories of most distros, make sure to read the manual first.
warning: you can REALLY kill the HDD physically with it!

you can also use hdparm to retrieve the sector size (and all sort of other info) by using the -l switch.

with a little luck your Linux system contains those 2 files that contain the sector sizes:
/sys/block/sdX/queue/physical_block_size
/sys/block/sdX/queue/logical_block_size
but it depends on the HDDs, WD ones for example don't support the needed functions so you don't find the files then.

:wink:
Image

Post Reply