[HD2 Android NAND Development] Yank555:
Swap partition ?

Hi,

I leave the post below for reference only, it was my first go on swap, I've created a small guide which you can find here :

http://xdaforums.com/showthread.php?p=25549259#post25549259

JP.

----------------------------------------------------------------------------------------------------------------------------------

Hi,

I've partitionend my SD-card as to use DATA2SD, which is working just fine.

Now I've read on some other ROM thread, that there is a way to create a swap partition to extend RAM, so there is less killing / reloading of apps using CPU-Power and by that draining the battery slightly more.

Has anybody given this a try yet ? Would it be compatible with DATA2SD ?

From what I've read, swap partition is limited to 256Mb max.

I've checked free RAM (shell - 'free' command), and I only have left ~17'108kB of the 421'000kB total.

I suppose this could be quite a good idea...

JP.

---------- Post added at 10:33 PM ---------- Previous post was at 09:59 PM ----------

Hi again,

OK, I've done it, I now have a swap of ~250Mb :cool:

I based my proceedings upon this post : http://xdaforums.com/showpost.php?p=15609465&postcount=2

I also used the "dataswap250.sh" script mentioned by dorimanx as guideline to create the swap-file (this is not a swap partition though !!).

Baseline to do this is to have DATA2SD, in order to have "/data" mounted from the sd-ext partition (2nd primary partition on the SD-card).

I say this again, do this ONLY if you have DATA2SD working !!

Here is what I did using Terminal Emulator :

Here is the same but with comments as to what this will do and why to do it :

Then there is some more to be done as to activate the swap after a restart...

We need to create a file in "/system/etc/init.d", I've called mine "95_swap". Anyway it has to have a bigger 2-digit number at the beginning than the script starting DATA2SD, since we need DATA2SD script to be executed first to mount the partition that we need to gain access to the swap-file... On my HD2 the DATA2SD script was called "01data".

Using Terminal Emulator do the following :

Don't know what this will change, but I'll be testing this now ;)

JP.

PS: Started a few apps at the same time, checked with free, swap started getting used, so it should have an impact of some kind ;)

---------- Post added at decembre 12th, 2011 at 15:08 PM ---------- Previous post was at 10:33 PM ----------

If you want to use hard swap, or in the correct terms, a swap partition instead of a swap file, I would suggest the following steps :

1) Backup all the files on your sd-card to your PC (if you have a real card reader, I'd use that one rather than MAGLDR's USB mass storage)

2) Using a tool like "MiniTool Partition Wizard Home Edition" create the follwing partitions, in that order on the card (!) :

--- primary partition of type FAT32 (whatever is left)

--- primary partition of type ext4 (1, 2, 3 or 4Gb) *

--- primary partition of type swap (256Mb)

As you might have guessed, it is most important that all partitions are primary ;)

* If you don't want to use an sd-ext partition to store your apps, just create the first and last partition.

BTW, ignore the warning telling you that Windows will not see more than one partition, that's exactly how we want it.

Applying these modifications will take some time, the bigger your card, the longer.

3) Reformat the FAT32 partiton from within Windows using 32k block size (it gives better performance)

NB: It's the only partition you'll see in Windows anyway, so you can't format the wrong one here

4) Restore the files you backed up under 1) from your computer

5) Insert your card into the HD2 and boot Android, once booted, start a terminal

6) Type the following commands in the shell :

su -
mkswap /dev/block/mmcblk0p[COLOR="Red"][B]3[/B][/COLOR][COLOR="Gray"] (if you did create an ext4 partition)[/COLOR]
mkswap /dev/block/mmcblk0p[COLOR="Red"][B]2[/B][/COLOR][COLOR="Gray"] (if you haven't created an ext4 partition)[/COLOR]
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
echo "/dev/block/mmcblk0p[COLOR="Red"][B]3[/B][/COLOR] swap swap" >> /system/etc/fstab[COLOR="Gray"] (if you did create an ext4 partition)[/COLOR]
echo "/dev/block/mmcblk0p[COLOR="Red"][B]2[/B][/COLOR] swap swap" >> /system/etc/fstab[COLOR="Gray"] (if you haven't created an ext4 partition)[/COLOR]
echo "/system/xbin/swapon -a" > /system/etc/init.d/00_swap
echo "echo 50 > /proc/sys/vm/swappiness" >> /system/etc/init.d/00_swap
chmod 750 /system/etc/init.d/00_swap
chgrp shell /system/etc/init.d/00_swap
mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system
exit
exit

7) Power off your HD2

8) Power on you HD2

9) Start a terminal and type "free", you should see a little less than 250000 behind swap, instead of the 0 you have now