Subject: parted optimal alignment fails minimal alignment check

From: George Fedorov <[email-masked]>
Date: Sat, 3 Aug 2019 12:26:56 +0000

Hi,

I was directed here by the page at https://www.gnu.org/software/parted/bugs.shtml ; is there any bugreport tracker where one can file a bug instead ?

Anyway, here's the problem ( manifested in parted 3.2 coming with Ubuntu 18.04 and checked vs. a manual build of the sources from http://ftp.gnu.org/gnu/parted/parted-3.2.tar.xz  ):

=== parted version ===

# parted --version
parted (GNU parted) 3.2
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.

=== print unit s print unit chs print ===

# parted /dev/sdi print unit s print unit chs print
Model: WDC WD30 EZRZ-00Z5HB0 (scsi)
Disk /dev/sdi: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

Model: WDC WD30 EZRZ-00Z5HB0 (scsi)
Disk /dev/sdi: 5860533168s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

Model: WDC WD30 EZRZ-00Z5HB0 (scsi)
Disk /dev/sdi: 364801,80,62
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 364801,255,63.  Each cylinder is 8225kB.
Partition Table: gpt
Disk Flags:

Number  Start  End  File system  Name  Flags

=== the problem ===

# parted /dev/sdi
GNU Parted 3.2
Using /dev/sdi
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart test1 0% 1T
(parted) unit B
(parted) print
Model: WDC WD30 EZRZ-00Z5HB0 (scsi)
Disk /dev/sdi: 3000592982016B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start      End             Size           File system  Name   Flags
 1      33553920B  1000007477759B  999973923840B               test1

(parted) align-check optimal 1
1 aligned
(parted) align-check minimal 1
1 not aligned
(parted)

=====

First of all, start sector value looks insanely big for "0%" ; second, one would imagine that passing an optimal check would imply passing a minimal check.

If one tries to start at e.g. 1 MiB, then of course the optimal check will not pass :

=====

# parted /dev/sdi
GNU Parted 3.2
Using /dev/sdi
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: WDC WD30 EZRZ-00Z5HB0 (scsi)
Disk /dev/sdi: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart test1 ext2 2048s 1T
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) unit B
(parted) print
Model: WDC WD30 EZRZ-00Z5HB0 (scsi)
Disk /dev/sdi: 3000592982016B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start     End             Size           File system  Name   Flags
 1      1048576B  1000000000511B  999998951936B  ext2         test1

(parted) align-check optimal 1
1 not aligned
(parted) align-check minimal 1
1 aligned

=====

As it turns out, the root of all evil comes from here :

=====

# cat /sys/block/sdi/queue/optimal_io_size
33553920
=====

So parted is not to blame, but the system. But from the user's point of view, it is quite hard to figure this out. And certainly the user deserves to know the actual values that parted considers to be of best performance -- I mean, pa->offset and pa->grain_size from parted.c::print_partition_alignment() shall probably be exposed in some way -- at least when it comes to a warning like the one above.

Kind regards
Georgy Fedorov
Senior Systems Specialist
Melbourne School of Engineering
The University of Melbourne, Victoria 3010, Australia
email: [email-masked]<mailto:[email-masked]>
http://www.eng.unimelb.edu.au

<https://owa.unimelb.edu.au/owa/redir.aspx?SURL=zZ66u8zSk7WjNEV9pSzLYdWdXh0cvHwxj-uz4bP1rcBS-JFIAfjRCGgAdAB0AHAAOgAvAC8AdwB3AHcALgBlAG4AZwAuAHUAbgBpAG0AZQBsAGIALgBlAGQAdQAuAGEAdQAvAA..&URL=http%3a%2f%2fwww.eng.unimelb.edu.au%2f>