Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Recently, I put more ram into my server and now I have got a total of 24GB of RAM. Originally, I setup the OS to have a 2GB swap size.

/dev/sdc1               1         281     2257101   82  Linux swap / Solaris
/dev/sdc2   *         282       60801   486126900   83  Linux

2GB is allocated for swap currently, but reading around it seems it is not much. For a system with 24GB, I am thinking to allocate at least 10GB of swap.

My questions is: Can I do it while the OS is running? Do I have to reinstall? I am using OpenSuse 11.3

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

You decided to create a separate swap partition upon installation. You can't resize it online - even an offline resize is going to take a considerable amount of time and bear the potential risk of damaging your subsequent filesystem on /dev/sdc2.

The easiest option to work around this is to either create a new swap partition on a different disk you don't currently use (or can afford to offline for re-partitioning) or simply use a swap file within an existing filesystem (which comes with some minor performance penalty due to the filesystem overhead).

The general procedure to add a swap partition/file:

  • create either a new partition of type 82h or a new 8 GB file using dd if=/dev/zero of=/swapfile bs=1M count=8192
  • initialize it using mkswap /swapfile or mkswap /dev/sdXX
  • use swapon /swapfile or swapon /dev/sdXX respectively to enable your new swap space on-the-fly
  • add an entry to /etc/fstab to make sure your new swap space gets activated upon reboot

Your current swap partition remains in use, you may want to get rid of it for the sake of complexity reduction. Just use swapoff /dev/sdc1 to disable its usage for the moment and remove the reference in /etc/fstab

share|improve this answer
    
@synticon-dj thanks. the data on the disk where the swap is is crucial, and I have another disk which I can use. Do you think setting a different disk as swap will affect performance? Will I have to swapoff the /dev/sdc1? –  x-man Jan 9 '12 at 13:37
    
It will affect it one way or the other - if /dev/sdc2 is seeing a lot of use, this I/O competes with swap I/O. If you add another disk's partition as swap, you just add the swap I/O load to this disk. What is going to be beneficial for swap performance, is inevitably detrimental to your other I/O on the affected disk. That being said, nothing is as bad for your system's performance as a high number of pageout/pagein requests. If you see this, fix it by adding memory or reducing your system's memory footprint. –  syneticon-dj Jan 9 '12 at 13:44
    
having two swap devices on different spindles will help your swap performance (as there are two disks which can be addressed simultaneously instead of just one to read from and write to). But as you should not see high I/O activity due to swapping anyway, you might prefer using just a single device/partition/file to ease administration –  syneticon-dj Jan 9 '12 at 13:49
add comment

You have to repartition the disk. If I remember well moving the begining of Linux partition isn't supported in parted but you can shrink your linux filesystem and partition as well and then make another swap at the end of your disk. You can't do this while the system is online.

Alternate solution is to use a big file as swap. (Don't know if it is a good idea nowdays.)

share|improve this answer
    
Not every filesystem can be shrunk, even offline. Unfortunately, this affects popular choices like XFS (xfs.org/index.php/Shrinking_Support). –  SvW Jan 9 '12 at 13:28
    
@Stone does this mean reinstalling the OS? –  x-man Jan 9 '12 at 13:28
    
No. It means making backups:), booting a LiveCD, shrink the linux filesystem then the sdc2 partition and make a new swap at the end of the disk and reboot your system. –  Stone Jan 9 '12 at 13:30
add comment

Would you be needing swap in this case? I do not know what you have running on your system system, but i try to have enough memory in my servers to avoid swap completely... (i do have it, but only as a failsafe, if my server starts swapping, i buy more memory...)

share|improve this answer
    
I'm on your side here, swap is mainly used to prevent crashes in case of (volatile) memory exhaustion and as soon as you start hitting platters your server is taking a hit I/O and/or bandwith wise, although SSDs can help they are at least 10 times slower than RAM which nowadays is really cheap. Prices of DDR3 ECC 1333MHz is about $1000 for 64GB (8x8GB) –  Shadok Jan 9 '12 at 14:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.