How will a swap partition/file affect the system? Some friends told me that their Android phones have very little (&lt;100MB) available memory for regular apps, because the OS and some un-killable services take most of the RAM. For example, one phone with 512MB only shows 90MB available memory, so only 2-3 apps can run at the same time.

I'm wondering if creating a swap partition/file will help, but I saw mixed opinions all over the web and I'm not sure what to do. Here are my questions:

(1) Will there be many not-oftenly-used memory pages to swap out, especially in OS and those un-killable services?

(2) How will swapping out small memory pages hurt flash memory life span? Does the flash (or SD card?) do wear-leveling automatically?

(3) Will swapping really help performance when running multiple apps? I assume if the answer to (1) is yes, it will.

(4) Will writing to flash be too slow and thus hurt responsiveness when swapping happens?

(5) Is it true that Android keeps the swapping mechanism from the Linux kernel, so as long as there is a swapping partition/file, it will do swapping without extra configuration?

Thanks for reading.
I don't think there will be much benefit with swapping for Android, as the Android Application Life Cycle is a much more advanced form of swapping.


  (1) Will there be many
  not-oftenly-used memory pages to swap
  out, especially in OS and those
  un-killable services?


You can't swap the OS kernel even in Desktop Linux and Android already kills services when it needs more RAM. If your device vendor persists that you have to have useless services running all the time, then root your device.


  (2) How will swapping out small memory
  pages hurt flash memory life span?
  Does the flash (or SD card?) do
  wear-leveling automatically?


Even if the SD-card does wear-leveling, swapping will hurt quite a lot.


  (3) Will swapping really help
  performance when running multiple
  apps? I assume if the answer to (1) is
  yes, it will.


Not in the context of Android. Unlike traditional OS that will keep trying to chug in processes as you requested it, Android will Force Kill older, unused processes and reclaims their memory; this killing is fast as applications will already save their state when you task switch.


  (4) Will writing to flash be too slow
  and thus hurt responsiveness when
  swapping happens?


Probably, probably not. Will need benchmarks for that.


  (5) Is it true that Android keeps the
  swapping mechanism from the Linux
  kernel, so as long as there is a
  swapping partition/file, it will do
  swapping without extra configuration?


I don't know whether Android keeps the swapping mechanism, but even if it does (or if you compile your own kernel), you will still need some configurations. It's usually just having an fstab file that points to the swap file and doing swapon -a.

In fact I have reasons why swapping may actually hurt performance: it prevents Application Life Cycle, Android's memory management scheme, to work correctly.