25

Does any Android today support swap area which is suppose to boost the performance?

What are the considerations that make most Android devices drop that feature?

JackWM
  • 10,085
  • 22
  • 65
  • 92
  • Your question is too vague and too broad to get a straightforward answer. If you have something specific to ask, please reword the question. –  Jul 04 '13 at 21:21

3 Answers3

31

Does any Android today support swap area?

Quoting Dianne Hackborn:

To be a little more specific, it does use paging but not swap space. That is, it relies heavily on being able to mmap() files and have the kernel page in data from the file as needed (and drop those pages when not needed). It does not however use swap space for paging out dirty pages.


With some slightly adaptions, swap area can work with Android's default low memory killer together well, right?

I certainly would not assume that.

Does any Android today support swap area which is suppose to boost the performance?

It is not supposed to "boost the performance".

what's the considerations that make Android drop this idea?

First, on-board flash is slow, much slower than the hard drives and SSDs that you are used to on desktops and notebooks. And while the quality of the flash storage used on Android devices today is better than it used to be, it's still not screaming fast. That's why, for example, we have to take special care when doing database I/O, to use transactions, to limit the number if disk write operations.

Second, historically, on-board flash was limited in space. We didn't have enough internal storage for our apps, let alone to dedicate some for swap.


If you wish to discuss this further, please use a more appropriate forum, such as http://android.stackexchange.com, as your question is only tangentially related to software development.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 2
    Nice answer, but I wouldn't agree that swap wouldn't boost performance. Even if swap memory would be slow, then it still wouldn't be slower then re-starting apps. And when memory is low the app gets killed. With app killed you need to restart it when you switch to it. That should be faster if Android would use swap. – Nux Aug 20 '16 at 09:04
  • 2
    Does most of this still hold true in 2017? We have phones with 128 GB storage, and the storage has gotten faster too. Is the storage still too slow to make this practical? How much more improvement in speeds would be necessary to make swap somewhat viable? – vanshg Aug 25 '17 at 04:15
  • @vanshg: "Is the storage still too slow to make this practical?" -- it is still much slower than desktop/notebook storage. "How much more improvement in speeds would be necessary to make swap somewhat viable?" -- I have no idea. Bear in mind that Android itself might need substantial changes to make use of swap space effectively. While Android is based on Linux, and on a rooted device you can probably hack in some swap, if Android bases its out-of-memory-killer logic solely on chip RAM, the swap space will be ineffective. – CommonsWare Aug 25 '17 at 11:12
  • 1
    Well, while there are still many old devices out there and not all recent Android phones have UFS, UFS alone is fast enough nowadays. And Samsung even introduced UFS 2.0 which is much faster than SSD two years ago. (https://www.tomshardware.com/news/samsung-256gb-ufs-2.0-announcement,31284.html) – Jenix May 03 '18 at 22:40
8

Android does support swap... Don't forget it's just plain Linux with some UI on it. :)

However the support is dependent on the kernel you are using.. When using a kernel you should know if it supports swap space or not..

If you are good in kernels, then grab the source, enable swap support and compile it. I guarantee that should be fun :p

Personally my kernel supports swap space and I use a 20 MB file to act as a swap file.

Miro Markaravanes
  • 3,285
  • 25
  • 32
  • nice, did you observe some improvements? – JackWM Jul 04 '13 at 21:49
  • 5
    A 20MB swap file seems suspect considering that modern medium-class devices easily have or exceed 512MB of main memory.. since the point of swap is to *off-load* main memory, so that memory is *available*, for infrequently used data the low ratio doesn't seem practical. – user2864740 Nov 13 '14 at 05:58
  • 1
    @user2864740 I wrote the comment while my phone had around 200 mb of memory, so 20 MB seemed not so low. Nowadays that devices are usually in the range of 1-3 GB of main memory, swap should at least be 512 MB. – Miro Markaravanes Nov 13 '14 at 07:10
6

For Android or even iOS to practically support non-kernel swapping, three hurdles must be overcome:

  1. Space Constraints: Due to the usage of flash memory, as opposed to HDD's, space comes at a relative premium
  2. Write Frequency: Flash memory tolerates fewer writes before becoming unreliable (relative to HDD)
  3. Communication Throughput: There is poor throughput between main memory and flash memory on mobile devices
Dean P
  • 1,841
  • 23
  • 23