How to make and use a swap partition on SD-card (Sensation)

How to make and use a swap partition on SD-card (Sensation)

Postby yank555 » 13 Mar 2013, 18:41

Before proceding, please consider learning from Garfield :

Image
(Thanx to MuertoKo for this educational image)

I have spend numerous hours making this mod ... and writing this OP, so please have the decency to at least read it before asking questions.


REMEMBER

FIRST OF ALL, do a Nandroid backup, as well as a backup of your sd-card content !

You're doing this at your very own risk, I'm not to be held responsible if something goes wrong :cool:


There's another little warning I need to add to this, using part of your sd-card as swap space will cause that part of your card to undergo lots of read/writes, thus shortening the life of that part of the card...

I've been using hard swap for quite a long time now, no issues to report, but don't tell me I didn't warn you :cool:

Now that said, let's get going ;)


In case somebody wants to check it out, here is the swap activation script I wrote (attached) as well as explanations on how to make it all work :

I. Hard swap v2.3 (using a swap partition on the SD card)

(This is the alternative I recommend, considering the SD card being worn to be cheaper than the internal Sensation memory to be worn)

Initially this was a script and a guide that explained how to format and use a swap partition, but I've gone further in the meantime, since this now is a flashable MOD that will, if you have a swap partition on your SD-card, format that partition and install a swap activation script in system startup for you.

Here is how to use this mod :

1) Have I mentiond to backup your system (Nandroid) and SD-card ?! Cause now would be a real good time to do so :D

2) Partition your SD-card (Minitool Partition Wizard, 4ext, CWM...) - for a step by step documentation have a look [url="http://forum.xda-developers.com/wiki/index.php?title=SD_card_partitioning"]here[/url].
You can create as many partitions as you like/can, as long as all are primary partitions. This MOD will look for the swap partiton and find it even if it's not the last, though it's common practice for swap to be the last partition.

Just please don't create more than one swap partition, I don't know how the script would react if there were more than one ! You've been warned !


3) Download "Hard-Swap-Yank555.lu_Flasher-v2.3.zip" and put it onto your SD-card

4) Boot into recovery

5) Flash "Hard-Swap-Yank555.lu_Flasher-v2.3.zip" from your SD-card (like a ROM or kernel)

6) Reboot and enjoy !!

To check if all went fine, start a terminal and type "free", you'll need to see something different than 0 in your swap line, look at the attached print-screen ;)

Enjoy and please let me know how it worked for you !

BTW, I've successfully tested this on Android Revolution HD 6.6.5 XE and Virtuous Inquisition 4.0.2.

If on the other hand you'd like to remove this hard swap mod, just download and flash the attached "Hard-Swap-Yank555.lu_Uninstall.zip" file.

PS: You can find the thread for hard swap for the htc HD2 [url="http://forum.xda-developers.com/showthread.php?t=1630083"]here[/url].

-----------------------------------------------------Previous-versions-----------------------------------------------------

I. Hard swap v1.1 (using a swap partition on the SD card)

(This is the alternative I recommend, considering the SD card being worn to be cheaper than the internal Sensation memory to be worn)

1) Partition your sd-card (Minitool Partition Wizard, 4ext, CWM...)
Backup your DATA first !! I won't be responsible for your lost data :cool:

I suggest to use a partition of 256Mb to start with. I tested with 1Gb partition, was way too big, so this is up to you !
(maybe 512Mb if you do lots of multitasking)


2) Boot your system with the partitionned sd-card
I suppose in this scenario that you only have a FAT and a swap partition on the sd-card (2 partitions in total)

This means "/dev/block/mmcblk1p2" is the second partition on your sd-card and is the swap partition you've created in step 1.

NB: If you have an sd-ext or even sd-ext2, your swap partition will be "/dev/block/mmcblk1p3" or "/dev/block/mmcblk1p4"


3) Install the init.rd script

Download "98swap-v1.1.zip", unzip it and put the "98swap" file onto the root of your SD card.

Open a terminal and type the following :

NB: Change "mkswap /dev/block/mmcblk1p2" accordingly to point to the swap partition you've created in step 1.
su -
mount -o remount,rw /system
cp /mnt/sdcard/98swap /system/etc/init.d
chmod 755 /system/etc/init.d/98swap
chown 0:2000 /system/etc/init.d/98swap
mkswap /dev/block/mmcblk1p2
mount -o remount,ro /system
exit


4) Reboot your Sensation, start a terminal again and type free, you'll need to see something different than 0 in your swap line, like this ;)

Image

Swappiness will be set to 60 by the script, which is a rather conservative swap use, made sense to me since SD-swap is slower than zram, better not to use it too agressively. Feel free to experiment with the swappiness variable in the script ;) (values between 0 and 100, 0 meaning "try not to swap", 100 meaning "try to swap all the time")

I. Hard swap v1.0 (using a swap partition on the SD card)

(This is the alternative I recommend, considering the SD card being worn to be cheaper than the internal Sensation memory to be worn)

1) Partition your sd-card (Minitool Partition Wizard, 4ext, CWM...)
Backup your DATA first !! I won't be responsible for your lost data :cool:

I suggest to use a partition of 256Mb to start with. I tested with 1Gb partition, was way too big, so this is up to you !
(maybe 512Mb if you do lots of multitasking)


2) Boot your system with the partitionned sd-card
I suppose in this scenario that you only have a FAT and a swap partition on the sd-card (2 partitions in total)

This means "/dev/block/mmcblk1p2" is the second partition on your sd-card and is the swap partition you've created in step 1.

NB: If you have an sd-ext or even sd-ext2, you need to change the "swap_partition" variable in the beginning of the script accordingly to "/dev/block/mmcblk1p3" or "/dev/block/mmcblk1p4", pointing to wherever your swap partition is !


3) If necessary customize the 98swap script (attached to this post) and then put it onto your sd-card's root folder, you'll need it while executing the commands in step 4.

4) Install the init.rd script

Download "98swap-v1.0.zip", unzip it and put the "98swap" file onto the root of your SD card.

Open a terminal and type the following :

NB: Change "mkswap /dev/block/mmcblk1p2" accordingly to point to the swap partition you've created in step 1.
su -
mount -o remount,rw /system
cp /mnt/sdcard/98swap /system/etc/init.d
chmod 755 /system/etc/init.d/98swap
chown 0:2000 /system/etc/init.d/98swap
mkswap /dev/block/mmcblk1p2
mount -o remount,ro /system
exit


5) Reboot your Sensation, start a terminal again and type free, you'll need to see something different than 0 in your swap line, like this ;)

Image

Swappiness will be set to 50 by the script, which is a rather conservative swap use, made sense to me since SD-swap is slower than zram, better not to use it too agressively. Feel free to experiment with the swappiness variable in the script ;) (values between 0 and 100, 0 meaning "try not to swap", 100 meaning "try to swap all the time")
Nexus 5 (aka. Hammerhead) 32Gb
Note 3 SM-N9005 32Gb Proudly eFused
SGS3 GT-I9300 32Gb
HTC Sensation XE
HTC HD2
TF300TG 32Gb

Image
Credits FAdrums !
User avatar
yank555
-----------
 
Posts: 3520
Joined: 11 Mar 2013, 20:51
Has thanked: 924 times
Been thanked: 4608 times

Re: How to make and use a swap partition on the SD-card

Postby yank555 » 13 Mar 2013, 18:41

Changelog : I. Hard swap

Version 2.3
  • Added more debugging info to the log file generated at each boot to be able to more easily help you debug if the mod is not working for.

  • Download Link

Version 2.2
    Added modified parameters for the Android low memory killer so it will start killing tasks very late, plus swappiness is set to 100. This way swap is better taken advantage of.

  • Download Link

Version 2.1
    Added subcommands needed during install into the zip file, this is safer !

    If you have flashed this MOD already, there is NO NEED to flash the updated 2.1 version, only the flashing process has changed, not the script.

  • Download Link

Version 2.0

Uninstaller


Frequently Asked Questions

I have started a F.A.Q. about hardswap in my SGS3 thread, well worth reading, I suppose ;)
Nexus 5 (aka. Hammerhead) 32Gb
Note 3 SM-N9005 32Gb Proudly eFused
SGS3 GT-I9300 32Gb
HTC Sensation XE
HTC HD2
TF300TG 32Gb

Image
Credits FAdrums !
User avatar
yank555
-----------
 
Posts: 3520
Joined: 11 Mar 2013, 20:51
Has thanked: 924 times
Been thanked: 4608 times

Re: How to make and use a swap partition on the SD-card

Postby Weeka89 » 17 Mar 2013, 13:25

thanks man for the best swap mod :)
Weeka89
 
Posts: 1
Joined: 15 Mar 2013, 21:22
Has thanked: 0 time
Been thanked: 0 time

Re: How to make and use a swap partition on SD-card (Sensati

Postby Harbir » 24 Mar 2013, 14:21

Yank u ate the best ;)
Harbir
 
Posts: 1
Joined: 24 Mar 2013, 09:43
Has thanked: 2 times
Been thanked: 1 time

Re: How to make and use a swap partition on SD-card (Sensati

Postby ture1989 » 16 Apr 2013, 17:05

Hi, where is the link to the unistaller?
ture1989
 
Posts: 2
Joined: 14 Apr 2013, 16:55
Has thanked: 0 time
Been thanked: 1 time

Re: How to make and use a swap partition on SD-card (Sensati

Postby yank555 » 16 Apr 2013, 18:05

Good point, link added in the changelog post.

JP.
Nexus 5 (aka. Hammerhead) 32Gb
Note 3 SM-N9005 32Gb Proudly eFused
SGS3 GT-I9300 32Gb
HTC Sensation XE
HTC HD2
TF300TG 32Gb

Image
Credits FAdrums !
User avatar
yank555
-----------
 
Posts: 3520
Joined: 11 Mar 2013, 20:51
Has thanked: 924 times
Been thanked: 4608 times

Re: How to make and use a swap partition on SD-card (Sensati

Postby ture1989 » 16 Apr 2013, 18:12

ture1989 wrote:Hi, where is the link to the unistaller?


cheers! i will try it and let you know!
ture1989
 
Posts: 2
Joined: 14 Apr 2013, 16:55
Has thanked: 0 time
Been thanked: 1 time

Re: How to make and use a swap partition on SD-card (Sensati

Postby smint86 » 30 Apr 2013, 12:03

I got some problems concerning this mod. I'm using it together with a 512mb swap partion on CM10.1 (by albinoman887, v. APR-26). First of all, I tried it completly stock.

1) Clean flash of ROM, no additional system apps, init.d scripts, everything stock.
2) Clean flash of hardswap v2.3, which worked perfectly. All checks showed, that swap is working as it is meant to be.
3) After ~7 hours medium usage, the phone started lagging. When I say lagging, I mean almost unusuable. I took the time to get through to terminal and checked with "free". I saw, that swap is filled up completly, nothing free anymore.

I think that is the reason why it did lag. I don't think, that it's meant to be like this. At some point, minfree should kick some apps out of RAM/swap, to let the phone be usable, shouldn't it?

After that, I started expermenting:

Installed system tuner (got a pro license anyway), set minfree to medium (4,8,16,32,48,64), checked set it after boot with init.d script, rebooted. I then saw that it's interfering with the swap script, which got minfree values in it on it's own. So I removed those values from swap script, init.d created by system tuner now was the only one in init.d folder changing minfree values. Anyway, after reboot, minfree values again were at those settings, which were set by swap script before, although I removed them from there (24,31,38,46,53,65).

I don't know what I'm doing wrong. For now, I change it manually after every reboot and changed to swapiness=90 as well. Do you have experiences with CM10.1? Maybe, there is some tuning needed.
smint86
 
Posts: 1
Joined: 15 Apr 2013, 21:52
Has thanked: 2 times
Been thanked: 0 time

Re: How to make and use a swap partition on SD-card (Sensati

Postby yank555 » 30 Apr 2013, 12:17

Never used CM on the Sensation :(

I would suggest to use higher minfree values, so lmk kicks in in time, also reduce swappiness both as you suggested.

JP.

Sent from my CM10.1 / Yank555.lu CM10.1 kernel v1.5l-beta6 (Linux 3.0.75) powered Galaxy S3 i9300 using Tapatalk 2
Nexus 5 (aka. Hammerhead) 32Gb
Note 3 SM-N9005 32Gb Proudly eFused
SGS3 GT-I9300 32Gb
HTC Sensation XE
HTC HD2
TF300TG 32Gb

Image
Credits FAdrums !
User avatar
yank555
-----------
 
Posts: 3520
Joined: 11 Mar 2013, 20:51
Has thanked: 924 times
Been thanked: 4608 times

Re: How to make and use a swap partition on SD-card (Sensati

Postby gezortenplotz » 08 Jul 2013, 19:15

Hi,
using this on Albinoman's CM10.1/4.22 Rom for several weeks now ... runs very well.

thx!
gezortenplotz
 
Posts: 1
Joined: 21 Jun 2013, 23:56
Has thanked: 0 time
Been thanked: 1 time


Return to Mods

Who is online

Users browsing this forum: No registered users and 1 guest

cron