Jan 12, 2017

Edit Swap size in linux - dynamically

-- To increase swap file in existing system

Cuurent swap size :
# free -g
             total       used       free     shared    buffers     cached
Mem:             7          0          6          0          0          0
-/+ buffers/cache:          0          7
Swap:            3          0          3

i.e., Avaialble is : 3G

Pre-requisites : Required space must be available in / ( root)

-- Add swap file

# dd if=/dev/zero of=/swapfile bs=1024 count=16777216
16777216+0 records in
16777216+0 records out
17179869184 bytes (17 GB) copied, 124.992 s, 137 MB/s
[root@dr1-oracle /]# 

Calculation:
bs : block size ( 1024)
count : Required value to add ( e.g., to increase 16GB, 16x1024x1024=16777216)

But, As per Oracle recommendation use 16G swap memory. So add 13GB in this scenario.

-- To setup swap

# mkswap /swapfile 
mkswap: /swapfile: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 16777212 KiB
no label, UUID=a02686f1-3c9b-46f7-bebc-cc839adfcc2e

-- To Enable swap file immediatly

# swapon /swapfile

-- Check swap size now

# free -g
             total       used       free     shared    buffers     cached
Mem:             7          7          0          0          0          6
-/+ buffers/cache:          0          6
Swap:           19          0         19


-- Add in fstab to make permanent

# vi /etc/fstab

/swapfile swap swap defaults 0 0


==================
To remove swap file
==================

# swapoff /swapfile
# rm /swapfile

No comments:

Post a Comment

Translate >>