Is the default 512 byte physical sector size appropriate for SSD disks under Linux?

19,081

Solution 1

In the old days, 512 byte sectors was the norm for disks. The system used to read/write sectors only one sector at a time, and that was the best that the old hard drives could do.

Now, with modern drives being so dense, and so fast, and so smart, reading/writing sectors only one sector at a time really slows down total throughput.

The trick was... how do you speed up total throughput, but still maintain compatibility with old/standard disk subsystems? You create a 4096 block size that are made up of eight 512 byte physical sectors. 4096 is now the minimum read/write transfer to/from the disk, but it's handed off in compatible 512 byte chucks to the OS.

This means that even if the system only needs one 512 byte sector of information, the drive reads eight 512 byte sectors to get it. If however, the system needs the next seven sectors, it's already read them, so no disk I/O needs to occur... hence a speed increase in total throughput.

Modern operating systems can fully take advantage of native 4K block sizes of modern drives.

Solution 2

Is the default 512 byte physical sector size appropriate for SSD disks under Linux?

Both of my disks are SSDs and AFAIK SSD disks require a sector size of 4K. Is this OK or am I missing something?

Old hardware and Operating Systems used 512 byte sectors, since 2011 (almost) all storage hardware has 4096 (or larger) byte sectors; but some hardware supports emulation of 512 byte sectors for legacy systems. There are exceptions, the Samsung 840 EVO SSD has blocks of size 2048 KB.

An Error Correcting Code (ECC) is calculated for each 512 byte chunk, and as you can imagine, ECC data also requires storage space. It goes without saying that one 4096 byte sector requires less ECC information than eight 512 byte chunks if the ECC algorithms remain unchanged. In the end, the total storage capacity of a hard drive increases as a result of less ECC data overhead.

Using 4K sectors makes sense from an architectural standpoint, as other key figures (like x86 memory pages and many file system clusters) also employ the 4 KB size. The Advanced Format allows for more robust ECC algorithms, which is important in light of ever-increasing capacities. Controllers employ additional techniques beyond error correction through an understanding of the NAND flash memory error characteristics and the workload behavior.

Advanced Format (AF) is any disk sector format used to store data on magnetic disks in hard disk drives (HDDs) that exceeds 512, 520, or 528 bytes per sector, such as the 4096, 4112, 4160, and 4224-byte (4 KB) sectors of an Advanced Format Drive (AFD). Larger sectors enable the integration of stronger error correction algorithms to maintain data integrity at higher storage densities.

For SCSI (SAS) disks the RAID block size is larger than a JBOD block size due to the SCSI T10 standardized data integrity fields along with logical bad block checking stored on each block with the data. The SAS RAID adapters support disk blocks based on 512 Bytes of data or 4K Bytes of data. The RAID block size for the 512 disks is 528 Bytes per sector and the RAID block size for the 4K disks is 4224 bytes per sector.

Because you are writing to memory and not a spinning disk physical sector size has less effect than ensuring that your partitions are aligned with the erase block size. Even so it's best to have up to date software and hardware, and use 4K sector size.

The larger sector size is recommended by Intel - "Gain Optimal Performance by Changes to SSD Physical Sector Size".

Solution 3

According to Wikipedia "Advanced Format (AF) is any disk sector format used to store data in disk drives that exceeds 512, 520, or 528 bytes per sector, such as the 4096-byte sectors of an Advanced Format Drive (AFD)." Advanced Format (AF) is a disk format that natively uses a sector size of 4,096 bytes instead of 512 bytes. To maintain compatibility with legacy systems, AF disks emulate a sector size of 512 bytes.

I got the same results as you got by running sudo fdisk -l /dev/sdX (where X is a letter) on two SSDs. I also got the same results as you got by running stat -f and smartctl on two SSDs. Both SSDs were automatically recognized by the OS when they were installed and required zero configuration, so it appears that the data you got is the default settings for block size and sector size.

Share:
19,081

Related videos on Youtube

FedKad
Author by

FedKad

Retired system administrator / programmer

Updated on September 18, 2022

Comments

  • FedKad
    FedKad over 1 year

    GSmartControl and any other command line tool (like fdisk, smartctl, cat /sys/block/sd*/queue/hw_sector_size, cat /sys/block/sd*/queue/physical_block_size) I had used report the same for both of my disks:

    Sector Size: 512 bytes logical/physical
    

    This is a default Ubuntu 18.10 (later upgraded to 19.04) installation. However, the stat -f command on both disks reports:

    Block size: 4096       Fundamental block size: 4096
    

    Both of my disks are SSDs and AFAIK SSD disks require a sector size of 4K. Is this OK or am I missing something? Does the information returned by stat (=4K) ensure that the OS will always send IOs to the disk in multiple of 4K and these blocks will never cross 4K boundaries (IO blocks will always be aligned to 4K)?

    Please note the following output (sdb2 is my root partition, sda is my /home disk):

    # fdisk -l /dev/sd?
    Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
    Disk model: SanDisk SDSSDH35
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/sdb: 238.5 GiB, 256060514304 bytes, 500118192 sectors
    Disk model: ADATA SU800NS38 
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: xxxx....
    
    Device       Start       End   Sectors  Size Type
    /dev/sdb1     2048   1050623   1048576  512M EFI System
    /dev/sdb2  1050624 500117503 499066880  238G Linux filesystem
    
    # df / /home
    Filesystem     1K-blocks      Used Available Use% Mounted on
    /dev/sdb2      244568380  17799136 214276188   8% /
    /dev/sda       479670976 129685112 325550152  29% /home
    
    • FedKad
      FedKad almost 5 years
      Yes. It does contain helpful information. But, I have not found an authoritative answer to the question: Does the information returned by stat (4K) ensure that the OS will always send IOs to the disk in multiple of 4K and these blocks will never cross 4K boundaries (IO blocks will always be aligned to 4K)?
    • Boris Hamanov
      Boris Hamanov almost 5 years
      I don't know what "stat (4K)" is. But most modern OS's know how to deal with native 4K I/O transfers. And no, it doesn't mean that blocks will never cross 4K boundries on the disk unless the partitions are aligned properly. Use fdisk -l to check for alignment issues. And apparently SSD's work slightly different, because of their physical construction, but I'm not an expert in that area.
  • karel
    karel almost 5 years
    @heynnema I can't do anything about "4096-byte sectors" because it's copied from Wikipedia, so I have to leave it the same as it is in Wikipedia.
  • MSalters
    MSalters almost 5 years
    @heynnema: The physical size is far bigger. SSD's are built from NAND flash memory, "which is physically partitioned in so-called "erase blocks". Those can be far larger, 4MB is definitely possible.
  • Peter Cordes
    Peter Cordes almost 5 years
    This is why it's important to align your partitions to a 4k boundary, otherwise every 4k block load/store actually touches two hardware sectors. (Filesystems inside partitions often use 4k blocks aligned to the start of the partition). Some formatting tools align the first partition by 1MiB, leaving a whole MiB unused except for the partition table. Modern drives do report their physical sector size as 4k, separate from their logical sector size which is still 512B.
  • sudodus
    sudodus almost 5 years
    @PeterCordes, Not only the boot sector and the partition table (in the first 512 bytes) are stored in the first Mibibyte. In an MSDOS partition table, grub puts additional code into the first Mibibyte for booting in BIOS mode. (In a GPT, grub needs a small partition with the bios_grub flag for that code to boot in BIOS mode).
  • Mitch McMabers
    Mitch McMabers about 3 years
    This answer is misleading! The stat -f command checks the FILESYSTEM cluster size. To see the PHYSICAL DISK sector size, you must instead run fdisk -l and it will say a line such as Sector size (logical/physical): 512 bytes / 4096 bytes