Tanel Poder’s blog: Core IT for Geeks and Pros

August 21, 2007

Oracle 11g internals part 1: Automatic Memory Management

Filed under: Oracle 11g — Tanel Poder @ 2:15 am

This is my attempt for getting cheap popularity out of recent Oracle 11g release. This is not going to be another Oracle 11g new features list, I’ll be just posting any of my research findings here, in a semi-organized way.

The first post is is about Automatic Memory Management. AMM manages all SGA + PGA memory together, allowing it to shift memory from SGA to PGAs and vice versa. You only need to set a MEMORY_TARGET (and if you like, MEMORY_MAX_TARGET parameter).

You can read rest of the general details from documentation, I will talk about how this feature has been implemented on OSD / OS level (or at least how it looks to be implemented).

When I heard about MEMORY_TARGET , then the first question that came into my mind was that how can Oracle shift shared SGA memory to private PGA memory on Unix? This would mean somehow deallocating space from existing SGA shared memory segment and releasing it for PGA use. To my knowledge the traditional SysV SHM interface is not that flexible that it could downsize and release memory from a single shared memory segment. So I started checking out how Oracle had implemented this.

One option of course is not to implement it at all – just do not use the extra space in the extra SGA area and it will be soon paged out if there’s memory pressure (as long as you don’t keep your SGA pages locked – which can’t be used together with MEMORY_TARGET anyway). However should this “unneeded” memory be used again, all would have to be loaded back from swap area.

I started by checking what are the shared memory IDs for my instance:

$ sysresv

IPC Resources for ORACLE_SID "LIN11G" :
Shared Memory:
ID              KEY
1900546         0x00000000
1933315         0xa62e3ad4
Semaphores:
ID              KEY
884736          0x6687edcc
Oracle Instance alive for sid "LIN11G"

Ok, let’s look for corresponding SysV SHM segments:

$ ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 1900546    oracle    660        4096       0
0xa62e3ad4 1933315    oracle    660        4096       0

The segments are there, but wait a minute, they are only 4kB in size each! If there are no large shared memory segments used, where does Oracle keep its SGA?

The immediate next check I did was looking into the mapped memory for an Oracle instance process – as the SGA should be definitely mapped there!

$ pmap `pgrep -f lgwr`
29861:   ora_lgwr_LIN11G
00110000      4K rwx--    [ anon ]
00111000     32K r-x--  /apps/oracle/product/11.1.0.6/lib/libclsra11.so
00119000      4K rwx--  /apps/oracle/product/11.1.0.6/lib/libclsra11.so
...
...
49000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_0
4a000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_1
4b000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_2
4c000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_3
4d000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_4
...
...
88000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_63
89000000  16384K rwxs-  /dev/shm/ora_LIN11G_3997699_64
bfc1f000     88K rwx--    [ stack ]
 total  1225048K

pmap output reveals that Oracle 11g likes to use /dev/shm for shared memory implementation instead. There are multiple 16MB “files” mapped to Oracle server processes address space.
This is the Linux’es POSIX-oriented SHM implementation, where everything, including shared memory segments, is a file.

Thanks to allocating SGA in many smaller chunks, Oracle is easily able to release some parts of SGA memory back to OS and server processes are allowed to increase their aggregate PGA size up to the amount of memory released.
(Btw, if your MEMORY_MAX_TARGET parameter is larger than 1024 MB then Oracle’s memory granule size is 16MB on Linux, otherwise it’s 4MB).

Note that the PGA memory is still completely independent memory, allocated just by mmap’ing /dev/zero, it doesn’t really have anything to do with shared memory segments ( unless you’re using some hidden parameters on Solaris, but that’s another story ).
PGA_AGGREGATE_TARGET itself is just a recommended number, leaving over from MEMORY_TARGET – SGA_TARGET (if it’s set). And Oracle uses that number to decide how big PGAs it will “recommend” for sessions that are using WORKAREA_SIZE_POLICY=AUTO.

So how does Oracle actually release the SGA memory when it’s downsized?

Compare these outputs:

/dev/shm before starting instance:

$ ls -l /dev/shm/
total 0

Obviously there’s nothing reported as no /dev/shm segments are in use.

/dev/shm after starting instance with fairly large SGA (note that some output is cut for brewity).
See how some of the memory “chunks” are zero in size. These chunks are the ones which have been chosen as victims for destruction (or for not-even-creation) when space was needed or PGA areas. If you look into pmap output for any server processes you will still see this memory mapped into the address space, but it’s not just used because Oracle knows this memory is really freed.

$ ls -l /dev/shm
total 818840
-rw-r----- 1 oracle dba 16777216 Aug 20 23:29 ora_LIN11G_1900546_0
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_0
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_1
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_10
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_11
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_12
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_13
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_14
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_15
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_16
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_17
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_18
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_19
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_2
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_20
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_21
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_22
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_23
-rw-r----- 1 oracle dba 16777216 Aug 20 23:37 ora_LIN11G_1933315_24
...

Another listing, taken after issuing “alter system set pga_aggregate_target=600M”
You can see from below that most of the /dev/shm files which were 16MB in previous listing, have also been zeroed out.

$ ls -l /dev/shm
total 408740
-rw-r----- 1 oracle dba 16777216 Aug 20 23:29 ora_LIN11G_1900546_0
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_0
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_1
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_10
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_11
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_12
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_13
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_14
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_15
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_16
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_17
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_18
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_19
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_2
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_20
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_21
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_22
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_23
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_24
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_25
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_26
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_27
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_28
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_29
-rw-r----- 1 oracle dba        0 Aug 20 23:29 ora_LIN11G_1933315_3
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_30
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_31
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_32
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_33
-rw-r----- 1 oracle dba        0 Aug 20 23:46 ora_LIN11G_1933315_34
-rw-r----- 1 oracle dba 16777216 Aug 20 23:29 ora_LIN11G_1933315_35
-rw-r----- 1 oracle dba 16777216 Aug 20 23:29 ora_LIN11G_1933315_36
-rw-r----- 1 oracle dba 16777216 Aug 20 23:29 ora_LIN11G_1933315_37
-rw-r----- 1 oracle dba 16777216 Aug 20 23:29 ora_LIN11G_1933315_38
...

So, in Linux (tested on OEL5) Oracle 11g is using a new mechanism for managing shared memory. Well this mechanism itself isn’t that new, but it’s unconventional considering the long history of Unix SysV SHM segment use for Oracle SGAs.


Does this all matter? Yes
Why does it matter? There are few administrative differences compared to the conventional implementation.First of all, ipcs -m doesn’t show the full size of these segments anymore. You need to list /dev/shm contents for that.Also, pmap always reports that the memory is mapped (because it is) even though it doesn not have physical backing storage on tmpfs on /dev/shm device.

One more important note is that if you have not configured your tmpfs size on /dev/shm properly, then Oracle fails to allocate new POSIX-style shared memory and will not allow you to use MEMORY_TARGET parameters (startup without those parameters will however succeed).

The error message you likely get looks like that:

SQL> ORA-00845: MEMORY_TARGET not supported on this system

And is accompanied by following entry in alert.log:

Sat Aug 18 12:37:31 2007
Starting ORACLE instance (normal)
WARNING: You are trying to use the MEMORY_TARGET feature. This feature requires the /dev/shm file system to be mounted for at least 847249408 bytes. /dev/shm is either not mounted or is mounted with available space less than this size. Please fix this so that MEMORY_TARGET can work as expected. Current available is 0 and used is 0 bytes.
memory_target needs larger /dev/shm

So you need to configure large enough tmpfs on /dev/shm device to fit all memory up to MEMORY_MAX_TARGET.

The configuration works roughly like that:
(run as root):

# umount tmpfs
# mount -t tmpfs shmfs -o size=1300m /dev/shm
# df -k /dev/shm
Filesystem           1K-blocks      Used Available Use% Mounted on
shmfs                  1331200         0   1331200   0% /dev/shm

This one allows /dev/shm to grow roughly up to 1300MB, allowing you to use MEMORY_MAX_TARGET (or MEMORY_TARGET) set to 1300MB. The Linux-specific Oracle 11g documentation has more details how to configure this.


Note that after resetting various parameters I played with I realized that finally Oracle has implemented the human-friendly way for resetting parameters in SPFILE:

Sys@Lin11g> alter system reset pga_aggregate_target;

System altered.

Sys@Lin11g> alter system reset sga_target;

System altered.

…no scope=spfile sid=’*’ is needed. This resets the parameter in spfile only, the values in memory persist.

Bookmark and Share

28 Comments »

  1. [...] Published August 21st, 2007 oracle Our OakTable Wunderkind, Tanel Poder, has started blogging about Oracle Database 11g Automatic Memory Management. Do pay his site a visit! In fact, his site is worth a regular [...]

    Pingback by Oracle Database 11g Automatic Memory Management « Kevin Closson’s Oracle Blog: Platform, Storage & Clustering Topics Related to Oracle Databases — August 22, 2007 @ 2:05 am

  2. Tanel thank you for this blog and your sharings, this post is one of the best posts I have experienced all through the Oracle blogs!

    And I hope you have more time for blogging in the future.

    Best regards.

    Comment by H.Tonguç Yılmaz — August 22, 2007 @ 5:10 am

  3. Wow, thanks a lot! Thats the best feedback I’ve got during my short blogging career :)

    Comment by tanelp — August 22, 2007 @ 6:33 pm

  4. [...] всички други процеси. За съжаление, както отбелязва Tanel Poder, управлението на споделената памет не е толкова [...]

    Pingback by блога на явор » Blog Archive » /dev/shm for Oracle 11g DBAs — August 22, 2007 @ 6:34 pm

  5. Hi Tanel,

    Thanks for the post.

    I assume this will work the same way on Linux x86-64?

    How, if at all, does this change other memory related configurations, such as hugepages?

    Thanks,

    -Mark

    Comment by Mark Bobak — August 22, 2007 @ 7:57 pm

  6. Tanel,

    Oracle on Linux has always used /dev/shm to implement the Indirect Data Buffers feature…just FYI

    Comment by kevinclosson — August 22, 2007 @ 11:59 pm

  7. Thanks Kevin. Yep I vaguely remember that from the one time I used that feature.

    Mark, regarding the hugepages, looks like they can’t be used (at least as per documentation):

    http://download.oracle.com/docs/cd/B28359_01/server.111/b32009/appc_linux.htm

    “MEMORY_TARGET and MEMORY_MAX_TARGET cannot be used when LOCK_SGA is enabled. MEMORY_TARGET and MEMORY_MAX_TARGET also cannot be used in conjunction with huge pages on Linux.”

    Comment by tanelp — August 23, 2007 @ 12:11 am

  8. oops, the way I wrote that insinuated that Oracle uses Indirect Data Buffers to implement 11g AMM…I didn’t mean that…what I meant was Oracle has exercised this style of shared memory before…albeit for an entirely different reason.

    Comment by kevinclosson — August 23, 2007 @ 12:28 am

  9. Excellent Post !!!!!!

    Comment by Robert Freeman — August 24, 2007 @ 12:49 am

  10. [...] Oracle11g Automatic Memory Management and Linux Hugepages Support Published August 23rd, 2007 oracle hugepages , Oracle 11g , Oracle performance , oracle I spent the majority of my time in the Oracle Database 11g Beta program testing storage-related aspects of the new release. To be honest, I didn’t even take a short peek at the new Automatic Memory Management feature. As I pointed out the other day, Tanel Poder has started blogging about the feature. [...]

    Pingback by Oracle11g Automatic Memory Management and Linux Hugepages Support « Kevin Closson’s Oracle Blog: Platform, Storage & Clustering Topics Related to Oracle Databases — August 24, 2007 @ 5:47 am

  11. Tanel
    As usual, I enjoyed your blog about this new feature. I am sure this knowledge will come handy.
    Thanks..

    Comment by Riyaj Shamsudeen — August 24, 2007 @ 10:53 pm

  12. [...] topic in Oracle blogsphere. Tanel Poder started an 11g internals series with an article about automatic memory management, getting into the implementation in Linux. Kevin Closson continued looking into this topic with a [...]

    Pingback by Log Buffer #59: a Carnival of the Vanities for DBAs « I’m just a simple DBA on a complex production system — August 25, 2007 @ 12:02 am

  13. Thanks alot … excellente

    Comment by MAQ. — October 4, 2007 @ 7:09 am

  14. Way to go Tanel! Excellent Post.
    Your unix level knowledge is really excellent.

    Comment by Porus — December 19, 2007 @ 1:16 pm

  15. [...] http://blog.tanelpoder.com/2007/08/21/oracle-11g-internals-part-1-automatic-memory-management/ (No Ratings Yet)  Loading [...]

    Pingback by ernie.cz » Blog Archive » ORA-00845 — February 6, 2008 @ 11:58 pm

  16. You, again made my day

    Cheers Tanel.

    Comment by coskan — March 4, 2008 @ 9:51 pm

  17. Hi Tanel, you made my day too!!!
    It worked on Ubuntu 7.10.

    # umount devshm
    # mount -t tmpfs devshm -o size=1300m /dev/shm

    But I am wondering: how do I configure this tmpfs permanently in order to be set on next boot ?

    Comment by Josir — June 10, 2008 @ 5:12 am

  18. I got it Tanel – I have to add it in /etc/fstab like any other mount…
    Shame on me…
    Thanks again!

    Josir Gomes
    Rio de Janeiro – Brasil

    Comment by Josir — June 10, 2008 @ 6:09 am

  19. :-)

    Comment by tanelp — June 10, 2008 @ 11:12 pm

  20. question for the experts.. We have Oracle 11g RAC with 6 nodes running Redhat 2.6.9-67.ELsmp x86_64

    After increasing /dev/shm to 14G, we continue to get the ORA-00845 errors…

    I noticed that a df -kh generates:
    # df -k /dev/shm
    Filesystem 1K-blocks Used Available Use% Mounted on
    shmfs 14G 0 14G 0% /dev/shm

    It appears that none of this memory is being used.. is this accurate? assuming that Oracle is not using it yet because of the failed startup?

    Is there something we are missing?

    thanks,
    Dave

    Comment by dave — November 7, 2008 @ 7:19 am

  21. Thanks for the great in depth explanation. I benifited alot from it. I have a question, I set my memory max target to 28G and memory target 24G, my system has by default max_sga=4G. Will the system ignore the max sga? or it will not give the sga_target more the 4GB? shall I set it to 0?
    my physical memory 32G and oracle 11g is the only app on the system
    Thanks again and keep up the good work

    Comment by sam — November 20, 2008 @ 8:09 pm

  22. @Dave – What’s your memory_target and memory_max_target value? These need to be smaller (or equal) to your /dev/shm size. If Oracle can’t put all SGA/PGA memory in there it won’t use it.

    @Sam – You should unset sga_target and pga_aggregate_target if you plan to use MEMORY_TARGET (unless you want to set some minimum values for sga_target/pga_aggregate_target)

    Comment by Tanel Poder — November 25, 2008 @ 4:37 am

  23. Thanks Tanel for your great stuff.

    When I enabled memory_target value in Oracle11g with RHEL5.1,my server consuming more than 85% of swap usgae.

    SGA and PGA value is 0 and memory_target is 4G.

    Do you have any fix to minimize swap usage.

    Comment by Senthil — February 9, 2009 @ 6:59 am

  24. Is there a part 2?

    Comment by Kirk Brocas — February 25, 2009 @ 7:40 pm

  25. Hi Kirk, no official part-2 yet, here are the posts which I’ve tagged as related to 11g:

    http://blog.tanelpoder.com/category/oracle-11g/

    Comment by Tanel Poder — February 26, 2009 @ 12:59 am

  26. Most users probably want the shm size adjustment to persist across reboots. So, here’s the /etc/fstab entry corresponding to Tanel’s mount command above:

    none /dev/shm tmpfs size=1300M 0 0

    (My very healthy OpenSUSE 11.1 system has no /dev/shm fs set up at all by default). Run “mount /dev/shm” to mount it on-demand.

    Comment by Blaine Simpson — March 4, 2009 @ 10:36 am

  27. Hello there,
    Thank you for all the info.
    I am very new to oracle 11g install on linux, tried to recover a db (created using dbca) using rman, ran into error,when tried to do startup mount, got the error described here, I am trying to implement the solution given by you,
    tried to umount /dev/shm- got the error device is too busy,
    does this mean I have to shut down the db and then try to unmount?
    Can you please help? Many thanks in anticipation.

    Comment by Uma — March 20, 2009 @ 8:48 pm

  28. thanks, a note to say:
    add this entry to /etc/fstab to mount shm every boot tmpfs :
    /dev/shm tmpfs size=2500m 0 0

    Comment by Hind — May 24, 2009 @ 2:51 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress