blockdev report different blocksize if mounted
I have a proliant running Red Hat 7, with two data disk with raid 1 (hardware raid).
I created the file sytem using this command:
mkfs.xfs /dev/sdb
Default block size for xfs is 4096.
So
blockdev --report
dispay this:
RO RA SSZ BSZ 1er sect. Taille Périphérique
rw 8192 512 4096 0 600093712384 /dev/sdb
That's ok.
If I mount the drive then
blockdev --report
dispay this:
RO RA SSZ BSZ 1er sect. Taille Périphérique
rw 8192 512 512 0 600093712384 /dev/sdb
So block size seems to be 512 instead of 4096 after mounting.
I can't figure out why. I have a database tu put on this drive and I need a 4096 block size. Any idea ? Is the block size 512 or 4096 ?
When there is a partition mounted, the block size will be set to reflect the partition's block size. Otherwise it will display the default block size of the actual device.
What is most confusing in your case is that you don't have partitions on it, which would have made the situation more apparent.
Short answer: at mount time XFS sets the block device's "block size" to the "sector size" shown in mkfs.xfs or xfs_info output. Changing the format's sector size at mkfs time will yield a different block device "block size" when mounted.
Longer answer: XFS sets the block device's block size at mount time to its internal "sector" size which is the smallest granularity of IO that it will perform. It does this today via a set_blocksize()
call within xfs_setsize_buftarg()
.
In the original question above, the filesystem has a block size of 4k but a sector size of 512 bytes; this means that metadata updates may still be done in 512 byte IOs, and hence XFS sets the block device "block size" to 512.
If you use the -s sectsize
parameter to mkfs.xfs, this will change the smallest unit of IO to the size you specify, and XFS will also set the block device "block size" to this same value at mount time.
Note: The sector size you select should not be any larger than the maximum atomic IO the drive can perform, because XFS expects a sector-sized write to either be completely written or fail, with no partial writes in between. In general, mkfs.xfs will query the device for the appropriate sector size, and choose the right defaults.