Why is SECTOR_SIZE = 512 inside kernel ?

Navin P navinp1912 at gmail.com
Mon Aug 17 07:05:59 EDT 2015


Hi,
 Why is SECTOR_SIZE 512 ?

http://lxr.free-electrons.com/source/include/linux/ide.h#L118

http://lxr.free-electrons.com/source/include/linux/device-mapper.h#L548

548 #define SECTOR_SHIFT 9

I was looking at disks with hw_sector_size . Most of them i looked at
had 512 bytes except for one which had 4096 (virtual disk). The one
with AF format ie has logical sector size as 512 and hw_sector_size as
512 . So it is fine for my calculation from /proc/diskstats.

But the one with 4096 logical and 4096 physical i multiply
hw_sector_size with the sectors read and written but that is wrong
since the kernel always defines sectors in terms of 512.


Is it going to change or is it  cast in stone ?


Here is an example. Again this is a VM virtual disk. vdc is the
subject in interest.


[root at hphuge-049 ~]# fdisk -l /dev/vdb /dev/vdc

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/vdc: 17.2 GB, 17179869184 bytes, 4194304 sectors
Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

[root at hphuge-049 ~]#


[root at hphuge-049 ~]# cat /sys/block/vdc/queue/hw_sector_size && cat
/sys/block/vdc/queue/logical_block_size  && cat
/sys/block/vdc/queue/physical_block_size
4096
4096
4096
[root at hphuge-049 ~]# cat /sys/block/vdb/queue/hw_sector_size && cat
/sys/block/vdb/queue/logical_block_size  && cat
/sys/block/vdb/queue/physical_block_size
512
512
4096
[root at hphuge-049 ~]#



Regards,
Navin



More information about the Kernelnewbies mailing list