Adding Swap Space On RHEL 5

1.     Overall Description

Computer systems have a finite amount of physical memory that is made available to the operating system. When the operating system begins to approach the limit of the available memory it frees up space by writing memory pages to disk. When any of those pages are required by the operating system they are subsequently read back into memory. The area of the disk allocated for this task is referred to as swap space.

2.     Recommended Swap Space for RHEL 5

The amount of swap recommended for RHEL 5 depends on a number of factors including the amount of memory in the system and the workload imposed on that memory. The current guidelines for Red Hat Enterprise Linux 5 swap space are as follows:

  • 4GB of RAM requires a minimum of 2GB of swap space
  • 4GB to 16GB RAM requires a minimum of 4GB of swap space
  • 16GB to 64GB of RAM requires a minimum of 8GB of swap space
  • 64GB to 256GB of RAM requires a minimum of 16GB of swap space

3.     Identifying Current Swap Space Usage

The current amount of swap used by an RHEL system may identified in a number of ways. One option is to cat the /proc/swaps file:

 

# swapon -s

[root@localhost Server]# swapon -s

Filename                                Type            Size    Used    Priority

/dev/mapper/VolGroup00-LogVol01         partition       524280  0       -1

4.     Adding a Swap File to an RHEL System

Additional swap may be added to system by creating a file and assigning it as swap. This is achieved as follows.

Create the swap file using the dd command (the size can be changed by adjusting the count= variable; the following creates a about 1.6GB file):

# dd if=/dev/zero of=/newswap bs=1024 count=1572888

[root@localhost Server]# dd if=/dev/zero of=/oracleswap bs=1024 count=1572888

1572888+0 records in

1572888+0 records out

1610637312 bytes (1.6 GB) copied, 139.644 seconds, 11.5 MB/s

 

Configure the file as swap:

mkswap /oracleswap

[root@localhost Server]# mkswap /oracleswap

Setting up swapspace version 1, size = 1610633 kB

Add the swap file to the system in real-time:

# swapon /newswap

[root@localhost Server]# free

             total       used       free     shared    buffers     cached

Mem:       2026732    1972316      54416          0      79500    1697052

-/+ buffers/cache:     195764    1830968

Swap:      2097160          0    2097160

 

Finally, modify the /etc/fstab to automatically add the new swap at system boot time by adding the following line:

vim /etc/fstab

/oracleswap              swap                    swap    defaults        0 0

 

你可能感兴趣的:(职场,swap,RHEL,休闲)