Disclaimer

Thursday 15 July 2021

REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB in ASM

 How ASM calculates the values of disk groups REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB?


Simply put, the REQUIRED_MIRROR_FREE_MB value in view V$ASM_DISKGROUP represents how much free space is required to re-satisfy the definition of redundancy if an ASM disk or ASM disk group fails. The value of USABLE_FILE_MB represents how much remaining space is available after redundancy is satisfied.


The question is: How does ASM calculate these values?


The answer to this question is to create some disk groups with different configurations and then look at REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB in view V$ASM_DISKGROUP. To find out, we just need some disks.


ASM> select label,os_mb from v$asm_disk
  2  where label like 'SAN%' order by label;

LABEL                                OS_MB
------------------------------- ----------
SAN01                                  255
SAN02                                  255
SAN03                                  255
SAN04                                  255
SAN05                                  255
SAN06                                  255

REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB in external redundancy disk groups

Let's start by creating an external redundant disk group. Here we use the six disks listed above, each of which is 255 MB in size:


ASM> create diskgroup demo external redundancy
  2  disk 'ORCL:san01'
  3  disk 'ORCL:san02'
  4  disk 'ORCL:san03'
  5  disk 'ORCL:san04'
  6  disk 'ORCL:san05'
  7  disk 'ORCL:san06'
  8  attribute 'compatible.asm' = '11.2.0.0.0';

Diskgroup created.


We query several columns in view V$ASM_DISKGROUP for information about disk groups:


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     EXTERN       1530    1468        0   1468


The above output shows that the total size of the disk group is 1530MB (TOTAL_MB), of which 1468MB (FREE_MB) is free space. Since this is an external redundant disk group, all free space can be used to store files. The value of the USABLE_FILE_MB column also shows this, and the value of REQUIRED_MIRROR_FREE_MB is 0.

Note: The missing 62MB is used to store ASM metadata.

REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB in normal redundancy disk groups

Next, we create a normal redundant disk group, which consists of six disks, each of which is a separate failure group.


ASM> create diskgroup demo normal redundancy
  2  failgroup FG1 disk
  3  'ORCL:san01'
  4  failgroup FG2 disk
  5  'ORCL:san02'
  6  failgroup FG3 disk
  7  'ORCL:san03'
  8  failgroup FG4 disk
  9  'ORCL:san04'
 10  failgroup FG5 disk
 11  'ORCL:san05'
 12  failgroup FG6 disk
 13  'ORCL:san06'
 14  attribute 'compatible.asm' = '11.2.0.0.0';

Diskgroup created.


ASM uses failgroup to provide data mirroring and redundancy in a disk group. While data is stored in a failure group, it stores the same copy of data from another failure group to ensure data security. In a normal redundant disk group, failure of a failure group does not affect the availability of the entire disk group. ASM can also make the data available according to the mirror data. The disk group meets the requirement of normal redundancy again, but in order to achieve this, it needs enough space for the disk group, so how big a failure group actually is is very important.


ASM> select failgroup,sum(total_mb) from v$asm_disk
  2  where label like 'SAN%' group by failgroup order by failgroup;

FAILGROUP                      SUM(TOTAL_MB)
------------------------------ -------------
FG1                                      255
FG2                                      255
FG3                                      255
FG4                                      255
FG5                                      255
FG6                                      255


The output above shows that the total size of each failure group is 255MB. Let's see how it affects the requirements of the remaining space and how it affects the available file space.


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     NORMAL       1530    1365      255    555


The above output shows that in order to be able to re-satisfy the disk group redundancy requirements after a failure group of the disk group fails, 255MB of residual space (REQUIRED_MIRROR_FREE_MB) is required. 255 is the size of a failgroup in a disk group. If the size of the failgroup in a disk group varies, ASM automatically selects the failure group with the largest space.


The output above also shows that we can use 555MB of space to store files. This value is calculated according to the following formula:


ASM> select trunc((free_mb - REQUIRED\_MIRROR\_FREE\_MB) / 2) as useable
  2  from v$asm_diskgroup where name='DEMO';

   USEABLE
----------
       555


The above formula translates as follows: the total available space is equal to the total remaining space minus REQUIRED_MIRROR_FREE_MB and then divided by the redundancy of the disk group, where the normal redundancy is divided by 2. The meaning of REQUIRED_MIRROR_FREE_MB has been mentioned above: the space needed to be able to meet the redundancy requirement of the disk group after a failure group of the disk group fails.


Since the free_mb value in the formula of available space is dynamic, such as adding files or resizing files will affect the remaining space of the disk group, the available space of the disk group is also dynamic, which can be explained by a simple example.


SQL> create tablespace foo datafile '+DEMO' size 200m;

Tablespace created.

ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     NORMAL       1530     939      255    342


Because we added a new 200 MB data file to the disk group, the available space of the disk group was reduced from 555 MB to 342 MB.


SQL> alter tablespace foo add datafile '+DEMO' size 200m;

Tablespace altered.

ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     NORMAL       1530     534      255    139


After adding another data file, as expected, the available space is further reduced, which is slightly larger than the actual size of the new file. Now there is only 139 MB of available space left. What if we add another 200 MB data file?


SQL> alter tablespace foo add datafile '+DEMO' size 200m;

Tablespace altered.


Although ASM shows only 139 MB of available space, we did succeed in creating a 200 MB data file, so it is important to emphasize that ASM does not force the reserve of space indicated by REQUIRED_MIRROR_FREE_MB.


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     NORMAL       1530     129      255    -63


The value of USABLE_FILE_MB has changed to a negative number, which means that if we encounter a failure ASM may not have enough space to meet the redundancy requirements, so it is very important to monitor the value of USABLE_FILE_MB. If the value of USABLE_FILE_MB of a disk group changes to a negative number, you should increase the space of the disk group or release some space. Now let's delete this table space and see:


SQL> drop tablespace foo;

Tablespace dropped.


Now let's create another normal redundant disk group. This time we only create three failure groups, each of which contains two disks (the previously created disk group contains six failure groups, each of which is a failure group):


ASM> create diskgroup demo normal redundancy
  2  failgroup FG1 disk
  3  'ORCL:san01',
  4  'ORCL:san02'
  5  failgroup FG2 disk
  6  'ORCL:san03',
  7  'ORCL:san04'
  8  failgroup FG3 disk
  9  'ORCL:san05',
 10  'ORCL:san06'
 11  attribute 'compatible.asm' = '11.2.0.0.0';

Diskgroup created.


After the disk group is successfully created, let's look at the size of failgroup:


ASM> select failgroup,sum(total_mb) from v$asm_disk
  2  where label like 'SAN%' group by failgroup order by failgroup;

FAILGROUP                      SUM(TOTAL_MB)
------------------------------ -------------
FG1                                      510
FG2                                      510
FG3                                      510


The three failgroup s are all 510MB in size. Let's look at the relevant columns in the following view V$ASM_DISKGROUP:


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     NORMAL       1530    1365      510    427


As expected, the value of REQUIRED_MIRROR_FREE_MB is 510, equal to the size of the largest failure group in the disk group, and the value of USABLE_FILE_MB is 427. As mentioned earlier, its value is calculated according to the following formula:


ASM> select trunc((free_mb - REQUIRED\_MIRROR\_FREE\_MB) / 2) as useable
  2  from v$asm_diskgroup where name='DEMO';

   USEABLE
----------
       427


Next, we continue to create a normal redundant disk group, this time with only two failgroup s, with three disks in each failure group:


ASM> create diskgroup demo normal redundancy
  2  failgroup FG1 disk
  3  'ORCL:san01',
  4  'ORCL:san02',
  5  'ORCL:san03'
  6  failgroup FG2 disk
  7  'ORCL:san04',
  8  'ORCL:san05',
  9  'ORCL:san06'
 10  attribute 'compatible.asm' = '11.2.0.0.0';

Diskgroup created.


Again, let's look at the size of each failure group in the disk group:


ASM> select failgroup,sum(total_mb) from v$asm_disk
  2  where label like 'SAN%' group by failgroup order by failgroup;

FAILGROUP                      SUM(TOTAL_MB)
------------------------------ -------------
FG1                                      765
FG2                                      765


Both failgroup s are equal to 765MB in size. Similarly, look at the values of the relevant fields in view v$asm_diskgroup:


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     NORMAL       1530    1416      255    580


The result is somewhat unexpected. The value of REQUIRED_MIRROR_FREE_MB is only 255MB, not 765MB (failure group size). Obviously, ASM only gives one disk size at a time as the value of REQUIRED_MIRROR_FREE_MB, not the whole group size.

Where is the truth? As mentioned at the beginning of this article, ASM will store mirror data in different failure groups. A normal redundant disk group requires at least two failure groups, and a high redundant disk group requires at least three failure groups. If two failure groups have normal redundant disk groups, and one failure group fails, how can the disk group meet the redundancy requirements again? No! In this case, ASM only gives the size of a disk as the value of REQUIRED_MIRROR_FREE_MB.

Similarly, we can calculate the value of USABLE_FILE_MB according to the formula:


ASM> select trunc((free_mb - REQUIRED\_MIRROR\_FREE\_MB) / 2) as useable
  2  from v$asm_diskgroup where name='DEMO';

   USEABLE
----------
       580

REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB in high redundancy disk groups

We've discussed external and normal redundant disk groups. Let's look at high redundant disk groups. First, we need to create a high redundancy disk group. The disk in the disk group is still the six disks we used above. Each disk is a separate failure group:


ASM> create diskgroup demo high redundancy
  2  failgroup FG1 disk
  3  'ORCL:san01'
  4  failgroup FG2 disk
  5  'ORCL:san02'
  6  failgroup FG3 disk
  7  'ORCL:san03'
  8  failgroup FG4 disk
  9  'ORCL:san04'
 10  failgroup FG5 disk
 11  'ORCL:san05'
 12  failgroup FG6 disk
 13  'ORCL:san06'
 14  attribute 'compatible.asm' = '11.2.0.0.0';

Diskgroup created.

ASM> select failgroup,sum(total_mb) from v$asm_disk
  2  where label like 'SAN%' group by failgroup order by failgroup;

FAILGROUP                      SUM(TOTAL_MB)
------------------------------ -------------
FG1                                      255
FG2                                      255
FG3                                      255
FG4                                      255
FG5                                      255
FG6                                      255


As expected, the size of all failgroup s is 255MB. Are the calculation methods for the values of REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB the same under normal redundancy and high redundancy? Let's take a look:


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     HIGH         1530    1365      510    285


The value of REQUIRED_MIRROR_FREE_MB is 510MB, which is equal to the size of two failure groups (if the size of failure groups is different, the two largest failure groups are chosen), because a high redundant disk group needs to be able to tolerate the loss of two failure groups without affecting the availability of data.

The value of USABLE_FILE_MB is 285, which is calculated according to the following formula:


ASM> select trunc((free_mb - REQUIRED\_MIRROR\_FREE\_MB) / 3) as useable
  2  from v$asm_diskgroup where name='DEMO';

   USEABLE
----------
       285


Finally, we create another high redundant disk group, a total of three disk groups, one failure group for each two disks:


ASM> create diskgroup demo high redundancy
  2  failgroup FG1 disk
  3  'ORCL:san01',
  4  'ORCL:san02'
  5  failgroup FG2 disk
  6  'ORCL:san03',
  7  'ORCL:san04'
  8  failgroup FG3 disk
  9  'ORCL:san05',
 10  'ORCL:san06'
 11  attribute 'compatible.asm' = '11.2.0.0.0';

Diskgroup created.

ASM> select failgroup,sum(total_mb) from v$asm_disk
  2  where label like 'SAN%' group by failgroup order by failgroup;

FAILGROUP                      SUM(TOTAL_MB)
------------------------------ -------------
FG1                                      510
FG2                                      510
FG3                                      510


The above output should not need me to explain too much, everything is in line with our expectations, if you have fully understood all the above, then the output of the following query content should not surprise you:


ASM> select name, state, type, total_mb, free_mb, REQUIRED\_MIRROR\_FREE\_MB req_free, USABLE\_FILE\_MB use_mb
  2  from v$asm_diskgroup where name = 'DEMO';

NAME       STATE       TYPE     TOTAL_MB FREE_MB REQ_FREE USE_MB
---------- ----------- ------ ---------- ------- -------- ------
DEMO       MOUNTED     HIGH         1530    1365      510    285


REQUIRED_MIRROR_FREE_MB has a value of 510MB. It is actually the size of two disks, not a failgroup. The reason is that, like the normal redundant disk group with two failgroups, our disk group is high redundant three failgroups. If one or two failgroups are lost, ASM can not meet the redundancy requirement again.

The following formula is used to calculate the value of USABLE_FILE_MB:


ASM> select trunc((free_mb - REQUIRED\_MIRROR\_FREE\_MB) / 3) as useable
  2  from v$asm_diskgroup where name='DEMO';

   USEABLE
----------
       285



In summary

The value of REQUIRED_MIRROR_FREE_MB represents the space required by ASM to re-satisfy redundancy defined by the disk group, which depends on the redundancy of the disk group and the number of failgroup s.

The value of REQUIRED_MIRROR_FREE_MB is equal to the size of a failure group for a normal redundant disk group with three failure groups. If there are only two failure groups for a normal redundant disk group, the value of REQUIRED_MIRROR_FREE_MB will be equal to the size of a disk rather than a failure group.

The value of REQUIRED_MIRROR_FREE_MB is equal to the size of two failure groups for a high redundant disk group with four failure groups. For example, if the high redundant disk group has only three failure groups, then the value of REQUIRED_MIRROR_FREE_MB will be the size of two disks.

The value of USABLE_FILE_MB represents the total space available to store data. Its value depends on the size of the disk group, the redundancy of the disk group and the value of REQUIRED_MIRROR_FREE_MB. The calculation method for the value of USABLE_FILE_MB is as follows:


USABLE\_FILE\_MB = (FREE_MB – REQUIRED\_MIRROR\_FREE\_MB) / [2|3]

Translator's Note: The following figure represents a redundant disk group with three failure groups. Each failure group: F represents free space and U represents used space.

So it's easy to deduce from the above assumption: (F+U) = the size of a failure group and then 3F+3U = the size of the total disk group.


So what is the remaining available space for the current disk group?

Very good calculation = total disk group size - 3U

Then, how much free space is left after a failure group is destroyed?

Here we continue to divide this step into two steps to make it easier to understand: (total space - 3U) - F, which is the value of the remaining space after a failure group is destroyed. This remaining space has not considered the space needed for RB on the failure group.

But in order to meet the requirement of redundancy, we still need to give the U part of the space to RB, that is:

(Total Space - 3U) - F-U, let's do a conversion that is (Total Space - 3U) - (F +U)=Free - a failure group size, and finally divide it by 2 or 3 according to redundancy. Is that clear?




No comments:

Post a Comment

100 Oracle DBA Interview Questions and Answers

  Here are 100 tricky interview questions tailored for a Senior Oracle DBA role. These questions span a wide range of topics, including perf...