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:
- Resize existing partition(s) or subpartition(s) to create spare space for a dedicated fixed-size swap partition.
- 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.
- 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?)
- Disable or deprioritise zRAM, and edit swappiness to about 20-30.
- 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.
"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 Nov 28 '14 at 04:22-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 Nov 28 '14 at 06:03free
increased to (128MB zRAM
+ the amount of KB I designated forswap.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 Nov 30 '14 at 15:16swapon
command after each boot (the other steps don't need to be repeated). As for location, you could try/data/local
. – Izzy Nov 30 '14 at 23:11/data/local
seems to work well as a location. Does Android have a standard (native) way to define a swap file or partition permanently, or if not, to run a script at boot-time to define it? Would like to use native methods if possible, myself, rather than download "yet more apps" that normally just package native methods anyway :) [And you might want to edit original answer again, you left the "-" before if=/of=] – Stilez Dec 01 '14 at 09:28swapon </path/to/swapfile>
did not work for me, but wrapping the file with a loop device did the trick:losetup /dev/block/loop0 </path/to/swapfile>; swapon /dev/block/loop0
– JepZ Jan 28 '19 at 00:36