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?
|
|
||||
|
|
|
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. |
||||
|
|
|
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:
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). |
|||||||||||
|
|
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 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. |
||||
|
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
(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. |
|||||||
|
|
