[Motorola Droid 4] LuH:
Script for creating and running swap in /cache attached.

Whole script init.sh:

#!/system/bin/sh

date >> /data/swap/swap-init.log 2>&1
echo "Initializing swap." >> /data/swap/swap-init.log 2>&1
if [ ! -f /cache/swap ]; then # when /cache/swap is not present
echo "Swap file not found, creating it." >> /data/swap/swap-init.log 2>&1
date >> /data/swap/swap-setup.log 2>&1
echo "Creating swap file as it was not present." >> /data/swap/swap-setup.log 2>&1
echo "Space in /cache:" >> /data/swap/swap-setup.log 2>&1
df /cache >> /data/swap/swap-setup.log 2>&1
freeCache=$(busybox df -k /cache | tail -1 | awk '{ print $4 }')
let swapSize=freeCache*80/100 # count 80% of free space in /cache
echo "Creating ${swapSize} KB swap file." >> /data/swap/swap-setup.log 2>&1
dd if=/dev/zero of=/cache/swap bs=1024 count=$swapSize >> /data/swap/swap-setup.log 2>&1 # create swap file called swap in /cache that takes up 80% of its free space.
mkswap /cache/swap >> /data/swap/swap-setup.log 2>&1 # format the previously created 'swap' file for swap, just as you'd do with a partition
echo "Creation of the swap file completed." >> /data/swap/swap-setup.log 2>&1
date >> /data/swap/swap-setup.log 2>&1
fi
if [ ! -f /data/swap/swappines.txt ]; then
echo 15 1> /proc/sys/vm/swappiness 2>> /data/swap/swap-init.log # set swappiness 15
else
cat /data/swap/swappiness.txt 1> /proc/sys/vm/swappiness 2>> /data/swap/swap-init.log # set swappiness as in swappiness.txt - PUT THERE ONLY NUMS 1-99!
fi
swapon /cache/swap >> /data/swap/swap-init.log 2>&1 # use the swap file created in the installation script for swap
echo "Swap initialization done." >> /data/swap/swap-init.log 2>&1
date >> /data/swap/swap-init.log 2>&1

Usage:

Extract init.sh (and optionally swappiness.txt as well) to /data/swap/

Setup SManager to run it on boot: View attachment 3397902 (don't forget to hit the top-right SAVE button after you select Su and Boot)

Run it manually for first-time init (if you don't, the next boot will be pretty slow)

It will create the swap file on the first run, utilizing 80% of free space in the /cache partition. It's better to do step 3 - run it manually first, so it doesn't compete for system resources with other stuff starting on boot. It took me over five minutes to create the swap file on boot, compared to about two minutes when the system was already running. While creating, it eats up system resources and blocks other apps -> wait 5+ mins for it to finish. You have been warned ;) If it fails for whatever reason, just delete the /cache/swap file and run it again. It writes a huge file (about 750M) while everything else competes for the flash memory read and write which is why it's so slow at boot.

My setup log:

Thu Jul 9 23:46:53 CEST 2015
Creating swap file as it was not present.
Space in /cache:
Filesystem Size Used Free Blksize
/cache 1007.9M 33.3M 974.6M 4096
Creating 756409 KB swap file.
756409+0 records in
756409+0 records out
774562816 bytes transferred in 301.058 secs (2572802 bytes/sec)
Creation of the swap file completed.
Thu Jul 9 23:51:59 CEST 2015

The script logs inits to /data/swap/swap-init.log and the setup (creation of the swap file) to /data/swap/swap-setup.log. It sets swappiness to 15 or whatever you have in /data/swap/swappiness.txt (if it's missing, it defaults to 15).

If you want to see whether it's done creating the swap file yet, either watch the /cache/swap file grow (i.e. over SCP) or watch the setup log grow (tail -f /data/swap/swap-setup.log in shell, wait for the "Creation of the swap file completed." text to appear and then exit tail by Ctrl+C).

If you have set your SELinux to permissive state, you can save init.sh as /data/local/userinit.sh and don't need SManager at all - it will be run by CM itself. Make sure to create the /data/swap folder though so the logs can be saved, otherwise it may exit on error.