lvmteam / lvm2

Mirror of upstream LVM2 repository
https://gitlab.com/lvmteam/lvm2
GNU General Public License v2.0
128 stars 72 forks source link

Why gigabytes are in 1024 base? #111

Closed MeinhardZhou closed 1 year ago

MeinhardZhou commented 1 year ago

It is written in the man page of lvcreate:

       -L|--size LogicalVolumeSize[b|B|s|S|k|K|m|M|g|G|t|T|p|P|e|E]
              Gives the size to allocate for the new logical volume.  A size suffix of B for bytes, S for sectors as 512  bytes,  K
              for kilobytes, M for megabytes, G for gigabytes, T for terabytes, P for petabytes or E for exabytes is optional.
              Default unit is megabytes.

while gigabytes is in 1000 base in IEC 80000-13, will lvm consider supporting gigabytes(1000) and gibibytes(1024) at the same time?

zkabelac commented 1 year ago

Hi, you are actually reading/working with several years old version of the lvcreate man page. Here comes the upstream description with more explanation:

-L|--size Size[m|UNIT] Specifies the size of the new LV. The --size and --extents options are alternate methods of specifying size. The total number of physical extents used will be greater when redundant data is needed for RAID levels.

Size[UNIT] Size is an input number that accepts an optional unit. Input units are always treated as base two val‐ ues, regardless of capitalization, e.g. 'k' and 'K' both refer to 1024. The default input unit is spec‐ ified by letter, followed by |UNIT. UNIT represents other possible input units: b|B is bytes, s|S is sectors of 512 bytes, k|K is KiB, m|M is MiB, g|G is GiB, t|T is TiB, p|P is PiB, e|E is EiB. (This should not be confused with the output control --units, where capital letters mean multiple of 1000.)

Thus lvm2 support 'SI' units on the output (i.e. lvs..., lvdisplay....).

Problem with the 'input' size specification is - that historically all the size value inputs very always given in 1024 unit based - so there is no way to 'reintroduce' 1000 unit without breaking backward compatibilty with some older written software.

When the user want to round by 1000 - he can always go with 'byte' units i.e. -l 1000000b

We would likely need to introduce new size option i.e. --sisize option to be able to give user option to use SI 1000x based units for input and so far there were basically zero requirements from any user to add this kind of support.

MeinhardZhou commented 1 year ago

Got it.

In some storage software, uppercase is sometimes regarded as 1000 base, and lowercase is regarded as 1024 units, so I am confused when specifying the size : )

I will now consider creating lv by specifying size with 'byte'.

Thanks for your explaining.

zkabelac commented 1 year ago

Yep - we know that some newer apps tried to use this differentiation on the input size - however historically the upper/lower case didn't matter in case of 'lvm2' commands - we would break existing working scripts. So long as there is no large group of users requiring to use 10-based units - we will likely keep simple traditional power-of-2 units here :)