LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-16-2013, 05:30 PM   #1
ej_219
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
Adding SWAP Partition


Talked my boss into installing Ubuntu on a desktop at work, XP kept locking up with BSOD. The desktop has 1GB ram and the SWAP partition is currently 1GB. PC is running very slow and I was thinking additional SWAP space would improve performance. Could anyone please explain the best way to add a SWAP partition to this desktop? I did find one method on thegeekstuff.com from 2010, URL attached. Would this a good method to try, or is there a better way? Thanks from a Linux nooby.

http://www.thegeekstuff.com/2010/08/...dd-swap-space/
 
Old 06-16-2013, 08:49 PM   #2
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,432

Rep: Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192
Hi,

welcome to LQ. Before considering adding more swap you should check that you actually need it. You should use the "free" command. To understand the output, have a look at www.linuxatemyram.com

HTH,

Evo2.
 
1 members found this post helpful.
Old 06-16-2013, 09:06 PM   #3
DOSJockey382
LQ Newbie
 
Registered: Aug 2005
Location: California
Distribution: Debian, Ubuntu, NetBSD, OS X
Posts: 25

Rep: Reputation: 15
First of all, have you identified that the system is using swap space in the first place? Unless you know you are hitting your swap cap, you probably do not need to increase swap space. Yes, hitting your swap cap will slow a computer down immensely. However, using swap space in and of itself will slow your computer down. You are going from RAM speed to HDD speeds. Even SSDs with swap will slow you down a little, though much less so than HDDs. You may wish to run TOP or some other program that tracks real-time memory usage (RAM and SWAP) to know exactly where the speed bottleneck is happening and if it is specifically memory related.

Now let's assume that the problem is a need for more swap space. I have heard different variations on what I am going to say next, but my general rule of thumb when it comes to swap space give swap 3x RAM size. But, should you use those instructions to increase the swap space? Don't know. I try to set my partitions correctly (or what I think is correct) before I even get to installing a system. I am not a big fan of dynamically altering partitions on installed systems, though I know very well it can be done. Too many things can go wrong that will force you to repartition and reinstall the system fresh anyway. But feel free to try it.

One last thought, If memory limitations are the problem, might want to consider increasing the RAM on the computer.
 
Old 06-16-2013, 11:49 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Definitely check to see if you NEED more swap before bothering.
Read the link provided by evo2 and run the 'top' cmd to see what's really happening.
 
Old 06-17-2013, 12:29 AM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
As a general rule
more swap will allow you to run more programs, slower and noisier ( disk thrashing ).


For a better experience, with just 1gb ram, look at lubuntu or xubuntu
 
Old 06-17-2013, 01:26 AM   #6
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,107

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
Quote:
Originally Posted by ej_219 View Post
PC is running very slow and I was thinking additional SWAP space would improve performance.
It is very unlikely that additional SWAP space would improve performance.

But answering your question anyway.

Quote:
Could anyone please explain the best way to add a SWAP partition to this desktop?
It is better to expand an existing swap partition than to add another.

You would boot in a liveCD (such as the install media) and use a GUI partitioning tool (such as gparted). You probably need to shrink some other partition in order to expand swap.

The liveCD boot might have enabled use of the swap for itself. If so, you need to disable that before using gparted. In command line that is:
/sbin/swapoff -a

Adding a swap file is easier than adding swap partition or expanding a swap partition. That can be done without rebooting.

Quote:
I did find one method on thegeekstuff.com from 2010, URL attached. Would this a good method to try, or is there a better way?
For adding a swap file, that looks right.
For adding a swap partition, that looks plausible for the correct second half of the task. You need to use a partitioning tool for the first part (actually creating the partition). Probably that would need rebooting in liveCD and first shrinking some other partition. By the time you do all that, it is easier to expand the existing swap than to add a new one.

Quote:
Originally Posted by DOSJockey382 View Post
First of all, have you identified that the system is using swap space in the first place? Unless you know you are hitting your swap cap, you probably do not need to increase swap space.
That is the important answer for this thread (same as evo2 and others said).

Quote:
Yes, hitting your swap cap will slow a computer down immensely.
Lack of swap space can slow a computer down. But "immensely" is very unlikely. Even if all the allocated swap space is used, lack of more swap space probably only slows the computer a little.

Quote:
Even SSDs with swap will slow you down a little, though much less so than HDDs.
If you actually need swap space, having it on SSD is inferior to having it on HDD. SSD is good for uses that are mostly read, not uses (such as swap) that are as much write as read. But I expect the computer discussed in this thread has no SSD, so this side topic is irrelevant.

Quote:
my general rule of thumb when it comes to swap space give swap 3x RAM size.
No such rule of thumb gives you good guidance on a good choice of swap size. In modern systems, there is no correlation between ram size and appropriate swap size. So all the various 1x or 2x or 3x "rule of thumb" suggestions are misleading.

If you need a blind "rule of thumb" (independent of looking at what you actually need) suggestion for swap space, you'll do better with mine: Swap space should be 2GB regardless of ram size (but less if you are very short of disk space).

Last edited by johnsfine; 06-17-2013 at 01:56 AM.
 
Old 06-18-2013, 01:55 PM   #7
vrrivaro
LQ Newbie
 
Registered: Jul 2008
Posts: 9

Rep: Reputation: 0
Post Adding swap space is valid!

While what most have previoualy said here is true (not all--there is zero risk involved), there is definetly an excellent reason for adding swap space to a machine. If Linux required a total reinstall to add it would be absolutly Stupid(TM)...

For starters, you might have added memory to the machine. Since the formula for the amount of swap recomended changes depending on the main memory size, it now has too little swap.

Secondly, you might have done a miscalculation when doing the instalation.

Third, your requirements might have changed.

Now, let me defend the 2x or 3x postures...

Linux uses the standard swap space for the "Suspend to Disk" feature. Therefore, if your free swap space is less than your physical ram plus the currently used swap memory, the "suspend to disk" operation will fail. As a result, your notebook's battery could drain out and you could loose important data. Keep that in mind when calculating the swap space. It s better to have unused swap space, than not enough...

Now, how do I go about dinamically adding swap space? Say you want to add 16 GB:

$ sudo -i
# dd if=/dev/zero of=/root/swapfile bs=$((1024*1024)) count=$((16*1024))
# mkswap /root/swapfile
# swapon /root/swapfile
Now, to make it permanet, you simply need to add that last line anywhere into the /etc/rc.local file, as long as it is before the "exit" at the end.

A comment on the dd command. It copies an endless stream of zeroes (/dez/zero) into our target directory in blocks (bs) of 1 MB (the amount in parenthesis) and exactly 16K of them. The result is a string of zeroes filling 16GB into the file /root/swapfile.

Edited for clarification:
  1. I used the bash construct $((...)) but forgot to explain it. It simply means to perform the math enclosed and substitute in the result. If instead you typed "dd if=/dev/zero of=/root/swapfile bs=1048576 count=16384", you would get the exact same result.
  2. The parameters to the dd command are not magical. This could get the exact same result:
    $ sudo -i
    # INPUT_FILE="/dev/zero"
    # OUTPUT_FILE="/root/swapfile"
    # BLOCK_SIZE=$((1024*1024))
    # BLOCK_COUNT=$((16*1024))
    # dd if=$INPUT_FILE of=$OUTPUT_FILE bs=$BLOCK_SIZE count=$BLOCK_COUNT

I do hope I have made myself clearer this time.

Last edited by vrrivaro; 06-29-2013 at 08:27 PM. Reason: Added some comments for clarification purposes
 
Old 06-26-2013, 07:34 PM   #8
ej_219
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for all the responses. Sorry I haven't gotten back sooner, busy work schedule. When I checked the swap space using free, on one occasion the swap was almost maxed and on another occasion it was using less than half of the space available. I normally set the swap size at twice the size of memory, with a 2GB max. My boss is an old IT guy (new to Linux) and installed Ubuntu over a weekend and set the swap at 1GB, same size as memory. When I get some slow time @ the job I will use DOSJockey382's recommendation of Top to see just what is slowing things down. If I do need to increase swap size I will try the script by vrrivaro.
Thanks again for all the advice.

Last edited by ej_219; 06-26-2013 at 07:35 PM.
 
Old 06-26-2013, 08:52 PM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
These days I'd go with min 2GB swap, even on a desktop. GUIs use a lot of RAM and diskspace is cheap; give it 4GB if you feel like it.

Last edited by chrism01; 06-26-2013 at 11:56 PM. Reason: typo
 
Old 06-26-2013, 09:23 PM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
Quote:
Originally Posted by vrrivaro View Post
For starters, you might have added memory to the machine. Since the formula for the amount of swap recomended changes depending on the main memory size, it now has too little swap.
Old time rule of thumb that is invalid for a running system. You are right that the amount of swap needed is determined by the amount of RAM when you want to use hibernating (suspend-to-disk), but it is not dependent on the amount of RAM for a running system per se.
The amount of swap needed is determined by the amount of RAM you have and the workload of the machine. If you never use all of the physical RAM adding more RAM will not change anything for the amount of swap needed. So the first thing to do is to check if your workload even hits the swap. If it does hit the swap you will still not get better performance with increasing the amount of swap, you will just get more room before the OOM killer is triggered. There is only one way to increase performance in that case: Add more physical RAM.
Or maybe, if you have the chance, decrease the memory load (with using lightweight software, for example, as mentioned already, using Lubuntu instead of Ubuntu).

Last edited by TobiSGD; 06-26-2013 at 09:26 PM.
 
Old 06-27-2013, 10:04 AM   #11
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,401

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
When you're looking for quick-fixes, "chips are cheap." Find out how much memory the system will hold, and go buy it. You'll almost always be glad that you did.

However, "slow performance" really does require digging a little deeper. If the system is "perceptibly slow," look to see if CPU utilization is "quite low." Usually it is, which means that processes are being forced to wait. High disk-activity is your easiest cue that "thrashing" due to memory over-utilization might be the problem: if one program is consuming too much memory, perhaps it has a configuration parameter that you can adjust, or you can impose a limit with ulimit.

Sometimes it turns out to be the GUI that is "slow," perhaps due to less-than-optimal settings concerning the video card, and so forth. Anything that serves as a "common choke-point" shared by many programs at the same time can have an unexpectedly-large influence on perceived performance ... and, when it comes to performance, "perception is everything."
 
Old 06-27-2013, 03:01 PM   #12
jefro
Guru
 
Registered: Mar 2008
Posts: 11,714

Rep: Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439Reputation: 1439
An old xp box that locked up in xp may or may not be a good choice for a modern distro like ubuntu.

If only slow then maybe try some lighweight distros for testing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can swap file or a swap partition be mounted and read? Mr-Bisquit Linux - General 3 06-08-2009 02:16 PM
Hard Drive Partition Management - Mandriva Double Partition with Swap File partition moshebagelfresser Linux - Hardware 2 05-23-2008 10:46 AM
Adding a swap partition after the fact? Mark Anderson Ubuntu 6 04-03-2007 04:06 PM
Adding Swap Partition Post-Install slickhare Linux - Newbie 2 11-28-2006 08:47 PM
Adding more SWAP after adding memory marc1978 Linux - General 6 03-19-2006 07:13 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration