Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I just rooted my phone (Android 2.3.6) and partitioned the sd card using CWM recovery. While partitioning, I noticed about swap size and while searching about it, different blogs (xda developers) recommended using 0M as swap size. What is the use of it? Why is it recommended to be 0M?

share|improve this question

4 Answers 4

up vote 7 down vote accepted

Primary reasons for the no swap recommendations are the basic uselessness of swap for most devices, performance reasons, and device longevity.

As Liam mentions, modern devices have no shortage of RAM (Even my old underpowered Wildfire S has as much RAM as my previous desktop.) and that RAM is managed fairly well by the modern Android system, making a swap largely pointless.

Also, even though flash is far better than platters of spinning rust, it's still orders of magnitude slower than RAM is, hence for performance reasons, you don't want to tier down to flash if you can at all avoid it.

Furthermore, flash memory has a limit on how many times you can erase and rewrite it. While this cycle limit is typically in the thousands or tens of thousands, which combined with modern wear leveling systems, means you're unlikely to hit the limit within the useful lifespan of the device, but if you're using it as swap, with loads and loads of itty-bity writes, you will chew through those cycles needlessly and might actually bump against those limits in time.

share|improve this answer
    
Your previous desktop only had 512 MB of RAM? Have you had a desktop machine since the 90's?? –  intuited Nov 23 '13 at 17:30
1  
@intuited I built my previous desktop in 2001. 512 was a fair amount at the time. My current desktop started with 2gb, then upgraded to 4, and now has 12. –  Compro01 Nov 23 '13 at 19:39

The use of a swap file it so save memory (RAM) to storage (hard drive/sd card).

The recommendation of 0mb for the file size is because it is not usually needed. Android takes care of memory management in a different fashion than swap files.

Background:

A Swap File is traditionally used to store what is typically in memory onto storage when memory is low. This allows it to be switched back into memory when needed.

To quote from Zero Credibility Blog

Android, while a fairly typical (but trim) Linux under the covers, has it’s own mechanism for handling low memory conditions. It terminates the application, but first gives it an opportunity to persist it’s state (via a series of callbacks). For example, a map application might persist a latitude and longitude before it is terminated. When you access the application again, the location is passed back so it appears that the app was running all along. In actuality the app was restarted completely.

(emphasis mine)

The above describes how I have seen applications appear to persist after switching from task to task.

There is no need to save the contents of memory to storage, because Android will just save the app's current data and terminate the app.

share|improve this answer
    
Can anyone please explain the down vote to improve the answer? –  Dylan Yaga Dec 20 '12 at 18:10
    
I don't believe it fully answers the question... –  Liam W Dec 20 '12 at 18:12
    
Thanks for the answer. But looking for a more clearer one. –  najus Dec 20 '12 at 18:15

As the other answers already cover most of the facts, just a small addition: I already edited the app Swapper for Root users into Liam's answer as an example. And Compro01's answer already mentioned the danger of wearing out the flash memory of your sdcard. Now let's bring both together:

When using the Swapper app to handle your swap, it recommends to not use a swap partition but a swap file, for exact this reasons. That swap file then is placed on a different location of the flash memory each time swap gets activated, which avoids to always write/delete the same blocks and thus saves some more lifespan for your flash memory.

So comparing both:

  • Swap partition: faster, but wears out flash memory faster, too.
  • Swap file: a little slower, but does not wear out flash memory that fast

Keeping this in mind it gets clear why a) 0M (i.e. no swap partition) is recommended, and b) a swap partition is offered at all (for those who do not care buying new cards, but want the extra little speed).

share|improve this answer
    
Swap partition vs. swap file wouldn't make any difference. Wear leveling is handled by the flash controller, not any portion of the firmware or Android system. The layout of the partitions has no fixed relation to the physical location of anything on the flash chip. –  Compro01 Dec 20 '12 at 20:35
    
This part of my explanation comes from the Swapper docs. As I never used swap on my Android devices, I didn't dig deeper. But I'm irritated that partition layout shouldn't be bound to blocks on the medium. Are you sure of this? "How does it then work" would be a different question -- but maybe you could at least mention a source? –  Izzy Dec 20 '12 at 21:08
    
Swapper represents something from the old way of things. Early in the history of Android, many devices used raw NAND flash chips for their storage and used special file systems like YAFFS to handle the wear leveling. This is where the file vs. partition comes into play, as a swap file would use the special wear leveling file system, as opposed to the swap partition using static allocation. This is no longer relevant, as all current devices instead use eMMC for storage rather than raw flash. eMMC has the controller integrated into the package, and is invisible to the OS and everything else. –  Compro01 Dec 20 '12 at 21:59
    
Sounds reasonable. "eMMC" stands for "emulated MMC" -- so does that apply to internal memory only, or also to (newer) sdcards? Might be relevant in this context. –  Izzy Dec 20 '12 at 22:12
    
No, eMMC is embedded MMC. It's basically a flash chip with the controller and cache embedded straight into the IC package. It's not really an MMC, as it's a chip, not a card, but it's the same as an MMC from a software level. This is the internal memory in basically all modern android devices. SD cards are an extension of the MMC spec, most notably adding DRM capability. Again, everything is handled by the controller. From outside the card/chip, all the wear leveling stuff is invisible. Unless you open up the package, you'd never know block 1 and 2 are nowhere near each other. –  Compro01 Dec 20 '12 at 22:29

Swap is basically virtual RAM used by the Linux kernel.

Swap in Android was used when devices had very limited RAM (I used it with my LG Optimus GT540), to increase the amount of RAM available to the Android OS.

Android kills apps when it run's out of memory - and is very good at doing this efficiently, however on devices with low RAM people may have seen their home screen apps being killed, and therefore have to wait a while to get to their home screens.

Swap can be mounted via either a partition or a file - mainly on an external (or internal) storage device. Swap is normally activated via the so-called Init scripts in the /etc/init.d folder of the device to mount/enable swap on device boot.

Linux desktops use a partition for swap, and the user is asked to create this during the install process.

A file is normally stored on the SD Card or storage medium. The swap file on Android is normally mounted (and created) by an app (e.g. Swapper for Root users).

Most newer devices won't see any benefit of using swap - as they normally have as much RAM as a desktop computer (my SGS2 has 1GB!), and therefore wouldn't benefit from having more virtual RAM.

Unfortunately, using swap can come at a price - even on low RAM devices, as the OS has to spend time writing to the SD card, which would normally have slow read/write speeds. As such, it isn't used much at all nowadays, unless a device has an obscenely small amount of RAM.

As well as this, using swap can have a negative effect on the life of your memory device, and should be used with caution. If anyone reading must use swap (and I would advise against it), then use a file with an app, as it varies the swap file location to maximise sd card life.

share|improve this answer
    
hmm..quite satisfying one. –  najus Dec 20 '12 at 18:16
1  
Swap is not needed in Android - plain and simple :) -1 from me, Compro01's answer is the best and sums it up exactly! –  t0mm13b Dec 20 '12 at 19:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.