LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-28-2006, 03:19 AM   #1
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,375

Rep: Reputation: Disabled
virtual memory


How do I make sure Linux has as much virtual memory as it needs? Will it automatically use HD space for virtual memory, or must I tell it to do so? And either way, if an operating system can use virtual memory, then isn't it possible to have a large amount of RAM without adding any more RAM boards, limited only by the amount of free HD space? I think I've never understood this about virtual memory.
 
Old 06-28-2006, 06:43 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Linux uses the "swap" partition for this. If you don't define one, Linux will take up as much of your root partition as it needs (probably, haven't checked it).

See also
Code:
man swapon
Quote:
if an operating system can use virtual memory, then isn't it possible to "have a large amount of RAM" without adding any more RAM boards, limited only by the amount of free HD space
Why did you think virtual memory was invented? Exactly for this reason: to extend the always limited amounted of physical RAM by using up disk space (which is usually MUCH larger) instead.
Any program you run will actually get to see an amount of memory which is always <= the sum of the amounts of physical memory and virtual memory (<= hard disk free space).
Downside is that accessing the hard disk is much slower than accessing a memory chip, so your system performance will degrade if your system is constantly swapping (=using virtual memory).

As to how operating systems (OS) handle virtual memory, that's a whole different story.
 
Old 06-28-2006, 07:33 AM   #3
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Quote:
If you don't define one, Linux will take up as much of your root partition as it needs (probably, haven't checked it).
No, it won't. The kernel likes to swap out certain things occasionally, even when you have available physical memory and should you not have a defined swap partition or swap file you will see out of memory errors.

Quote:
accessing the hard disk is much slower than accessing a memory chip
Correct. Many, many, many times slower, thousands of times slower. Swapping constantly is something to avoid at all costs.
 
Old 06-28-2006, 09:57 AM   #4
tamoneya
Member
 
Registered: Jan 2005
Location: MA
Distribution: Ubuntu 7.10
Posts: 558

Rep: Reputation: 31
what you need to do to get more is to make another partition using fdisk or something. Then you should run 'mkswap /dev/hdax' and 'swapon /dev/hdax' assuming that your partition is on the master primary ide.
 
Old 06-28-2006, 11:38 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
A good rule of thumb is this ...

(1) Chips are cheap now. Find out how much physical RAM your machine can hold and stuff it.

(2) Allocate swap partitions (if possible) about twice the size of physical RAM.

(3) If you have more than one drive, especially on different channels that can perform I/O simultaneously, distribute your swap space across several spindles.

Extraordinary use of memory by an application strongly suggests the presence of "a bug."
 
Old 06-28-2006, 01:15 PM   #6
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,375

Original Poster
Rep: Reputation: Disabled
As regards physical RAM, I am in a difficult position. My six-year-old PC has 256K of RAM, and apparently only two physical RAM slots, both occupied.
 
Old 06-28-2006, 01:49 PM   #7
Michael_aust
Member
 
Registered: Aug 2005
Location: Lancashire (United Kingdom)
Distribution: Debian Etch, on 686 machine.
Posts: 509

Rep: Reputation: 31
Quote:
Allocate swap partitions (if possible) about twice the size of physical RAM
I read that you should not go above a 512mb swap partition, does this rule still apply, because with the above if you had 1gb memory then you would have a 2gb swap.
 
Old 06-29-2006, 01:55 AM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
@Michael_aust, the "swap size = 2x RAM size" rule is just a rule-of-thumb. If you really need 2GB (which is quite a lot) of swap when you already have 1GB of RAM is doubtful, but it really depends on what you want to do with your system. For a basic desktop system with no fancy games or graphical stuff, your 1GB RAM should do most of the work anyway, so you don't really need the 2GB of swap.
But, as hard disks grow in size constantly, why not just apply the rule anyway? What harm will losing 2GB do to you, if you have a hard disk of 100+ GB?
If you apply the 2xRAM size rule, at least you should be safe in practically any situation.
 
Old 06-29-2006, 02:01 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
@newbies_forever:
Surely you mean 256MB of RAM, not 256KB? The days of measuring RAM in KB are long gone, I'd say...

Even though your physical slots are occupied, you could still consider switching one (or both) of the DIMMs for a larger one. However, if you do so, keep in mind:
-the operating frequency of your system bus and of your memory.
For optimal operation, the FSB frequency should be an integer multiple of the operating frequency of your
memory.
-any limitations on RAM size imposed by your motherboard.
-keep an eye out for the RAM technology (DRAM, SDRAM, etc) as this can make quite a lot of difference performance-wise.
 
Old 06-29-2006, 10:14 AM   #10
Michael_aust
Member
 
Registered: Aug 2005
Location: Lancashire (United Kingdom)
Distribution: Debian Etch, on 686 machine.
Posts: 509

Rep: Reputation: 31
Quote:
But, as hard disks grow in size constantly, why not just apply the rule anyway? What harm will losing 2GB do to you, if you have a hard disk of 100+ GB?
If you apply the 2xRAM size rule, at least you should be safe in practically any situation.
II thought if you have a stupid amount of swap space that you will most likely suffer performance problems because the system will spend all of its time swapping (taken from a book im reading which claims this is called thrashing)

is this correct, would thios end up happening?
 
Old 06-29-2006, 10:56 AM   #11
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Quote:
Originally Posted by Michael_aust
II thought if you have a stupid amount of swap space that you will most likely suffer performance problems because the system will spend all of its time swapping (taken from a book im reading which claims this is called thrashing)

is this correct, would thios end up happening?
Not unless you run out of physical memory. The kernel will always choose physical memory over virtual but swap isn't _just_ for virtual memory, the kernel also swaps out other data which is just how it works, it's not negatively impacting performance. The negative hit comes when you run out of physical memory (RAM) and the kernel has to use virtual memory (swap) because of the reasons mentioned above.
 
Old 06-29-2006, 01:07 PM   #12
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,375

Original Poster
Rep: Reputation: Disabled
Yes, Timmeke, I meant MB, not KB.
 
  


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
Virtual Memory Related ramkumarv Linux - General 1 03-20-2006 07:09 AM
Virtual Memory usage redhatrosh Linux - Software 1 03-20-2005 01:22 AM
C and virtual memory abdobl Programming 3 10-04-2004 12:14 PM
Virtual Memory? mikeshn Linux - General 11 01-15-2004 01:47 PM
RH 8.0 Mapping Virtual Memory to get access to VMIC Reflective Memory PCI card. Merlin53 Linux - Hardware 0 05-05-2003 12:50 PM

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

All times are GMT -5. The time now is 01:26 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