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

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

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 (using a swap partition on the SD card)(This is the alternative I recommend, rather than using a pagefile on internal memory, considering the SD card being worn to be cheaper than the internal memory to be worn)

Here is how to use this mod :

NB: This mod will only work if the kernel you use has swap support built in !

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

==> While doing so, now would be a great time to read the F.A.Q. in post 3. Especially do read at least the first question !!

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 !

So CPU speed is up by way much more than RAM, and I'm not taking GPU into consideration, plus storage speed increase etc...

Now those devices tend to be used in multitasking, having many apps running at the same time.

What those need is :

- CPU power to run on (we have plenty !)- RAM to fit in (we have little)

Now even though an APP is running, not every bit of it is really needed, so those parts can be swapped out (put into swap) freeing these memory blocks and making room for more apps to fit in RAM.

So what will this mod do for you : Allow for more multitasking

Keep more apps running in RAM at the same time, making the device snappier when switching from one app to the other.

One app won't run faster !

If now you don't have swap, Android will have to gently ask the least used app to please close (save data, and quit) to free up RAM. Now when you get back to that app, Android will have to reload it, the app will start and reload it's data.

You can see, this will take more time.

How do swap and Android Low Memory Task Killer get along ?

1) What is swap ?

Memory is divided into memory blocks that apps can use. In Android one memory block has 4096 bytes. Each memory block holds also the information when it has been used for the last time.

Considering this, one single app will be using many blocks. Some of those the app will be using a lot, some it won't. Take a simple card game. When you're playing, you're not using the app's settings menu, thus not using any of the blocks that hold those parts of the app.

Swap is a process that is used in most of modern operating systems. The virtual memory management system (that's swap !) will swap out all the blocks that were not used for a certain time, this "certain time" is influenced by swappiness and a few other parameters that we can change.

The plus is that the memory blocks that have been swapped out will free up RAM to be used by other apps, thus allowing for more apps to run at the same time.

On the other hand, if you need a swapped out block, that will cost extra time, since it's not located in memory any more but on the swap partition, so it will need to be reloaded into RAM (possibly by swapping out another block to make room for this).

That should give you a glimpse on the benefits and the costs of using swap.

That should also give you an idea of why LMK (= Android's own Low Memory Killer) settings matter, since if almost no free ram is available, a swap in will generally cost a swap out first the the swap in !

Consider swap as a way to have only part of the apps in RAM instead of having all of it, and as such allowing for more apps to run at the same time.

BTW, it does not add RAM, you can only add RAM by actually adding physical RAM, anyone telling you otherwise is either lying or does not know what she/he's talking about

2) What does Android Low Memory Killer do ?

All the apps you run are put into different categories (as a degree of importance).

Each category will have a number of memory pages (the 4Kb pages I spoke about above) limit, which as soon as free ram drops below of that limit, will make LMK start killing tasks of that category.

So the higher the limits, the sooner it will start its blood bath and kill away, or put otherwise, the higher the limit, the more free RAM you will have at any time.

ALMK is your guardian of free RAM.

3) Now swap & ALMK ??? How can swap work if ALMK keeps killing away ??

If you understood correctly the way those two work, you will have noticed they have two different triggers :

- LMK : number of free memory blocks per app category- swap : time a block has not been used

So swap will be filled over time, by unused blocks of apps running for a longer period of time (widgets, background apps mostly, but not exclusively).

By filling swap, memory blocks are beeing freed, so more free RAM is available.

If more memory blocks are freed, the LMK will be triggered later, since as long as it sees enough free blocks, it's happy and will do nothing.

Hopefully this explains to everyone how this all works, and helps you understand what is what, and why some combos work and some just don't.

In essence, don't use too low LMK values, as low memory will induce lag, because it will either require app kills (which need resources) or swap out / swap in operation (which also need resources, less though).

High LMK settings will not impeed swap to work, it will be used less or it will take more uptime to be used the same, since less apps can reside in memory, but with swap and given LMK settings, you will always be able to run more apps than without swap at the same given LMK settings.

Can I umount / remove my SD card without powering off the phone when using this mod ?

You can unmount / remount the SD card, since that will only unmount / remount the FAT/exFAT partition (e.g. the one you see in Windows and "/mnt/extSdCard").

But you should by no means remove the SD card (even if unmounted) while your system is running !

It would be as if removing part of RAM without prior notice while the system is running.

Always power off the device before removing the SD card !

What tool can I use to partition my SD card ?

I can recommend using Minitool Partition Wizard Home Edition, it is free and it is really good.

PS: Remember, all the partitions you create must be primary partitions, else neither Windows nor your SGS3 will recognise the SD card. If you make a mistake, don't worry, just repartition and you're good to go !

Swappiness 100 is too harsh for me, can I change that ?

I set it to 100, max... This is what the mod will do for you. If you want to change that, just edit the following file :

I personally have used 256Mb on my previous devices and that was far more than enough. Since the SGS3 is a "bigger" device, I've granted it 512Mb (since I can spare them), and so far I have not seen much more than ~230Mb being used by the system, so I will stick with that.

But you're free to use more, it will work and be available as swap, even if I don't believe an Android system will take any benefit from this.

I know that on computer systems, Linux recommends using a swap of 1x - 2x the RAM size, but let's not forget, we're talking mobile device, not computer/server system.

If you can prove me wrong here, I'll galdly change my point of view on this

What is the speed of my SD card ? Will it be fast enough ?

Obviously, the faster, the better I would recommend a class 4 card at least.

If you want to benchmark your card, be carefull, you might wrongfully test the internal SD card thinking it's the external. The internal card is faster, so you might be mislead here...

In his post Yusei recommends using AnTuTu and change the sdcard location in AnTuTu settings (set it to "/mnt/extSdCard").

If the internal sdcard is faster, why not use that one ?

It is not advisable to try to repartition intermal memory, it most certainly can be done, but the risk to brick the device is rather high, plus I don't know if anything would still be working, since everything relies on the current partition table. As I said, you could modify it, making one partitions smaller, keeping the same partition table logic and adding one last partition at the end, but I don't advise going there !!

You could then use a swap file rather that a swap partition, and put that file on the internal sd card, that would work, I've tested that already.

But ... using a swap means generating a potentially high amount of I/O operation on the storage that holds it.

Since flash memory is subjet to fail at certain amount of I/O operations (very high amount, but nontheless lifespam is limited somewhere), I had rather my sdcard fails, than the internal storage since sd cards are easy to replace and way cheaper than our phone.

Why is this supposed to be better than zram ?

I'm coming from the htc HD2, which I had for quite a long time, then went to an htc Sensation for a few months and now just got the SGS3.

RAM, zram and swap have been a topic I've spend countless hours on !

There are quite a few things I learned going that path, so I'd like to share some of the conclusions I have come to hoping they might be of help and shed some light on this :

1) if there is anything our devices lack most, it's RAM, CPU / GPU power is far better then the amount of RAM we're given which impeeds us from really using that power, EVEN in a device like the SGS3 !

Hence even though I'm happy to have an intl SGS3, I somewhat envy those that have an operator specific device in the US because those come with 2Gb of RAM, and that would have been a VERY clever thing to have in the intl. version as well.

2) Android uses swap very poorly if swappiness is set to anything less than the max (100). Why ? Well because Android Low Memory Killer starts kicking processes before RAM gets too low, which doesn't motivate Linux to swap that much. Plus the default settings when it is supposed to start kicking in are set way too high, which again increases the bad use of swap even more.

To check swappiness, type "cat /proc/sys/vm/swappiness" in a terminal. To set it to 100, type "echo 100 > /proc/sys/vm/swappiness" (as root, won't stick at reboot !).

You can verify swap usage after using your phone a little, by opening a terminal and typing free. You will not see that much swap used.

3) Using zram has proven to be a not so good idea imho. It will give you swap, yes, but as stated above, it is poorly used, at the extreme cost of eating up real RAM to give you that swap (and RAM is what is lacking most and we're looking to free up). CPU overhead here is really no issue, as stated in the wiki posted and quoted above.

So instead of helping, it merely does to opposite, which some here have already found out by increasing zram things get worse.

4) So for me the only way to go is keep the RAM as RAM as much as possible, while adding real swap so everything that clutters real RAM can be put somewhere else and free real RAM for other processes that need it.

To do this I use a Linux swap partition on an sdcard. And yes, this will wear the sd card faster, since it's going to generate more I/Os on that part of the card. But by experience it's not that bad, I never have had an issue so far and been using swap since like forever. Plus the sdcard is a not so expensive add-on, which on top can easily be replaced as well !

Can I use this mod with zram enabled ?

Yes you can, but you miss the whole point of this mod in that case, you're wasting precious RAM to hold a virtual swap partition, plus you use a real swap partiton.

The point of this mod is to keep as much RAM available as possible, so I'd recommend to disable zram to take fully advantage of this mod.

I seem to have set up everything fine, I can manually activate swap, but swap is not automatically enabled on boot, what can I do ?

Hardswap MOD relies on busybox symlinks to the necessary commands to be installed in /system/xbin, so please check if this is the case for the setup you're running.

You may also want to check if your kernel/ROM handles the execution of init.d scripts (residing in /system/etc/init.d). Even though most combo's do, some don't, and if the script is not executed at boot, swap will most obviously not be enabled.

Hello Yank! This is my first post here Nice to meat you :-pI have finally decided to make a swap partition on my sd card and have done everything as you Doc says.Now:I am trying to download the Hard-Swap-Yank555.lu* software but it's unavailable... can you plz fix the Links that I could finish my swap partition?

Hey JP, i need a little help here. I managed to create a swap partition on my ExtSD, and the scrip finds its when i flash it on recovery, and everything goes well on flashing, but when i reboot back to the system, and type "free" on terminal, in the swap partition line everything is 0s, not like the screenshot you posted on OP. Why is that? Am i missing something?

djluis48 wrote:Hey JP, i need a little help here. I managed to create a swap partition on my ExtSD, and the scrip finds its when i flash it on recovery, and everything goes well on flashing, but when i reboot back to the system, and type "free" on terminal, in the swap partition line everything is 0s, not like the screenshot you posted on OP. Why is that? Am i missing something?