Sunday, December 5, 2010

Configuring SHMMAX and SHMALL for Oracle in Linux

Home | Profile 

SHMMAX and SHMALL are two key shared memory parameters that directly impact’s the way by which Oracle creates an SGA. Shared memory is nothing but part of Unix IPC System (Inter Process Communication) maintained by kernel where multiple processes share a single chunk of memory to communicate with each other.

While trying to create an SGA during a database startup, Oracle chooses from one of the 3 memory management models a) one-segment or b) contiguous-multi segment or c) non-contiguous multi segment. Adoption of any of these models is dependent on the size of SGA and values defined for the shared memory parameters in the linux kernel, most importantly SHMMAX.

So what are these parameters - SHMMAX and SHMALL?

SHMMAX is the maximum size of a single shared memory segment set in “bytes”.

silicon:~ #  cat /proc/sys/kernel/shmmax


SHMALL is the total size of Shared Memory Segments System wide set in “pages”.

silicon:~ #  cat /proc/sys/kernel/shmall


The key thing to note here is the value of SHMMAX is set in "bytes" but the value of SHMMALL is set in "pages".

What’s the optimal value for SHMALL?

As SHMALL is the total size of Shard Memory Segments System wide, it should always be less than the Physical Memory on the System and should be greater than sum of SGA’s of all the oracle databases on the server. Once this value (sum of SGA’s) hit the limit, i.e. the value of shmall, then any attempt to start a new database (or even an existing database with a resized SGA) will result in an “out of memory” error (below). This is because there won’t be any more shared memory segments that Linux can allocate for SGA.

ORA-27102: out of memory

Linux-x86_64 Error: 28: No space left on device.

So above can happen for two reasons. Either the value of shmall is not set to an optimal value or you have reached the threshold on this server.

Setting the value for SHMALL to optimal is straight forward. All you want to know is how much “Physical Memory” (excluding Cache/Swap) you have on the system and how much of it should be set aside for Linux Kernel and to be dedicated to Oracle Databases.

For e.g. Let say the Physical Memory of a system is 6GB, out of which you want to set aside 1GB for Linux Kernel for OS Operations and dedicate the rest of 5GB to Oracle Databases. Then here’s how you will get the value for SHMALL.

Convert this 5GB to bytes and divide by page size. Remember SHMALL should be set in “pages” not “bytes”.

So here goes the calculation.

Determine Page Size first, can be done in two ways. In my case it’s 4096 and that’s the recommended and default in most cases which you can keep the same. 

silicon:~ # getconf PAGE_SIZE



silicon:~ # cat /proc/sys/kernel/shmmni

Convert 5GB into bytes and divide by page size, I used the linux calc to do the math.

silicon:~ # echo "( 5 * 1024 * 1024 * 1024 ) / 4096 " | bc -l


Reset shmall and load it dynamically into kernel

silicon:~ # echo "1310720" > /proc/sys/kernel/shmall
silicon:~ # sysctl –p

Verify if the value has been taken into effect.

silicon:~ # sysctl -a | grep shmall
kernel.shmall = 1310720

Another way to look this up is

silicon:~ # ipcs -lm

------ Shared Memory Limits --------
max number of segments = 4096                          /* SHMMNI  */
max seg size (kbytes) = 524288                  /* SHMMAX  */
max total shared memory (kbytes) = 5242880      /* SHMALL  */
min seg size (bytes) = 1

To keep the value effective after every reboot, add the following line to /etc/sysctl.conf

echo “kernel.shmall = 1310720” >> /etc/sysctl.conf

Also verify if sysctl.conf is enabled or will be read during boot.

silicon:~ # chkconfig boot.sysctl
boot.sysctl  on

If returns “off”, means it’s disabled. Turn it on by running

silicon:~ # chkconfig boot.sysctl on
boot.sysctl  on

What’s the optimal value for SHMMAX?

Oracle makes use of one of the 3 memory management models to create the SGA during database startup and it does this in following sequence. First Oracle attempts to use the one-segment model and if this fails, it proceeds with the next one which's the contiguous multi-segment model and if that fails too, it goes with the last option which is the non-contiguous multi-segment model.

So during startup it looks for shmmax parameter and compares it with the initialization parameter *.sga_target. If shmmax > *.sga_target, then oracle goes with one-segment model approach where the entire SGA is created within a single shared memory segment.

But the above attempt (one-segment) fails if SGA size otherwise *.sga_target  > shmmax, then Oracle proceeds with the 2nd option – contiguous multi-segment model. Contiguous allocations, as the name indicates are a set of shared memory segments which are contiguous within the memory and if it can find such a set of segments then entire SGA is created to fit in within this set. 

But if cannot find a set of contiguous allocations then last of the 3 option’s is chosen – non-contiguous multi-segment allocation and in this Oracle has to grab the free memory segments fragmented between used spaces.

So let’s say if you know the max size of SGA of any database on the server stays below 1GB, you can set shmmax to 1 GB. But say if you have SGA sizes for different databases spread between 512MB to 2GB, then set shmmax to 2Gigs and so on.

Like SHMALL, SHMMAX can be defined by one of these methods..

Dynamically reset and reload it to the kernel..

silicon:~ #  echo "536870912" >  /proc/sys/kernel/shmmax

silicon:~ #  sysctl –p           -- Dynamically reload the parameters.

Or use sysctl to reload and reset ..

silicon:~ #  sysctl -w kernel.shmmax=536870912

To permanently set so it’s effective in reboots…

silicon:~ #  echo "kernel.shmmax=536870912" >>  /etc/systctl.conf

Install doc for 11g recommends the value of shmmax to be set to "4GB – 1byte" or half the size of physical memory whichever is lower. I believe “4GB – 1byte” is related to the limitation on the 32 bit (x86) systems where the virtual address space for a user process can only be little less than 4GB. As there’s no such limitation for 64bit (x86_64) bit systems, you can define SGA’s larger than 4 Gig’s. But idea here is to let Oracle use the efficient one-segment model and for this shmmax should stay higher than SGA size of any individual database on the system.

Hope this helps. Regards, Raj


  1. Perfect article! thank you very much for sharing your knowledge!

  2. Great! Thanks a lot for this wonderful article.

  3. Hi - Thanks for the article.

    Then, on a 16GB Linux x86_64 system, what is the max MEMORY_TARGET that can be set? Also, I noticed only if /dev/shm value is increased, the MEMORY_TARGET param can be increased. What would be an ideal setting for a 16 GB machine?


  4. It's Awesome.......

  5. One caveat on your statement "As there’s no such limitation for 64bit (x86_64) bit systems, you can define SGA’s larger than 4 Gig’s. But idea here is to let Oracle use the efficient one-segment model and for this shmmax should stay higher than SGA size of any individual database on the system" : (11gR1) introduces a bug that is exposed when memory_target and shmmax are higher than 3G and results in ORA-27103: internal error on startup. For details see Doc. ID 743012.1 on MetaLink.


    1. Thanks Rob, that's good to know. Seems like it's patched from; anyways we have few DB's that are on utilizing > 4GB mem with no issues.

    2. I think the article is great.
      As for the bug, doesn't seem to be universal
      I have used with higher memory target with no problem ofstartup on centos.
      I think you have to make sure the /dev/shm is also bigger


    3. Hi, Marvelous article.. simple and easy to under stand.
      Same error is giving for me also. Kindly can u suggest me the value for Shmall and Shmmax .

      Iam getting java pool error and shared pool error so i want to increase the SGA_MAX_SIZE.

      ORA-04031: unable to allocate ORA-04031: unable to allocate 4064 bytes of shared memory ("shared pool")

      ora-04031 unable to allocate 4096 bytes of shared memory ( java pool

      1. Iam having two DB PROD and LUMPROD. SGA_MAX_SIZE is 2gb and 1.5gb. total 3.5gb.

      2. Iam not able to increase sga_max_size for PROD from 2gb to 3gb.

      3. ------ Shared Memory Limits --------
      max number of segments = 4096
      max seg size (kbytes) = 1953124
      max total shared memory (kbytes) = 13118188
      min seg size (bytes) = 1

      cat /etc/sysctl.conf

      # Kernel sysctl configuration file for Red Hat Linux
      # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
      # sysctl.conf(5) for more details.

      # Controls IP packet forwarding
      net.ipv4.ip_forward = 0

      # Controls source route verification
      net.ipv4.conf.default.rp_filter = 1

      # Do not accept source routing
      net.ipv4.conf.default.accept_source_route = 0

      # Controls the System Request debugging functionality of the kernel
      kernel.sysrq = 0

      # Controls whether core dumps will append the PID to the core filename.
      # Useful for debugging multi-threaded applications.
      kernel.core_uses_pid = 1

      kernel.sem = 250 32000 100 150
      kernel.shmmax = 6294967295 (or larger)
      kernel.shmmni = 4096
      kernel.shmall = 3279547
      fs.file-max = 327679
      kernel.msgmni = 2878
      kernel.msgmnb = 360000
      net.ipv4.ip_local_port_range = 1024 65000
      net.ipv4.tcp_wmem = 262144 262144 262144
      net.ipv4.tcp_rmem = 4194304 4194304 4194304

      cat /proc/sys/kernel/shmall


      cat /proc/sys/kernel/shmmax

      M Jain.

    4. Can you please paste the output of below commands?

      free -g
      cat /proc/meminfo | grep MemTotal

      Also, I assume you are getting the below while trying to resize the SGA from 2GB to 3GB?

      ORA-27102: out of memory

      Linux-x86_64 Error: 28: No space left on device.

  6. Hello Raj,
    We have 2 node RAC using OCFS2 file system.while transferring one file around(800G) suddenly error arise as "No space left on device" even if df -h show available space in that particular LUN.while we gone through the oracle support and different blogs we came to know that was the bug of ocfs2 .support suggest to upgrade the oscf2 version which is not feasible for us right i want to know that how can i calculate that how much space is actually available in the disk to avoid this type of error while transferring huge files in the LUN.Please help.

    Thanks in advance.


  7. You are getting this while doing a normal file transfer (FTP/SCP ) etc. or an error thrown through Oracle with an "ORA-" error associated with it like below? Thanks.

    ORA-27102: out of memory
    Linux-x86_64 Error: 28: No space left on device.

  8. Awesome detail information, saved my time !!

  9. Hi

    Very Good Explanation. Thank you

  10. Hello,
    thank you so much

  11. Hi Raj,
    On "As SHMALL is the total size of Shard Memory Segments System wide, it should always be less than the Physical Memory on the System and should also be less than sum of SGA’s of all the oracle databases on the server."

    Shouldn't SHMALL be "greater than or equal" to sum of SGA’s of all the oracle databases on the server, instead of "less than"?


  12. Also on "cat /proc/sys/kernel/shmmni", I believe this is for "max number of shared memory segments segments allocated at a given time" (output you would see as part of ipcs -ml).


  13. Hi Raj,

    Thanks for this information. This is really helpful.


  14. Hi Raj,

    Thanks for the info! One correction, when making the SHMMAX change permanent there is a typo:
    silicon:~ # echo "kernel.shmmax=536870912" >> /etc/systctl.conf
    it should be
    silicon:~ # echo "kernel.shmmax=536870912" >> /etc/sysctl.conf

  15. max total shared memory (kbytes) = 5242880 /* SHMALL */
    it should be 5242880*1024
    silicon:~ # echo "kernel.shmmax=5368709120" >> /etc/sysctl.conf

  16. Thankx Raj.Great article.Very easz to understand.

  17. Very helpful. Thanks for sharing.

  18. Thanks, nice explanation for shmall.
    But PAGESIZE is always not equal to shmmni. Right?

  19. Shouldn't SHMALL be "greater than or equal" to sum of SGA’s of all the oracle databases on the server, instead of "less than"?

  20. Thanks Raviraj; yes that's right. I just corrected it.

  21. very informative article

  22. Sometimes doing an echo "" /proc/sys/kernel/shmall might not work. Reason being sysctl -p reads the file /etc/sysctl.conf. So for a permanent fix, I would suggest changing the parameter in: /etc/sysctl.conf and then running sysctl -p

    Thusjanthan Kubendranathan M.Sc.

  23. I'm a UNIX Admin w/28 yrs experience, and have what looks to be a misconfiguration by my DBA team. On a x86_64 server running Oracle Linux 5.7 with 32GB of physical memory, they are setting:
    kernel.shmmax = 68719476736
    kernel.shmall = 4294967296
    which to me appears to be WAAAAY over the system's limitations. Am I missing something here?

    1. Yes that's the wrong configuration. shmall set to 4294967296 which means sum of all SGA's on the server is 16TB (based on 4096Kb pagesize) which can't be possible on 32GB physical memory system. Also shmmax is set to 64GB which is higher than the actual physical memory.

  24. awesome article raj... thanks a ton !!

  25. Perl online training|Perl training|call us+919000444287 ...
    Perl Online Training, Perl Scripting online training by real time Experts from Hyderabad, India. Call 9000444287 for online training demo. Online Perl training ...

  26. Very informative indeed! Thanks for posts like these.

  27. nice information.Thanks for sharing.Page Size Checker is used for checking the total length of a web size checker tool

  28. Excellent ! I am truly impressed that there is so much about this subject that has been revealed and you did it so nicely.
    Linux Training in Chennai

  29. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

  30. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point. | |

  31. Collect your Windows Professional Product Keys From Here. Today I Provide you working Windows 8 Professional Product keys or licence key free. If you searching for
    windows 8 pro activation key free ,windows 8 pro activation key free downloads . Source URL

  32. This comment has been removed by the author.


  33. Really very informative and creative contents. This concept is a good way to enhance the knowledge.
    thanks for sharing. please keep it up.
    Linux Training in Gurgaon

  34. This Blog Provides Very Useful and Important Information. I just Want to share this blog with my friends and family members. United States Medical Licensing Examination

  35. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.

    click here

    Selenium Training in Bangalore|
    Selenium Training in Chennai

  36. Wow.Great post to read.Such a nice and interesting to connect these 2 legand domains.Good job.
    lenovo service centre chennai
    lenovo service center
    lenovo mobile service center near me

  37. Thank you for sharing such great information very useful to us.
    Linux Training in Gurgaon

  38. Thanks for the post and it is very useful information about a mobile phones. Vivo Service Center in Chennai
    Onepluse Service Center in Chennai

  39. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
    Data Science Training in Chennai | Data Science Course in Chennai
    Python Course in Chennai | Python Training Course Institutes in Chennai
    RPA Training in Chennai | RPA Training in Chennai
    Digital Marketing Course in Chennai | Best Digital Marketing Training in Chennai

  40. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    AWS Training in Chennai | Best AWS Training in Chennai
    Best Data Science Training in Chennai
    Best Python Training in Chennai
    Best RPA Training in Chennai
    Digital Marketing Training in Chennai
    Matlab Training in Chennai
    Best AWS Course Training in Chennai
    Best Devops Course Training in Chennai

  41. Thanks for sharing this post.

    Want to make your own website!!!
    Contact ACIL the best web design company in Delhi.

    Interested in Graphic Designing Course!!!
    Contact ACIL for the best Graphic designing Institute in Gurgaon.

    Interested in Python training!!!
    Contact ACIL for the best Python Training Institute in Gurgaon.

  42. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    blue prism training in chennai | blue prism course in chennai | best blue prism training institute in chennai | blue prism course in chennai | blue prism automation in chennai | blue prism certification in chennai

  43. Thanks for the amazing post which is really useful and more informative both in manually and technically. To handle the products. There are some best service centers.
    Oppo Service Center in Chennai
    Vivo Service Center in Chennai