2

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
  • 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
    Commented May 28, 2018 at 18:37

5 Answers 5

1

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.

1
  • 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
    Commented Jun 1, 2018 at 3:05
1

This is simply not true.

If you have block size: 512B configured, 4096B native

Its not wasting space its the opposite. Its not using just 512 out of 4096 that would be a waste. Its saving space at the cost of "Minor performance hit"

I have that on a RAID 1 ZFS so did a buddy. He reformatted it so block size 4096 matched Native. He did not notice any WOW its so much faster but he lost around 90 GB of space because now the smaller files are taking up the full 4096 while before a small file would only use 512.

On a Raid 1 pool and a 1 GB lan connection I max out the gigabit on transfer speed and don't notice any degradation in performance (even though there is some)

Bottom line the space hit is much more noticeable than any speed hit.

Im keeping mine

block size: 512B configured, 4096B native

0

Short answer: Yes, it's possible.

Longer answer: It's complicated! On most classic magnetic disks: It's possible but uncommon and will hurt performance.

On magnetic drives that use shm and on flash media is completely normal. Because "Block size" is a much more complicated thing there! Logical block size does not always align with the minimal write block (page) size and the delete block (block) size is also a lot bigger in most cases!

0

Old question but, the OP seems to have misused the term logical block to refer to filesystem block (aka cluster), which has led people who try to answer to think of the actual "logical block" when writing their answers.

What's worse is that what the OP refers to as "physical sector" is essentially the actual "logical block":

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).

I don't think you can have filesystem block smaller than logical block, at least not when the developer of the filesystem driver wants to keep it sane. It would imply that each logical block will either be used by multiple filesystem blocks (and the byte offsets will either need to be recorded or calculated all the time), or only a fraction of each logical block will be actually used (with the trailing capacity "abandoned").

I admit that I haven't really dug deep, but IMO no one has common sense would bother designing or implementing anything like that. (It's not like there's any historical need we need to cater for like the case of AF 512e.)

0

From a Windows file system perspective I'd be inclined to say the answer is no.

Cluster / 'blocksize' is defined as a number of sectors per cluster in the boot record of the volume. AFAIK minimum value is 1 (or zero in exFAT, but this means 1 sector/cluster).

One could argue the drive itself may present/expose a 512 KB sector size even though it works with 4096 byte sectors internally.

And while this is true and so clusters could be smaller than the actual physical sector size, you can not configure Windows file systems with a cluster size smaller than reported sector size.

Sector size aside: At the drive firmware level we can make the file system 'believe' a lot of things, even the physical drive size to be larger than it actually is as scammers discovered and utilize to produce fake memory cards.

As others argued, it would make very little sense, a physical sector is smallest addressable unit, so to read a emulated/fake 512 byte sector from a 4096 physical sector disk, the entire 4096 sector will be read anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .