Recently, while utilizing Linux on my Android phone, I ran into an interesting problem. Android uses memory differently than Linux usually does. In the Android world, programs that you open are suspended in RAM, and a portion of that RAM is kept active even when you “close” a program. This allows the programs you have previously opened to become available again very quickly.

Linux does not typically operate in this fashion, although there are options and configurations to do similar things. The problem, however, is that Debian is sharing the RAM with Android on my phone, rather than being a seperate chroot program under Android. So Debian can only utilize the RAM that Android is not hogging.

I decided that a swap file may help me while I am utilizing Debian. So I set about to create one:

phone@localhost:~$ dd if=/dev/zero of=./swapfile bs=512 count=102400
102400+0 records in
102400+0 records out
52428800 bytes (52 MB) copied, 9.79242 s, 5.4 MB/s
phone@localhost:~$ ls -lah
total 63M
drwxr-xr-x 24 phone phone 4.0K May 27 20:02 .
drwxr-xr-x 3 phone phone 4.0K Feb 12 15:32 ..
————- Edited
-rw-r–r– 1 phone phone 50M May 27 20:02 swapfile
————- Edited

phone@localhost:~$ sudo chmod 0600 swapfile
phone@localhost:~$ sudo chown root:root swapfile
phone@localhost:~$ sudo mkswap ./swapfile
mkswap: ./swapfile: warning: don’t erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 51196 KiB
no label, UUID=c083a787-70da-40e1-bd44-e2a18875cf75
phone@localhost:~$ sudo swapon ./swapfile
swapon: ./swapfile: swapon failed: Function not implemented
phone@localhost:~$ sudo mkswap -f ./swapfile
Setting up swapspace version 1, size = 51196 KiB
no label, UUID=55faa525-9190-45da-888e-01c829eca1dc
phone@localhost:~$ sudo swapon ./swapfile
swapon: ./swapfile: swapon failed: Function not implemented
phone@localhost:~$ uname -a
Linux localhost 2.6.32.9-ga541f1b #1 PREEMPT Fri May 27 09:18:49 KST 2011 armv7l GNU/Linux
phone@localhost:~$

What we can see here, however, is that it didn’t work. The question was why did it not work. The answer is that the Android/Linux kernel was compiled without CONFIG_SWAP=y. WIthout this compiled into the kernel, then swap is disabled. Unfortunately, since these kernels are digitally signed, I cannot simply find a swap module for the kernel and load it. Not to mention, as far as I can tell there isn’t one. I would need a whole new digitally signed kernel with that option enabled.

As of Android 4.0, I have been told this option is enabled, but for all of these older phones and tablets, it is not an option without specific kernels or patches. Bummer.

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *