Does running without swap memory hurt performance?

Using applications, configuring, problems
Message
Author
illidan.modeler
Posts: 37
Joined: Mon 02 Sep 2013, 17:22

#21 Post by illidan.modeler »

musher0 wrote:This is what I would suggest, then:

Download and unzip the slaxsave.zip file attached above.
Unzip save512.zip. A slaxsave.dat file of 512 Mg will be unpacked.
Rename this slaxsave.dat to pupswap.swp.
Move this pupswap.swp to /mnt/home.
and at next boot you will have a 512 Mg swap file.

I do not wish to start an argument, but in my experience,
it doesn't make sense to put your swap file in / , since that
will only occupy space on your pupsave file.

I believe the proper place for it is on a disk partition
such as /mnt/sda1 or /mnt/sda2 (which are traditionally
the hard drives) or even on your USB drive if you
have space enough there.

Regards.

Code: Select all

#if no go, try for a swap file...
 if [ "$SWAPON" != "yes" ];then
  SWAPFILE="/pupswap.swp"
  if [ -f /initrd${PUP_HOME}${SWAPFILE} ];then
   echo -n "Loading swap file ${SWAPFILE}..." >/dev/console #loading swap file
   swapon /initrd${PUP_HOME}${SWAPFILE}
   status_func $?
   [ $? -eq 0 ] && SWAPON="yes"
  fi
  if [ -f $SWAPFILE ];then
   echo -n "Loading swap file ${SWAPFILE}..." >/dev/console
   swapon $SWAPFILE
   status_func $?
   [ $? -eq 0 ] && SWAPON="yes"
  fi
 fi
I found this script snippet in /etc/rc.d/rc.sysinit, following the suggestions of Godt. I think I should assgin a swap file under root path accroding to this piece of script. Maybe I was wrong for I did not read the script as a whole and I might make a misunderstanding.

I just tried to make one swap file under /mnt/home. It works fine. Great.

Code: Select all

cd /mnt/home
dd if=/dev/zero of=pupswap.swp bs=1024 count=102400
chmod 600 pupswap.swp
mkswap pupswap.swp
swapon -v pupswap.swp
These commands make a swap file of 100M. Change count according to your need.

Code: Select all

swapon -s
free
to see the effect and result.
Laptop1(Core i3, 2G , 320G ): Ubuntu 12.04
Laptop2(Celeron SU2300, 2G , 320G ): Lubuntu 13.04
Laptop3(Turion64 MT28, 1280M, 40G): Bodhi 2.4 with E17
External HDD1: SalixOS 14.0 with fvwm
External HDD2: Blag Linux and GNU 140k
Pen Drive: Slacko 5.6

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#22 Post by sunburnt »

Generally a swap partition or file is a good idea.
But with 2 GB or more of ram, then no swap is needed.

Having no swap is faster as the cpu isn`t doing R/W to the slow H.D. all the time.
And if the O.S. is setup with no initramfs, then the cpu and ram don`t have it either.

But as said, enough ram is needed, at least 512 MB, but I`d say 1 to 2 GB is better.
To run even a few apps at one time have 1 GB, and maybe more for heavy use.
.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#23 Post by musher0 »

Hi, sunburnt.

FWIW, I read somewhere (was it a post by Flash?) that you needed a swap partition or file even if you have enough RAM and the swap is not used, because it is "a habit" of Linux. (Coded in the kernel?)

Maybe it's psychological, but I find that the old Windows rule of (the size of static swap should equal the size of RAM x 2.5) gives the best performance and speed on my older machine.

Probably no technical basis to it, but still...

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#24 Post by amigo »

The best advice is to always have at least even a tiny bit of swapspace -whether it be a partition or as a file. In fact, even as a file or partition in a RAM-disk or tmpfs.

The reason is that in the case that all RAM is used, the kernel must move something out of the cache into swapspace -otherwise an OOM condition occurs (Out Of Memory). There is a kernel config option which enables the kernel to ask you which process to kill -or if this is not enabled you get a hard freeze. 'All RAM used' means that both running processes and those in cache are occupying the net RAM available -a RAM-disk or tmpfs are still separate. That's why even a small swapfile in such dedicated RAM can save your bacon.

Editing huge sound or video files or compiling huge, complex sources can definitely exhaust RAM of 1-2GB -just yesterday I read of something that needs 8GB swap+RAM to compile and link.

The key to a usable size for a swap device lies in the minimum configurable value= 4K -exactly one page of memory. If you run a machine with just 256MB of RAM, you can easily run out of RAM just from opening a few tabs in the browser at the same time. Having an extra 16-128MB of swapspace can avoid lots of lockups and really slow program response. I think a minimally-useful swapspace should be at least 512K for emergencies -that's 128 pages of memory.

While technically true that data input/output to a swap *partition* is faster than to a swap *file*, one would be hard-put to measure the speed difference. Accessing a swapfile takes a bit longer as the file must be accessed as part of the filesystem instead of directly as a partition.

There are other scenarios which can cause OOM conditions other than those described above -every now and then the kernel may decide to swap a page or two out -even when there appears to be 'available' RAM.

Under any heavy swapping or OOM conditions the machine is definitely going to slow down.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#25 Post by mikeb »

Hmm in one situation I did notice the kernel automatically killing processes to try and save ram space (firefox and then thunderbird disappeared)... might have been a slax kernel but not 100% on that. I assume puppy kernel do not have such an option set as hard loacking is what i usually get with them. Perhaps the killing processes should be included as standard since the makeup of puppy is more likely to use up ram than other more conventional systems.

swap in tmpfs...hmm so basically if the kernel can warn or kill automatically then this will happen while ram still exists even though ram is used for the swap space as the kernel will trigger its low ram mechanism(s)... is that the basic idea?

My swap calculation is usually swap = 1GB - real ram... or whatever the ideal working ram space is considered. Our 512mb machines have 512mb swap..the 1GB + ones I don't bother...seems to be ok with OUR usage. Its also worth seeing if applications can be tweaked or replaced to reduce ram usage..browsers come to mind..their usage is not set in stone.
Also..probably repeating myself..puppy can use ram for the filesystem so avoid filling it up needlessly in such configs.

mike

mike

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#26 Post by sunburnt »

Yes, I`ve understood swap should be about approx. 2x the ram size.

I`ve wondered if the kernel`s swap code handled out-of-swap conditions gracefully.
As amigo says, no swap is terminally fatal. I had 256 MB and over 3 Firefox tabs was death.

But I still think that with at least 1 or 2 GB of ram, having no swap would be noticeably faster.
Having 4 GB of ram would seem to be best unless you`re a power user.

And coping Puppy`s main SFS file to ram may allow fast app. loading, but it`s a waste of ram.
.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#27 Post by mikeb »

And coping Puppy`s main SFS file to ram may allow fast app. loading, but it`s a waste of ram.
actually doing that along with the save avoids those dirty shutdowns... ;)

mike

gcmartin

#28 Post by gcmartin »

What Amigo shares is very accurate.

The OP's question on swap missing to hurt performance is contained in his answer.

On the other note, I have and continue to run FATDOG. For those who are unaware, the most recent release, OOTB, will NOT implement a SWAP whether or not it is present as either a partition or a file. Thus, to use SWAP, requires the users to know to turn it on.

I cannot detect ANY differences in desktop operations with or without the use of SWAP. The primary reason why: SWAP operations are handled as background operations. The systems (whether Linux/Unix/Macs/Windows/Mainframes) do NOT wait for RAM to fill before deciding to use RAM protect operations. This is the primary reason why it is advised and the primary reason, it is NOT noticed during system operations. If there exist some penalty, its not evident to the user or most system application operations. I always run with SWAP to provide the kind of protection that Amigo already has mentioned not to mention that I do NOT see a negative downside in my system's performance or its use.

There are some operations where a dedicated machine would want to have ALL the horse-power aimed for an application's operation. One I can think of is a PC dedicated to Music recording while a band is playing, live. There are probably some similar kinds of others, too.

Beyond that, the SWAP benefit is there, if used.

Hope this helps

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#29 Post by sunburnt »

Hi mikeb; Yes, but probably only because Puppy`s scripts don`t handle it properly.
I`m sure it can be done without any problems, running in ram is no different really.

Hi gcmartin; There is of course a huge difference in the speed of ram compared to a HD.
In a SFS file test I copied a 500 MB folder and then an SFS file with the same contents.
Because the SFS file was smaller it`s "contents" copied almost twice as fast as the raw files.
It not only demonstrates how slow a HD is, but also what a big improvement a Squash file is.

If initrdfs used a compressed swap partition or file, then it`s be faster. But it doesn`t have one.

A Squash file in ram may be slower than raw files are as amigo ( I think...) pointed out.
But a Squash file does save approx. 3 times the ram as compared to raw files. No viruses too.
.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#30 Post by mikeb »

The hijack bunnies are at it again :D
Hi mikeb; Yes, but probably only because Puppy`s scripts don`t handle it properly.
I`m sure it can be done without any problems, running in ram is no different really.
DEFINATELY don't handle it properly. Well it was either a total rewrite or use slax. (control has to be handed back to the initrd...with cpio thats not possible) Was much easier to have saves in ram. Having done that then puppy can run without any hard drives mounted and flash stick removed...dirty shutdowns simply cannot happen that way. I did add a couple of lines to unmount loaded sfs files at shutdown too in case apps were added while running. I suppose my pups are around the 100mb or less so don't take up as much room.
regards
mike

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#31 Post by sunburnt »

For once I think we`re actually staying within the realms of the thread..!

# 2 thoughts:

1) Use a ramdisk ( image ) instead of initrdfs ( cpio ) like the old Puppies did ( 0 - 1 series ).

2) Bare-bones Puppy with no-install swappable apps. No bloat and easy app. management.

# Total ram used with main SFS loaded into ram is ~ 70 MB or so, not 130 to 170 MB.
.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#32 Post by mikeb »

Yes perhaps so but we should send a postcard to the op.....

Well my puppy 4 and lucid thingies are all initrdfs.... that at least gives the possibility of reverting to the initrd to shut down. Keeps the init script simpler too and I like being able to access the initrd file system once booted. I dynamically create all the pup_ro(n) so its simpler for that too. Not sure if cpio initrd can do a boot loadiing splash either ... me like pretty.
Cpio initrd like busybox init is great for embedded systems though seems to leave us a little short changed with a mini distro.

100MB or less..my sweet spot... we might even be in agreement :)

mike

Post Reply