Jump to content

how to speed up linux


ilia_kr
 Share

Recommended Posts

* Have you noticed how slow your computer is after after unzipping a big file?
Nope
* Perhaps you can also notice this effect overnight as well — you return to your computer, and every open application takes a while before they behave snappily again.
Not really
* Do you use Amarok? Then you’ll notice this effect after Amarok has finished scanning your music collection.
I don't use amarok. :P
This problem happens all the time.
Huh? :huh:

 

MHO: Don't turn off swap. I don't know what the guy did to his machine, but mines are not choking and are significantly faster and more stable than Windows XP. I turned of swap once and it was a huge annoyance once my system needed the swap space (and I do have 1 GB Ram!). Furthermore, I haven't noticed any significant differences when setting swappiness e.g. to 20 instead of 60.

 

I always prefer stability over exterme speed. I cannot risk my system to go down at will. That said: Try the suggested things only on a secondary system/partition before considering to apply them to your main system.

Link to comment
Share on other sites

Don’t believe me? If you have two gigabytes to spare on your / partition, then run the following commands in order:

 

sync

echo 3 > /proc/sys/vm/drop_caches

dd if=/dev/zero of=/tmp/testfile count=1 bs=900M

find / > /dev/null

cp /tmp/testfile /tmp/testfile2

 

Don’t do anything else while they run. Yes, they will take a while. Be patient. What this does is rather simple: creates a big 900 MB file, attempts to find all files on your file system, then copies the file one more time.

 

Finished? Now do something with your computer. Un-minimize your minimized applications, do something relating to your everyday work…

 

What happened? Excruciatingly slow, right? Did you notice how applications were hung for a while, while the hard disk light blinked frantically?

 

OK, let’s tune swappiness. As root, run:

 

sysctl -w vm.swappiness=1

 

and retry the commands above. Big difference, right?

 

 

What happens to your systems if you try this?

 

(A side note, indeed, do not turn off swap.)

 

I see what he means, it happens a lot on my internet/audio server.

If I leave it for a few days, come back and try to use the konqueror on it, it really takes ages to react.

Sure, the best way to deal with this is to add ram - if it happens often.

If not, it shouldn't really be a big nuisance. But then again, my old server doesn't need upgrading, it needs getting replaced...

Link to comment
Share on other sites

If you run out of ram or if your ram fails for whatever reason, you have swap as a backup. Now imagine the systems ram failing and not having any swap. The system will freeze immediately and your work might be lost. Not a good idea imho.

Link to comment
Share on other sites

If you run out of ram or if your ram fails for whatever reason, you have swap as a backup. Now imagine the systems ram failing and not having any swap. The system will freeze immediately and your work might be lost. Not a good idea imho.

 

I do not agree with you. Let's say i have 256mb of ram and another 512mb of swap, in total i have 768mb, less than amount of ram on an average up-to-date pc. Lets suppose i ran a process that swallowed all of that 768mb. The system will freeze? In that case it will be one major bug for an OS - i mean there should be some mechanism that prevent RAM overflow. A good programmer would have that in mind and i suppose that at least one of the whole bunch of people who develop linux kernel could have think of that.

Link to comment
Share on other sites

I keep a small swap partition (256MB) for every system with 512M (or more) of physical RAM.

Con Kolivas has explained in the past quite convincingly that while no swap at all isn't totally sane, the "RAMx2" rule of a thumb is wrong - factly a remnant of the ole "good" days of Linux.

 

I'm now just curios, as everybody claim that not using swap is bad, but none knows exactly why. I would like to hear a proffessional's opinion. scarecrow, can you post a link to wat Con Kolivas said, or it is too old?

 

About the RAMx2 rule - i think it is another Linux myth, although Fedora installer will warn you if you leave less swap then twise a RAM.

Link to comment
Share on other sites

Ram x 2 rule is from the times that whatever you did with your system, some swap would always be used.

 

Use

free

to check; with 1GB of RAM you should see that no swap is used.

 

Also, to be able to suspend to RAM it's nice (but again, since some time apparently not absolutely required) to have the swap larger than the RAM.

If your swap is not used, and larger than RAM, doing a suspend just means writing out the ram data to swap partition. If the swap is used or smaller than RAM, the kernel first has to make place to be able to suspend...

 

Be aware that many many embedded Linux systems have no swap at all.

It just limits the system a bit more, you'll more quickly run into memory limitations.

 

 

Having lots of swap will not hurt your system.

 

 

You may also want to make sure you place your swap partition correctly.

If you know you'll be using it a lot (say, on a laptop where you'll be using suspend to disk) you want it to be at the beginning of the harddrive, i.e. hda1.

If you're not going to be using it (2GB of RAM, no suspend to disk / not a laptop), put it at the end of the drive.

 

On my laptop, the drive throughput is 40MB/s at the start, and down to 22MB/s at the end (160GB ATA drive), both swap are 2GB in size.

I have used either as swap partition to suspend & resume, and it takes twice as long if I'm using the swap partition at the end of the drive.

BTW you can use dd to measure throughput.

 

Does a large swap hurt? Well, if you put 10GB of swap at the start, and then the system root '/' partition, your apps will be started slightly slower than if you had only 1GB of swap. It seems linear with the drive, likely around half the speed at the end compared to the start of the drive.

 

And yes, this is perfectly normal; unlike cds/dvds, harddrives are written from the outside to the inside, and they rotate at a fixed speed; at the same time, the 'length' of path per data is the same, so in one revolution the data the heads read at the start of the drive is more than one revolution at the end.

No magic there.

Link to comment
Share on other sites

SWAP!

 

Too much? Doesnt hurt, but just unneccesarily wastes hdd space.

 

How much is suitable? The 2* rule is complete nonsense nowadays.

 

Swap is used

a- When memory hasnt been accessed for long periods of time so data can be evicted and memory used for other things

b- When memory usage is high.

But mostly for B. Swap usage is tunable, which means at what point a system will swap will may vary somewhat distro to distro.

 

So think of what applies to your usage.

 

For basic usage, web browsing, email, media playback, editing, etc, "b" isnt going to occur often, and "a" will depend on usage habits. So not much is needed. Unless you have >1gb ram, about 512mb is good as a fallback, but you could safely go with less.

 

For *frequent* heavy usage such as compiling, encoding, heavy multitasking, video/audio editing 3D games, heavy processing, it's best to have some swap, as both "a" and "b" will come into play, particularly "b". Here I'd suggest 1gb as a fairly good all round value.

 

Keep in mind, Low ram systems and 'extremely heavy' usage systems may need more. If you plan to use suspend, make swap equal to your ram. Though things scale here, higher load systems should and probably will have more ram, and much lower ram systems (<=256mb) should be running older or lighter or less software.

 

If you don't want to think about it, 1gb is a good easy default. On many systems and usage patterns it may be overkill but the hdd usage is generally insignificant.

 

James

 

me: I run both my laptop and desktop without swap happily, i don't do heavy stuff often, and my ram suffices when I do. Laptop currently has swap for suspend.

Link to comment
Share on other sites

Well, I managed to get my system close to its limits some weeks ago. Sharing some ten bittorrents at the same time while doing heavy graphical editing (200MB big mulit-layer files), having the webbroswer, email and instant messanger open and listening to music, my system started to choke a bit. 1 GB RAM was used up, almost 1,6 of my 2 GB swap partition were in use. Had to kill some bittorrents in order to get the system a bit more responsive again. That said: I don't think that the swap=2xRAM rule is out of place. But maybe I am just an old paranoid guy...

Link to comment
Share on other sites

Well, I managed to get my system close to its limits some weeks ago. Sharing some ten bittorrents at the same time while doing heavy graphical editing (200MB big mulit-layer files), having the webbroswer, email and instant messanger open and listening to music, my system started to choke a bit.

200mb files count's as very heavy usage :)

 

 

That said: I don't think that the swap=2xRAM rule is out of place. But maybe I am just an old paranoid guy...

I can't see how it makes much sense at all now.

128mb ram, 256mb swap

256mb ram, 512mb swap

512mb ram, 1gb swap

1gb ram, 2gb swap

2gb ram, 4gb swap.

4gb ram, 8gb swap

 

The 256/512 and 512/1gb are only ones that really work out well, but that's because they work out to a common sense size of 512-1gb. Either side of that, it becomes trash for the average system. Over 1gb ram and most peole could just go without swap altogether.

 

2* is an arbitrary function from another era, and has no technical merit now.

 

James

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...