[Motorola Droid 4] LuH:
We have started this discussion in Mentor.37's [RECOVERY]Safestrap 3.75 for unused partitions thread and I decided to create a new thread for it.

Why swap?

Since D4 is low on RAM, especially for Lollipop (CM12), idea of having the system swap out some data instead of closing all apps but the one I currently use seems appealing to me, even for the trade-out of slowing the system down a bit when loading. More comprehensive (dated, but still valid) information on whether to use swap can be gathered from this article: Why Android Swap Doesn’t Make Sense. While even its name suggests you shouldn't swap in Android, the conclusion works in favor of trying swap in my installation of Lollipop where system and background apps eat up over 75% of RAM straight after boot:

Also in comments there are some persuasive arguments in favor of swapping, such as not having to reload content of apps (especially browsers) after they get killed off by Android. In my use, this is crucial when I'm without Internet connection for some time.

Current status: swapping works, but I have mixed feelings on whether it helps or not. It needs more tinkering with swappiness to find the right value, CM12's default of 60 is way too high.

Script for automated install and init with swappiness parameter in post #2 ;)

[MENTION=2956957]Milp[/MENTION]'s original post:

My next post, summing up how I got there. I've been running the system like this for over a day, with mixed feelings about result.

Great idea, inspired me to this little adventure (CM12 in system slot):

Putting swap file to cache partition (as it's 1 GB and using under 30 MB) and making preinstall swap:

/ # tar -cv /cache | gzip > /sdcard/cache.tar.gz
/ # dd if=/dev/zero of=/cache/swap bs=1024 count=819200
/ # mkswap /cache/swap
/ # swapon /cache/swap
/ # mkswap /dev/block/preinstall
/ # swapon /dev/block/preinstall

Now we need to make this mapping persistent - let's use /data/local/userinit.sh (don't forget to chmod 755 userinit.sh after you create it):

#!/system/bin/sh

swapon /cache/swap
swapon /dev/block/preinstall

This should run on startup (invoked by /system/etc/init.d/90userinit). It doesn't and I don't know why (yet), so I use SManager instead.

Results:

Not much tested, but it looks like it works. I ran CG Transit (offline timetables for Czech public transport) and then Hill Climb Racing (only resource-heavy game I have installed), which would usually kill off everything else, making the timetables forget its state. This didn't happen and switching out of the game felt a bit snappier, woohoo :D We'll see after some time though, this may be just me REALLY wanting this to help.

/ # free
free
total used free shared buffers
Mem: 859572 845284 14288 0 3336
-/+ buffers: 841948 17624
Swap: 1441784 66716 1375068

[MENTION=2956957]Milp[/MENTION] what script do you use? How exactly did you create your swap files?

To revert preinstall back to ext3 if you don't want to use it as swap anymore (it's been formatted as swap by mkswap):

/ # mke2fs /dev/block/preinstall
/ # tune2fs -j /dev/block/preinstall

(following is not finished)

Using webtop as dalvik-cache (and backup in case something goes wrong after restart):

/data # mv dalvik-cache/ dalvik-cache-old
/data # mkdir dalvik-cache
/data # mount -t ext4 /dev/block/webtop /data/dalvik-cache
/data # rm -rf dalvik-cache/*
/data # cp -r dalvik-cache-old/* dalvik-cache/
/data # rm -rf dalvik-cache-old/
/data # tar -cv dalvik-cache/ | gzip > /sdcard/dalvik-cache.tar.gz

Then it's needed to be mounted when startup. My initial attempt utilizing /data/local/userinit.sh failed, will need to edit ramdisk for this to work :/ Not today.

Random info about my system for understanding why did I also move dalvik cache elsewhere:

Tip: I use SSHDroid to easily ssh to device. adb shell doesn't suit me, especially for its lack of completing paths. And to have it nice and colorful, this is my first command: su -c bash

/ # cat /proc/partitions
major minor #blocks name alias

7 0 27160 loop0
7 1 25068 loop1
7 2 22980 loop2
7 5 35516 loop5
7 6 43872 loop6
7 7 4096 loop7
179 0 15552512 mmcblk1
179 1 128 mmcblk1p1
179 2 512 mmcblk1p2
179 3 512 mmcblk1p3
179 4 1 mmcblk1p4
179 5 512 mmcblk1p5
179 6 512 mmcblk1p6
179 7 4096 mmcblk1p7 pds
179 8 512 mmcblk1p8 utags
179 9 1024 mmcblk1p9
179 10 2048 mmcblk1p10
179 11 512 mmcblk1p11
179 12 512 mmcblk1p12
179 13 4096 mmcblk1p13
179 14 8192 mmcblk1p14 boot
179 15 9216 mmcblk1p15 recovery
179 16 217088 mmcblk1p16 cdrom
179 17 512 mmcblk1p17 misc
179 18 512 mmcblk1p18 cid
179 19 4096 mmcblk1p19 kpanic
179 20 655360 mmcblk1p20 system
179 21 1048576 mmcblk1p21 cache
179 22 622592 mmcblk1p22 preinstall
179 23 1364992 mmcblk1p23 webtop
179 24 3203072 mmcblk1p24 userdata
179 25 8401792 mmcblk1p25 emstorage
179 26 128 mmcblk1p26
179 32 62367744 mmcblk0
179 33 62366720 mmcblk0p1
254 0 27160 dm-0
254 1 25068 dm-1
254 2 22980 dm-2
254 5 35516 dm-5
254 6 43872 dm-6
7 8 21936 loop8
254 7 21936 dm-7
7 9 22980 loop9
254 8 22980 dm-8
7 10 28204 loop10
254 9 28204 dm-9
7 11 40736 loop11
254 10 40736 dm-10
7 12 5224 loop12
254 11 5224 dm-11
7 13 11492 loop13
254 12 11492 dm-12
7 14 10448 loop14
254 13 10448 dm-13
7 16 42824 loop16
254 15 42824 dm-15

/data # du -sh *
4.0K adb
6.6M anr
703.4M app
4.0K app-asec
4.0K app-lib
4.0K app-private
4.0K ash_history
116.0K backup
12.0K battd
0 bugreports
0 chargeonlymode
1.0G dalvik-cache
441.6M data
288.0K dontpanic
8.0K download
20.0K drm
4.0K emt
32.0K kernelpanics
32.0K local
4.0K location
84.0K logger
20.0K lost+found
12.0K media
20.0K mediadrm
1.6M misc
8.0K panicreports
4.0M pdsdata.img
44.0K property
4.0K resource-cache
4.0K security
24.0K ssh
4.3M system
16.0K tmp
5.1M tombstones
16.0K tpapi
4.0K user

/ # df
Filesystem Size Used Free Blksize
/dev 419.7M 60.0K 419.7M 4096
/sys/fs/cgroup 419.7M 12.0K 419.7M 4096
/mnt/asec 419.7M 0.0K 419.7M 4096
/mnt/obb 419.7M 0.0K 419.7M 4096
/system 636.7M 604.2M 32.5M 1024
/data 3.0G 2.2G 798.2M 4096
/cache 1007.9M 33.4M 974.5M 4096
/pds 3.9M 1.1M 2.8M 1024
/storage/sdcard0 8.0G 2.9G 5.1G 8192
/mnt/media_rw/sdcard0 8.0G 2.9G 5.1G 8192
/mnt/secure/asec 59.5G 58.0G 1.5G 32768
/mnt/media_rw/sdcard1 59.5G 58.0G 1.5G 32768
/mnt/secure/asec 59.5G 58.0G 1.5G 32768
/mnt/media_rw/sdcard0/.android_secure 59.5G 58.0G 1.5G 32768
/storage/sdcard1 59.5G 58.0G 1.5G 32768
[asec stripped]

Milp's response showing how did he approach the swapping problem, including setting swappiness to 15:

In the next post I'll elaborate on the scripts and hopefully upload nice automatic scripts here :) You still need to use SManager to run them though.