LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 07-29-2008, 02:12 AM   #1
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Rep: Reputation: 15
swap options


Hi

I need to increase my swap space (to satisfy an application) and as there are a couple of options I thought I'd ask people more experienced than me as to what the pitfalls / advantages of each strategy are. I guess that I have 2 options:
  1. increase swap partition
  2. add a swap file

1) I suspect that increasing swap will be the most troublesome, but I wonder if it might not be the best option. I guess that I'd need to backup my system (say to an external drive) and repartition. Is it possible to repartion without destroying existing file system?

2) adding a swap file seems simple enough, but I have a question about the commands for this. For example I could do:

Code:
dd if=/dev/zero of=/swappie bs=128M count=1
or
Code:
dd if=/dev/zero of=/swappie bs=1M count=128
would there be any differences in this? So (for instance) is it better to have one big block than heaps of tiny ones?


Lastly, my current configuration is something like this :

Code:
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /dev/shm                tmpfs   defaults        0 0
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
and while I have 4 gig of memory I have only 1.9 Gig of swap space

Code:
$ free -m
             total       used       free     shared    buffers     cached
Mem:          3795        782       3013          0         54        582
-/+ buffers/cache:        144       3651
Swap:         1983          0       1983
I'd have thought it enough, but the software I'm installing wants there to be x4

Thanks :-)
 
Old 07-29-2008, 03:03 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Personally I prefer partitions - note you can have more than one. Just create more partitions and add them to fstab. RH also have a modification in place to allow you to use swap partitions larger than 2 Gig - this is a RH (only) feature.
I do not like the idea of putting swap files on LVM - just another layer of software to (needlessly) get in the way and slow things down.

I also wouldn't like the idea of software purveyors telling me I need that much swap - must be java.
 
Old 07-29-2008, 07:49 AM   #3
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Original Poster
Rep: Reputation: 15
Hi

Quote:
Originally Posted by syg00 View Post
I also wouldn't like the idea of software purveyors telling me I need that much swap - must be java.
yep, it definitely makes use of java. Problem is that the installer seems to make the calculation on swap being 4x system memory, if you don't have that it conks out ... as to why it needs 16 gig of swap (when its not getting even 2 gig of memory to itself is beyond me

can I repartition on the fly?
 
Old 07-29-2008, 08:05 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by pellicle View Post
Is it possible to repartion without destroying existing file system?
Yes. It's easiest to boot a liveCD and use the partitioning tools on the liveCD. You can resize and/or move partitions (with existing file systems) and create and/or extend swap partitions.

Depending on what you do to the partition containing stage 1.5 of grub, you might need to reinstall stage 1 of grub after partitioning. That also is pretty easy to do while booted on the liveCD. Everything else in the partition is accessed in a way that won't be upset by the partition being in a different physical location.

BTW, do you have a 32-bit kernel or 64-bit? I'm not sure of the limits (max size per swap partition or file, etc.) in 32-bit, but I expect you need to worry about some of those to get to 16GB of swap.

Quote:
Code:
dd if=/dev/zero of=/swappie bs=128M count=1
or
Code:
dd if=/dev/zero of=/swappie bs=1M count=128
would there be any differences in this? So (for instance) is it better to have one big block than heaps of tiny ones?
That choice shouldn't affect the resulting file. It only affects the sequence of I/O operations used to create the file, which might significantly affect the time it takes to create the file, but no lasting effects.

BTW, why are those just 128M? Don't you need much more than that?

Quote:
Originally Posted by pellicle View Post
Problem is that the installer seems to make the calculation on swap being 4x system memory, if you don't have that it conks out
Seems unbelievably lame. Your pretty sure it insists on 4x? Is it just the installer? In other words, once installed, does it still need the excess swap space?

Maybe you should create swap file(s) just for the install, then remove them once the program is installed.

Quote:
can I repartition on the fly?
You can't move nor resize a mounted partition. That restriction gets very tricky when booted on the same hard drive you are repartitioning. But it is pretty easy when booted from a liveCD.

Last edited by johnsfine; 07-29-2008 at 08:11 AM.
 
Old 07-29-2008, 08:28 AM   #5
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Original Poster
Rep: Reputation: 15
Hi

Quote:
Originally Posted by johnsfine View Post

You can resize and/or move partitions (with existing file systems) and create and/or extend swap partitions.

BTW, do you have a 32-bit kernel or 64-bit?

BTW, why are those just 128M? Don't you need much more than that?

Seems unbelievably lame. Your pretty sure it insists on 4x? Is it just the installer? In other words, once installed, does it still need the excess swap space?
live CD is very interesting option ... I'll look into that!

I believe that I have 64 bit kernel (not sure how to be sure though)

the examples I quoted were form other posts here ... naturally I'd alter them but just wanted to have some examples to 'discuss'

I've (since) got it installed (with errors) as it is. So I'll delay partitioning till I see some actual needs for that (why waste HDD??).
 
Old 07-29-2008, 08:30 AM   #6
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Original Poster
Rep: Reputation: 15
Hi

whoops, its not x4 its:

Quote:
The minimum RAM required is 512MB, and the minimum required swap space is
1GB. Swap space should be twice the amount of RAM for systems with 2GB of
RAM or less and between one and two times the amount of RAM for systems with
more than 2GB.
 
Old 07-29-2008, 08:35 AM   #7
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Original Poster
Rep: Reputation: 15
My current setting (from /proc/meminfo)

MemTotal: 3886992 kB
SwapTotal: 2031608 kB
 
Old 07-29-2008, 11:01 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, that 2nd sentence is the basic guideline for swap space on Linux generally.

There's no hard & fast rules though...
 
Old 07-30-2008, 12:33 AM   #9
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Original Poster
Rep: Reputation: 15
Hi

Quote:
Originally Posted by chrism01 View Post
Well, that 2nd sentence is the basic guideline for swap space on Linux generally.

There's no hard & fast rules though...
did you mean this one:

Swap space should be twice the amount of RAM for systems with 2GB of RAM or less and between one and two times the amount of RAM for systems with more than 2GB.

so probably I should make it 2Gig then ... not a big sacrifice.

Still, if the graphical tool that reports system loading is to be believed then there is nothing much even using the existing swap...

Last edited by pellicle; 07-30-2008 at 12:34 AM. Reason: clicked too soon :-)
 
Old 07-30-2008, 01:10 AM   #10
pellicle
Member
 
Registered: Jul 2008
Location: Finland
Distribution: RHEL4
Posts: 139

Original Poster
Rep: Reputation: 15
Folks

I thought I'd use top to monitor my system for a bit (to see what was happening with the demands on swap) and found the following:

Code:
top - 09:05:58 up 49 min,  3 users,  load average: 0.08, 0.19, 0.09
Tasks: 125 total,   1 running, 123 sleeping,   0 stopped,   1 zombie
Cpu(s):  0.7% us,  0.3% sy,  0.0% ni, 98.8% id,  0.2% wa,  0.0% hi,  0.0% si
Mem:   3886992k total,   728300k used,  3158692k free,    21244k buffers
Swap:  2031608k total,        0k used,  2031608k free,   479516k cached

USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP COMMAND
cje       17   0  605m  22m  20m S  1.0  0.6   0:00.03 583m oracle
cje       16   0  2216  972  752 R  0.3  0.0   0:00.67 1244 top
cje       16   0  574m  83m  24m S  0.3  2.2   0:16.84 491m java
root      16   0  3160  556  476 S  0.0  0.0   0:00.56 2604 init
root      RT   0     0    0    0 S  0.0  0.0   0:00.00    0 migration/0
this actually raises some questions for me (doesn't good information always:-)

the process oracle seems to be consuming 583m of swap memory, yet nothing is being consumed (or so it seems) in swap. Is this because I have 3158692k free?
 
Old 07-30-2008, 01:23 AM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Quote:
Originally Posted by pellicle View Post
the process oracle seems to be consuming 583m of swap memory, yet nothing is being consumed (or so it seems) in swap. Is this because I have 3158692k free?
Yes (you actually have a bit more than that free BTW).
Having tried to make sense of that metric in the past, I now consider it meaningless. Probably the swapcache count, but I know of no way to verify my conjecture.
 
Old 07-30-2008, 06:27 AM   #12
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by pellicle View Post
this actually raises some questions for me (doesn't good information always:-)
It raises a slightly different question for me, because I know the answer to the one that confused you:

Quote:
the process oracle seems to be consuming 583m of swap memory, yet nothing is being consumed (or so it seems) in swap. Is this because I have 3158692k free?
That "SWAP" column in top does not tell you how much swap memory the task is consuming. It tells you how much of the process's memory isn't resident in physical memory.

In a typical system, most non resident pages aren't in the swap space.

When pages are read in unmodified from a binary executable, Linux can keep track of the association between those pages and their source position in executable file. If Linux decides to push those pages out of memory, it can just discard the copy in memory (rather than write it to swap space). Then, if the page is needed in physical memory again, Linux can reread it from the executable file.

I'm pretty sure (especially seeing that 538MB) that memory mapped files are accounted the same way in top. A process can map part of a file into part of its virtual address space. Any pages brought in by that mapping are backed by the original file, not the swap space.

So what I wonder about your top output is did your system ever kick any pages out of physical memory. If it did, does that mean it was temporaraily doing so much file caching that free physical ram went nearly to zero?

The alternative is that everything listed in your SWAP column is mappings those processes created but never used. The process bound pages of its virtual address space to parts of a file, but then never read nor wrote those pages of its address space. A file mapping starts non resident (as if it had been paged out) and gets paged in as each page of the mapping is read or written.
 
Old 07-30-2008, 06:38 AM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Swap is only used for (dirty) anonymous pages.
All other user pages - including shared binaries - are managed through the normal page cache.
 
  


Reply



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
Need Help Increasing Swap by creating a swap file froggo Red Hat 3 06-13-2006 08:04 AM
Linux swap / solaris not appearing as swap in Ubuntu? Erik_the_Red Linux - Newbie 1 07-30-2005 12:57 PM
How to unmount actual swap and mount a new(bigger) swap space? isaac Linux - Newbie 1 06-06-2004 01:23 AM
Kernel 2.6.2 options question - LOCKED options ? tvojvodi Linux - General 0 02-17-2004 04:23 AM
Difference between Swap Virtrual memory and Swap Parition Nappa Slackware 4 11-27-2003 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration