Thursday, January 3, 2013

Swap Size - This Is a Prerequisite Condition Tested during Oracle Installation

During the "Prerequisite Checks" of Oracle Database installation[1], one of three issues we have seen is:
  • Swap Size

Detailed Message


The detailed description looks like this:

Swap Size - This is a prerequisite condition to test whether sufficient total swap space is available on the system.

Expected Value:11.2438GB (1.1790008E7KB)
Actual Value:7.8125GB (8191968.0KB)
Details:
PRVF-7573 : Sufficient swap size is not available on node "perf-x4600-4" [Required = 11.2438GB (1.1790008E7KB) ; Found = 7.8125GB (8191968.0KB)] - Cause: The swap size found does not meet the minimum requirement. - Action: Increase swap size to at least meet the minimum swap space requirement.

Swap Space Recommendation


For systems with a certain amount of physical RAM, the following recommendation for Oracle 11g Release 2 is typical[4]

  • 1GB <= RAM <= 2GB
    • Swap space of 1.5 times the size of RAM
  • 2GB <= RAM <= 16GB
    • Swap space to equal the size of RAM
  • RAM >= 16 GB
    • 16GB of swap space

The performance of disk-based storage is orders of magnitude slower than memory. Oracle should always run in RAM for the best performance. However, swapping is necessary for two important reasons:
  • When the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately
  • A significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

Memory and Swap Space


There are multiple ways to find the amount of physical RAM and swap space on a Liunx server:

To confirm the size of physical RAM on a Linux server:

$ grep MemTotal /proc/meminfo
MemTotal:     11790008 kB


To verify the amount of memory and swap space, run the following command:

$ free -t
             total       used       free     shared    buffers     cached
Mem:      11790008   11194300     595708          0     207588    9868888
-/+ buffers/cache:    1117824   10672184
Swap:      8191968      11824   11768092
Total:    19981976   11206124   12363800

How to Increase Swap Size?


In [2], it describes two ways of increasing swap space:
  • Use a dedicated hard drive partition to add new swap space
  • Create a swap file on an existing filesystem and use it as swap space
We used the second approach and here were our steps. Before you start, login as "root".
  1. swapon command with option -s, displays the current swap space in KB
    • #swapon -s
      Filename              Type    Size  Used Priority
      /LOCAL_SWAP/swapfile1 file 2047992 11824       -1
      /LOCAL_SWAP/swapfile2 file 2047992 0           -2
      /LOCAL_SWAP/swapfile3 file 2047992 0           -3
      /LOCAL_SWAP/swapfile4 file 2047992 0           -4

  2. dd command creates two swap files with the names “swapfile5” and “swapfile6”  under /LOCAL_SWAP directory
    • #dd if=/dev/zero of=/LOCAL_SWAP/swapfile5 bs=1000 count=2097152
      #dd if=/dev/zero of=/LOCAL_SWAP/swapfile6 bs=1024 count=1539964
  3. mkswap sets up a Linux swap area in a file
    • #mkswap /LOCAL_SWAP/swapfile5
      #mkswap /LOCAL_SWAP/swapfile6
  4. swapon enables files for paging and swapping
    • #swapon /LOCAL_SWAP/swapfile5
      #swapon /LOCAL_SWAP/swapfile6
  5. free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers  used  by  the  kernel
    • #free -t
                total       used     free  shared buffers   cached
      Mem:   11790008   11193432   596576       0  214136  9871196
      -/+ buffers/cache: 1108100 10681908
      Swap:  11779916      11824 11768092
      Total: 23569924   11205256 12364668
Note that our system has 11.2438GB physical RAM.  So, the installer recommends 11.2438GB swap space. Initially, we had only 7.8125GB swap space.  After adjustment, swap space finally reaches 11.5038GB.

To make this swap space partition available even after the reboot, add the following lines to the /etc/fstab file:
/LOCAL_SWAP/swapfile5           swap    swap    defaults        0 0
/LOCAL_SWAP/swapfile6           swap    swap    defaults        0 0

As a final note, you should not place /LOCAL_SWAP in root which may cause out-of-space-in-root problem later.

References

  1. Installing Oracle Database 11g Release 2
  2. UNIX / Linux: 2 Ways to Add Swap Space Using dd, mkswap and swapon
  3. All about Linux swap space
  4. Pro Oracle Database 11g Administration
  5. How I Simplified Oracle Database Installation on Oracle Linux (Good)
  6. Removing a swap file
  7. HugePages consideration
    • On Linux, the HugePages feature allocates non-swappable memory for large page tables using memory-mapped files. If you enable HugePages, then you should deduct the memory allocated to HugePages from the available RAM before calculating swap space.
  8. Oracle Cloud - Adding swap space to your Oracle Linux compute instance

No comments:

Post a Comment