• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root [Boost Mobile] RAM Swapping without Swapper2

drewhill77

Android Enthusiast
Aug 26, 2012
662
206
Indianapolis, IN
If your'e like me and don't need one more program taking up space on your phone you can enable RAM swap through any terminal manager.

The following method will create a swapfile on your SD card...I use the SD card instead of /data because RAM swapping will increase the number of read/writes wherever the swapfile is located and I would rather have to replace my SD card than have my NAND go out:rolleyes: IF you want to use your internal memory you can replace /mnt/sdcard/ with /data/...

What you need:
Root
Busy Box (I use 1.19)
Terminal Manager (I use Smanager)
Kernel capable of swapping (I'm using glitch)

Open your terminal manager and enable SU if needed

To create your swapfile
Code:
# dd if=/dev/zero of=/mnt/sdcard/swapfile bs=1048576 count=X

X is the size of your swapfile in MB...should only take a couple minutes.

Now that you've got the swapfile on your SD we've got to turn it on
Code:
# mkswap /mnt/sdcard/swapfile
# swapon /mnt/sdcard/swapfile

Ta-DA! you now have an active ram swap type "free" and you should see your active swap...but we're not done yet. Still have to enable it at boot:D

Go to /etc/init.d/ and create file 99swapon (or whatever you want to name it) edit the file and type
Code:
#!/system/bin/sh
sleep 75
swapon /mnt/sdcard/swapfile

Depending on how fast your phone mounts your SD card you can reduce the sleep value to as low as 30.

Reboot...open terminal...type free and you should see your swap listed.

The default "swappiness" for android is 60 you can check this by typing
Code:
cat /proc/sys/vm/swappiness

To change this go to /etc/ and create a file named sysctl.conf edit the file and type
Code:
vm.swappiness=X

X is the level of swappiness and can be 0 - 100...the higher the number the more android uses swap. In your terminal type
Code:
sysctl -p

Output should show your new swappiness level...again to check this "cat /proc/sys/vm/swappiness" In order to have these settings applied at boot edit your 99swapon file and add
Code:
sysctl -p

Reboot...open terminal...type free to check swap is on...type cat /proc/sys/vm/swappiness to check your swappiness level.

For those of you who don't want to actually have to type out all of that here are some scripts I wrote up to automate it all...made a 32M and 64M version for /mnt/sdcard and /data.

Make Swapfile
http://dl.dropbox.com/u/101517904/32m_swapfile_data.sh
http://dl.dropbox.com/u/101517904/32m_swapfile_sdcard.sh
http://dl.dropbox.com/u/101517904/64m_swapfile_data.sh
http://dl.dropbox.com/u/101517904/64m_swapfile_sdcard.sh

Activate Swap, Set Swappiness and Set at Boot
http://dl.dropbox.com/u/101517904/data_swapon_boot.sh
http://dl.dropbox.com/u/101517904/SD_swapon_boot.sh

Enjoy!!:D

A brief note on swapping - This does not actually extend you RAM...Android swapping only moves mapped in-active apps from memory to swapfile. To put it in simple terms bigger is not better...so create yourself a nice little 32M or 64M swapfile and set your swappiness to 100. Also minfree does not account for swap so you can get by with lower minfree values if you're using V6 supercharger.
 
No offense there buddy but why would anyone do it this way? Swapper2 is less than a megabyte. It can place the swap file anywhere and will set you with a 256mb swap file in about 2 minutes.

Do I even need to say more? Lol
I mean it's neat and all yea. But not economic. Especially since there are alot of not savvy people on the forums that just Need the easiest way to do things
 
  • Like
Reactions: zeke86
Upvote 0
No offense there buddy but why would anyone do it this way? Swapper2 is less than a megabyte. It can place the swap file anywhere and will set you with a 256mb swap file in about 2 minutes.

Do I even need time say more? Lol
I mean it's neat and all yea. But not economic. Especially since there are alot of not savvy people on the forums that just Need the easiest way to do things

First off I'd like to point out that your thread http://androidforums.com/warp-all-things-root/604361-guide-zte-warp-swap-extra-ram.html
has people puting their swapfile in /data (i.e. internal memory)...flash memory (aka nand, sdcard, etc.) has a limited number of read/writes and using swap will decrease the lifespan of whatever flash you place it on. I'd much rather buy a new SD card than a new phone. Granted that is simply what you've told people to do and Swapper2 does have the option to use the SD Card.

Now for ease of use I would suggest Swapper2...however if you want more control over what's going on with your VM my method is not limited to 256M (although I see no reason to exceed that anyway lol), it enables sysctl.conf which actually gives more VM options than I listed (vm.dirty_ratio, vm.dirty_background_ratio and vm.vfs_cache_pressure) and you can add it directly to any rom release with just a little more scripting;)

question once i set up swapper2 do ihave to keep going back into it to free up ram

To answer your question...no. Once it's set up it should load on boot. Also this thread is actually about NOT using Swapper2...the thread you should've posted to is http://androidforums.com/warp-all-things-root/604361-guide-zte-warp-swap-extra-ram.html
 
  • Like
Reactions: Deleted User
Upvote 0
Actually your SD card has a limited number of read writes. Placing swap in data puts it in the system which is constantly read writing anyway. Everything you do does some r/rw in data. Not to mention system r/w is much faster than SD card.

This method is like I said not user friendly. And thanks to down we now have kernels with swap file added into it and activated at startup. .also in DATA. Because the system is meant for constant r/w. SD is not


Notice I'm not arguing for swapper2 but for placing swap in data. Because it's faster and internal memory was built for that
 
  • Like
Reactions: Deleted User
Upvote 0
It's really just a matter of preference lol...yes the internal memory is faster and designed for more read/writes but that number is still limited. The speed factor can be somewhat overcome by having a class 6 or higher sd card...and yes my sd card will wear out faster than internal memory but I would personally prefer to replace the SD card over replacing the phone.
 
Upvote 0
I am using a stock r.o.m. with glitch kernel and I can not locate the init.d file in the directory listed in this guide. i used es file explorer to search and was not able to find the file anywhere on my phone. if anyone could point me in the right direction as what what file i need to edit on a stock r.o.m. for this i would be very grateful
 
Upvote 0
I am using a stock r.o.m. with glitch kernel and I can not locate the init.d file in the directory listed in this guide. i used es file explorer to search and was not able to find the file anywhere on my phone. if anyone could point me in the right direction as what what file i need to edit on a stock r.o.m. for this i would be very grateful

You more than likely don't have init.d support activated...go to /system/etc and find "install-recovery.sh" if it doesn't exist then create it.

if it already existed add this at the end of the file
Code:
#init.d support
busybos run-parts /system/etc/init.d/
be sure to add a blank line at the end of the file

if it didn't exist put this in there
Code:
#!/system/bin/sh
#init.d support
busybox run-parts /system/etc/init.d/

in /system/etc/ add a folder named "init.d" and place any bootscripts you want run there
 
  • Like
Reactions: k4jxo
Upvote 0
You more than likely don't have init.d support activated...go to /system/etc and find "install-recovery.sh" if it doesn't exist then create it.

if it already existed add this at the end of the file
Code:
#init.d support
busybos run-parts /system/etc/init.d/
be sure to add a blank line at the end of the file

if it didn't exist put this in there
Code:
#!/system/bin/sh
#init.d support
busybox run-parts /system/etc/init.d/

in /system/etc/ add a folder named "init.d" and place any bootscripts you want run there

Thank you that fixed my problem:D
 
  • Like
Reactions: Dm47021
Upvote 0
Thank you for your praise... I too am new to programming and scripting and just recently started developing my own ROM. When I saw the post about swapper2 I wanted to see if there would be a way of doing that 100% in the background and when I found it I decided to share it.

Also at the time of writing this it took my phone nearly 75 seconds to mount the SD card after booting... I have since streamlined it and opted to to place the swapfile in /data. Even though that means more read/writes to my nand I figure something else will probably go out on my phone before it does lol.

If you want to continue using the swapfile on SD card you can tweak the sleep time and run free from your console to see if it loaded or not...or you can add an if the file exists then swapon else sleep 5 function...
 
Upvote 0
OK, so before finishing the entire instruction set above I had already gone and set my swap file size to a size I'm not going to admit to here...

How can I go about changing the partition size, and then the swap setup? For example's sake, let's say I set it to 512MB....and I'm looking to change it to 128MB. I DO run a ton of shit on my phone, so even 256 might be appropriate, I'm not really sure, but I've noticed with much joy that my phone hasn't rebooted once since I did this XD

Also, further argument for this method of setting swapfile up- I personally prefer, whenever possible, to know exactly (as much as I can understand) the process and effects of modifications to my stuff, and tighter control over what exactly happens. An app may decide to add something (like tracking, or something) I don't want, and I would never know until it is called out by someone who can deduce that stuff. Unlikely I'm sure, but still a valid (although admittedly ignorant) argument.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones