FORUMS

[SCRIPT] MySwap v1.0 (SD and NAND) 13/11/2013

43 posts
Thanks Meter: 19
 
By darklight2k2, Member on 13th November 2013, 06:06 PM
Post Reply Email Thread
THIS IS A SCRIPT TO HAVE SWAP AND NOT A ROM!
I tested the swap on "CM10.x" by volk204 but there isn't a reason it shouldn't work on other rom versions.

version 1.0 13/11/2013 18:29 GMT+2

I experienced some lag with my wave due to its low ram memory. So after testing a few things i found myself more comfortable with setting up swapfile on sd card(NAND memory); after few minutes this terminal becomes really smooth. (It strangely is faster than setting it up on the phone memory, atleast for me)
The idea is mine, but checking around i found that many other script were made. I got the sleep line to boot part idea from "Defiant07 @ XDA" (http://forum.xda-developers.com/show....php?t=2359182). Everything else (as simple it is it's all mine)

Swap is the *nix term for virtual memory, that maybe many are familiar with on windows.
You set up a partition/file and use that as virtual memory. It will be much slower than real ram, but it will be much faster than reloading everything from disk everytime.
Code:
#!/system/bin/sh
# This script was authored by Defiant07 @ XDA.  If you use/redistribute it, eve$
# Thanks to zeppelinrox most of all, but also many thanks to dk_zero-cool & gu5$
# Much thanks to pikachu01 @ XDA for permission to use the sysctl tweaks from T$
# Read Karl Marx!
# Nearly entirely modified by skyglow
swapfile="/storage/sdcard0/swapfile"
#swapsize in KB
swapsize=524288
swappiness=90
vfs_cache_pressure=100
dirty_background_ratio=5
dirty_ratio=20
dirty_writeback_centisecs=500
dirty_expire_centisecs=200
while [ ! "`ps | grep -m 1 [a]ndroid`" ]; do sleep 10; done
if [ ! -f "$swapfile" ]; then
  dd if=/dev/zero of=$swapfile bs=1024 count=$swapsize
  mkswap $swapfile
fi
#  sleep 30
#  mkswap $swapfile
swapon $swapfile
busybox sysctl -e -w vm.swappiness=$swappiness
busybox sysctl -e -w vm.vfs_cache_pressure=$vfs_cache_pressure
busybox sysctl -e -w vm.dirty_background_ratio=$dirty_background_ratio
busybox sysctl -e -w vm.dirty_ratio=$dirty_ratio
busybox sysctl -e -w vm.dirty_writeback_centisecs=$dirty_writeback_centisecs
busybox sysctl -e -w vm.dirty_expire_centisecs=$dirty_expire_centisecs
exit 0
Requirements
Superuser rights on terminal to change permission and copy this file

Configuration
1) set up "swapfile" field to where you want your swap
2) set up "swapsize" field to an appropriate value in KB! ( i think you should try values over 307200 => 300MB to have performance improvements)

(SD or NAND version)
SD version
size=512 MB
position=sdcard root

NAND version
size=300MB
position=bada application partition

How to install
1) Download the right zip from this page
2) Extract the file from the zip
3) Upload the file in some way on the phone
4) Become superuser
5) move it to "/system/etc/init.d"
6) this file should keep hits name "99myswap"
7) change permissions of "99myswap" to 755
8) change its rights to "root:shell"
9) done, next reboot your swap will be set up automatically

P.S.
How to check if swap is activated:
Open terminal
cat /proc/swaps
Swap filename should be displayed with the right size

[ADDED DEBUG SCRIPT]
Attached Files
File Type: zip MySwap-SD.zip - [Click for QR Code] (858 Bytes, 767 views)
File Type: zip MySwap-NAND.zip - [Click for QR Code] (854 Bytes, 521 views)
File Type: zip myswapdebug.zip - [Click for QR Code] (139.9 KB, 128 views)
The Following 5 Users Say Thank You to darklight2k2 For This Useful Post: [ View ] Gift darklight2k2 Ad-Free
13th November 2013, 06:10 PM |#2  
OP Member
Thanks Meter: 19
 
More
Possible problems

1) System hangs on cyanogen loading screen ( rotating circle)
INVESTIGATING

2) Battery charge lasts less.
Any kind of virtual memory use more electrical power to perform write/read on disk (SD). This is a side effect of swap.

3) File format
*NIX file format is LF and not CR-LF (for reference why this happens http://en.wikipedia.org/wiki/Newline#Representations)
You can't edit the file with windows notepad, but use something else such as notepad++ and save it in LF coding.

4) System is slower
Possible causes are:
a) you have applications on the same filesystem where you placed the swap
b) your memory (such as SD card) is too slow. Swap will work, it will just go much slower. Try it with a better sd. I tested it with a class 4 and class 10 sdcard and they both speed up. I don't have any possibility at the moment to test a class 2. (reference http://en.wikipedia.org/wiki/Secure_Digital#Speeds)

5) How to change permissions (thanks Eltjo for copy paste from your answer)
Open terminal
Type: su
Type: cd /system/etc/init.d
Type: chmod 0755 99myswap
Type: chown root:shell 99myswap

6) zRam
On my mobile it's faster if i disable zRam from Settings > Performance > Memory Management > zRam .
Anyway i think outcome may change. Try both solutions.
The Following 5 Users Say Thank You to darklight2k2 For This Useful Post: [ View ] Gift darklight2k2 Ad-Free
13th November 2013, 07:19 PM |#3  
Member
Thanks Meter: 32
 
More
could be possible to use free nand memory as swap instead of sd card?
13th November 2013, 07:30 PM |#4  
OP Member
Thanks Meter: 19
 
More
Quote:
Originally Posted by cfernr

could be possible to use free nand memory as swap instead of sd card?

I added the NAND version that installs itself in the bada partition. If you installed the sd version remember to remove the swapfile.
The Following User Says Thank You to darklight2k2 For This Useful Post: [ View ] Gift darklight2k2 Ad-Free
13th November 2013, 08:05 PM |#5  
Member
Thanks Meter: 32
 
More
Quote:
Originally Posted by darklight2k2

I added the NAND version that installs itself in the bada partition. If you installed the sd version remember to remove the swapfile.

lets try both, thank you very much
13th November 2013, 08:51 PM |#6  
OP Member
Thanks Meter: 19
 
More
no problem.

DEBUG REQUEST
Who had the loading screen on cyanogen circle may tell me which sd card class have?
The following procedure do not install the script, it just will work till reboot.
may them try to upload the script in a generic directory such as /storage/sdcard0 and execute it with
su
cd /storage/sdcard0
sh ./99myswap
I'd like the output of that command and the resulting /proc/swaps
then use the phone, (play/call/charge/reboot)
next boot start the script again please and tell me the resulting /proc/swaps again
Thank you for the help
The Following User Says Thank You to darklight2k2 For This Useful Post: [ View ] Gift darklight2k2 Ad-Free
13th November 2013, 08:59 PM |#7  
Member
Thanks Meter: 32
 
More
seems work on my phone.

installed swapfile on nand and ram increased 30mb, but low improvement in real performance.

need to change zram options, but cant find this on my phone, maybe due to language discrepancy. can you explain better?

thank you a lot
13th November 2013, 09:36 PM |#8  
saltcushy's Avatar
Junior Member
Thanks Meter: 0
 
More
I also cannot find zram a options under B.U.X V3.1 (4.3.1 CM10.2) by Tigrouzen
13th November 2013, 11:24 PM |#9  
OP Member
Thanks Meter: 19
 
More
If you don't have the menu for zRam it's disabled by default. To see it you should enable all developer settings.
Settings > About phone > Build number (tap 7 times)
Some more tweaks will unlock.

Quote:
Originally Posted by saltcushy

I also cannot find zram a options under B.U.X V3.1 (4.3.1 CM10.2) by Tigrouzen

Unfortunally i didn't test that rom yet but i think the procedure above will work.
The Following User Says Thank You to darklight2k2 For This Useful Post: [ View ] Gift darklight2k2 Ad-Free
14th November 2013, 01:14 AM |#10  
Member
Thanks Meter: 32
 
More
Quote:
Originally Posted by darklight2k2

If you don't have the menu for zRam it's disabled by default. To see it you should enable all developer settings.
Settings > About phone > Build number (tap 7 times)
Some more tweaks will unlock.


Unfortunally i didn't test that rom yet but i think the procedure above will work.

tested and I have to say this is necessary if you want to enjoy a few extra mb in this phone.

I recommend nand swap because everybody have 300-400 unused mb in bada apps partition.

disabling zRAM seems also recommendable.


I hope everybody take care of this script for future ROM releases

*** I will decrease swappiness to 70 or 60, I think it is enough.
14th November 2013, 01:57 PM |#11  
Senior Member
Thanks Meter: 64
 
More
Quote:
Originally Posted by darklight2k2

no problem.

DEBUG REQUEST
Who had the loading screen on cyanogen circle may tell me which sd card class have?
The following procedure do not install the script, it just will work till reboot.
may them try to upload the script in a generic directory such as /storage/sdcard0 and execute it with
su
cd /storage/sdcard0
sh ./99myswap
I'd like the output of that command and the resulting /proc/swaps
Thank you for the help

i've a samsung class 10 32gb.

i've not run the script with sh command, just copied it to /system/etc/init.d (aplied chmod and chown) and reboot the phone. after that it hangs on CM circle on first boot and have to re-install the rom. wipe data/factory reset didn't help.


best regards
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes