Parted reports "Warning: The resulting partition is not properly aligned for best performance."

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux (RHEL)
  • Parted

Issue

  • While creating a partition using parted utility, it reports that new partition is misaligned and this may result in very poor performance:

      (parted) mkpart primary 128 1048575
      Warning: You requested a partition from 128s to 1048575s.                 
      The closest location we can manage is 128s to 1048542s.
      Is this still acceptable to you?
      Yes/No? Yes                                                               
      Warning: The resulting partition is not properly aligned for best performance.          <-----
      Ignore/Cancel? C  
    
  • What is the reason for above warning messages? how to eliminate it?

  • How to align a partition? I have a lun from Dell storage system compellant. When I do fdisk /dev/mapper/mpatha, I am getting the following messages that concerns me.

      [root@localhost ~]# fdisk /dev/mapper/mpatha
    
      The device presents a logical sector size that is smaller than
      the physical sector size. Aligning to a physical sector (or optimal
      I/O) size boundary is recommended, or performance may be impacted.
    
      WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
               switch off the mode (command 'c') and change display units to
               sectors (command 'u').
    
      Command (m for help):
    
  • How can I make a partition so that this is aligned? This is raw Lun that will be used as oracle ASM voting lun.

Resolution

  • Choose a starting partition placement that satisfies the rules listed within the Root Cause section below.

    • Typically using percentages vs a specific sector or size location will allow parted to choose where to start the partition so it is properly aligned.
      • mkpart primary 0% 100% or mkpart primary 0% 320GB to create a single partition, or
      • mkpart primary 0% 50% and mkpart primary 50% 100% to create two equal sized partitions, etc.
    • Nominally a large percentage of disks will end up with a default allocation quanta/alignment calculation of 1MiB, so using MiB as the units in mkpart will, in most cases, result in an aligned partition. Since the first MiB of on disk space includes the legacy Master Boot Record (MBR) in sector 0 and the gpt primary table right after that (if gpt type), the first MiB on disk needs to be skipped and the partition started at 1MiB:
      • mkpart primary 1MiB 100% for example to create a single partition.
        • the 1MiB is used when rule 2b in Root Cause applies.
  • If using percentages or the 1MiB offset didn't work, then see Diagnostics section below for a script that can be run against a device. The script will apply the rules in Root Cause and output the alignment value parted will use to check partition alignment. Then use that alignment value for creating partitions that will pass the parted alignment check and prevent the warning message. The start of each partition just need to be evenly divisible by the alignment quanta value.

  • See How to create a partition with parted for additional details on creating partition with parted.

Root Cause

  • parted uses the following algorithm to determine optimal partition alignment when creating partitions. If none of the 2a, 2b or 2c rules are satisfied, then the warning message "The resulting partition is not properly aligned for best performance." will be displayed by parted utility.

         1.   Always use the reported alignment offset as offset
         2a.  If optimal io size is present in the topology info use that as grain
         2b.  If optimal io size is not present in topology info and alignment
              offset is 0 and minimum io size is a power of 2, use the
              default optimal alignment (grain 1MiB).
         2c.  If not 2a and 2b, use the minimum io size, or if that is not defined
              the physical sector size as grain (iow the minimum alignment).
    
  • For example, specifying mkpart primary 0 320MB is requesting the start of the partition be at 0MB or sector 0 (the default units within parted is in megabytes). Since the legacy Master Boot Record (MBR) occupies that sector, parted needs to find the next available sector nearest to sector 0. If the partition type is gpt, then the primary gpt information is located right after the MBR. Typically when specifying 0MB (sector 0) the first available space starts at sector 34 which will seldom pass the alignment check.

    • using percentages with partition creation, for example mkpart primary 0% 100%, allows parted the choice to define where 0% starts and will align the partition for you. Only when specifying a specific place, in sectors or MB or other specific sized unit, will parted attempt to locate the partition as close to that specified sector as possible.
    • using 1MiB alignment will work for a large percentage of drives as most do not specify an optimal io size but do specify a minimum io size. And the minimum io size is typically smaller than 1MiB.
  • Another example, when optimal io size is not present in topology information, alignment offset is 0 and minimum io size is a power of 2, the starting sector value for a partition needs to be specified in equal units of 2048 sectors (2048 sectors x 512 byte-per-sector = 1MiB). If the starting sector sector value is greater then 2048, then it must be evenly divisible by 2048. Again, sector 0 cannot be used because the first portion of the disk is where the partition table data resides so the lowest sector number that could be used and still satisfy the rules is 2048 (and multiples thereof after that).
    (parted) p
    Model: IET VIRTUAL-DISK (scsi)
    Disk /dev/sdf: 1048576s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start  End  Size  File system  Name  Flags
    
    (parted) unit s
    (parted) mkpart primary 128 1048576
    Error: The location 1048576 is outside of the device /dev/sdf.  
              
    (parted) mkpart primary 128 1048575
    Warning: You requested a partition from 128s to 1048575s.                 
    The closest location we can manage is 128s to 1048542s.
    Is this still acceptable to you?
    Yes/No? Yes                                                               
    Warning: The resulting partition is not properly aligned for best performance.
    Ignore/Cancel? C                                                          
    
    (parted) mkpart primary 2048 1048575                                  
    Warning: You requested a partition from 2048s to 1048575s.                
    The closest location we can manage is 2048s to 1048542s.
    Is this still acceptable to you?
    Yes/No? Yes
    
    (parted) p                                                                
    Model: IET VIRTUAL-DISK (scsi)
    Disk /dev/sdf: 1048576s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
     Number  Start  End       Size      File system  Name     Flags
      1      2048s  1048542s  1046495s               primary 
    

    OR the necessary alignment can be directly calculated by querying the appropriate sysfs entries for the device

  • Get the values as below:
    
    # cat /sys/block/sdb/queue/optimal_io_size
    # cat /sys/block/sdb/alignment_offset
    # cat /sys/block/sdb/queue/physical_block_size
    • Now to get the right correct sector add `optimal_io_size` to `alignment_offset` and then divide the result by `physical_block_size`.
    • For example:
      
      optimal_io_size = 1310720
      alignment_offset = 0
      physical_block_size = 512
      

      i.e 1310720+0/512 = 2560

      Now create the partition in parted:

      
      (parted)  mkpart primary 2560 100%    OR
      
      (parted)  mkpart primary 2560 1000G
      

Diagnostic Steps


The following information has been provided by Red Hat, but is outside the scope of the posted This content is not included.Service Level Agreements and This content is not included.support coverage as it involves software not provided by Red Hat.. The information is provided as-is and any configuration settings or installed applications made from the information in this article could make the Operating System unsupported by Red Hat Global Support Services. The intent of this article is to provide information to accomplish the system's needs. Use of the information in this article at your own risk.

Download and run This content is not included.shalign bash script, which applies the same alignment rules as the parted command and determines which of the above rules from the Root Cause section applies. It then outputs the recommended allocation quanta/alignment size that can be used such that created partitions will pass the parted alignment checks.

Examples:

$ ./shalign sdafj
 
Disk name: sdafj
--------------------------------------------------
 
Disk Type:   512 bytes/sector logical&physical
 
physical_sector_size 512   logical_sector_size  512    ratio: 1
optimal_io_size      0   minimum_io_size      512    ratio: 1     alignment_offset 0
 
[ ] 1. Always use the reported alignment offset as offset
[ ] 2a. If optimal io size is     present in the topology info use that as grain
[x] 2b. If optimal io size is not present in the topology info and alignment
        offset is 0 and minimum io size is a power of 2, use the default
        optimal alignment (grain 1MiB)
[ ] 2c. If not 2a and 2b and minimum io size is defined (>0), use the minimum io size as grain
[ ] 2d. If not 2a,2b, 2c use the physical sector size as grain (iow the minimum alignment). 
 
Alignment: 2048 sectors (suggested minimum:rule 2b.), 
           - minimum quanta/increments of 1048576 bytes (2048 sectors) should be 
             specficied for parted START partition value, that is each partition's  
             starting sector should be evenly divisible by 2048.
--------------------------------------------------
 
example: mkpart primary   2048s 100%   << 2048/2048 =  1 (START/quanta)
example: mkpart primary  32768s 100%  << 32768/2048 = 16
 

$ ./shalign sdf
 
Disk name: sdf
--------------------------------------------------
 
Disk Type:  4096 bytes/sector logical&physical (Advanced Format 4k Native - 4kN)
 
physical_sector_size 4096   logical_sector_size  4096    ratio: 1
optimal_io_size      0   minimum_io_size      4096    ratio: 1     alignment_offset 0
 
[ ] 1. Always use the reported alignment offset as offset
[ ] 2a. If optimal io size is     present in the topology info use that as grain
[x] 2b. If optimal io size is not present in the topology info and alignment
        offset is 0 and minimum io size is a power of 2, use the default
        optimal alignment (grain 1MiB)
[ ] 2c. If not 2a and 2b and minimum io size is defined (>0), use the minimum io size as grain
[ ] 2d. If not 2a,2b, 2c use the physical sector size as grain (iow the minimum alignment). 
 
Alignment: 256 sectors (suggested minimum:rule 2b.), 
           - minimum quanta/increments of 1048576 bytes (256 sectors) should be 
             specficied for parted START partition value, that is each partition's  
             starting sector should be evenly divisible by 256.
--------------------------------------------------
 
example: mkpart primary   256s 100%   << 256/256 =  1 (START/quanta)
example: mkpart primary  4096s 100%  << 4096/256 = 16
SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.