0

Let's say we have a block device (eg. Hard Drive) with 4096 bytes sector size and no 512 bytes emulation is available (The hard drive only understands units of 4096 bytes size).

Is is possible to format the device with a file system which has a logical block of 512 bytes ? How will the fs use the disk blocks ? I mean is it just going to use 512 bytes out of the 4096 bytes and the rest is wasted (one to one mapping between disk sectors and fs blocks) ? I assume if the file system knows about this issue he can make some kind of 512-bytes emulation by itself (read disk sector, modify a portion of 512 bytes in RAM then write back sector to disk) although there will be some overhead or redundant work at every write. I'm not really sure if that makes any sense ! Correct me please.

  • 1
    It's possible, but very inefficient. Just like the OS normally hides the physical block size of media from the user/applications by using buffers, an additional driver to perform 512-byte emulation could be layered over the basic disk driver. " I mean is it just going to use 512 bytes out of the 4096 bytes ..." -- No that's wasteful and foolish. Bottom line: For about the same amount effort it would be better to fix the filesystem to match sector size. – sawdust May 28 '18 at 18:37
0

It is possible to have such a configuration but it is not very common. All major filesystems (NTFS, FAT32, ext4, btrfs ...etc) use 4KB blocks that match with the most used memory page size configuration (4096 bytes pages). Disks prior to this decade used 512 physical sectors but all modern hard drives (and even SSDs) use 4KB physical sectors (Because of aerial density problems) but because there is a big legacy software stack that have 512 bytes assumption on block devices (Windows Vista, Windows XP, Linux Kernel prior to 2.6 and many other userspace utilities and embedded applications) hard drive manufacturers implement a so called 512-bytes emulation that exposed a 512b sector size to the software (Operating System) but uses a 4096b underlying sector size.

XFS can be configured to use 512 bytes blocks but if you are willing (I am i talking to myself !!?) to use this configuration on 4096b disks you have to make sure your partitions are well aligned, otherwise, you will suffer from performance degradation : if you write a 512b block, the disk will first fetch the whole 4096b sector into its internal DRAM, modify a portion of 512b of it then write it back to disk (Although, some caching techniques may reduce the impact of this issue).

So the final answer is : Yes it is possible but it may cause performance degradation and usually it isn't a common configuration seen IRL.

  • even if the disk is properly aligned, you're still suffering from performance degradation because a read-modify-write is always needed for a write smaller than block size – phuclv Jun 1 '18 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.