About
swapping in an Linux Context.
You created partitions of the type “swap” when you scheduled the hard disks during the installation of your Linux distribution.
The Linux kernel usually does not require much swap space, since other limits have already been reached before the swap space has reached full capacity (“late swap allocation”). However, if you notice the need for more swap space when using a software, you can use the distribution-specific tools to increase your swap space at any time.
If possible, use an entire physical disk as a swap space partition.
You can configure multiple swap partitions. The maximum depends on the Linux distribution.
Articles Related
Property
The characteristics of a paging space are
- the paging-space name,
- physical-volume name,
- volume-group name,
- size,
- percentage of the paging space used,
- whether the space is active or inactive,
- and whether the paging space is set to automatic.
Utility
- lsps Displays the characteristics of a paging space.
How to
Check the allocated Swap Space
Check if there is sufficient swap space. To check the allocated swap space, enter the following command:
swapon -s
$/sbin/swapon -s
or
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/mapper/VolGroup00-LogVol01 partition 2031608 0 -1
See how much swap is in use ?
Run the free command.
[oracle@oel11g etc]$ free -m
total used free shared buffers cached
Mem: 1483 894 589 0 35 741
-/+ buffers/cache: 117 1365
Swap: 1983 0 1983
Turn off the swap space ?
To turn off the swap space, it muse not be in use. You may need to:
- reboot into single user mode, shut some applications down until it is free,
- or add a separate swap drive or file for swap use temporarily.
Once the swap space is free, to turn off the swap space, fire the following commando:
# /sbin/swapoff /dev/VolGroup00/LogVol01
swapoff: on: No such file or directory
Verification:
# free -m
total used free shared buffers cached
Mem: 1483 893 589 0 35 741
-/+ buffers/cache: 116 1366
Swap: 0 0 0
Add swap space ?
on Red Hat
- Create a 65Mb file to use it as swap file with the dd utility
# mkdir /data/
# dd if=/dev/zero of=/data/swapfile.1 bs=1024 count=65536
65536+0 records in
65536+0 records out
67108864 bytes (67 MB) copied, 1.3094 seconds, 51.3 MB/s
- Transform it as a swap file
# /sbin/mkswap /data/swapfile.1
Setting up swapspace version 1, size = 67104 kB
# /sbin/swapon /data/swapfile.1
- add it in the /etc/fstab in order to be recognize on boot
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/data/swapfile.1 swap swap defaults 0 0
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5 0 0
# End of the block added by the VMware software
Others
- Swap space: Between 1 GB and 2 GB: 1.5 times the size of the RAM, Between 2 GB and 16 GB: Equal to the size of the RAM
grep SwapTotal /proc/meminfo
# swapon will display a summary of swap usage and availability:
swapon -s
If the amount is not enough, create a file to use it as swap file with the dd utility. Doc
dd if=/dev/zero of=/mnt/swapfile bs=1024 count=3248960
3248960+0 records in
3248960+0 records out
3326935040 bytes (3.3 GB) copied, 94.2048 s, 35.3 MB/s
- Transform it as a swap file
mkswap /mnt/swapfile
Setting up swapspace version 1, size = 3248956 KiB
no label, UUID=3205ad4b-a9d7-4bab-ba00-b3e105b52818
chmod 600 /mnt/swapfile
swapon /mnt/swapfile
swapon: /data/swapfile.1: swapon failed: Invalid argument means
Not to self: suppress a swapfile swapoff -v /mnt/swapfile
- Verify
swapon -s
# or
free -h
total used free shared buff/cache available
Mem: 3.1G 361M 115M 8.6M 2.6G 2.5G
Swap: 3.1G 0B 3.1G
- add it in the /etc/fstab in order to be recognize on boot
/mnt/swapfile swap swap defaults 0 0
On SUSE LINUX
On SUSE LINUX, enter one of the following commands:
yast
yast2
Get the page size?
# getconf PAGESIZE
4096
# getconf PAGE_SIZE
4096
Support
swapon: /data/swapfile.1: Invalid argument
# /sbin/swapon /data/swapfile.1
swapon: /data/swapfile.1: Invalid argument
Verify that the file (/data/swapfile.1) has been made as a linux swap file with the command /sbin/mkswap.