[Motorola Droid 4] LuH:
Works with if=/dev/zero ;)

Well, did you format the file for swap using mkswap?

I'm not advanced in batch scripting either, but this looks fine to me for your purpose. Holy Mother of Logging though :D However, the first "start" won't be in the log and log gets overwritten each run - you use > (save to file) instead of >> (append to file) in first two lines.

All this is quite heavy approach, may I suggest mine? :D

To put it into shell script format:

One-time installation:

#!/system/bin/sh

dd if=/dev/zero of=/cache/swap bs=1024 count=819200 # create 800 MB swap file called swap in /cache (this is for systems running in stock slot where there's 1GB partition for cache that's almost not used - adjust size (count=<size in KB>) for your system). I didn't experience any deletion of this. If you do like Milp did, just re-run this script.
mkswap /cache/swap # format the previously created 'swap' file for swap, just as you'd do with a partition
swapon /cache/swap # use this file as swap
umount /preinstall # not needed in CM12, it's not mounted (the folder is there though). Let's do it for legacy compatibility though :)
mkswap /dev/block/preinstall # format the whole /preinstall partition as swap so we don't have to deal with stupid deletions or mounts or whatever later
swapon /dev/block/preinstall # use preinstall as swap (this is kinda like mount for swap partition/device)

I didn't use any logging as I run these over ssh or from adb shell so I can see stdout and stderr. If you wish to, you can add Milp's >> /storage/sdcard0/swap.log 2>&1 at the end of each line before my comments:

#!/system/bin/sh

date >> /storage/sdcard0/swap-setup.log 2>&1
echo "Swap files installation started." >> /storage/sdcard0/swap-setup.log 2>&1
dd if=/dev/zero of=/cache/swap bs=1024 count=819200 >> /storage/sdcard0/swap-setup.log 2>&1 # create 800 MB swap file called swap in /cache (this is for systems running in stock slot where there's 1GB partition for cache that's almost not used - adjust size (count=<size in KB>) for your system). I didn't experience any deletion of this. If you do like Milp did, just re-run this script.
mkswap /cache/swap >> /storage/sdcard0/swap-setup.log 2>&1 # format the previously created 'swap' file for swap, just as you'd do with a partition
swapon /cache/swap >> /storage/sdcard0/swap-setup.log 2>&1 # use this file as swap
umount /preinstall >> /storage/sdcard0/swap-setup.log 2>&1 # not needed in CM12, it's not mounted (the folder is there though). Let's do it for legacy compatibility though :)
mkswap /dev/block/preinstall >> /storage/sdcard0/swap-setup.log 2>&1 # format the whole /preinstall partition as swap so we don't have to deal with stupid deletions or mounts or whatever later
swapon /dev/block/preinstall >> /storage/sdcard0/swap-setup.log 2>&1 # use preinstall as swap (this is kinda like mount for swap partition/device)
echo "Swap files installation finished." >> /storage/sdcard0/swap-setup.log 2>&1
date >> /storage/sdcard0/swap-setup.log 2>&1

Then you need this script running on boot, I use smanager as well:

#!/system/bin/sh

swapon /cache/swap # use the swap file created in the installation script for swap
swapon /dev/block/preinstall # use preinstall as swap
echo 15 > /proc/sys/vm/swappiness # set swappiness 15

Version with logs:

#!/system/bin/sh

date >> /storage/sdcard0/swap-init.log 2>&1
echo "Initializing swap." >> /storage/sdcard0/swap-init.log 2>&1
swapon /cache/swap >> /storage/sdcard0/swap-init.log 2>&1 # use the swap file created in the installation script for swap
swapon /dev/block/preinstall >> /storage/sdcard0/swap-init.log 2>&1 # use preinstall as swap
echo 15 1> /proc/sys/vm/swappiness 2>> /storage/sdcard0/swap-init.log # set swappiness 15
echo "Swap initialization done." >> /storage/sdcard0/swap-init.log 2>&1
date >> /storage/sdcard0/swap-init.log 2>&1

CM12's default is 60, which is way too much - after day of use I have sometimes been unable even to unlock the phone as seemingly the lock screen has been swapped away and it took several wakings of the phone before it allowed me to swipe the lockscreen up (I don't use any lock protection, just plain swipable lockscreen). It even worsened with Poweramp's custom lockscreen.

Will toy around with it for a bit in upcoming days.

I don't think I have ever gotten much over 300 MB swapped, making my current combined of almost 1,5 GB swap huge overkill. Will see after some time, but the /cache/swap file should be very sufficient and there's no need to mess up preinstall :)