Changes

Jump to: navigation, search

Disk quota, df and stat weird behaviour

1,285 bytes added, 10:55, 22 November 2006
First part is revised, moving to <math> disgnation
The aim of this article is to understand where the numbers, that are shown by <code>stat</code>/<code>df</code> utils in [[VE, ]] come from.
Consider typical OpenVZ setup, where <code>ext2 <code> separate filesystem is mounted on <code>/vz</code>. So <code>ext2</code> is called ''underlying filesystem '' in this such situation is ext2.
Linux VFS design allows simfs (root file system type for VE) every filesystem to export to get userspace the following information concerning disk space from underlying (here and further I use subscript to specify paricular filesystemtype):
* '''ext2_total''' <math>total_{ext2}</math> - total amount of disk space that potentially can be acquired(e.g. HDD capacity)* '''ext2_free''' <math>free_{ext2}</math> - amount of disk space that is still free* '''ext2_avail''' <math>avail_{ext2}</math> - amount of disk space that is still available for non-root users
Note, that not all free blocks can be used by non-root users. By default ext2 sets 5% barrier: 5 percent of total some amount of disk space is reserved for super userroot. For example on <code>ext2</code> filesystem only root can use last free 5 percent (by default) of disk space. This is the difference between '''ext2_avail''' <math>avail_{ext2}</math> and '''ext2_free'''<math>free_{ext2}</math>. NoteAlso mark, that the following inequality is always true:: '''ext2_avail ≤ ext2_free <math>avail_{ext2} \le free_{ext2}</math> (1)'''
Absolutely the same set of information about disk space Inside [[VE]] special filesystem type is used: <code>simfs should export </code>. This filesystem allows to user-space if it is asked about it (e.gisolate particular [[VE]] from other [[VE]]s. Hence, when <code>statdf</code> or <code>dfstat</code> command were utils are invokedthey get information from <code>simfs</code>, which exports to them the following values (by analogy with <code>ext2</code>):
* '''simfs_total'''<math>total_{simfs}</math>* '''simfs_free'''<math>free_{simfs}</math>* '''simfs_avail'''<math>avail_{simfs}</math>
In OpenVZ environment This article is in fact devoted to how simfs filesystem calculates the values above.  To produce any calculations input data are required. What are input data for <code>simfs</code>? Except already discussed information from underlying filesystem (<math>total_{ext2}</math>, <math>total_{ext2}</math>, <math>total_{ext2}</math>) one more element comes into force in OpenVZ environment. It is pertinent in the situation weOpenVZ ''re considering: OpenVZ per-VE disk quotaquotas''. First level The values that provide this element are: * <math>quota_{used}</math> - the number of blocks currently used by [[VE]]* <math>quota_{barrier}</math> - the number of blocks this VE potentially can obtain. OpenVZ disk quota counts the number of blocks currently used by VE ('''q_used''') and prevents this number to be greater than the limit/barrier set ('''q_barrier''').
<!-- TODO: Uncoment after adding examples.
* '''Quota is off for VE'''
: If quota is off for VE (DISK_QUOTA=no), the total amount of space, that VE potentially can acquire, equals amount of total space on partition. Certainly some space can be used by other VEs, but potentially VE can have all the space on device. Number of free blocks for VE equals number of free blocks on partition. Note, that it implies that VE root user, can fill all the space, including the space, that is reserved for root user of HN. This is why, you shouldn't reside VEs private areas on root filesystem of your HN. Amount of available disk space for VE also equals the number of available blocks for underlying filsystem. Thus, we have the following relationships:
:: '''simfs_total <math>total_{simfs}</math> = ext2_total''' <math>total_{ext2}</math>:: '''simfs_free <math>free_{simfs}</math> = ext2_free''' <math>free_{ext2}</math>:: '''simfs_avail <math>avail_{simfs} = ext2_avail'''avail_{ext2}</math>: Rather valueable valuable disadvantage of swithching OpenVZ quota off is that you will not be able to get information about how much disk space is used by VE (without doing possibly long term <code>du</code> command). I mean, that :: '''df_usage <math>df_{usage} = simfs_total total_{simfs} - simfs_free free_{simfs} = ext2_total total_{ext2} - ext2_free'''free_{ext2}</math>
: thus in VE you obtain information about disk usage of partition, but not disk usage of VE. By the way, just this number is displayed by <code>df</code> tool in "Usage" column.
* '''Quota is on for VE and there is enough space on partition'''
: If quota is on, amount of disk space that VE potentially can acquire should be equal quota barrier:
:: '''simfs_total <math>total_{simfs} = q_barrier'''quota_{barrier}</math>
: Amount of free space in this case should logically be the following:
:: '''simfs_free <math>free_{simfs} = q_barrier quota_{barrier} - q_used'''quota_{used}</math>
: However here is a pitfall. Suppose that amount of free disk space actually on underlying filesystem is less than it is estimated from quota using the formule above, i.e.:
:: '''q_barrier <math>quota_{barrier} - q_used quota_{used} > free_{ext2}</math> ext2_free'''
: Then, definitely, amount of free disk space reported by simfs should be other! This situation will be considered in the next point and in this point we assume that there is enough space on partition, i.e
:: '''q_barrier <math>quota_{barrier} - q_used ≤ ext2_free quota_{used} \le free_{ext2}</math> (2)'''
: As concerns amount of disk space available for non-root users, if there is enough disk space:
:: '''q_barrier <math>quota_{barrier} - q_used ≤ ext2_avail'''quota_{used} \le avail_{ext2}</math>: and this is right in current point due to assumption (2) and the inequality (1), then amount of disk space available for non-root users in [[VE ]] equals free space estimated from quota::: '''simfs_free <math>free_{simfs} = q_barrier quota_{barrier} - q_used'''quota_{used}</math>
* '''Quota is on for VE and there is NOT enough space on partition'''
: This is the most interesting and difficult to explain case. Nevertheless I tried to do it. So, our assumption is that:
:: '''q_barrier <math>quota_{barrier} - q_used quota_{used} > free_{ext2}</math> ext2_free''': What should be reported as free space in such case? Of course, '''ext2_free'''<math>free_{ext2}</math>! This is the actual amount of space that can be used by VE. Hence::: '''simfs_free <math>free_{simfs} = ext2_free'''free_{ext2}</math>
: And now consider the following situation. There is two VEs. One of VEs writes nothing to disk. Second VE writes to disc some information. Administrator of VE #1 looks at <code>df</code> output. He observes the "Usage" column. What does he see?
:: '''df_usage <math>df_{usage} = simfs_total total_{simfs} - simfs_free free_{simfs} = simfs_total total_simfs - ext2_free free_{ext2}</math> (3)''': '''ext2_free''' <math>free_{ext2}</math> decreases because [[VE ]] #2 writes to disc, consequently '''<math>df_usage''' </math> increases! "What the hell is going on?!" - thinks the administrator? - "Nobody writes on the disk in my [[VE]], but the usage increases!" To avoid such situation the following approach is used in OpenVZ disk quota: decrease '''<math>simfs_total''' </math> so, that '''<math>df_usage''' </math> remains the same, i.e.::: '''simfs_total <math>total_{simfs} = ext2_total total_{ext2} - (q_barrier quota_{barrier} - q_usagequota_{usage}) </math> (4)'''
: Substituting (4) in (3) obtain:
:: '''df_usage <math>df_{usage} = (ext2_total total_{ext2} - ext2_freefree_{ext2}) - (q_barrier quota_{barrier} - q_usagequota_{usage}) = const'''</math>
: In this case, administrator of VE #1 sees that total amount of space decreases, but usage however is constant and it is good.
: The same reasoning as with '''simfs_free''' <math>free_simfs</math> suits for calculating '''simfs_avail'''<math>avail_simfs</math>. Two cases are possible. If:: '''q_barrier <math>quota_{barrier} - q_used ≤ ext2_avail'''quota_{used} \le avail_{ext2}</math>
: then
:: '''simfs_avail <math>avail_{simfs} = ext2_free'''free_{ext2}</math>
: and if
:: '''q_barrier <math>quota_{barrier} - q_used quota_{used} > avail_{ext2}</math> ext2_avail'''
: then
:: '''simfs_avail <math>avail_{simfs} = q_barrier quota_{barrier} - q_used'''quota_{used}</math>
The table below summarize all possible cases.
'''
-----
TODO: add info about inconsisten quota problems
-----
TODO: Add Roma's images
TODO: Add examples with stat/df
 
TODO: Change to math: <math> avail_{ext2} <= free_{ext2} (1) </math> an alike
172
edits

Navigation menu