LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need for SWAP with 1 GB RAM? (https://www.linuxquestions.org/questions/linux-newbie-8/need-for-swap-with-1-gb-ram-531762/)

Aleksandersen 02-23-2007 01:51 PM

Need for SWAP with 1 GB RAM?
 
Hi,

I have read that there is no need for a SWAP partition on a computer with 1 GB RAM? Is this correct? What is the advantages/disadvantages with having such a partition? And how large should it be, if any?

Hardware: 1.83 GHz Intel Core 2 Duo (64-bits), 100 GB hard drive space, and 1 GB RAM.

Electro 02-23-2007 01:54 PM

Yes and no. Yes, you could get by with out swap. You will not last long with out swap. You can make 256 MB of swap and if you need more look up fly swapping.

b0uncer 02-23-2007 01:58 PM

SWAP is not (at least much) used as long as there is free RAM available; the moment RAM starts to get filled, SWAP is used. SWAP can be used, though, even if your RAM isn't full. But anyway if you ever do any tasks with your pc that consume memory resources, you probably want SWAP; it's a place on the harddisk where the kernel can -- without any actual defined filesystem -- store files temporarily, and that may (or may not, it depends) boost up the speed of your tasks.

With a 100GB harddrive you won't even notice having a SWAP partition as big as 1GB, and since it doesn't hurt you, I'd say it's good to have it there -- in case you find it useful one day. Another option would be to use a SWAP file instead of a partition, but I'd still pick up the partition way; 1G swap space should be big enough for you, and it's still only one percent of your whole HD space.

bskrakes 02-23-2007 02:15 PM

SWAP partition - is always a good thing to have
 
I would always have a SWAP partition, no questions asked! Like previous post, if you run out of ram then the system can use the SWAP file. If you are not hard up for space like having a 100GB HD then make a 1GB swap. The general rule has always been to double ram in the system. So if you have 1 GB I would make the system have a 2GB SWAP partition. Now this rule was probably meant more for the older systems and hardware but it would probably still be a very good idea to include in systems today!

Tinkster 02-23-2007 02:28 PM

There *is* no fixed rule as to whether you will or will not
need swap (to begin with or at some stage later in your linux
life). I've seen machines w/ 256MB never swap, and I've seen
machines w/ 2GB using lots of swap space. The only thing that's
always valid is that once your swap fills twice the amount of
your RAM you should go and buy more RAM :}

My current notebook has 1GB RAM and I have a 1GB swap-partition
(of which it currently only uses 0 MB).
My server has 256MB RAM and 756MB swap (of which it currently
only uses 90MB).

If I were to edit a video on my notebook things would change
dramatically, and so they would if I ran a complex query against
my PostgreSQL database on the server.




Cheers,
Tink

bskrakes 02-23-2007 02:35 PM

Sure you should probably buy more ram, but what is the point if you have a 100GB HD and can spare 2GB? It is not like this guy is running a huge database, unless I read something wrong and he has a Database that would require like 8GB of ram and two dual core processors.... just makes sense to double the swap size, especially if you have the space.... I think anyone who has worked with a Linux system professionally doubles there SWAP size.

See this link for some more GOOD info: http://www.hccfl.edu/pollock/AUnix1/Partitioning.htm

See this link for more info: http://forums.vnunet.com/thread.jspa?messageID=735750

YOU SHOULD DOUBLE YOUR SWAP SIZE, especially if you have a large database. At work we have a server that has 8GB of ram and we did double the SWAP size, mind we also have 1500 GB of space to work with. We have a large Database that requires POWER and MEMORY.

Ciao,
B

Tinkster 02-23-2007 03:17 PM

Quote:

Originally Posted by bskrakes
Sure you should probably buy more ram, but what is the point if you have a 100GB HD and can spare 2GB? It is not like this guy is running a huge database, unless I read something wrong and he has a Database that would require like 8GB of ram and two dual core processors.... just makes sense to double the swap size, especially if you have the space.... I think anyone who has worked with a Linux system professionally doubles there SWAP size.

If that's a response to my post you either didn't
read it or didn't understand what I am saying.

I never suggested that he use any given size. I
said if his SWAP exceeds double his RAM he should
get more RAM. And I'll stick with that: if you
use more that double your RAM for SWAP the
performance deteriorates DRASTICALLY.

Quote:

YOU SHOULD DOUBLE YOUR SWAP SIZE, especially if you have a large database. At work we have a server that has 8GB of ram and we did double the SWAP size, mind we also have 1500 GB of space to work with. We have a large Database that requires POWER and MEMORY.
And I'll bet it hardly uses half of that. If it
did your DBAs would be jumping up and down because
of the POOR PERFROMANCE.


Cheers,
Tink

bskrakes 02-23-2007 03:25 PM

No, may bad, I did not interpret your post the right way... sorry TINK. I couldn't agree more, never do more than double you swap size and 9 times out of 10 you won't use it but there has to be a reason why all linux people suggest it.

As for our work DB your right, it doesn't use the SWAP space or hardly at all. It never usually uses more than a few hundred MB's. I find that the SWAP is good for large HOT/COLD DB backups, thats when the SWAP is used most.

Electro 02-23-2007 03:46 PM

After 14 hours of use and counting, only 168 KB of swap is being used while folding@home and other programs are running. When I play a game like UT2004, swap gets used up to 8 MB even with out folding@home running.

The kernel comes with default parameters so use sysctl to adjust them to suit your setup. I have vm.swappiness set to 30 on my computer with 1 GB of RAM.

rshaw 02-23-2007 04:00 PM

"but there has to be a reason why all linux people suggest it."

folklore. it once made sense years ago when mainboards wouldn't support large amounts of ram. now it gets parroted by some as if it's "the law" .

Emerson 02-23-2007 04:06 PM

RAM + swap = 512 MB is OK for a Gentoo desktop.

AdaHacker 02-23-2007 04:44 PM

Is 1GB enough RAM to do without swap? Maybe, depending on what you do with your system. However, swap helps performance, among other things, so it's generally a good idea to have some, regardless of how much RAM you have.

If you don't want to commit an entire partition to swap, you can always use swap files. That would allow you to play with different sizes and see what works best for you.

PTrenholme 02-23-2007 05:13 PM

I've got 1Gb RAM on this laptop, and 2Gb swap. As far as I know, "swap" has never been used, but I saw no harm in allocating a couple Gb from my 80Gb drive. "Just in case."

custangro 02-23-2007 05:20 PM

Swap is always good. The rule of thumb is twice your RAM, but you don't HAVE to do this. With 1GB of RAM, I think 1GB or even 512MB swap is good. You don't HAVE to...but I suggest it.

Quakeboy02 02-23-2007 05:29 PM

I read a bit of that thread on swapping. It got old after awhile, and I think the bit that I read must have been out of date as compared to current kernels. I don't buy the full memory theory. Things have simply changed. http://gentoo-wiki.com/FAQ_Linux_Mem...2.6_kernels.29

If you simply MUST have a swap space, then spend another $100 on a 1GB stick, and put your swap space on a RAMdisk. If that doesn't make sense to you, then you understand why the need to have a swapspace on disk makes no sense to me. :)

custangro 02-23-2007 05:32 PM

Quote:

Originally Posted by Quakeboy02
I read a bit of that thread on swapping. It got old after awhile, and I think the bit that I read must have been out of date as compared to current kernels. I don't buy the full memory theory. Things have simply changed. http://gentoo-wiki.com/FAQ_Linux_Mem...2.6_kernels.29

If you simply MUST have a swap space, then spend another $100 on a 1GB stick, and put your swap space on a RAMdisk. If that doesn't make sense to you, then you understand why the need to have a swapspace on disk makes no sense to me. :)

Good point. But I look at it this way. Swap space is like RAM. It Dosen't hurt to add it :D

Hitboxx 02-23-2007 06:54 PM

The swap is hardly used on my system, its just for namesake.

jschiwal 02-23-2007 07:03 PM

If you have a laptop and want to use the sleep feature, you will need to have a swap partition. I don't know how large you will need to make it, but I suspect that it needs to be a little bit bigger than the ram on your system.

Hard drive space is a lot cheaper than ram space, so you can easily spare a gig or two of drive space these days. Today, a better rule of thumb for the average computer might be to use the same size of swap as you have ram, then sometime later when you find yourself using a number of programs at once, check what the swap memory usage is.

dasy2k1 02-24-2007 06:49 PM

i have 2G ram and 2G swap,
some programs seem to swap themselves out when idle to free up RAM

a great idea if ever i saw one

custangro 02-24-2007 08:09 PM

Quote:

Originally Posted by dasy2k1
i have 2G ram and 2G swap,
some programs seem to swap themselves out when idle to free up RAM

a great idea if ever i saw one


That's a good point too! Why waste RAM on a proccess that is idle?...Also I don't know if it's true an ALL distros...or even on Fedora 6. But when I instaleld Fedora 5, I wouldn't let me go on until I made a swar....it MADE me add swap space before I could install....

Quakeboy02 02-24-2007 08:19 PM

"That's a good point too! Why waste RAM on a proccess that is idle?"

Another point is why waste TIME paging a process out merely because it's idle? If memory's precious, sure, it's a no-brainer. But, if the machine has a couple gig of memory and most of it's free, what's the point?

AdaHacker 02-24-2007 10:30 PM

Quote:

Originally Posted by Quakeboy02
Another point is why waste TIME paging a process out merely because it's idle? If memory's precious, sure, it's a no-brainer. But, if the machine has a couple gig of memory and most of it's free, what's the point?

There would be no point, which is why the process won't be swapped out. Then again, because the kernel will try to fill up as much RAM as possible with cache, your system will typically have little or no truly free memory.

That's where the performance gain comes in. With no swap, that process that's been idle for the last three days has to stay in memory. With swap, you can move it out so you can get faster access to that data you were just working on 30 seconds ago. It's not a waste of time because swapping out the idle process gives another process faster access to its data.

Quakeboy02 02-24-2007 10:48 PM

Have you guys read this article on swappiness? This is a gentoo wiki page, but I believe it applies to all 2.6 kernels.

http://gentoo-wiki.com/FAQ_Linux_Mem...2.6_kernels.29

I've got 2GB on this machine, plus a 627MB swap space. I don't think I've ever seen the swap above 76K which is what it boots with. Memory usage rarely goes above 200-250MB, either. My problem here, I guess, is that I don't have anything to run that would cause this system to start swapping. I've got 2 kernel compiles and gimp running, along with Firefox and Gnumeric. Used memory is more or less 250MB, and used swap stays at 76K.

AdaHacker 02-25-2007 08:09 AM

Quote:

Originally Posted by Quakeboy02
Have you guys read this article on swappiness?

Yes, but that link is about tuning when the kernel swaps. I don't see how it lends any support to the "swap is unnecessary" theory. Perhaps you could elaborate?

Quote:

I've got 2GB on this machine, plus a 627MB swap space. ... My problem here, I guess, is that I don't have anything to run that would cause this system to start swapping.
Well, you could always send some of that extra RAM my way. ;) I only have 512MB of RAM and 267MB of my 1GB of swap is currently in use.

It sounds like you genuinely have more RAM than you can use, so you need little if any swap space. That's fine, but it doesn't tell us anything about whether or not other people need swap. For someone who has 1GB of RAM and uses more of it, swap might be helpful. It all depends on the user.

In general I'd say, "When in doubt, have swap." At current prices, a swap partition/file that's double your RAM will cost less than $3.00 in disk space. Worst-case scenario, it eats up some disk space that probably would have been unused anyway. And if you later find you don't need it, you can always reclaim the drive space, so no harm done.

Tinkster 02-25-2007 11:13 AM

Quote:

Originally Posted by Quakeboy02
"That's a good point too! Why waste RAM on a proccess that is idle?"

Another point is why waste TIME paging a process out merely because it's idle? If memory's precious, sure, it's a no-brainer. But, if the machine has a couple gig of memory and most of it's free, what's the point?

It still may be better used for caching files for
some other process(es) than having something that
was idle for a long time resident in RAM.



Cheers,
Tink

Electro 02-25-2007 12:54 PM

The maximum amount of swap space that can be allocated at once is a little less than 2 GB. If the computer has 2 GB and you are using the formula 2 X RAM_SIZE = SWAP_SIZE, creating a swap partition of 4 GB in size will not work. You need to create multiple swap partitions to hold 4 GB of space. It is not bad to create multiple swap partitions, but can be helpful to create instant RAID-0 to increase throughput when Linux needs to dump a lot of data at once from RAM to swap. To create instant RAID-0 with swap partitions, make sure the swap partitions are on separate IDE channels, size of the swap partitions are the same size, and the pri or priority value is the same value.

Swap is necessary because if Linux runs out of memory, it will be unresponsive until it gets more memory.

BTW, The majority of my RAM that is taken up is cache and buffers.

Quakeboy02 02-25-2007 01:51 PM

"Swap is necessary because if Linux runs out of memory, it will be unresponsive until it gets more memory."

Yes, agreed. But, let's consider: If you have 256 MB of RAM, you'll probably have 512MB of swap space. You're going to run out of memory at 768MB; period. If you have 2GB of memory and no swap space, 768MB is only a small percentage of your total memory availability. The 2GB machine will still be purring along when the swapping machine is thrashing itself to death.

When we're talking about small memory space machines, then, yes, swap is an issue that needs to be taken into account. However, when we're talking about a home vanity machine, swap is not an issue, because the memory isn't sized according to the process needs; it's sized according to the ego and wallet of the owner. Unless I start messing with something that takes a serious amount of memory, something that, I will note, would be UNRUNNABLE on a machine with 256MB RAM and 512MB swap, then I simply do not need swap. It will never be used unless I start monkeying with kernel variables.

Quakeboy02 02-25-2007 02:24 PM

AdaHacker says:
Quote:

Well, you could always send some of that extra RAM my way. I only have 512MB of RAM and 267MB of my 1GB of swap is currently in use.

It sounds like you genuinely have more RAM than you can use, so you need little if any swap space. That's fine, but it doesn't tell us anything about whether or not other people need swap. For someone who has 1GB of RAM and uses more of it, swap might be helpful. It all depends on the user.
Now, this I can agree with! It all depends on the user. In your case, if you added another 512MB stick of RAM, your swap would go away. If someone has a laptop with 168MB of RAM, then they have my sympathy all the way around. Not only is the system bus on a laptop probably miserably slow, but the disks are generally only 5400RPM and doing anything serious under those circumstances is miserable.

At my point in life, it's no longer exciting to see the hard disk thrashing away swapping things in and out of memory. I want the command to finish as soon as possible; preferably before I finish pressing the enter key. :) Large amounts of memory go a long way toward accomplishing that desire. A motherboard with a fast bus and quick drives helps, to.

To sum it up: I don't have a problem with swap space. What I do have a problem with is the knee jerk reaction, by some, that you have to have twice as much swap space as you do RAM. 'Tain't so for large memory machines. If you've got more memory than you'll ever need, you don't need no steenkin' swap. If your needs grow, it's easy enough to add swap later. But, really, sit down and ask yourself: "Self, are you going to run anything or any set of things that will need more memory space than you put in the machine?" If the answer is no, then swap is irrelevant.

Electro 02-25-2007 04:16 PM

Quote:

Originally Posted by Quakeboy02
"Swap is necessary because if Linux runs out of memory, it will be unresponsive until it gets more memory."

Yes, agreed. But, let's consider: If you have 256 MB of RAM, you'll probably have 512MB of swap space. You're going to run out of memory at 768MB; period. If you have 2GB of memory and no swap space, 768MB is only a small percentage of your total memory availability. The 2GB machine will still be purring along when the swapping machine is thrashing itself to death.

When we're talking about small memory space machines, then, yes, swap is an issue that needs to be taken into account. However, when we're talking about a home vanity machine, swap is not an issue, because the memory isn't sized according to the process needs; it's sized according to the ego and wallet of the owner. Unless I start messing with something that takes a serious amount of memory, something that, I will note, would be UNRUNNABLE on a machine with 256MB RAM and 512MB swap, then I simply do not need swap. It will never be used unless I start monkeying with kernel variables.

Do the following test and see if your system can handle with out swap and assume RAM capacity is 1 GB.

1) mount shmfs with the size of 2048 MB.
2) mount /tmp and bind it to /dev/shm. Also set permission to 1777.
3) Download source code of WINE.
4) Decompress WINE to /tmp
5) Start the compiling process of WINE.

Soon you will experience Linux is not responding.

This is a bad case scenario, but you eventually need swap.

If Suspend to RAM is used, taking the amount RAM and then double it for swap space is a good start. More may need to be allocated if you are intend to upgrade the RAM in the future.

Though it comes down to planning the partition scheme so the amount you provided for swap and other partitions is what you are stick with unless you do not mind backing up your data to resize the partitions to better suit your setup.

Quakeboy02 02-25-2007 04:38 PM

"This is a bad case scenario"

No, it's just a bad example. What you are describing is a test that won't run on a system with 1GB ram and no swap and trying to draw implications from that against a 1GB system with swap. Do the test case between a) 1GB ram and 1GB swap vs b) 2GB ram and no swap. You will be much happier with the 2GB ram system under all circumstances, including those where you have to add swap, than you will be with the 1GB system running identical processes. The important thing for judging what mix of processes can be run at the same time is RAM plus SWAP. A system with 3GB RAM will run the same mix of concurrent processes as a system with 1GB RAM and 2GB swap. But, you won't be happy with any machine that has 2GB swapped out.

Added:
In the mid 90s, I had the good fortune to move from ACP/TPF (Airlines Reservations Programming) to the Open System department (Unix). I wrote an application to replicate the online res system passenger records on a Unix machine. The records came to my system as tape dumps. I couldn't rely on order, so I did an in-core (swap space, actually) sort of the data before doing the database updates. I well remember what it was like to run a small memory system with a large swap space.

Electro 02-26-2007 05:17 PM

The test will run but it will not run for long until more memory is added. After more memory is added, it will eventually continue. I have done it, but I was not logged in as root create a swap file to provide more memory. Linux just pauses when memory is 100% used unlike in Windows which will freeze before it ever hits 100% of memory usage.

On my 80386DX-40 with 8 MB of RAM, I ran a program that requires 16 MB. It ran because swap memory is there to take up the slack. Yes it is slow, but it ran it.

Sure we can upgrade our computers with a terabyte of memory, but when bloated programs are used we still need swap memory to take up the slack.

The RPM of the hard drive rarely has no relationship of how fast a hard drive can work. There are two categories for hard drive that can be quick. One is accessing time (may include latency from the firmware, controller, filesystem, and data bus). The other is bandwidth or throughput. If you want the fastest drive, pick the drive with lowest accessing times. Read or write big files in hurry, buy hard drives that has the highest throughput. A 5400 RPM hard drive can actually be better than a 7200 RPM hard drive because it produces less errors, produces less heat, consumes less energy, and provides more space. RPM of the hard drive is there to provide a sustain rate. If a manufacture took actuator and heads from a SCSI hard drive and place it in a IDE hard drive that has a spindle rate of 5400 RPM, the drive will be a lot faster than any 7200 RPM hard drive. Though a solid-state hard drive could be used but the cost will turn a wallet into ash.

E-disk - http://www.bitmicro.com/
Gigabyte Technology I-RAM - http://tw.giga-byte.com/Products/Sto...ame=GC-RAMDISK

Linux has issues with the I-RAM but there is video on Google Video that shows how fast Windows can boot up and how long it takes to find files.

Quakeboy02 02-26-2007 05:26 PM

"Sure we can upgrade our computers with a terabyte of memory, but when bloated programs are used we still need swap memory to take up the slack."

You're simply not going to accept that the total memory available to you on your computer is more or less the amount of RAM plus the amount of swap space, are you? I give up.

"If a manufacture took actuator and heads from a SCSI hard drive and place it in a IDE hard drive that has a spindle rate of 5400 RPM, the drive will be a lot faster than any 7200 RPM hard drive."

There are a lot of things that "could" be done in this world. The fact is that they aren't. 5400RPM drives are slow as compared to other drives with a faster revolution. The slower speed means that the bits go by more slowly. If they could compact the bits more on the disk, an equivalent 7200 RPM drive would always be faster. When I speak of 5400RPM drives, I am speaking about laptop drives. They generate less heat because the heads move move slowly. This contributes to slower access. Unless you can point to a specific 5400RPM drive that is blazingly fast, or even as fast as an equivalent 7200 RPM drive, then I remain unconvinced.

Electro 02-26-2007 06:24 PM

Quote:

There are a lot of things that "could" be done in this world. The fact is that they aren't. 5400RPM drives are slow as compared to other drives with a faster revolution. The slower speed means that the bits go by more slowly. If they could compact the bits more on the disk, an equivalent 7200 RPM drive would always be faster. When I speak of 5400RPM drives, I am speaking about laptop drives. They generate less heat because the heads move move slowly. This contributes to slower access. Unless you can point to a specific 5400RPM drive that is blazingly fast, or even as fast as an equivalent 7200 RPM drive, then I remain unconvinced.
Faster the RPM speed, further the bits are. Slower the RPM, closer the bits can be. A 5400 RPM hard drive can pack a lot more data than a 7200 RPM hard drive. The reason for this is how fast the head can detect the change in magnetic field.

The heads do not move around the disk. They only move in two directions (in and out). The actuator that moves the heads can be changed with a better and faster version.

You do not understand accessing time versus throughput of hard drives. If you understand them, you will understand that RPM only effects throughput but not accessing times.

Quakeboy02 02-26-2007 06:57 PM

"Faster the RPM speed, further the bits are. Slower the RPM, closer the bits can be. A 5400 RPM hard drive can pack a lot more data than a 7200 RPM hard drive. The reason for this is how fast the head can detect the change in magnetic field."

Then why do they bother making 7200 and 10,000 RPM drives? Could it be because they actually are faster? This week, perhaps they can't use the same bit density on a 7200RPM drive that they can on a 5400RPM drive. Next week would probably be a different story, though.

"You do not understand accessing time versus throughput of hard drives. If you understand them, you will understand that RPM only effects throughput but not accessing times."

Can you pick two specific hard drives to talk about instead of woulda, coulda, shoulda? The drives should be relatively the same size, but I'd accept an 80GB drive vs a 100GB drive. The cost to the consumer should be relatively the same, but I'd accept a 5400RPM drive that cost 10% more than an equivalent 7200RPM drive. In practice, just show me a 5400RPM drive that outperforms a relatively equivalent 7200RPM drive; where you're not picking an obsolete bottom of the barrel 7200RPM drive vs a state of the art shiny new 5400RPM drive. To be fair, both should have the same interface (PATA or ATA or SCSI), and more or less the same cache size, though cache is normally disabled in benchmark tests. Show me the real world case where the 5400RPM drive is faster and I'll cede the point.

Tinkster 02-26-2007 07:24 PM

Girls, can you please take that HDD discussion out via e-Mail? It doesn't
belong to the thread, and there seems to be lots of emotion involved at
this stage, which won't do the discussion any good either.



Thanks,
Tink

Quakeboy02 02-26-2007 07:37 PM

Sorry. You're right, of course.

Electro 02-26-2007 07:54 PM

I do not respond by email on these type of topics.


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