Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


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

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


I have a embedded device with kernel 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
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Take a look at
Old 05-19-2009, 07:52 AM   #3
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
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
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 220

Original Poster
Rep: Reputation: 32
Very clear

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

Rep: Reputation: 136Reputation: 136
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
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,815

Rep: Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180Reputation: 2180
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
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.


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 > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 09:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration