4

System: Rooted Android 4.4 phone (actual rom: CM 11 Milestone 6) with 1GB ram, plenty of internal storage, but no sdcard slot. My phone's partition scheme is unmodified CyanogenMod 11.

Problem: lowmemorykiller/OOM handler on my phone keeps killing vital system processes such as the lockscreen, or incallui, or acore, causing at best long freezes, and more often soft and hard system lockups. I'm probably running apps that push RAM beyond system minimum, and it's making a suboptimal choice of background process to kill. I looked into fine-tuning lowmemkiller but got nowhere.

As ram and not CPU is the issue, I want to try enabling internal storage based swap instead of zRAM as a workaround, which the phone should handle. But I can't find clear instructions how to do so. Every instructional page I found is either desktop not Android specific, external (SDcard) storage specific ("partition using USB+windows"), assumes you want file not partition based swap, or suggests a Google Play app to use. None explain step by step how to actually do it.

Assuming I've read the warnings and know the risks, and want to go ahead anyway, how do I do it? I really just want to get a list of the example console commands for using partition-based swap. I assume it goes something like this:

  1. Resize existing partition(s) or subpartition(s) to create spare space for a dedicated fixed-size swap partition.
  2. Create or define a new partition in the free space, and ensure it's formatted as swap, or the OS will format or use it as swap on boot.
  3. Edit some other system files to ensure swap will be mounted and enabled appropriately on boot, so the OS can recognise and use it. (fstab, or something else?)
  4. Disable or deprioritise zRAM, and edit swappiness to about 20-30.
  5. Reboot, cross fingers, and hope I did it right.

My current *nix experience level: I know Linux uses partitions and subpartitions, that new partitions and partition changes probably need me to manually edit fstab or other files, and manual edits may also be needed to ensure partitions will be mounted/enabled/used at boot. I'm haven't used the actual commands or changed the actual files so I don't know what to expect. I'm comfortable with console, but this is a bit of a new area for me.

How do I do this, step by step, and what are the commands I'd use if they aren't obvious. I can figure the rest from that.

2 Answers 2

6

Just a raw idea, not tested/verified by myself:

Swap can also be established using a swap file, so you could easily test whether it works at all. Try via adb shell or a terminal app, after becoming root, whether the dd, mkswap, and swapon commands are available. If so, you can try:

# create a file to be used for swapping
# (adjust the filename to where the file should reside, and the count
# to the size in kb it should occupy)
dd if=/dev/zero of=</path/to/swapfile> bs=1024 count=65536

# initialize the file for swap use
# (use the file created in the previous step)
mkswap </path/to/swapfile>

# enable swapping
swapon </path/to/swapfile>

# to disable swapping to that file:
# swapoff </path/to/swapfile>

There are ways to fine-tune this (e.g. setting specific values for swappiness) – but with the steps described you can easily test whether it works at all, without big danger of breaking things. Not even a reboot is required. In the best case, it simply works – in the worst case it does not, and you might have to manually delete the </path/to/swapfile> ;)

10
  • dd worked once I replaced -if/-of with if=/of=, respectively. mkswap didn't give any response (might be how it works if there isn't a problem to report). swapon errored out (message was minimal: "swapon failed for /path/and/file"). No verbose option for swapon, 3GB spare; I couldn't see how to learn what the issue was.
    – Stilez
    Commented Nov 28, 2014 at 4:22
  • Sorry for the typo with -if/-of (fixed). What file size have you tried with? What storage is the swapfile located on (e.g. an external card, or internal)?
    – Izzy
    Commented Nov 28, 2014 at 6:03
  • One more thing coming to my mind: It might be the kernel has no swap support. You can check that with this app.
    – Izzy
    Commented Nov 28, 2014 at 6:23
  • Just checked and says it's supported. I tried 512 MB on the internal storage /sdcard/swap.file (as mentioned in the OP, it doesn't have SDcard or external storage). It says it's able to work, judging by the "congrats, you can do it" message. So... what are the console commands to do so? Alternatively, it could be a permissions or path issue and the commands above are fine, what permissions/path should I use on Android for a test swap file?
    – Stilez
    Commented Nov 30, 2014 at 15:01
  • Update I just checked again, using a different path (/cache/swap.file rather than /sdcard/swap.file) and it now apparently works - free increased to (128MB zRAM + the amount of KB I designated for swap.file). I haven't tested if it is retained on reboot, but the above commands do seem to work. So it looks like it's path-dependent. So next question is... how do I set up a contiguous file/partition for swap, and where to put a file, or how to modify partitioning? The /cache partition is too small for 400 MB swap. Plus, I'd like it somewhere more "visible", if Android allows it.
    – Stilez
    Commented Nov 30, 2014 at 15:16
3

I was having the same issue. Tried 4 apps all failed. I know how to do this in other Linux distros, also shown manually above, still failed. Tried other ideas given above: moving to other mount points. Most you are denied, others are too small to be worth it.

Then noticed when running df

I saw an output like this:

/storage/sdcard0
/mnt/media_rw/sdcard0

Using the /mnt instead of /storage or /sdcard appears to have allowed me to enable swap successfully.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .