LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 05-19-2009, 07:38 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Rep: Reputation: 32
SWAP partition, is it necessary????


Hello,

I have a embedded device with kernel 2.6.24.7-rt26 and compact flash WITHOUT swap partition and 256 Mb of RAM.
Well, when application startup, at the begin it works fine, but a piece of time later, application does not work fine.

After check all my configuration, I see that compact flash have not SWAP partition, then I made a new compact flash with SWAP partition. After do it, I run my application and I notice that it works fine.

So, what is the difference to use or not SWAP partition??

Thank very much.
Best regards.
 
Old 05-19-2009, 07:40 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,496

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
Take a look at
http://www.linux.com/news/software/a...nux-swap-space
 
Old 05-19-2009, 07:52 AM   #3
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
not necessary

SWAP partitions are not necessary, but depending on what you do, and your hardware (mostly RAM), you'd better have one.
If you have lots of programs running, you eventually run out of RAM memory(if you don't understand why, you'd better start by stfw for this), when that happens you'd just the data you are not going to use for a while in that SWAP partition, and retrieve it when needed again.
So, most of the time, you'd need one. But of course if you don't have such worries (have lots of RAM memory, etc) you may not need it.
You know you can actually just make a swap-file in your linux partition and mount it as a swap partition too.
 
Old 05-19-2009, 09:47 PM   #4
titan22
LQ Newbie
 
Registered: Apr 2009
Posts: 17

Rep: Reputation: 3
YES. Swap effectively prevents a machine from getting into out of memory at certain level. Many programs die or show problems at low memory scenario. The example below should give you a clear picture why. (You won't see this clear example in any text book)

Let's assume you have 300 programs in disk, 2 pages each. Each program mallocs 2-page buffer to process data. Each program needs 4 pages of memory when it is running (2 pages for code, 2 pages for data).

Given 100 pages of RAM the system can run approximately 25 programs concurrently. Anything above that VM needs to reclaim memory by kicking out programs. Let's see what happen when more than 25 programs run.

=== Scenario 1: (no SWAP)
disk: 1000 pages (0 pages for swap, 1000 pages for files and directories)
Memory 100 pages

Without swap the buffers have to stay in memory. Only memory used by code can be freed because the can be refetched from disk. Eventaully your 100 pages of memory will be filled with buffers, only 2 page is left for the running program. Total 49 programs can be running.

memory (2-page buffer * 49 + 2-page code).

=== Scenario 2: (with SWAP, swap space == memory size)
disk: 1000 pages (100 pages for swap, 900 pages for files and directories)
Memory 100 pages

With 100 pages of swap space 50 2-page buffers from 50 programs can be stored there. Total 99 programs can be running concurrently.

memory (2-page buffer * 49 + 2 page code)
swap(2-page buffer * 50)

=== Scenario 3: (with SWAP. swap space = 2*memory size)
disk: 1000 pages (200 pages for swap, 800 pages for files and directories)
Memory 100 pages

memory (2-page buffer * 49 + 2 page code)
swap(2-page buffer * 100)
149 programs can run concurrently.


================================================
The system starts to experience out of memory at 50th program without swap, at 100th program with one time memory size swap, 150th with two times memory size swap. That says a system without swap hits out of memory much easier and programs that cannot handle out of memory start to show problems.

Last edited by titan22; 05-20-2009 at 08:11 AM.
 
Old 05-20-2009, 07:29 AM   #5
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Original Poster
Rep: Reputation: 32
Very clear

Thank very much.
 
Old 05-22-2009, 04:47 PM   #6
nini09
Member
 
Registered: Apr 2009
Posts: 976

Rep: Reputation: 67
Can the feature, save page to disk, be turned off because a lot of embedded system doesn't have disk on system?
 
Old 05-22-2009, 07:42 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,103

Rep: Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985
You have the option of not configuring swap in the kernel.
I wouldn't normally recommend it, but can certainly see the applicability for embedded. Mind you, it makes memory sizing and decent (non-leaking) application code even more important.
 
Old 05-22-2009, 08:10 PM   #8
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
It may not be a good idea having swap on an embedded device. Flash has a limited number of writes. You will shorten the life of your flash.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
swap file vs. swap partition verndog Ubuntu 16 07-09-2012 08:49 PM
need bigger swap partition but missing a valid partition table compused Linux - Hardware 3 07-02-2008 08:46 AM
Hard Drive Partition Management - Mandriva Double Partition with Swap File partition moshebagelfresser Linux - Hardware 2 05-23-2008 10:46 AM
swap partition vikassoft Linux - General 3 11-27-2005 10:11 AM
Newbie Installing Debian3 on m68k w/250M Partition Needs help creating swap partition AppleMac Linux - Newbie 2 11-01-2002 08:45 AM


All times are GMT -5. The time now is 06:13 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration