What is /dev/shm ????


It is an in-memory mounted file system (tmpfs) and is very fast, but non-persistent when Linux is rebooted.

In Oracle 11g, it is used to hold SGA memory by storing the SGA structures in files with the samegranule size. This granule size comes in 4M and 16M flavours, depending the MEMORY_MAX_TARGET smaller or larger than 1G.

When these MEMORY_TARGET and MEMORY_MAX_TARGET parameters are set, oracle will create as much as =(MEMORY_MAX_TARGET / granule size) files. For instance, when MEMORY_MAX_TARGET set to 512M, it will create 512/4 = 128 files (actually 129, the sneaky…).

The output of ‘ls -la /dev/shm’, will show you that not all the 128 files are taking the 4M of space:

shm> ls -la
total 151780
drwxrwxrwt  2 root   root        2620 Sep 10 11:13 .
drwxr-xr-x 12 root   root        3880 Sep 10 08:47 ..
-rw-rw----  1 oracle oinstall 4194304 Sep 10 14:17 ora_ianh_3768323_0
-rw-rw----  1 oracle oinstall 4194304 Sep 10 14:11 ora_ianh_3768323_1
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_10
-rw-rw----  1 oracle oinstall 4194304 Sep 10 14:17 ora_ianh_3768323_100
(...)
-rw-rw----  1 oracle oinstall 4194304 Sep 10 14:17 ora_ianh_3768323_127
-rw-rw----  1 oracle oinstall 4194304 Sep 10 11:13 ora_ianh_3768323_128
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_13
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_14
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_15
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_16
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_17
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_18
-rw-rw----  1 oracle oinstall       0 Sep 10 11:13 ora_ianh_3768323_19
-rw-rw----  1 oracle oinstall 4194304 Sep 10 11:13 ora_ianh_3768323_2

Now this is the trick Oracle is using. When you add up all the files that do take 4M of space, it will never take more space than MEMORY_TARGET. Therefor, Oracle does not allocate more memory than the MEMORY_TARGET and the sum of these files might even be smaller than MEMORY_TARGET.

When you look at the SGA memory size using ‘select ceil(sum(bytes)/(1024*1024*4)) from v$sgastat’, you will see it is near the sum of the files in /dev/shm (again, plus one…).

0 bytes in memory

When a file in /dev/shm is 0 bytes, it does not use memory. That memory is ‘free’ to other applications. Now this is Oracle’s implementation of releasing memory back to the Linux OS, by cleaning up one or more of these in-memory files (will it do a ‘cat /dev/null > ora_sid_number_id’ ?).

Funny thing is, PGA is not stored in shared memory, because this is private memory. MEMORY_MAX_TARGET (used for SGA and PGA) is ‘allocated’ in /dev/shm, but PGA is not stored in /dev/shm. This means, when memory for PGA is allocated (and/or pga_aggregate_target is set), not all files in /dev/shm will get used!

Increase /dev/shm

If you increase the MEMORY_MAX_TARGET above the available /dev/shm space (df -h), you will receive:

ORA-00845: MEMORY_TARGET not supported on this system

If you have enough memory on your Linux machine, but /dev/shm is mounted to small by default, one can increase this amount of memory by changing /etc/fstab for permanent changes. The default is half of your physical RAM without swap.

For temporary changes to at least start the database, execute the following (change the 1500m to your environment):

> umount tmpfs
> mount -t tmpfs shmfs -o size=1500m /dev/shm

152M boundary

When I was playing around with these settings, it seems 152M is an initial minimal memory target.

If you start oracle with a pfile setting of lower than 152M, it fails to start and you will get the following message:

ORA-00838: Specified value of MEMORY_TARGET is too small, needs to be at least 152M

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s