LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to check swap available and how to increase it (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-check-swap-available-and-how-to-increase-it-929996/)

cheesewizz 02-17-2012 11:18 PM

How to check swap available and how to increase it
 
Hi


Awhile ago my centos server cannot access by other users
since this is running as terminal mode not gui when I opened it
lots of message appeared on my LCD something swap is 0%


i used this command df -ha to check swap

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
130G 63G 61G 51% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
/dev/cciss/c0d0p1 99M 20M 75M 21% /boot
tmpfs 501M 0 501M 0% /dev/shm
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs



but i dont know which swap is there?
and how to increase swap without reinstalling of Distro.
and is it possible to check and review error message the time i restarted the server which log is that?



Thanks

btmiller 02-18-2012 12:24 AM

Look at your memory usage with the "free" command -- it will tell you available and used swap space. I believe in principal you can use a file on a normal partition as swap, but it will be less efficient than having a swap parttion on your disk.

cheesewizz 02-18-2012 01:12 AM

Quote:

Originally Posted by btmiller (Post 4605620)
Look at your memory usage with the "free" command -- it will tell you available and used swap space. I believe in principal you can use a file on a normal partition as swap, but it will be less efficient than having a swap parttion on your disk.

Thanks for your reply

I execute free command and here is the result

total used free shared buffers cached
Mem: 1025884 1012324 13560 0 3584 103532
-/+ buffers/cache: 905208 120676
Swap: 2064376 424904 1639472


Thanks

devilboy09 02-18-2012 03:52 AM

you can use free -h for enabling human readable option.also if you want to increase the swap space i suggest you to create a swp file, like this:
Code:

dd if=/dev/zero of/swapfile bs=1024 count=1024
mkswap /swapfile

these command will create a 1 MB swap file that can be mounter automatically on boot time with fstab file.like this:
Code:

/swapfile none swap sw 0 0

johnsfine 02-18-2012 09:00 AM

Quote:

Originally Posted by devilboy09 (Post 4605712)
these command will create a 1 MB swap file

Are you assuming the OP will understand how to scale up from the 1MB swap file you described to the desired size, and that the OP can estimate a good size?

The bs=1024 in your example tells dd to work 1KB at a time, which is small and possible slow for creating a big file. The count=1024 tells how big in units of bs= to make the file.

The output from free that was posted shows the 2GB swap space less than one quarter used, which would be OK. But I think we are inferring from the vague info in the first post that at some other time the swap space was entirely used.

If 2GB of swap was used then adding 2GB more would not be generous. Having swap 2GB bigger than the most you've seen used is a reasonable safety margin. If the main disk were larger, I would suggest adding more than 2GB swap space now. But with only 61GB free disk space, I wouldn't want to be too generous with the safety margin on swap space.

If I understand dd syntax properly, then using bs=1M count=2048 would give a 2GB swap file instead of your 1MB example.

Since the system has only 1GB ram, the fact that it needs more than the 2GB swap it already has, may mean it is seriously underconfigured for the work it is doing, so adding swap will allow things to work that would have otherwise failed but they will only work slowly because 1GB is not enough ram.
Alternately, needing more than 2GB swap might indicate a memory leak in some program. Adding more swap space would reduce and delay the consequences of the memory leak and make the memory leak easier to diagnose. But it still doesn't diagnose itself. If you don't diagnose and correct it, even with added swap space, a memory leak will probably grow until it causes a serious failure.

chrism01 02-19-2012 08:11 PM

As implied above, you really want to diagnose the underlying problem, if any.
Try 'top' in batch mode -b http://linux.die.net/man/1/top & accumulate results in a file, then examine the file to try and pinpoint the culprit(s)

satyadev75 02-20-2012 03:03 PM

the above posts are really good solution . and you can create the swap from partitions also


"#fdisk /dev/sda (hda/sda/vda are types of disks)
command:n
2
.
.
:wq
#partprobe
#mkswap /dev/sda2
#vi /etc/fstab
/dev/sda2 swap swap defaults 0 0
:wq
#swapon /dev/sda2
#free "


and if your doubt is clear plese post it as solved question


All times are GMT -5. The time now is 07:07 AM.