5,593,401 Members 36,360 Now Online
XDA Developers Android and Mobile Development Forum

[HOW TO] Create SWAPFILE to extend memory

Tip us?
 
omegahanggara
Old
#1  
omegahanggara's Avatar
Senior Member - OP
Thanks Meter 116
Posts: 381
Join Date: Jan 2013
Location: Jakarta
Default [HOW TO] Create SWAPFILE to extend memory

Hi guys. I want to share with you how to create SWAPFILE to extend memory.

Requirements :
- rooted ROM
- working init.d (if you want to mount it at boot, you need init.d capability)
- busybox (Stericson version is recommended)
- terminal emulator

1. Create swapfile
Open your terminal emulator, then escalate to root access using command

Code:
 $ su
Before we step further, choose where you want to make swapfile. In this tutorial, I'll create swapfile on /data directory. Different locations, means different command!

To create swapfile, apply this command
Code:
 # dd if=/dev/zero of=/data/swap bs=$((1024*1024)) count=YOUR_DESIRE_VALUE
Make your choice, how big your swapfile will be created. In this tutorial, I'll make 1024 kb of swapfile, yes it's 1 GB of swapfile.

So my command is
Code:
 # dd if=/dev/zero of=/data/swap bs=$((1024*1024)) count=1024
Wait a second. The bigger your value, the longer the process. After it's finished, and there's no error. Proceed to next step.

2. Format swapfile using mkswap command
After the creation is success, format the file using mkswap, so that file can be used as swap.

Code:
 # mkswap /data/swap
Remember, my swapfile is located in /data directory. Yours maybe different. Depends on where you created it in 1st step.

3. Mount your swapfile
After we format it, now we can mount it as swap using following command

Code:
 # swapon /data/swap
Remember, my swapfile is located in /data directory. Yours maybe different. Depends on where you created it in 1st step.

4. Tweak swappiness value to optimize swap system

Code:
  # echo 20 > /proc/sys/vm/swappiness
You can put value between 1 - 100. The less the value, the better the result. Why? Swappiness is a condition when to put overload memory to swap when your RAM is running out of memory. If you put value 20, System will put overload memory to swap when RAM is 80% (free 20%). By the way my value is 1 (ONE) :P

After that, drop cache so next time overload memory will be placed in your swap.

Code:
 # echo 3 > /proc/sys/vm/drop_cache
I need to wait 1 - 2 hour(s) to make it work.



As you can see, my swap is really working. You may need sometime to make it work.

Hit thanks if this helpful.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2014-01-02-08-44-49.png
Views:	2978
Size:	158.3 KB
ID:	2488987  
The Following User Says Thank You to omegahanggara For This Useful Post: [ Click to Expand ]
 
eclyptos
Old
#2  
eclyptos's Avatar
Senior Member
Thanks Meter 468
Posts: 2,480
Join Date: Jun 2008
Location: Planet Earth
Is this really necessary on Z1? What improvement we will get have 2gb real Ram + 2gb Swap Ram on SD?
The Following User Says Thank You to eclyptos For This Useful Post: [ Click to Expand ]
 
xasbo
Old
#3  
Senior Member
Thanks Meter 44
Posts: 250
Join Date: Feb 2012
Quote:
Originally Posted by eclyptos View Post
Is this really necessary on Z1? What improvement we will get have 2gb real Ram + 2gb Swap Ram on SD?
Agreed. Do you see any measurable difference on benchmarks, even?
The Following User Says Thank You to xasbo For This Useful Post: [ Click to Expand ]
 
benben972
Old
#4  
Member
Thanks Meter 8
Posts: 98
Join Date: Mar 2008
I can't activate swapp on official 4.3... Can you help me?

Sent from my C6903 using xda app-developers app
 
Crayt
Old
#5  
Junior Member
Thanks Meter 1
Posts: 19
Join Date: Jan 2011
On stock rooted .257, last command is

Code:
echo 3 > /proc/sys/vm/drop_caches
with an "s" to drop_cache.
The Following User Says Thank You to Crayt For This Useful Post: [ Click to Expand ]
 
Rekoil
Old
#6  
Rekoil's Avatar
Senior Member
Thanks Meter 327
Posts: 904
Join Date: May 2008
Location: Göteborg
This is the most idiotic idea ever, do not do this people, it will not increase performance in the slightest.
sony xperia z1 c6903 metallic purple

previous phones
sony xperia z c6603 royal purple - faulty backplate, returned
samsung galaxy s3 lte (gt-i9305n) marble white - sold... no more samsungs for me
htc one x glacier white - dead :'(
apple iphone 4s white - sold
 
xasbo
Old
#7  
Senior Member
Thanks Meter 44
Posts: 250
Join Date: Feb 2012
Quote:
Originally Posted by benben972 View Post
I can't activate swapp on official 4.3... Can you help me?

Sent from my C6903 using xda app-developers app
No one knows what you did and what went wrong. Learn to ask questions.
 
jamespmi
Old
#8  
Member
Thanks Meter 35
Posts: 93
Join Date: Jan 2012
Quote:
Originally Posted by xasbo View Post
No one knows what you did and what went wrong. Learn to ask questions.
He did.
4.3 is the point - on locked bootloaders as no system rw access. In orher words not possible on LB. A part of that the swap idea is nonsense as it slows down the device.

Sent from my C6903 using xda app-developers app
 
bahathir
Old
(Last edited by bahathir; 6th January 2014 at 04:54 AM.)
#9  
bahathir's Avatar
Senior Member
Thanks Meter 124
Posts: 295
Join Date: Feb 2010
Swap file is useful when the system needs more 'memory space than available physical memory (RAM)

Z1 has 2GB of RAM and able to provides resources for most of the time without the needs for swap file.

BTW ,swapping to external storage is slow and may increasing the storage failure.

On my Z1, it uses about 1GB of RAM and still have some more ready to be use.

Thank you.

Ref:
Code:
$ cat /proc/meminfo
Sent from my C6903 using xda app-developers app
Current: Motorola RAZR XT910, PHAsia (SEAOP), rooted stock.
Tablet: Nexus 7 (16GB) Vanilla stock,.

Was: Google Nexus One, boot unlocked + rooted, Asus Transformer TF101

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes