Sunday, July 9, 2017

Creating and enabling an internal storage swap partition on rooted Android Kitkat


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.



Answer



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= bs=1024 count=65536

# initialize the file for swap use

# (use the file created in the previous step)
mkswap

# enable swapping
swapon

# to disable swapping to that file:
# swapoff

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 ;)



No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...