Do hard disk drives turn on 512e (512byte emulation of 4k sectors) as-needed depending on host controller?

13

1

I have a 4 TB hard disk that has 4k physical sector size (Advanced Format) and I attached it to two SATA host controllers (one internal and one in a USB enclosure). On the (older, about 2010) it comes up as 512B logical sector size, but reports its physical sectors are 4096 bytes. In the recent USB enclosure, it is reported as having 4096B logical and physical size:

# internal host controller
sd 4:0:0:0: [sdd] 7814037168 512-byte logical blocks: (4.00 TB/3.63 TiB)
sd 4:0:0:0: [sdd] 4096-byte physical blocks

# USB enclosure
sd 18:0:0:0: [sdd] 976754646 4096-byte logical blocks: (4.00 TB/3.63 TiB)

The "internal" controller shows behavior I had previously seen, which is usually called "512e" where the drive's firmware emulates 512 sector LBA addressing even though it does not physically write sectors that way. Operating systems (and admins) can ensure that partitions are aligned such that (small) write commands can be grouped so that the disk can overwrite full sectors instead of falling back to writing to part of a physical sector, where it needs to read the remainder of content first.

However, seeing "4k native" behavior on a drive (USB enclosure) was new to me and my initial thought was the enclosure is emulating 4096B addressing on top of the drive's emulated 512B emulation.

The only occurrences of this that I could find with a Web Search where USB storage facilities that registered with 4k logical sectors. I presume they emulate 4k over 512e so allow for MBR partition tables so that large drives can be used on legacy/embeeded devices (Smart TVs and what not) that only support MBR+FAT32 usb mass storage.

After contacting the manufacturer, they claimed the drive is actually operating in non-emulated (native) 4k mode, the USB SATA controller is also doing no emulation at all. This would require the drive's firmware to detect whether the host controller supports (desires?) addressing sector sizes of 4KB. I could not find anything about this in the public documentation of SATA standards. So I ask:

  • Has anyone seen "4096-byte logical blocks" on their SATA controller?
  • Do drives actually support enabling/disabling emulation on demand? If so,
    • How does this determination work?
    • Can you override it on the drive via a flag?
    • Can you override it on the host controller via a driver/flag?

Nathan Summers

Posted 2014-02-21T11:02:52.203

Reputation: 131

Does the logo on the drive say "AF" or "4Kn"? – Jamie Hanrahan – 2014-08-26T05:53:35.477

This question is really in need of a high-quality, modern answer. – Hashim – 2018-04-23T22:04:45.250

Answers

2

I've seen a few 4Kn SATA drives working in the hard drive validation industry, but I wasn't aware they were shipping any to customers, due to the limited hardware and software support for them and lack of customer demand.

There are two competing mappings for physical vs. logical sector sizes. The Long Logical Sector feature allows a device to have logical sectors longer than 512B (e.g. 4Kn), and the Long Physical Sector feature allows a device to have multiple logical sectors per physical sector (e.g. 512e), though they are not necessarily mutually exclusive. If the manufacturer is claiming the drive is 4Kn, the older controller may providing an emulation layer, like read-modify-write, for older applications and hardware, as older systems simply don't support the 4Kn format.

The sg_sat_identify command from the sg3_utils package would probably give you the information you need (check words 106-108 for Physical sector size/logical sector size information).

It doesn't look like SATA drives can support emulation on-demand, per se, but if the drive is indeed using 512e, instead of 4Kn, performance optimization is maximized by the driver (or possibly USB SATA controller) limiting reads/writes to 4K boundaries, e.g. having the transfer start on an LBA where the lower 3 bits are 0, and end on an LBA where the lower 3 bits are 1:

start_lba & 0x3 == 0
end_lba & 0x3 == 1

So, basically, there's no "switch" that can tell the drive to start or stop emulation. From an end-user perspective, your best bet is probably to make sure your drives are using the best file system for whichever mapping your drive uses and to make sure it's aligned correctly. The following site gives a pretty good breakdown of the common file systems and their stats on performance vs. block alignment on different file systems: http://www.ibm.com/developerworks/library/l-linux-on-4kb-sector-disks/index.html

Adam Naber

Posted 2014-02-21T11:02:52.203

Reputation: 103