Why Android Swap Doesn’t Make Sense

Reading through forums about to to tweak and increase performance, one of the items I found was enabling a swap partition, or file. Maybe an expert can correct me, but I don’t understand how this could possibly help, and probably hurts.

Unix swap, and virtual memory in general, allows physical memory to be extended. A section of the disk is turned into what is essentially very slow memory. When the system starts to run low on memory, the OS moves inactive processes into virtual memory to make space for new or active processes. This works well in general as there are usually a large number of background processes that are idle for long periods of time. If the processes aren’t active, it doesn’t matter if the memory in which they reside is slow.

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.

Both swap, and Android’s native application swapping mechanism do the same thing, at a high level anyway: they move inactive processes out of physical memory free up space for those that are active. However, which does it more efficiently?

  1. An Android swap partition must live on your SD card. SD cards are very, very slow memory. They are 100 to 1000x slower than a SIM. They are   10 to 100x slower than a hard drive. They are marginally faster than a network connection. When an application is “swapped out” it is copied into this very slow memory, and copied back to physical memory when it needs to run. On the other hand, when an app needs to be restarted after being terminated by Android, it is loaded not from the SD card but from the device’s (relatively) fast physical memory.
  2. When an Android app is terminated because of low memory, it decides what information must be persisted to represent it’s state. This can be very, very small. For example, it might be an integer index into a database. When an app is moved into virtual memory, the OS has no idea what’s important. It just moves the application in whole. It can’t be smart about it.
  3. Having swap actually prevents the native Android memory management scheme from activating. The system sees memory and doesn’t distinguish between physical and virtual. It will therefore prefer swap over the native Android memory management scheme, and won’t activate the native scheme until swap is full.
  4. Having swap requires some overhead of system resources.

And here’s a few counter arguments that I can imagine,

  1. The native Android memory management scheme is there for apps, but not for other processes. That is, having swap allows the many processes that run to support the Linux operating system to be moved out of physical memory.
  2. If you are running AppToSD, point #1 is negated as in that case the apps are being loaded from the SD card not physical memory.
  3. ?
About these ads

71 Responses to Why Android Swap Doesn’t Make Sense

  1. atrant says:

    I need swap because if swap file size is not large I can run more programs in parallel mode. I’m sick and tired of I’M disconnecting no matter what native method allows to store

    • Jeffrey Blattman says:

      well … no, you can’t. programs don’t run when they are in swap. they need to be moved back into main memory before they can run. swap is just a temporary holding space for your app (the memory image of your app). so again, is it better to let android use its native process lifecycle (create, pause, resume, stop) to manage memory, or to give the underlying linux kernel swap, and let it manage?

      • Bill says:

        here’s a case where having swap on android makes sense:

        open android browser, load a couple web pages… maybe one to look up the address of a business and another to look up a product price on google product search. run google maps and get some directions to the store, open text messaging and send a text telling a friend to meet you there. go back to maps and follow the directions to the store, go back to the browser and try to view one of the web pages. good luck viewing either of the previously fully-loaded pages without waiting for it to re-download the entire thing.

        now set up a swap partition and enable swap with a market app on a class 6 microSD card (about $20 at any store), and do the same thing. as programs are swapped in and out of memory you might see a very slight delay to wait for the SD card, but this is an extremely short wait time compared to having to wait for a web page to be re-downloaded, especially if you’re in an area where you only have a 2G signal. you can even open many more web pages without having to wait for them to re-download.

        the re-downloading of web pages almost made me switch from android to something else because it was so annoying, but with swap the phone is actually pleasant to use, and makes true multitasking possible.

      • Ugh says:

        Alright. How do I enable swap with a market app? My SD card has 32 MB of swap partition on it. Is that enough to make apps responsive again?

      • Jeffrey Blattman says:

        download an app called “swapper”. you can create a swap file and use that, or you can point it to a swap partition if you have one. the more advanced way is to use the “userinit” mechanism. google for that if you are interested.

        as to the amount of swap and swappiness, you can ask ten people and get 10 different answers. you should experiment and see what works for you.

      • Hmmm says:

        “programs don’t run when they are in swap. they need to be moved back into main memory before they can run.”

        That’s not quite how Android works. When you switch to a different program, Android will force kill any other programs that are running in order to free up memory.

        In theory, every app is supposed to store its state, so that it can be safely killed without losing data, and then when you switch back to it, it will be restarted and can resume in the same state it was previously in.

        In the real world, this rarely ever actually works. The built-in browser, for instance, doesn’t save its state; it only saves the address of the page that it’s on. It has to reload the entire page from the web in order to appear as though it is still in the same state. This is a lot slower than loading from swap. Other apps don’t even bother saving their state, and you have to navigate back through the menus to get to where you were.

        “is it better to let android use its native process lifecycle (create, pause, resume, stop) to manage memory, or to give the underlying linux kernel swap, and let it manage?”

        The best solution would be the theoretical Android solution, where the entire state of an app is saved and they can then be killed automatically, and restarted quickly in exactly the same state. This would be like swap, but better. The problem is that nothing actually works this way in practice. So in the real world, swap makes more sense.

      • Maradona says:

        Agree with Bill. It happens to my android browser. if i open many tabs, its downloading again when i open the first tab..

  2. atrant says:

    I think there is a chance to get into swap for another app than is important for you. And swapping is better than killing for example I hate my browser reloading the page from which I have switched to another app 20 secs before. So it is not the best way but it is a chance for your app not to die fastly in silence bugaga

  3. Ugh says:

    Ugh. I wish there were definitive answers to things like this instead of people just speculating as if they’re experts with no hard evidence to back it up.

  4. atrant says:

    bla bla bla so clever you are =) I used swapper apk for a couple of days and got nothing but slow device speed. So swapping is a bad idea =(

  5. Weber K. says:

    Consider this context:
    You use a lot of widgets, then they will consume a lot of memory in background tasks. After that you open your browser and it will consume o lot of memory.
    What the OS does? It unloads the home app. :(
    Then you press home and it takes a lot to reload the home and all the widgets.
    Or maybe if someone calls… Then you got black screen and can have missed calls because of the lag. This lag/ black screen is a known issue in Android OS.
    Enabling swap prevented me a lot of this occurrences. Another workaround is purchasing dxTop home app, that registers itself as a persistent task. But I wont purchase it, neither warez. :p
    So, if you use a few widgets, you dont need swap. For me, using swap is worth enough. It is slower, but is fastest than reloading my home and all widgets. :)
    Greetings from Brazil!!

    • Jeffrey Blattman says:

      okay, so the home “app” is not in main memory. before it can be used, it either has to be 1) loaded into main memory from swap, or 2) loaded back into main memory from the disk. so why is it faster to load it from swap? either way it’s loading the app from the SD card.

      i’m not discounting your experience, i’m just not sure how to account for it.

      • tomei says:

        It’s because Android home app takes forever to load the list of installed applications. I have 60+ apps installed. When home app restarts it takes over 10 seconds.

    • andrew says:

      hey so how do i enable swap for my homescreen and browser (i use dolphin browser and have cyanogen mod) or anything else for that matter please respond fast its fairly important that my homescreen loads fast lol

  6. Weber K. says:

    If I am not using swap, Android closes the Home App. Then Home App needs restarting, and all widgets too, causing a lot of lag.
    Using swap with low swappiness almost the same as above occurs.
    Using swap with high swappiness, then home is sent to swap. It causes the lag you described above, but will be less lag than restarting the home app and widgets.
    You need to try a lot of settings before you got the right swappiness. Sometimes you get very bored.
    But it is worth enough only if you have a lot of home screens with a lot of widgets. If you have few home screens and few widgets, you dont need to use swap.
    Thanks for sharing you experience too.
    Greetz from Brazil!!

    • Steve says:

      Can’t someone just figure out a good swappiness that gives best performance? Is it really that variable from card to card?

      • Jeffrey Blattman says:

        i agree steve. for the most part, the hardware running android today is almost identical. there shouldn’t be that many different configuration permutations.

    • Jeffrey Blattman says:

      if it’s faster to load apps from swap then to load them again from scratch, then why not make say a 256MB swap partition and let the OS load every app you every use into there?

  7. Mike says:

    Um, I’m not sure where you’re getting data from, but an SDHC is not 10 -100x slower than a hard drive… a class 6 SDHC ought to be able to read at ~16 MB/s. Running HD Tune on my internal 80 GB, 7200 RPM, IDE drive, it reads at an average of 43 MB/s. So, though the hard drive may be faster, it’s more like 2 to 3 times, not 10 to 100. Theoretically, SATA has the ability to run faster, perhaps what you were trying to elude to, but hard drives are still bound to there physical limitations and are not able to achieve speeds allowed by the bus.

    • Jeffrey Blattman says:

      i agree, ~40-60MB/s is normal for a modern laptop, so i misquoted there. i don’t agree with your quoted SD card rate though. a class 6 SDHC card is a minimum of 6MB/s. you might be looking at the word “minimum” and assuming you can get higher than that, but this so-called minimum rate is quoted for a completely unfragmented, empty Card. a swap partition is going to have at least some fragmentation.

      on my laptop with an SDHC port, i see transfer rates around 2-4MB/s on a class 6 card, transferring a single large file (which is going to be the very fastest rate). i’m assuming the bus on my laptop is at least as good as that in the cheap HTC hardware. so i’ll revise my figure, the hard drive is 10-20x faster.

    • Lothar says:

      I can _really_ read at 17MB/s on the T-Mobile G1, tested by dd’ing a 100MB file from a fat filesystem on the (Class 6) SDHC-Card. So even after filesystem overhead, it is fairly fast.

      Write speed is in fact around the expected/advertised 6MB/s. For most SD-Card usage like in Cameras write speed is what counts (how many photos can i take per second), so they are right to advertise and classify the minimum write speed.

      But when talking about the bottleneck “reading applications back from swap”, I’ll use the 17 MB/s (for my card, yours might in fact be inferior.

  8. bryan says:

    flash memory has very minimal random seek times. Fragmentation should not affect performance like a HDD. SD spec 2.0 specified a max clk of 52MHz. Since an SD card can operate at either 1-bit or 4-bit wide bus, the theoretical max is 6.5MB/s in 1-bit and 26MB/s in 4-bits. Packet overhead takes a percentage off the top. I know most designs opt for the 4-bit bus width, but not all designs can provide the maximum 52MHz clock.

    So although the card speed class is important. Controller implementation can be the weaker link. Different USB card readers can give different speed with the same card.

  9. Skrki says:

    Guys, this is a very interesting topic.. Also, I would disagree with the “zero credibility” remark, cos there is actually credible info here :)

    Here’s some of my views after having messed around with Android for a few months:

    Swap? Use it, but don’t abuse it. Someone said it slowed down their phone. A classic example of abuse. Whether is the wrong size, wrong partition, wrong swappiness, or used in a bad conjunction with compcache, there are several ways you can break it, so you get an impression it is bad. Not true.

    Swappiness? Nobody can give a definitive answer to the infamous question “What swappiness is best for me?”. It solely depends on how many apps one runs simultaneously, and what expectations one has from their device. If you run just a few apps, then make the swappiness lower. This will tell Android not to push those few apps to swap very aggresively (i.e. unless it is absolutely needed).
    If you run more than a few apps, your RAM will likely get filled up quickly, and OS will start pushing apps out, killing the processes. In this case you want to raise the swappiness, tell the OS to push RAM to swap more frequently, so your app’s current memory state will be preserved in swap. Jeffrey is right here: They aren’t active while in swap space, but their state is preserved, so you get the impression the corresponding processes are in fact, still alive. Makes our life easier!

    Finally, speed at which apps are brought back from SD can not be compared to the speed of RAM. Widely known fact, these are the basics..but, I don’t see a valid argument here, because pages that are being brought back to RAM, from swap, aren’t “that” big. Differences probably invisible to the naked eye, from a fragment of a second to a few secs (in case of Home), won’t bother anyone much – and we probably won’t notice them, on a daily basis. However, we will (and we do) notice Home screen reloads that sometimes take up to 30 seconds!

    As a conclusion, the way I see it, on some Android builds, swap is absolutely necessary, otherwise the system is unusable. On others, not necessary at all.
    So, swap will occasionally enhance our Android experience, and in many cases reduce the frustration. On the down side, have an extra $20 in your pocket, cos so many read/writes will definitely “burn up” the SD card a lot faster :)

  10. Wim says:

    Swap does make sense in a way. It doesn’t force an entire app to be persisted. It allows the OS to simply move the rarely used memory pages to swap, instead of the entire application.

    • Steve says:

      Agreed. I tried using swap and my applications opened up MUCH faster. You can open up the browser and Gmail and switch back and forth between them, and it goes right back to where you were, instead of re-loading the entire app and web page from scratch. Unfortunately, it makes the entire phone really slow if you do much more than that. I’m guessing the system needs to be confined to real memory and the apps can be swapped out or something? But with some tweaking, SD card swap would make it much more responsive.

  11. Anonym says:

    One thing that is forgotten about Swap. Swap is selective. It can swap out parts/blocks of a programs memory that isn’t used much.

    Things like libraries etc could be swapped out. Look at the desktop/home screen background. It is quicker to swap out 10k for the image footprint in ram, rather than having to reload the jpeg library and then to decode/decompress the file, rescale it, and then put it as background.

    • Pilotgeek says:

      THANK YOU. I don’t know why everone seems to think that an ENTIRE application and ALL its data needs to be loaded into swap. If memory is running low, it can take select parts and move it to swap. For the home screen as an example, the home screen process will not get moved to swap and will keep running, but the data ASSOCIATED with it may get moved to swap.

  12. Rafael says:

    In the case of the N1, would swap be necessary? I have swap partitioned to 32 megs just in case, I suppose, but having flashed CyanogenMOD’s ROM onto the phone, my current available memory when apps are inactive has doubled to 300 megs.

  13. frater mus says:

    My first-gen G1 running was painfully slow running CM 6.x froyo without swap. With 32mb swap partition on the /sdcard it’s nearly as responsive as a newer handheld. It’s a huge diference. .25sec to load homescreen vs 10-15secs. I run a fast screen timeout (15secs) and before swap it was common for the screen to turn off before the homescreen [re-]loaded.

    And this is just with a normal cheap class 2 sd. I’ve got a class 6 on the way that may improve things further.

  14. Ryan says:

    Here’s my confusion. I was always under the impression that a Class 6 SD car was FASTER then the onboard memory of android smartphones, least the case for some smart phones (IE Cliq, G1)

  15. White--Hawk says:

    I am running CM6.0 on a G1, swap enabled, with a class 6 SD card. I have Apps2SD_EXT enabled as the FroYo Apps2SD_FAT method sucks dry balls.

    I believe the class 6 card provides demonstrably better performance than the internal memory ever did, and is suited perfectly to both Apps2SD and the use of a swap partition.

    It runs considerably more quickly than it ever did with stock firmware, and appears to be more stable and responsive than CM6.0 without swap.

    Application crashes are minimal, and wait times when switching between apps are also less annoying than the swap-less reload times for apps including the browser, Market, social networking apps like Facebook and Twitter, and various others.

    The simple truth is that a program can be restored from swap substantially faster than it can be loaded, restore its previous configuration, search for its data, load its data, and eventually compose itself appropriately for use. Switching back and forth between programs that would otherwise have to be initialised from scratch, reference their previous state, and then re-load the required data is so much more of a pleasant experience with a swap partition that I never plan to be without one on my G1 again.

    In theory, the native android memory handling should be more efficient, and with a brand-spanking-new device like my Galaxy (which has oodles of memory and blazing IO speeds) this would probably be the case… but with this old G1, the swap method blows a hole right through that logic. It just goes to show that you never know everything, eh? ;)

  16. Just a little point that may have been overlooked. On phones with very little RAM, such as the HTC Magic 32B with only 96 MB RAM, a 64 MB swap partition makes all the difference when you load a new, big Android version on it, like CyanogenMod 6.

    Swappiness may make a difference, but even a very low swappiness setting like 10 allows full swapping when the RAM would otherwise fill up completely.

    If anybody here knows why Menu, Settings, Applications, Running services does not show the entire RAM + swap total at the bottom, please let me know. I suspect the thing changes total virtual RAM size dynamically, rather than indicating the full available size even to the rest of the operating system. This perhaps makes some sense, but I would like to know for sure.

    • brokdikdog says:

      Because your swap is not added as part of the RAM as is the case with Windows Phone 7. If you want to check the amount of swap available and used just open a terminal enter su then enter free and it will list all the memory info.

  17. [...] Zitat von AddiB @pOOB73: Weist du ob der neue Kernel SWAP-Support hat? MfG AddiB Um mal wieder back to topic zu kommen: SWAP support wurde auch im neuen Kernel unter Froyo nicht aktiviert. Nach etwas einlesen bin ich mir auch nicht so sicher, ob's nicht eher kontraproduktiv sein kann.: Why Android Swap Doesn’t Make Sense Zero Credibility [...]

  18. Android says:

    Fine app for android thanks for the tip I am already experimenting in my android and perfect
    a work in very nice.

  19. [...] Swap or not to Swap? I read an article that warns against setting up a swap file: Why Android Swap Doesn’t Make Sense Zero Credibility Are there any thoughts on using a swap file, is it good or bad, why, and how do you do it right? [...]

  20. [...] Originally Posted by aish_varya there are different kinds of memory for different purposes 1. Cache Memory (inside processor) 2. RAM 3. other storage purpose memories like hard disk, SD card, DVDs etc Cache memory:- works MIGHTY MIGHTY MIGHTY fast, so as to fetch instructions to the processor from RAM RAM:- little less fast(than cache) but still MIGHTY fast, purpose is to act as buffer between "storage memory" and Cache memory. Hence purpose of ram is to quickly fetch data both ways IN n OUT of processor which cannot be substituted by virtual memory. Anyways virtual memory will be your SD card which is not even 1/100th the speed at which RAM operates. Cheers why do i think you didn't answer the question? i know how a computer works in general, so explaining cache, ram and hard disks doesn't really solve anything. so does my processor use all of the allocated RAM? correct me if i'm wrong, but i don't think so because afaik android only kills apps if you back out, not if you exit by pressing the menu button. so i wouldn't really care if that were stored on a swap partition. just so you know, i don't think swap partitions make sense (because those 280mb of RAM seem sufficient for me, so i just wouldn't bother), but either say you don't know the answer or give a good one (not lol omfg so stoopid srsly doode never bin to school, ay?), there are already enough fake facts flying around in the interwebs and everywhere else. here you get a proper discussion about it Why Android Swap Doesn’t Make Sense Zero Credibility [...]

  21. Violn says:

    how about creating swap partition lets say 64mb .. and tuning android internal killer to accomodate… meaning “empty” apps killed at 64 maybe other levels to.. it would be a more “inteligent” than pure swappieness while maintaining the ability to keep backgroud processes running (or sort of hibernating like opera browser tith 6 tabs openwhile you check out new message that arrived on gmal etc) i know sd cards are sloooow… but it’s still often faster than relaunching an app (while killing another one) and reloading pages or if some apps cant sae theit state manualy recreate their state there is nothing wrong with swapping per s but you should be smart about it.. it’s not a magic cure for low ram it’s slow but can be the lesser of two evils

    btw… maybe a little better would be to make software raid 0 for internal memory device and sd card and then using it as swap ;]

  22. Palletje says:

    Well I have an android with a swap partition aswell, the rom or apps2sd program will allow me to use a maximum of 100mb of swap, it works fine, but i do agree with the person starting this thread. Every program that uses this sawp has a delay, market takes about 10 sec to start, and other programs aswell, the real problem is when the 100mb is reached, then the whole phone gets really really slow i deactivated the swap and it is fast again and it seems to stay fast

  23. claudio says:



  24. I have had quite a bit of experience now with the HTC Magic 32B, these days running ezGingerbread-beta.20110828-1 with the included Kernel version: and the Baseband version: 62.50SF.20.17H_2.22.27.08

    The previous version was somewhat unstable, but this version is rock-solid with a 32 MB swap file created with swapscriptv2.

    Of course this phone is slow, and swapping makes it even slower. Occasionally the Force close or Wait dialog comes up, and you have to tap Wait to keep the phone going. But that is to be expected with the slow processor and the insufficient RAM for the relatively big operating system and some big programs. The question is whether such a phone can still be useful, and I think, yes, it can be.

    I have come to the following conclusions, regarding a few interesting points.

    Size of swapfile

    I feel we are walking a narrow path. Without a swapfile the phone cannot be used fully, because there is simply not enough RAM for larger applications like navigation, Angry Birds, or a Bitcoin wallet, so that is out of the question. I absolutely need a swapfile.

    With a large swapfile between 64 and 128 MB the phone can become extremely slow, presumably because Android likes to keep programs in RAM if available, even though they could be killed. I found 32 MB a very good compromise, which avoids the very long waiting times, but still allows at least one large program to run.


    There is really not much choice here. You want to set swappiness to zero, because you don’t really want Android to swap more than absolutely necessary. Swapping is very slow and should only be used as a last resort when there is otherwise not enough available RAM. Making Android swap more is counterproductive, unless you have a very good reason.

  25. yuvi says:

    no one gives the exact solution……

  26. [...] Let the OS do its thing – it was designed knowing that there's no swap partition (or need for one). Why Android Swap Doesn’t Make Sense Zero Credibility is one simple and fairly non-technical explanation. (There's another one, written by one of the [...]

  27. Let me add a point to the exact solution I had given above.

    If you do not absolutely need a swapfile, don’t use one. It makes the phone very slow and can lead to the occasional spontaneous reboot. You need a swapfile only if you have too little RAM to run a program you are desperate to run on exactly that phone.

    In all other cases don’t even waste any time thinking about a swapfile. If you can do without a swapfile, spare yourself the trouble.

  28. RoXeon says:

    “An Android swap partition must live on your SD card” – this is not true. Swap can be on internal memory, so loading apps from swap is as fast as starting new instance or even faster.

    • Jeffrey Blattman says:

      “so loading apps from swap is as fast as starting new instance”. so then adding swap can make loading apps as fast as if you didn’t have swap to begin with?

      • Anne says:

        No. Starting an app without swap means it has to initialize the whole app from a minimal amount of settings it stored in flash before it was killed. Restoring an app from swap restores the entire app and its previous state without having to process anything or load anything from flash.

      • Jeffrey Blattman says:

        i don’t know where to start with that one.

        you keep talking about flash memory. android devices have 1) internal memory that is used to run applications, 2) internal storage where apps are installed and their data is stored, and 3) flash memory for storing larger chunks of data, media, etc. in modern devices, 2 and 3 are combined. #2 is also flash memory. it’s just soldered into the device and not on an SD card. it’s the same memory.

        the only place you can create a swap partition is flash memory. whether that’s internal storage (#2) or the SD card (#3), it’s all the same. that’s the same place where apps are loaded and application state is persisted.

        first, making statements that it is faster to load from swap vs. restoring application state do not make sense. it’s the same memory. swap can’t magically load data faster. if you have an app that needs to be brought into memory, it doesn’t matter if it’s in swap or if it’s just loading the app in the normal memory.

        second, you make a statement that it’s faster to load from swap than to load otherwise. please cite your sources. android is optimized to move apps in and out of main memory and restore their state. it’s very specialized and tuned for that purpose. it definitely does not follow that a general purpose mechanism like swap could do a better job than the android OS.

        and finally, and this is the kicker, if swap really made so much of a difference for performance, don’t you think we’d see stock devices with swap enabled? i mean, why not? right? we can get faster devices on the exact same hardware. almost like magic.

      • Anne says:

        “first, making statements that it is faster to load from swap vs. restoring application state do not make sense.”

        Yeah, it does actually. Loading a web page from the web takes a hell of a lot longer than loading it from memory. Do you know anything about how Android handles processes?

      • Jeffrey Blattman says:

        a web page is loaded over the network, which is orders of magnitude slower than a memory bus.

        again, let me make this clear to you. whether you are loading an app from swap, or loading it in the traditional way, it all comes from the same memory. there’s no magical super-fast swap memory. IT’S ALL THE SAME MEMORY. if you create a swap partition, you are just setting aside a part of that memory that’s already used to store apps and their data.

        please cite your sources. if i’m wrong, give me the link. i admit i don’t know all the factors that could be at play here, but you certainly haven’t provided anything other than unsubstantiated claims.

      • Jeffrey, Anne means that a web browser, as long as it is loaded (swap or RAM, no matter), can keep loaded web pages in its cache.

        If, however, the web browser is killed, it keeps only the web address and must therefore reload at least the current page over the Internet connection, which is often slower as the swap file.

        However, this is a questionable argument, as this case does not happen too frequently. And the bigger problem is that not only the web browser could use the slow swap file, but also all other programs, possibly making them much slower.

        As I had already written, the swap file is a means of last resort, as it always makes the phone rather slow. I would use it only if without it I could not run an important program at all, due to lack of RAM.

    • Jeffrey Blattman says:

      SD card, internal memory. it’s all flash. the only difference is that one is built into the device, and one is removable.

      • nickmcminn60 says:

        Wow really Jeffrey? Flash is Flash is Flash=NO it is not. That is like saying an HD is a HD is a HD. There are numerous factors weather it’s a Flash, IDE or SATA. They are NOT all Made the same. I know this OP is as old as Android is but If you have less than 512 of ram a 32MB swap with a 10 or less swappiness would increase overall performance. If you dont like the “Redraw time of your Launcher then add ro.home=1 to the end of your build.prop in order to lock home in RAM. Then if the wait for file loading is unbearable write a script to raise your RAC (Read Ahead Cache). stock is normally 128-148 on the 17 Devices I have owned and developed on for the last 4yrs. If you have 345mb-512 RAM then up it to 1024. You guy’s have to realize why swap works well for some and not others. People assume that…..let’s make a 200mb swap and that will really boost my RAM….NO! the closer the size of the swap is to the “Available” RAM you have FREE will confuse the Android Ecosystem and in turn can potentially decide to use the Swap more frequently than ikeeping more used apps in RAM. I have a duel core 1.5ghz Qualcom with Adreno 220 GPU and 1 GB of RAM and I use 64MB Swap with 10 swappiness on a class 10 16 GB ex-sd Card. Oh but wait that class 10 sd is the same as a 2gb class2 right? You did say they are the same didn’t you? There is everyone something to go by depending on your RAM, but if you got a 800mhz or less CPU…..that is your problem. Get you a stock deodexed rom and a OC/UV Kernel and bump the 800mhz to 1Ghz.
        SOURCE: My Bible: http://forum.xda-developers.com/showthread.php?p=24271656#post24271656
        Facebook Group #1: http://www.facebook.com/groups/360Productions/
        Facebook Group #2: http://www.facebook.com/Infernoroms

        I’m own 360 Production’s and compiled MIUI for the Samsung Vibrant for MIUI.us for 2 years

        **You asked for credentials** Now I have moved towards Linux Distro’s…..Cheer’s hope this helps someone

  29. whitehawkuk says:

    My old G1 ran better with a swap file only because it had so little RAM. With a swap file, re-opening my browser after an interruption (like an incoming call) was noticeably quicker. Though there was noticeable additional latency when switching between applications, the time saved reloading an entire web page more than made up for it.

    Another good example would be (for instance) my favourite tower-defence game. If a call came in right in the middle of a game, without the swap file, I would have to re-load the game after the call. This would entail the usual loading delays related to license checks, resource unpacking, etc. As an added kick in the teeth, I would be unable to continue the game from where I left off, and starting a difficult level from the beginning again was a little disheartening.

    With the swap file, the game would load as a running process, no license check to complete, no resources to unpack, and I would be able to continue from the point at which I left it. It was both quicker and more convenient.

    Yes, this could be coded around by the game developer, but in the absence of such coding practices, the swap file made my memory-poor G1 substantially more useful, and with the use of a decent flash card, speed was not a great issue.

    That old G1 has been re-tasked as a bedside clock and weather station now, and my SGS has no such issues switching fast between applications, and no major memory limitations. A swap file on my current device would be counter-productive, and would likely result in much, much slower performance while providing no greater convenience.

    The long and the short of it is that unless you’re running ancient technology beyond its design limits (and after all, it was not very long before the G1, with its pathetic amount of RAM, hit its limits), a swap file has no place on an Android device. Worse, the additional read/write activity will serve only to substantially shorten the life of your device’s flash storage – woe betide anyone daft enough to create a swap file/partition on the internal flash storage, as that can’t be popped out and replaced when it reaches its inevitable end…

  30. [...] also found details on why using swap on Android doesn’t make sense, as well as discussion on the cyanogenmod wiki about why swap is not [...]

  31. asdfsdf@yahoo.com says:

    Blaaaa… blaaaa … blaaaa…..
    You guys all talk too much about “We don’t need swap memory”.
    if swap really no use then let me tell you this:
    1. why linux, windows and mac OS and any other OS implement virtual memory ha? cause they somewhat useful for some conditions.
    2. why they ask for swap ( virtual memory ) for Android ha? cause their device is really low on RAM.
    3. Swapping decrease SD card life? Using your phone also reducing it’s processor, GPU, RAM, ROM, LCD life span either, so please don’t use it. just put it in the box, seal it and it’ll last for centuries. nice wasn’t it?. Please knows the fact that the life span of an SD card is much longer than your phone’s life time. You probably break 3 phone before you break your SD card. So still afraid that you’ll break your SD before your phone? I don’t think so.

    The only problem about swapping is. It’s hard to find a 100% OMFG SO NICE SWAP APPLICATION YOU GOT. So if you clever, just find a very good swap software and share it. Or else just shut your mouth. We dont need this crap article shit.

    • Jeffrey Blattman says:

      to respond to #1, the OS has to be designed to take advantage of virtual memory. android isn’t, as it has other memory management schemes in place that will be fighting with virtual memory to do the right thing.

      to respond to #3, it’s called memory wear, and you can read about it here,

      it only applies to flash memory of course.

      • He may be right though. Memory wear exists, but I have yet to see a Flash chip that is truly worn out. The chips have gotten better, and the have always used automatic memory block replacement with spare memory blocks for worn-out areas.

        The real question is whether a swap file solves low memory situations in older Android phones. My own experience with the HTC Magic was mixed. It is certainly true that a big program, like Angry Birds, would not run without a swap file.

        But on the other hand the phone did not really run well with a swap file. Large swap files made it so slow it became virtually unusable. A relatively small swap file, 32 MB, worked better, but still caused the occasional problem, like a spontaneous reboot.

        All in all I think the truth is somewhere in the middle. My recommendation is to test thoroughly and see whether a particular phone and operating system version works well with a small swap file or not. Don’t even try large swap files.

        The biggest problem may be that Android is designed to use all the available RAM to leave programs loaded, so the user can call them up again in the state they were left in. This means that Android always tends to gobble up the entire swap file and becomes slow when these memory areas are actually used. Only after some time, longer than in normal Linux operation, will the working set be moved out of the swap file, and only then the phone will show fair performance.

        If you observe too many problems, like frequent program Force Closes or spontaneous reboots, you may be out of luck. And do not use a swap file and CyanogenMod’s RAM compression method (forgot its name) at the same time.

        Finally, set the swappiness parameter to zero. You don’t want your phone to swap any more than absolutely necessary to load that big program.

  32. 10uRSHiN says:

    “first, making statements that it is faster to load from swap vs. restoring application state do not make sense. it’s the same memory. swap can’t magically load data faster.”

    Well, actually it does make sense. It’s same memory, right, but different content. A page file contains application’s memory dump and to load application back you simply just need to read it in to memory. This is faster than loading application state back with 2 ways;

    1, if your application deals with too many files and keeping them on memory, loading this files from a random access file(page file) is way faster than loading them from their original resources,

    2,To save application’s current state, you need to serialize it’s contents, and than deserialize them to load it back which requires a lot of cpu cycles, but dumping to/loading from page file requires less cycles even can be done with only a few cpu cycles if direct memory access(DMA) is supported on device.

    Think like, you are working with a bunch of bitmaps, a bitmap’s memory data can be different than file data, and usually it take times to create memory data from file data. For instance to load Jpegs you need to load all of it’s file data, determine pixel color from color table for each pixel, and convert it to the color space you are loading into (ARGB444, ARGB8888 etc.) It can even take minutes depending on bitmap size and count. So if you created a jpegs memory data, why you should spend time to load it again or serialize/deserialize it rather than dumping it.

    Also paging make things easier for developers…

    • Jeffrey Blattman says:

      if it’s so much faster, then why don’t any stock android devices come with a swap partition? let’s face it, MANY android devices leave a lot to be desired in the area of performance.

  33. Esperanza says:

    I used to be suggested this website via my cousin. I am no longer sure whether this put up is written by
    means of him as nobody else recognize such distinct about
    my problem. You are amazing! Thank you!

  34. Gatak says:

    Actually, Swap on zRam is the bigger benefit, as it compresses the swap space into 1/3 ram – thereby freeing up valuable ram for active pages (yes, pages .- not apps), while restoring pages from the compressed swap is 10-50x faster than sdcards read-speed.

    • brown says:

      Are you never try swap?

      Even on big memory device it still have benefit

      Swap space is like your bag
      Ram is like your table to work

      And apps memory is source

      So android take source and build that in the table, if the table is full you will dump it to make space. Clear?
      So if you wanna build something again you will starting from scratch.

      But if you have a bag(swap memory) something that full in the table doesn’t necessary to dump it. But save it on your bag
      Anytime you need it it will faster to take from bag rather than rebuilding again!

      The conclusion is, starting apps from source and swap is different task! Rebuilding if from source, just bringing it back if from swap!

  35. Wut says:

    I’ve just quitted using swap partition in my Galaxy Note 2 and neglect it now. It’s useless as you mentioned and annoying, very little it applied to swap partition and wasted my time!

  36. ivan kol says:

    Bullshit1 – ” They are 100 to 1000x slower than a SIM.” – DO YOU KNOW WHAT I2C PROTOCOL IS? DO YOU KNOW HOW “fast” IT IS?
    Bullshit2 – “They are 10 to 100x slower than a hard drive. ” – ordinary HDD makes 80MB/s linear transfer rate, Class 10 SDCARD makes 30MB/s read speed without any problems, but try to measure reading speed for 4k chunks – HDD makes no more than 0.5-1MB/s, SDCARD easy goes over 10MB/s

  37. Nuno Venâncio says:

    There is a very good guide here:
    looks the best guide i’ve seen to use a swap file. Even the partition is important in order to get better results.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: