Filesystem config for 4k sector drive that reports 512 byte sectors

10,902

As I stated in my comments, as long as the actual filesystem on the partition has been set to use 4kb clusters and these clusters are aligned with with the drives 4kb sectors by ensuring that the sector start value of the partition is a multiple of 8 then the operating system itself will always write its data in 4kb clusters and thus always write to the drive in a 4kb sector block. This means you will never see the read-modify-write performance penalty.

Western Digital tells you how to ensure that your partitions are 4kb aligned at http://wdc.custhelp.com/app/answers/detail/a_id/5655

The Linux partition editor: parted, has an alignment option to ensure that Advanced Format drives are correctly configured from version 2.1:

-a alignment-type, --align alignment-type

valid alignment types are:

     none              Aligns to 512 byte sector boundaries. 

     cylinder         Align partitions to cylinders. 

     minimal          Use minimum alignment: 4KB on AF drives 

     optimal          Use optimum alignment: 1MB boundaries  

The default from parted 2.2 is to align to 1MB boundaries - optimal. Use minimal or optimal for Advanced Format drives. For example if your drive is sda:

parted -a optimal /dev/sda

will ensure that parted creates partitions on 1 MB boundaries.

Share:
10,902

Related videos on Youtube

Malvineous
Author by

Malvineous

Updated on September 18, 2022

Comments

  • Malvineous
    Malvineous almost 2 years

    Possible Duplicate:
    Western Digital Green drive from 512 byte sectors (jumpered) to 4k byte sectors (removal of jumper)

    I have just purchased two Western Digital WD20EARS disks and discovered that they incorrectly report their physical sector size to the OS as 512 bytes, even though the specs suggest they have 4k sectors.

    If I proceed to correctly align my partitions on this disk, do I need to perform any additional configuration to tell the filesystem that all write operations must be multiples of 4k, and only on 4k boundaries? Or can I just make sure my filesystem block size is a multiple of 4k, and all will be well? (As in, I won't encounter any read-modify-write operations done by the drive firmware.)

    I am running Linux and plan to use software RAID0 + ext4, but information for other OSes and filesystems would be interesting too.

    • Mokubai
      Mokubai about 13 years
      The question I linked seems to be almost exactly the same problem as you are having and it looks like you can specify the alignment of the partitions in fdisk, just ensure that you use a multiple of 8 sectors (4096 bytes) from the start of the drive as your partition start and it should be correctly aligned. This reporting of 512byte sectors is odd, confusing and apparently by design and for compatibility with older OSes that will never support 4k sectors. en.wikipedia.org/wiki/Advanced_Format#Advanced_Format_512e seems relevant too.
    • Malvineous
      Malvineous about 13 years
      The question you linked to is asking how to enable 4k sectors. My question is that since you can't enable 4k sectors on these drives, what filesystem settings should you use to work around the issue. Sadly aligning the partitions is not enough on its own, as this doesn't prevent a filesystem from using blocks <4k and causing read-modify-write.
  • Malvineous
    Malvineous about 13 years
    This does seem to be the case. For the record, mkfs.ext4 uses the -b option to set block size. 1024, 2048 and 4096 are all valid, so for small partitions you should make sure the block size is set to 4096, for large partitions this seems to be the default. (Also I think you mean the filesystem, not the partition, being set to use 4k clusters.)
  • Malvineous
    Malvineous about 13 years
    This is what I meant by "if I proceed to correctly align my partitions". I am mostly concerned about the filesystem trying to write in 512 byte blocks instead of 4k blocks, since the drive tells the OS this is best, by reporting the wrong physical sector size.
  • Mokubai
    Mokubai about 13 years
    Yes, as you say I do actually mean that the filesystem on the partition should be set to use 4kb clusters, I'll adjust my answer.
  • Mitch McMabers
    Mitch McMabers over 3 years
    @Malvineous Don't worry. Your SSD will cache the incoming data in its RAM or SLC cache before it permanently writes it to the NAND. So the SSD has plenty of time to collect all of the written data and arrange it into coherent sectors on disk.
  • Malvineous
    Malvineous over 3 years
    @MitchMcMabers This is what I want to avoid, because if the filesystem writes to a bunch of 512b sectors that aren't grouped together, the SSD will need to do read-modify-write cycles when it flushes them out to the NAND. By getting the filesystem to write 4kB sectors to begin with, you can avoid that and flush the cache much faster, increasing overall write performance when you are writing a large amount of data.