[MOD](MIROSLAV_MM WE NEED YOU) Swap on data. - GT540 Optimus Android Development

I found an interesting script for Galaxy I5500, which does allow users to create swap file in data/system partition. I tested it on I5500 because i own one right now and the script does indeed work, i also noticed improvement in the swap performance. Right now i'm trying to do this on GT540 but i found some difficulties and i need your help. If we'll make it working i will create script for GT540.
First of all, this is how it's done:
1. Open up your terminal.
2. Get superuser permission using su command.
3. Type this( make sure you have 64 mb of free memory on data partition ):
Code:
dd if=/dev/zero of=/data/swapfile1 bs=1024 count=65536
mkswap /data/swapfile1
swapon /data/swapfile1
It does work fine until swapon command usage which does give some retarded error "Invalid argument" Anyone have idea how to make this work?
You can delete swapfile1 using:
Code:
rm /data/swapfile1

This is not good idea, there is chance to broke nand.

Erm how much swap can we squeeze in there :/

I don't think it would do much difference, phone is accessing nand very often anyway when loading apps and system components which are stored there. I just want to try it out because it gives noticeable performance improvement on Galaxy I5500. I can test for bad blocks as well after some time of use.
@UP
It depends how much free memory do you have on your data partition, altough i don't advice to use swap bigger than 64 MB. Android won't use that much even with swappiness set to 100, so using large swap partition or file is just waste of memory. Not mentioning the fact that it will decrease performance.

bataya said:
This is not good idea, there is chance to broke nand.
Click to expand...
Click to collapse
Yeah, but probably in a few years, when you would probably use another, newer phone.

Do you have any idea what to do with this invalid argument error? If now i'll try to pm miroslav and ask him for help.

shadovraven said:
I don't think it would do much difference, phone is accessing nand very often anyway when loading apps and system components which are stored there. I just want to try it out because it gives noticeable performance improvement on Galaxy I5500. I can test for bad blocks as well after some time of use.
@UP
It depends how much free memory do you have on your data partition, altough i don't advice to use swap bigger than 64 MB. Android won't use that much even with swappiness set to 100, so using large swap partition or file is just waste of memory. Not mentioning the fact that it will decrease performance.
Click to expand...
Click to collapse
you can create many swap files/partitions at the same time. the OS will choose which swap to use depend on its priority. if 2 swap files/partitions have the same priority, it will be used in a round-robin fashion
by default many swap apps create only 32MB swap file because it's sufficient enough for the system. I've seen many people create a swap partition as large as 512MB-1GB. It won't give them any increase in speed because the system will only use a very small amount of them. My SD card have a 54MB swap partition and android use only about 8-16MB swap with swappiness set to 10. If I set it to 60 as default, the swap usage will be about 40-50MB

SWAP on Data (30mb)
Code:
#!/system/bin/sh
if [ -e /data/.swap.img ];
then
losetup /dev/block/loop7 /data/.swap.img;
mkswap /dev/block/loop7;
swapon /dev/block/loop7;
echo "swap on data"
else
dd if=/dev/zero of=/data/.swap.img bs=1024 count=30000;
losetup /dev/block/loop7 /data/.swap.img;
mkswap /dev/block/loop7;
swapon /dev/block/loop7;
echo "swap create & on data"
fi;
put file in init.d

miroslav_mm said:
SWAP on Data (30mb)
Code:
#!/system/bin/sh
if [ -e /data/.swap.img ];
then
losetup /dev/block/loop7 /data/.swap.img;
mkswap /dev/block/loop7;
swapon /dev/block/loop7;
echo "swap on data"
else
dd if=/dev/zero of=/data/.swap.img bs=1024 count=30000;
losetup /dev/block/loop7 /data/.swap.img;
mkswap /dev/block/loop7;
swapon /dev/block/loop7;
echo "swap create & on data"
fi;
put file in init.d
Click to expand...
Click to collapse
Thank you miroslav, gonna put this into start post.
EDIT: I tried that and it doesn't seem to work, i've put that into init.d but free command returns that swap size is 0. What permission i should set? I will try to do this manually.
EDIT2: I tried it manually, swapon /dev/block/loop7 returns invalid argument. I attached screenshot so you can see for yourself.

Bump for miroslav to see, I hope this will work.

/dev/block/loop7 for 2.6.29 for Android 2.1 for example
open RE
/proc/ open file partitions
find you Data part by side
look like mtdblock6 on SDSL 3.0
That is all.

I tried it on SDSL v3 and swapon /dev/block/mtdblock6; also does return invalid argument error.

Not recommended, it makes phone lag

Related

[Q] What about swap in the Milestone?

Hi guys,
I'm a milestone owner, and very happy with this device, I've upgraded it with 1,1ghz ULV module, memhack, busybox and JIT and it's a lighting, but here is a question that I have:
I'm a linux user so I started to "play" with the busybox addon of the terminal (straight on the device), I am also a maemo user where the swap file was usual to create on the sd to make the device more usable;
Now, how about the milestone? Using the swapper app in the market, it seems to not work (using "busybox free"in the terminal doesn't show me any swap) so how to enable a swap file or partition on the milestone? I think it will help a lot for the memory hungry systems, themes, and on developing roms linke the Dexter's froyo and sense mods (which lacks on the ram front)
Have anyone managed to have swap to work on the milestone? or Is out there any guide to do it?
This sounds like an excellent idea. As I am also a linux (Ubuntu 10.04) user too, having a swap "partition" on your Milestone will give "memory hungry" applications exactly what the need.
Will be watching this Thread!
Yeah, my question is about the fact that other phones (i heard about spica,dream,g1) have this feature, but the common command on linux/maemo does not work :/
Hope there is a solution :-(
So guys, the problem is in the kernel I frear...
using busybox, I've managed to create a small 128mb partition, and also a. Swap file (to test), but the function
"Swapon" says it's" not implemented" so where is the origin of the pWow thats strange that nobody tried ;-( ok I will try to find a solution and I will report back what I find. Hope to have skme help lol xD
Edit:
so" not implemented" is in the swapper2 application; doind it in the terminal these are the results:
export PATH=/data/local/bin:$PATH
$ su
# busybox swapon
BusyBox v6905964.73458437589.3945345.RELEASE_FROM_FUTURE (2010-04-10 21:43:08 MSD) multi-call binary.
Usage: swapon [-a] [-p PRI] [DEVICE]
Start swapping on DEVICE
Options:
-a Start swapping on all swap devices
-p PRI Set swap device priority
# busybox swapon -a
swapon: /etc/fstab: No such file or directory
# busybox swapon -a /sdcard
swapon: /etc/fstab: No such file or directory
# sudo gedit /etc/fstab
sudo: not found
# gedit /etc/fstab
gedit: not found
# vi /etc/fsteb
vi: not found
So thats it....what is this fstab file?? I know its about partition table or something like that, but why we lack it? We have to figure how to implement it...maybe in that way the swap can be set via busybox... help :-(
#roblem??? :-( help!
Looks like someone has figured it out!
Please someone try and report back
http://www.droidforums.net/forum/bl...built-source-fast-working-3dlauncher-220.html
kreat1ve said:
Looks like someone has figured it out!
Please someone try and report back
http://www.droidforums.net/forum/bl...built-source-fast-working-3dlauncher-220.html
Click to expand...
Click to collapse
nice find keat1ve ... perhaps i will try out in the evening. if my wife gets me some spare time ... the instructions at droidforums is not really correct for milestone. it has to be adapted a little bit!
Will try right now, I will tell you ^_^
Thx a lot!!
yes it can and has been done. swap adds working memory true, but all those writing/reading to/from a partition/file in your sdcard WILL slow down your phone and shorten your sd card's life. its your choice eventually: either you want more memory, or you want speed. you cant have both.
yantz
@kreat1ve
this guide about the partitioning with adb does not work with milestone, I will try to create a swap partition with partition magic and then use droid swapper to enable it... let's hope xD
I dont wonna sound negative or anything but this is for the droid which is completly open which probably has a customized kernel with swap enabled, while our milestone is locked and does not have swap enabled in its kernel . Anyway i dont think trying this will hurt so i hope it works out
Following the guide, does not gave me results, but I asked to he one that posted it for more info;
meanwhile I've managed to create a .swap file and mkswap it using busybox, these are the results:
export PATH=/data/local/bin:$PATH
$ $ su
# dd if=/dev/zero of=/sdcard/.swap bs=1024 count=262144
262144+0 records in
262144+0 records out
268435456 bytes transferred in 57.985 secs (4629394 bytes/sec)
# mkswap/sdcard/.swap
mkswap/sdcard/.swap: not found
# mkswap /sdcard/.swap
mkswap: not found
# swapon /sdcard/.swap
swapon: not found
# busybox mkswap /sdcard/.swap
Setting up swapspace version 1, size = 268431360 bytes
UUID=16e9c236-61d9-49ec-a023-c529adb3109c
# busybox swapon /sdcard/.swap
swapon: /sdcard/.swap: Function not implemented
# busybox swapon -a
swapon: can't stat '/dev/block/mmcblk0p3': No such file or directory
# busybox free
total used free shared buffers
Mem: 230500 227516 2984 0 32
Swap: 0 0 0
Total: 230500 227516 2984
#
so the problem is that swapon does not recognize the file (but manually puting fstab in /etc and a file 06userinit within /etc/init.d/ containing
Code:
#!/system/bin/sh
swapon -a) but probably a partition of the sdcard may be recognized....now the problem form me...
I use windows 7 64bit...how the hell can I partition my sdcard with a swap partition?? LOL! XD
This is what blocks me...lol
try here
or
here
kassy_ok said:
try here
or
here
Click to expand...
Click to collapse
sadly the problem is in the kernel...."not supported" is the result of every swapon command...have to wait an official support or a custom kernel in 2nd boot...let's hope and wait...
Question: can't it be solved by creating a module supporting swap-filesystem?
TheSSJ said:
Question: can't it be solved by creating a module supporting swap-filesystem?
Click to expand...
Click to collapse
I'm wondering if someone has created such module?
I don`t know~~
alncool said:
I'm wondering if someone has created such module?
Click to expand...
Click to collapse
It seems that creating such a module is very hard. See the page cyanogenmod for milestone here :
http://code.google.com/p/cyanogenmo...ID Type Status Priority Version Owner Summary
I suggest everyone to star the feature. Maybe it will be developped by someone ... who knows !
So my friends... anyone could avance on this thread?
Sounds promising... but i also get stuck when enabling the swapon...
Anyone?
Cya
Hi!
Now, when we have official Froyo for MM with 2.6.32.9 kernel, can anyone create SWAP module for this kernel?
kilabdg said:
Hi!
Now, when we have official Froyo for MM with 2.6.32.9 kernel, can anyone create SWAP module for this kernel?
Click to expand...
Click to collapse
unfortunately no. Swap is not a module in Linux kernel, it changes the kernel's internal behaviour, so you cannot compile as swap=m, it is definitely y or n.

compcache swappiness

I am running sparks mod 1.6.4 compcache 32% hack.
I want to change the swappiness to 60.
How would I go about doing this?
Don't do it, it's much too high. I would suggest something around 10-20, i.e. type in terminal:
su
echo 10 > /proc/sys/vm/swappiness
Sent from my Gingerbread on Sapphire using XDA App
Why so low? Just seeking some wisdom.
Thanks.\
Also is this a permanent change or do i have to do this every boot?
This is not a permanent change, you have to apply this every time you reboot your phone. If you want it permanent, you should include it into the /system/bin/compcache script.
Swappiness defines, when data will be put into the swapfile. 100 means, all inactive data can be put into the swap, 0 means, that cached data will be removed first before using the swap. Disadvantage when too much data is within swap: the system speed goes down ... so you have to find a good compromize.
AndDiSa said:
This is not a permanent change, you have to apply this every time you reboot your phone. If you want it permanent, you should include it into the /system/bin/compcache script.
Swappiness defines, when data will be put into the swapfile. 100 means, all inactive data can be put into the swap, 0 means, that cached data will be removed first before using the swap. Disadvantage when too much data is within swap: the system speed goes down ... so you have to find a good compromize.
Click to expand...
Click to collapse
ok so i edited the file and pushed it.
now compcache is not starting and when i type it in the terminal it says permission denied.
Any help?
should i try inputting the command you first gave me into compcache?
After the modification, the compcache file should look something like
...
start)
echo 3 > /proc/sys/vm/drop_caches
modprobe $MODULE
rzscontrol $DEV --disksize_kb=32576 --init
swapon $DEV
echo 10 > /proc/sys/vm/swappiness
;;
...
this is what i have
#!/system/bin/sh
#
# Compcache manager
# [email protected] (cyanogen)
#
DEV=/dev/block/ramzswap0
MODULE=ramzswap
MODULES_DIR=/system/modules/lib/modules/`uname -r`
case "$1" in
start)
echo 3 > /proc/sys/vm/drop_caches
echo 30 > /proc/sys/vm/swappiness
modprobe $MODULE
rzscontrol $DEV --disksize_kb=$2 --init
swapon $DEV
;;
stop)
swapoff $DEV >/dev/null 2>&1
rmmod $MODULE >/dev/null 2>&1
;;
stats)
rzscontrol $DEV --stats
;;
*)
echo "Usage: $0 {start <size>|stop|stats}"
exit 1
esac
exit 0
I cant seem to get it to work.
this is the original too.
it just keeps saying permission denied
You are running the script as root, i.e
> su
# /system/bin/compcache start
to start the script manually?
Before modifing the script, you have to remount /system to set it read-write, otherwise it's read only!
try to fix the permission

[Q] Moving Linuxswap to NAND

Hello. i wanted to know if anybody has tried moving your swap to your data or cache partition on your phone since it's faster then sd. I found this and i'm guessing you could remount your your cache as swap instead of sdcard.
i'm new to the android/linux thing and this site, but this has really helped alot!
There's some smart mofo's and TONS of info on here.
i found this more or less. This is a mixture of threads
Enable swap:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
mkswap /dev/block/mmcblk0p3
echo "swapon -a" >> /system/etc/init.d/05userinit (on my phone it was 20userinit)
echo "/dev/block/mmcblk0p3 swap swap" >> /system/etc/fstab (i didnt have fstab, use > instead)
reboot
Move swap to data:
mkdir /data/swap
echo "ln -s /data/swap mtdblk0p3" >> /system/etc/init.d/??userinit (whatever it is on your phone)
so i guess this thread can be deleted. sorry
Please Read Carefully!
Do NOT, I repeat DO NOT put swap on the phone's nand. Swap is accessed very often and causes further wearing of the NAND chips.This is why it was never implemented before, it can end up killing the chip completely, you're better off leaving it on the SD card. And the phone is about 2-3yrs of age now, so the NAND is probably worn something bad...
rdhoggattjr said:
i found this more or less. This is a mixture of threads
Enable swap:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
mkswap /dev/block/mmcblk0p3
echo "swapon -a" >> /system/etc/init.d/05userinit (on my phone it was 20userinit)
echo "/dev/block/mmcblk0p3 swap swap" >> /system/etc/fstab (i didnt have fstab, use > instead)
reboot
Move swap to data:
mkdir /data/swap
echo "ln -s /data/swap mtdblk0p3" >> /system/etc/init.d/??userinit (whatever it is on your phone)
so i guess this thread can be deleted. sorry
Click to expand...
Click to collapse
Uh, this doesn't do what you might think it does. The swap remains on the sd card (mmcblk0p3), assuming you typo'ed on the ln command...
Jeff
Ditto what they said about wearing out the internal flash...
SDcard is replacable, plus if your builtin is faster, you need a new card.
Class 10 cards are much faster, and far cheaper than killing your phone by wearing out the flash.

Swap speed testing

Now we have working swap in lastest CM7 builds. I use swap partition on my SD card, and i want to test, how fast it works with different tweaks of sysctl. Can somebody recommend benchmarking utility for testing swap work speed? Not only SD read/write ratio, i want to test exactly swap speed.
And sorry for my bad English.
I'm not sure if it' possible.
Swap is handled as the extension of ram and only used of the there is not enough free space in the memory.
I think i've never seen any app for swap benchmarking.
But swap's performacnce greatly depends on your sdcard's speed.
Erovia said:
I'm not sure if it' possible.
Swap is handled as the extension of ram and only used of the there is not enough free space in the memory.
I think i've never seen any app for swap benchmarking.
But swap's performacnce greatly depends on your sdcard's speed.
Click to expand...
Click to collapse
Thank you for reply. It is sad that we can not test swap working speed. Ok, now i will try some tweaks from this thread.
If you want to achieve the best performance with swap, you should use a Class10 card and a not to big swap file (around 32MB).
I have a Class 10 Kingston 8 GB SDCard.
I used the MiniTool Partition Wizard to make 3 partitions:
1. Primary FAT32, approx. 6.2 GB.
2. Primary EXT2, 1 GB
3. Primary Linux Swap, 256 MB (yes, I know is too much, but I wanted to test how much it would be used)
With -FuFu- OR Minimod, I upgraded the EXT2 partition to EXT3 and right after, to EXT4.
I'm using the 98swapon script from -FuFu-.
The result: my Milestone is performing very good! Using ~ 120 MB of swap, if I understood the values correctly.
stswonL Days
Tiago Costa said:
I have a Class 10 Kingston 8 GB SDCard.
I used the MiniTool Partition Wizard to make 3 partitions:
1. Primary FAT32, approx. 6.2 GB.
2. Primary EXT2, 1 GB
3. Primary Linux Swap, 256 MB (yes, I know is too much, but I wanted to test how much it would be used)
With -FuFu- OR Minimod, I upgraded the EXT2 partition to EXT3 and right after, to EXT4.
I'm using the 98swapon script from -FuFu-.
The result: my Milestone is performing very good! Using ~ 120 MB of swap, if I understood the values correctly.
Click to expand...
Click to collapse
I have 16 Gb class 10 sdcard, and my partitioning of it very similar with your - with 1 Gb Ext2 and 256Mb Linux Swap in the same sequence.
I have used at least 130 Mb of swap partition, but after this value some applications (like Dolphin HD with many pages) was closed. How to save more applications in background amd use more place in swap partition?
And i use swappiness=100 and "Agressive 2" profile of V6 Supercharger script. Before it i used swappiness=15 and profile "Multitasking" and had worse multitasking and work speed. Now all works very nice.
I read about this settings in the thread about swap on SGSIII.
Upd
I tried make swap file in the internal memory of device in /data partition just for test. I think, we can use ~32 Mb in /data. Swap file was made but not connected . I think, internal memory storage is faster then SDCard. But it may be dangerous for phone.
100% of swappiness? Strange, this should be worse than 15%. My phone is performing well with default value (15%).
Tiago Costa said:
100% of swappiness? Strange, this should be worse than 15%. My phone is performing well with default value (15%).
Click to expand...
Click to collapse
Yes, it's strange for me too, but it works!
Andrew Morton sets his workstation vm.swappiness parameter to 100. “My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don’t want hundreds of megabytes of BloatyApp’s untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful.”
Click to expand...
Click to collapse
Sorry, i can not post prooflink now.
I'm using swappiness=100, so far so good and i have not perfomance decrease.
My settings now (script for init.d):
Code:
#!/system/bin/sh
# VM tweaks (/proc/sys/vm)
# The intensity of the work with the swap
# This defines the memory cache filling threshold before foreground app data is written to internal memory (default 20%):
echo "90" > /proc/sys/vm/dirty_ratio
# This defines the memory cache filling threshold before background app data is written to internal memory (default 5%):
echo "70" > /proc/sys/vm/dirty_background_ratio
# This is the interval of when the writeback daemons periodically wake up and write old data out to disk (1/100 s; default 500):
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs
# How old dirty data should be before the kernel considers it old enough to be written to disk (1/100 s; default 200):
echo "1000" > /proc/sys/vm/dirty_expire_centisecs
# Number of pages which are written to swap in a single attempt. The swap I/O size is 2^n (0-8; default 3):
echo "1" > /proc/sys/vm/page-cluster
# Controls how agressively the kernel will swap memory pages (default 10%):
echo "100" > /proc/sys/vm/swappiness
# Memory tweaks
# This is used to force the Linux VM to keep a minimum number of kilobytes free (default 5120):
echo "4096" > /proc/sys/vm/min_free_kbytes
# File system cache use ratio versus memory system cache (default 100%):
echo "50" > /proc/sys/vm/vfs_cache_pressure
# Causes the kernel to drop clean caches, dentries and inodes from memory, causing that memory that become free (0-3; default 0):
echo "3" > /proc/sys/vm/drop_caches
# SD card I/O tweaks
# Changing I/O sheduler type for SD to "noop" (default "cfq"):
chmod 777 /sys/block/mmcblk0/queue/scheduler
echo "noop" > /sys/block/mmcblk0/queue/scheduler
if [ ! -e /sys/block/mmcblk0/queue/scheduler]
then
sleep 60
fi
chmod 777 /sys/block/mmcblk0/queue/scheduler
echo "noop" > /sys/block/mmcblk0/queue/scheduler
# Changing cache size for SD card (default 256 Kb):
chmod 777 /sys/block/mmcblk0/queue/read_ahead_kb
echo "2048" > /sys/block/mmcblk0/queue/read_ahead_kb
chmod 777 /sys/devices/virtual/bdi/179:0/read_ahead_kb
echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb
if [ ! -e /sys/block/mmcblk0/queue/read_ahead_kb]
then
sleep 60
fi
chmod 777 /sys/block/mmcblk0/queue/read_ahead_kb
echo "2048" > /sys/block/mmcblk0/queue/read_ahead_kb
chmod 777 /sys/devices/virtual/bdi/179:0/read_ahead_kb
echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb
# swap partition
mkswap /dev/block/mmcblk0p3
swapon /dev/block/mmcblk0p3
What are you think about it? It is my first script for Android, and i used FuFu swap script and this thread about tweaks. And System Tuner. V6 Supercharger script upd8 installed with 'Agressive 2 +Bulletproof Launcher' settings.
Multitasking works perfectly, but swap partition using is limited by 130 ~Mb, i don't now, why. Maybe it is linked with FREE ram size (full ram minus ram, used for kernel)?
And how i can make spoilers on this forum? Please say me a tag,
Spoiler
not works.

[WIP] Swap in CM 11/12

We have started this discussion in Mentor.37's [RECOVERY]Safestrap 3.75 for unused partitions thread and I decided to create a new thread for it.
Why swap?
Since D4 is low on RAM, especially for Lollipop (CM12), idea of having the system swap out some data instead of closing all apps but the one I currently use seems appealing to me, even for the trade-out of slowing the system down a bit when loading. More comprehensive (dated, but still valid) information on whether to use swap can be gathered from this article: Why Android Swap Doesn’t Make Sense. While even its name suggests you shouldn't swap in Android, the conclusion works in favor of trying swap in my installation of Lollipop where system and background apps eat up over 75% of RAM straight after boot:
Jeffrey Blattman said:
And here’s a few counter arguments that I can imagine,
1. The native Android memory management scheme is there for apps, but not for other processes. That is, having swap allows the many processes that run to support the Linux operating system to be moved out of physical memory.
Click to expand...
Click to collapse
Also in comments there are some persuasive arguments in favor of swapping, such as not having to reload content of apps (especially browsers) after they get killed off by Android. In my use, this is crucial when I'm without Internet connection for some time.
Current status: swapping works, but I have mixed feelings on whether it helps or not. It needs more tinkering with swappiness to find the right value, CM12's default of 60 is way too high.
Script for automated install and init with swappiness parameter in post #2
@Milp's original post:
Milp said:
I placed 550mb swap files in both /webtop and /preinstall (mounted under storage), also smaller ones in cache, system and data. Swapped on all of them, it's like a brand new phone now, speed wise.
Using 40 swappiness. cm11.
I created the swap files in an app called swapper and moved them to the locations. If anyone is interested in the swapon script for smanager, i can post it here.
somehow using dd with if=/dev/null did not work and filling those files with /dev/urandom didn't let me swap on them.
I don't know if its a good test for how fast things got, but i'm now able to watch a 720p video in the desktop site of youtube in firefox with 3 addons. It plays fluently.
Hope this is the right place for it, not sure whether it deserves it's own thread.
Click to expand...
Click to collapse
My next post, summing up how I got there. I've been running the system like this for over a day, with mixed feelings about result.
Milp said:
I placed 550mb swap files in both /webtop and /preinstall (mounted under storage), also smaller ones in cache, system and data. Swapped on all of them, it's like a brand new phone now, speed wise.
Click to expand...
Click to collapse
Great idea, inspired me to this little adventure (CM12 in system slot):
Putting swap file to cache partition (as it's 1 GB and using under 30 MB) and making preinstall swap:
Code:
/ # tar -cv /cache | gzip > /sdcard/cache.tar.gz
/ # dd if=/dev/zero of=/cache/swap bs=1024 count=819200
/ # mkswap /cache/swap
/ # swapon /cache/swap
/ # mkswap /dev/block/preinstall
/ # swapon /dev/block/preinstall
Now we need to make this mapping persistent - let's use /data/local/userinit.sh (don't forget to chmod 755 userinit.sh after you create it):
Code:
#!/system/bin/sh
swapon /cache/swap
swapon /dev/block/preinstall
This should run on startup (invoked by /system/etc/init.d/90userinit). It doesn't and I don't know why (yet), so I use SManager instead.
Results:
Not much tested, but it looks like it works. I ran CG Transit (offline timetables for Czech public transport) and then Hill Climb Racing (only resource-heavy game I have installed), which would usually kill off everything else, making the timetables forget its state. This didn't happen and switching out of the game felt a bit snappier, woohoo We'll see after some time though, this may be just me REALLY wanting this to help.
Code:
/ # free
free
total used free shared buffers
Mem: 859572 845284 14288 0 3336
-/+ buffers: 841948 17624
Swap: 1441784 66716 1375068
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
@Milp what script do you use? How exactly did you create your swap files?
To revert preinstall back to ext3 if you don't want to use it as swap anymore (it's been formatted as swap by mkswap):
Code:
/ # mke2fs /dev/block/preinstall
/ # tune2fs -j /dev/block/preinstall
(following is not finished)
Using webtop as dalvik-cache (and backup in case something goes wrong after restart):
Code:
/data # mv dalvik-cache/ dalvik-cache-old
/data # mkdir dalvik-cache
/data # mount -t ext4 /dev/block/webtop /data/dalvik-cache
/data # rm -rf dalvik-cache/*
/data # cp -r dalvik-cache-old/* dalvik-cache/
/data # rm -rf dalvik-cache-old/
/data # tar -cv dalvik-cache/ | gzip > /sdcard/dalvik-cache.tar.gz
Then it's needed to be mounted when startup. My initial attempt utilizing /data/local/userinit.sh failed, will need to edit ramdisk for this to work :/ Not today.
Random info about my system for understanding why did I also move dalvik cache elsewhere:
Tip: I use SSHDroid to easily ssh to device. adb shell doesn't suit me, especially for its lack of completing paths. And to have it nice and colorful, this is my first command: su -c bash
Code:
/ # cat /proc/partitions
major minor #blocks name alias
7 0 27160 loop0
7 1 25068 loop1
7 2 22980 loop2
7 5 35516 loop5
7 6 43872 loop6
7 7 4096 loop7
179 0 15552512 mmcblk1
179 1 128 mmcblk1p1
179 2 512 mmcblk1p2
179 3 512 mmcblk1p3
179 4 1 mmcblk1p4
179 5 512 mmcblk1p5
179 6 512 mmcblk1p6
179 7 4096 mmcblk1p7 pds
179 8 512 mmcblk1p8 utags
179 9 1024 mmcblk1p9
179 10 2048 mmcblk1p10
179 11 512 mmcblk1p11
179 12 512 mmcblk1p12
179 13 4096 mmcblk1p13
179 14 8192 mmcblk1p14 boot
179 15 9216 mmcblk1p15 recovery
179 16 217088 mmcblk1p16 cdrom
179 17 512 mmcblk1p17 misc
179 18 512 mmcblk1p18 cid
179 19 4096 mmcblk1p19 kpanic
179 20 655360 mmcblk1p20 system
179 21 1048576 mmcblk1p21 cache
179 22 622592 mmcblk1p22 preinstall
179 23 1364992 mmcblk1p23 webtop
179 24 3203072 mmcblk1p24 userdata
179 25 8401792 mmcblk1p25 emstorage
179 26 128 mmcblk1p26
179 32 62367744 mmcblk0
179 33 62366720 mmcblk0p1
254 0 27160 dm-0
254 1 25068 dm-1
254 2 22980 dm-2
254 5 35516 dm-5
254 6 43872 dm-6
7 8 21936 loop8
254 7 21936 dm-7
7 9 22980 loop9
254 8 22980 dm-8
7 10 28204 loop10
254 9 28204 dm-9
7 11 40736 loop11
254 10 40736 dm-10
7 12 5224 loop12
254 11 5224 dm-11
7 13 11492 loop13
254 12 11492 dm-12
7 14 10448 loop14
254 13 10448 dm-13
7 16 42824 loop16
254 15 42824 dm-15
Code:
/data # du -sh *
4.0K adb
6.6M anr
703.4M app
4.0K app-asec
4.0K app-lib
4.0K app-private
4.0K ash_history
116.0K backup
12.0K battd
0 bugreports
0 chargeonlymode
1.0G dalvik-cache
441.6M data
288.0K dontpanic
8.0K download
20.0K drm
4.0K emt
32.0K kernelpanics
32.0K local
4.0K location
84.0K logger
20.0K lost+found
12.0K media
20.0K mediadrm
1.6M misc
8.0K panicreports
4.0M pdsdata.img
44.0K property
4.0K resource-cache
4.0K security
24.0K ssh
4.3M system
16.0K tmp
5.1M tombstones
16.0K tpapi
4.0K user
Code:
/ # df
Filesystem Size Used Free Blksize
/dev 419.7M 60.0K 419.7M 4096
/sys/fs/cgroup 419.7M 12.0K 419.7M 4096
/mnt/asec 419.7M 0.0K 419.7M 4096
/mnt/obb 419.7M 0.0K 419.7M 4096
/system 636.7M 604.2M 32.5M 1024
/data 3.0G 2.2G 798.2M 4096
/cache 1007.9M 33.4M 974.5M 4096
/pds 3.9M 1.1M 2.8M 1024
/storage/sdcard0 8.0G 2.9G 5.1G 8192
/mnt/media_rw/sdcard0 8.0G 2.9G 5.1G 8192
/mnt/secure/asec 59.5G 58.0G 1.5G 32768
/mnt/media_rw/sdcard1 59.5G 58.0G 1.5G 32768
/mnt/secure/asec 59.5G 58.0G 1.5G 32768
/mnt/media_rw/sdcard0/.android_secure 59.5G 58.0G 1.5G 32768
/storage/sdcard1 59.5G 58.0G 1.5G 32768
[asec stripped]
Milp's response showing how did he approach the swapping problem, including setting swappiness to 15:
Milp said:
Hi there, I'm using the following code. I'm using some random app to create swapfiles since dd doesn't work for me with if=/dev/null, it creates 0byte files. And swapping on a file filled with /dev/urandom doesn't seem to work. No idea how else i could go about that.
Code:
#!/system/bin/sh
echo start > /storage/sdcard0/swap.log 2>&1
echo mountstuff > /storage/sdcard0/swap.log 2>&1
umount /preinstall >> /storage/sdcard0/swap.log 2>&1
mount -o rw,remount / >> /storage/sdcard0/swap.log 2>&1
rm -r preinstall >> /storage/sdcard0/swap.log 2>&1
mkdir /storage/preinstall >> /storage/sdcard0/swap.log 2>&1
mkdir /storage/webtop >> /storage/sdcard0/swap.log 2>&1
mount -o ro,remount / >> /storage/sdcard0/swap.log 2>&1
mount -t ext3 /dev/block/preinstall /storage/preinstall >> /storage/sdcard0/swap.log 2>&1
mount -t ext4 /dev/block/webtop /storage/webtop >> /storage/sdcard0/swap.log 2>&1
chmod 777 /storage/preinstall >> /storage/sdcard0/swap.log 2>&1
chmod 777 /storage/webtop >> /storage/sdcard0/swap.log 2>&1
echo swappiness...15 >> /storage/sdcard0/swap.log 2>&1
echo 15 1> /proc/sys/vm/swappiness 2>> /storage/sdcard0/swap.log
echo cping... >> /storage/sdcard0/swap.log >> /storage/sdcard0/swap.log 2>&1
cp /storage/sdcard0/Swapper/swap.swp /storage/preinstall/swap.swp >> /storage/sdcard0/swap.log 2>&1
chmod 666 /storage/preinstall/swap.swp >> /storage/sdcard0/swap.log 2>&1
cp /storage/sdcard0/Swapper/swap.swp /cache/swap.swp >> /storage/sdcard0/swap.log 2>&1
chmod 666 /cache/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /storage/preinstall/swap.swp >> /storage/sdcard0/swap.log 2>&1
mount -o remount,rw /dev/block/system /system >> /storage/sdcard0/swap.log 2>&1
swapon /system/swap.swp >> /storage/sdcard0/swap.log 2>&1
echo swappingon... >> /storage/sdcard0/swap.log 2>&1
swapon /storage/sdcard0/Swapper/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /storage/webtop/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /data/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /cache/swap.swp >> /storage/sdcard0/swap.log 2>&1[/HIDE]
This might not be too good of a batch script, but i've never before in my life made linux batch scripts, I'm happy it works. I use smanager to execute it on boot.
There is a pre-created 100mb swapfile in /storage/sdcard0/Swapper/swap.swp that gets copied to /cache/ and /storage/preinstall/, since the files there seem to get wiped regularily.
Of course swapping on sdcard0 does not work since sdcard0 does not support permissions (fat?), i was just too lazy to remove it. A logfile is generated in sdcard0 called swap.log.
Been messing around with the swappiness a lot. 30-40 swappiness really enhances multitasking but the phone seems to get slow after some time because it has to do a lot of swap io i guess. Trying 15 now.
Click to expand...
Click to collapse
In the next post I'll elaborate on the scripts and hopefully upload nice automatic scripts here You still need to use SManager to run them though.
Script for creating and running swap in /cache attached.
Whole script init.sh:
Code:
#!/system/bin/sh
date >> /data/swap/swap-init.log 2>&1
echo "Initializing swap." >> /data/swap/swap-init.log 2>&1
if [ ! -f /cache/swap ]; then # when /cache/swap is not present
echo "Swap file not found, creating it." >> /data/swap/swap-init.log 2>&1
date >> /data/swap/swap-setup.log 2>&1
echo "Creating swap file as it was not present." >> /data/swap/swap-setup.log 2>&1
echo "Space in /cache:" >> /data/swap/swap-setup.log 2>&1
df /cache >> /data/swap/swap-setup.log 2>&1
freeCache=$(busybox df -k /cache | tail -1 | awk '{ print $4 }')
let swapSize=freeCache*80/100 # count 80% of free space in /cache
echo "Creating ${swapSize} KB swap file." >> /data/swap/swap-setup.log 2>&1
dd if=/dev/zero of=/cache/swap bs=1024 count=$swapSize >> /data/swap/swap-setup.log 2>&1 # create swap file called swap in /cache that takes up 80% of its free space.
mkswap /cache/swap >> /data/swap/swap-setup.log 2>&1 # format the previously created 'swap' file for swap, just as you'd do with a partition
echo "Creation of the swap file completed." >> /data/swap/swap-setup.log 2>&1
date >> /data/swap/swap-setup.log 2>&1
fi
if [ ! -f /data/swap/swappines.txt ]; then
echo 15 1> /proc/sys/vm/swappiness 2>> /data/swap/swap-init.log # set swappiness 15
else
cat /data/swap/swappiness.txt 1> /proc/sys/vm/swappiness 2>> /data/swap/swap-init.log # set swappiness as in swappiness.txt - PUT THERE ONLY NUMS 1-99!
fi
swapon /cache/swap >> /data/swap/swap-init.log 2>&1 # use the swap file created in the installation script for swap
echo "Swap initialization done." >> /data/swap/swap-init.log 2>&1
date >> /data/swap/swap-init.log 2>&1
Usage:
Extract init.sh (and optionally swappiness.txt as well) to /data/swap/
Setup SManager to run it on boot: View attachment 3397902 (don't forget to hit the top-right SAVE button after you select Su and Boot)
Run it manually for first-time init (if you don't, the next boot will be pretty slow)
It will create the swap file on the first run, utilizing 80% of free space in the /cache partition. It's better to do step 3 - run it manually first, so it doesn't compete for system resources with other stuff starting on boot. It took me over five minutes to create the swap file on boot, compared to about two minutes when the system was already running. While creating, it eats up system resources and blocks other apps -> wait 5+ mins for it to finish. You have been warned If it fails for whatever reason, just delete the /cache/swap file and run it again. It writes a huge file (about 750M) while everything else competes for the flash memory read and write which is why it's so slow at boot.
My setup log:
Code:
Thu Jul 9 23:46:53 CEST 2015
Creating swap file as it was not present.
Space in /cache:
Filesystem Size Used Free Blksize
/cache 1007.9M 33.3M 974.6M 4096
Creating 756409 KB swap file.
756409+0 records in
756409+0 records out
774562816 bytes transferred in 301.058 secs (2572802 bytes/sec)
Creation of the swap file completed.
Thu Jul 9 23:51:59 CEST 2015
The script logs inits to /data/swap/swap-init.log and the setup (creation of the swap file) to /data/swap/swap-setup.log. It sets swappiness to 15 or whatever you have in /data/swap/swappiness.txt (if it's missing, it defaults to 15).
If you want to see whether it's done creating the swap file yet, either watch the /cache/swap file grow (i.e. over SCP) or watch the setup log grow (tail -f /data/swap/swap-setup.log in shell, wait for the "Creation of the swap file completed." text to appear and then exit tail by Ctrl+C).
If you have set your SELinux to permissive state, you can save init.sh as /data/local/userinit.sh and don't need SManager at all - it will be run by CM itself. Make sure to create the /data/swap folder though so the logs can be saved, otherwise it may exit on error.
Milp said:
Hi there, I'm using the following code. I'm using some random app to create swapfiles since dd doesn't work for me with if=/dev/null, it creates 0byte files.
Click to expand...
Click to collapse
Works with if=/dev/zero
Milp said:
And swapping on a file filled with /dev/urandom doesn't seem to work. No idea how else i could go about that.
Click to expand...
Click to collapse
Well, did you format the file for swap using mkswap?
Milp said:
Code:
#!/system/bin/sh
echo start > /storage/sdcard0/swap.log 2>&1
echo mountstuff > /storage/sdcard0/swap.log 2>&1
umount /preinstall >> /storage/sdcard0/swap.log 2>&1
mount -o rw,remount / >> /storage/sdcard0/swap.log 2>&1
rm -r preinstall >> /storage/sdcard0/swap.log 2>&1
mkdir /storage/preinstall >> /storage/sdcard0/swap.log 2>&1
mkdir /storage/webtop >> /storage/sdcard0/swap.log 2>&1
mount -o ro,remount / >> /storage/sdcard0/swap.log 2>&1
mount -t ext3 /dev/block/preinstall /storage/preinstall >> /storage/sdcard0/swap.log 2>&1
mount -t ext4 /dev/block/webtop /storage/webtop >> /storage/sdcard0/swap.log 2>&1
chmod 777 /storage/preinstall >> /storage/sdcard0/swap.log 2>&1
chmod 777 /storage/webtop >> /storage/sdcard0/swap.log 2>&1
echo swappiness...15 >> /storage/sdcard0/swap.log 2>&1
echo 15 1> /proc/sys/vm/swappiness 2>> /storage/sdcard0/swap.log
echo cping... >> /storage/sdcard0/swap.log >> /storage/sdcard0/swap.log 2>&1
cp /storage/sdcard0/Swapper/swap.swp /storage/preinstall/swap.swp >> /storage/sdcard0/swap.log 2>&1
chmod 666 /storage/preinstall/swap.swp >> /storage/sdcard0/swap.log 2>&1
cp /storage/sdcard0/Swapper/swap.swp /cache/swap.swp >> /storage/sdcard0/swap.log 2>&1
chmod 666 /cache/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /storage/preinstall/swap.swp >> /storage/sdcard0/swap.log 2>&1
mount -o remount,rw /dev/block/system /system >> /storage/sdcard0/swap.log 2>&1
swapon /system/swap.swp >> /storage/sdcard0/swap.log 2>&1
echo swappingon... >> /storage/sdcard0/swap.log 2>&1
swapon /storage/sdcard0/Swapper/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /storage/webtop/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /data/swap.swp >> /storage/sdcard0/swap.log 2>&1
swapon /cache/swap.swp >> /storage/sdcard0/swap.log 2>&1[/HIDE]
This might not be too good of a batch script, but i've never before in my life made linux batch scripts, I'm happy it works. I use smanager to execute it on boot.
There is a pre-created 100mb swapfile in /storage/sdcard0/Swapper/swap.swp that gets copied to /cache/ and /storage/preinstall/, since the files there seem to get wiped regularily.
Click to expand...
Click to collapse
I'm not advanced in batch scripting either, but this looks fine to me for your purpose. Holy Mother of Logging though However, the first "start" won't be in the log and log gets overwritten each run - you use > (save to file) instead of >> (append to file) in first two lines.
Milp said:
Of course swapping on sdcard0 does not work since sdcard0 does not support permissions (fat?), i was just too lazy to remove it. A logfile is generated in sdcard0 called swap.log.
Click to expand...
Click to collapse
All this is quite heavy approach, may I suggest mine?
To put it into shell script format:
One-time installation:
Code:
#!/system/bin/sh
dd if=/dev/zero of=/cache/swap bs=1024 count=819200 # create 800 MB swap file called swap in /cache (this is for systems running in stock slot where there's 1GB partition for cache that's almost not used - adjust size (count=<size in KB>) for your system). I didn't experience any deletion of this. If you do like Milp did, just re-run this script.
mkswap /cache/swap # format the previously created 'swap' file for swap, just as you'd do with a partition
swapon /cache/swap # use this file as swap
umount /preinstall # not needed in CM12, it's not mounted (the folder is there though). Let's do it for legacy compatibility though :)
mkswap /dev/block/preinstall # format the whole /preinstall partition as swap so we don't have to deal with stupid deletions or mounts or whatever later
swapon /dev/block/preinstall # use preinstall as swap (this is kinda like mount for swap partition/device)
I didn't use any logging as I run these over ssh or from adb shell so I can see stdout and stderr. If you wish to, you can add Milp's >> /storage/sdcard0/swap.log 2>&1 at the end of each line before my comments:
Code:
#!/system/bin/sh
date >> /storage/sdcard0/swap-setup.log 2>&1
echo "Swap files installation started." >> /storage/sdcard0/swap-setup.log 2>&1
dd if=/dev/zero of=/cache/swap bs=1024 count=819200 >> /storage/sdcard0/swap-setup.log 2>&1 # create 800 MB swap file called swap in /cache (this is for systems running in stock slot where there's 1GB partition for cache that's almost not used - adjust size (count=<size in KB>) for your system). I didn't experience any deletion of this. If you do like Milp did, just re-run this script.
mkswap /cache/swap >> /storage/sdcard0/swap-setup.log 2>&1 # format the previously created 'swap' file for swap, just as you'd do with a partition
swapon /cache/swap >> /storage/sdcard0/swap-setup.log 2>&1 # use this file as swap
umount /preinstall >> /storage/sdcard0/swap-setup.log 2>&1 # not needed in CM12, it's not mounted (the folder is there though). Let's do it for legacy compatibility though :)
mkswap /dev/block/preinstall >> /storage/sdcard0/swap-setup.log 2>&1 # format the whole /preinstall partition as swap so we don't have to deal with stupid deletions or mounts or whatever later
swapon /dev/block/preinstall >> /storage/sdcard0/swap-setup.log 2>&1 # use preinstall as swap (this is kinda like mount for swap partition/device)
echo "Swap files installation finished." >> /storage/sdcard0/swap-setup.log 2>&1
date >> /storage/sdcard0/swap-setup.log 2>&1
Then you need this script running on boot, I use smanager as well:
Code:
#!/system/bin/sh
swapon /cache/swap # use the swap file created in the installation script for swap
swapon /dev/block/preinstall # use preinstall as swap
echo 15 > /proc/sys/vm/swappiness # set swappiness 15
Version with logs:
Code:
#!/system/bin/sh
date >> /storage/sdcard0/swap-init.log 2>&1
echo "Initializing swap." >> /storage/sdcard0/swap-init.log 2>&1
swapon /cache/swap >> /storage/sdcard0/swap-init.log 2>&1 # use the swap file created in the installation script for swap
swapon /dev/block/preinstall >> /storage/sdcard0/swap-init.log 2>&1 # use preinstall as swap
echo 15 1> /proc/sys/vm/swappiness 2>> /storage/sdcard0/swap-init.log # set swappiness 15
echo "Swap initialization done." >> /storage/sdcard0/swap-init.log 2>&1
date >> /storage/sdcard0/swap-init.log 2>&1
Milp said:
Been messing around with the swappiness a lot. 30-40 swappiness really enhances multitasking but the phone seems to get slow after some time because it has to do a lot of swap io i guess. Trying 15 now.
Click to expand...
Click to collapse
CM12's default is 60, which is way too much - after day of use I have sometimes been unable even to unlock the phone as seemingly the lock screen has been swapped away and it took several wakings of the phone before it allowed me to swipe the lockscreen up (I don't use any lock protection, just plain swipable lockscreen). It even worsened with Poweramp's custom lockscreen.
Will toy around with it for a bit in upcoming days.
I don't think I have ever gotten much over 300 MB swapped, making my current combined of almost 1,5 GB swap huge overkill. Will see after some time, but the /cache/swap file should be very sufficient and there's no need to mess up preinstall
I'm testing swap on stock 4.1.2 and I'm using app called Roehsoft Ram-Expander (I bougth this when I was xperia user). Seems to work but I'm wondering if the app is necessary.
Borchuck said:
I'm testing swap on stock 4.1.2 and I'm using app called Roehsoft Ram-Expander (I bougth this when I was xperia user). Seems to work but I'm wondering if the app is necessary.
Click to expand...
Click to collapse
Just added my scripts to post #2. It still needs a third-party app (SManager) to be run automatically though.
It seems the app you mentioned puts the swap file on the sd card, while my script puts it to internal memory to the /cache partition. If internal storage is faster than SD (haven't tested, but it probably is), then the swap file created by my script should be faster as well. On the other hand, the app is easily controllable through its UI, while my script is just a script and you need to run it by a third-party app anyways. So whatever you like more, use it
Uploaded automated script for creation and initialization of swap in /cache (to be run on startup). Please let me know if you stumble upon any error
If there's a problem with swap file creation, make sure you have busybox installed with support for df - the built-in df in my shell doesn't recognize the -k flag so it's not good for free space counting.
LuH said:
Just added my scripts to post #2. It still needs a third-party app (SManager) to be run automatically though.
It seems the app you mentioned puts the swap file on the sd card, while my script puts it to internal memory to the /cache partition. If internal storage is faster than SD (haven't tested, but it probably is), then the swap file created by my script should be faster as well. On the other hand, the app is easily controllable through its UI, while my script is just a script and you need to run it by a third-party app anyways. So whatever you like more, use it
Click to expand...
Click to collapse
Thanks for answer!
In this app you can choose swap file path and I've chose /preinstall (512 mb).
Scripts can be ran by placing them into init.d folder, am I right?
Borchuck said:
Thanks for answer!
In this app you can choose swap file path and I've chose /preinstall (512 mb).
Scripts can be ran by placing them into init.d folder, am I right?
Click to expand...
Click to collapse
In theory yes, but SELinux somehow blocks it in CM12 - that's why you need to run it using SManager instead. I have no idea what stock system does on boot.
Borchuck said:
Scripts can be ran by placing them into init.d folder, am I right?
Click to expand...
Click to collapse
Unless something has changed, init.d is disabled by default in CM11/12. I haven't checked Cm11 in a long time, nor in 12.1, though. There's an app that emulates it, as well as at least one app that tries to enable it, in the play store. The former works as it should in both KK and LP as long as you accept its limitations (scripts get run when the app autostarts, after boot), but I have no idea if the latter does.
Using /cache is a neat idea, when you're installed into the stock partitions. It's there and almost completely unused in CM12/.1, and it's not like we can usefully reallocate it or anything 'cause Motorola. Getting the webtop/preinstall stuff going is an extra step, and that space might be put to better use anyway. Though, preinstall is just about the perfect size for a swap...
The problems I see with swapping on any internal partition are 1: you're going to wear the eMMC out a lot faster writing to it all the time (though how much faster is anyone's guess), and 2: the eMMC in our phone isn't especially fast. It's not slow, but it's slower than a modern high-end SD card, and definitely slower than RAM.
I'm a little curious about how fast our device can read/write to external SD cards. A good one, with both fast read/write and good small-block performance, would be "safer" to use for swapping. If it happens to wear out, pop in a new one, good to go.
@LuH
Maybe you should use zRAM? I use it on my phone ...
Fervi
Septfox said:
The problems I see with swapping on any internal partition are 1: you're going to wear the eMMC out a lot faster writing to it all the time (though how much faster is anyone's guess),
Click to expand...
Click to collapse
Well, I've had my device for three years now so if it decides to retire, it's worked enough to earn it However, I have yet to see a phone dead because of worn out memory - it always was some radio chip in my previous ones. So 'm taking my chances I have considered the risk, just don't think it will affect me.
Septfox said:
and 2: the eMMC in our phone isn't especially fast. It's not slow, but it's slower than a modern high-end SD card, and definitely slower than RAM. I'm a little curious about how fast our device can read/write to external SD cards. A good one, with both fast read/write and good small-block performance, would be "safer" to use for swapping. If it happens to wear out, pop in a new one, good to go.
Click to expand...
Click to collapse
eMMC is of course slower than RAM, but my SD doesn't seem to outperform it - at least in big file read and writes it's about the same. I haven't found a working benchmark app for random I/O testing, but I think the onboard eMMC and my SanDisk 64GB SDXC U1 are on par in D4. Then again, I've had my SD longer than I've had my D4, originally bought it for my previous Windows Mobile 6.5 Sony Ericsson Xperia X2
Attached benchmark (usually ~600 MB write and read): SD card (SanDisk 64 GB U1) R13.56/W9,57, SD card (eMMC storage partition) R15.82/W5.31, Internal memory (eMMC /data partition) R8.90/W4.23, Custom location (eMMC /cache partition) R13.82/W4.17.
I don't get why three partitions of same eMMC flash memory chip get so different results, either it's differently managed by the system (but why give preference to media storage?), or the parts of chips are worn out differently, or the benchmarking app sucks
ferviverus said:
@LuH
Maybe you should use zRAM? I use it on my phone ...
Click to expand...
Click to collapse
I'll probably try as well, but thought I'll give swapping a try first... I heard more problems than advantages about using zRAM on D4, what's your experience?
LuH said:
Attached benchmark (usually ~600 MB write and read): SD card (SanDisk 64 GB U1) R13.56/W9,57, SD card (eMMC storage partition) R15.82/W5.31, Internal memory (eMMC /data partition) R8.90/W4.23, Custom location (eMMC /cache partition) R13.82/W4.17.
I don't get why three partitions of same eMMC flash memory chip get so different results, either it's differently managed by the system (but why give preference to media storage?), or the parts of chips are worn out differently, or the benchmarking app sucks
Click to expand...
Click to collapse
Double the write speed isn't "outperforming"? :v
Big file transfers are mostly irrelevant, small-block performance is where you need speed. You can mount both SD and internal storage in Safestrap, test there using CrystalDiskMark (which gives not only bulk transfer speeds, but 512k and 4k as well).
My results, using three passes and a 500mb test file
Internal storage
Sequential Read : 19.844 MB/s
Sequential Write : 13.899 MB/s
Random Read 512KB : 18.571 MB/s
Random Write 512KB : 10.263 MB/s
Random Read 4KB (QD=1) : 3.917 MB/s [ 956.3 IOPS]
Random Write 4KB (QD=1) : 1.770 MB/s [ 432.2 IOPS]
Random Read 4KB (QD=32) : 4.964 MB/s [ 1212.0 IOPS]
Random Write 4KB (QD=32) : 1.947 MB/s [ 475.4 IOPS]
External storage/SD card (Sandisk 16gb Class 10/UC1)
Sequential Read : 14.311 MB/s
Sequential Write : 4.907 MB/s (!)
Random Read 512KB : 13.667 MB/s
Random Write 512KB : 1.468 MB/s
Random Read 4KB (QD=1) : 2.267 MB/s [ 553.5 IOPS]
Random Write 4KB (QD=1) : 0.985 MB/s [ 240.5 IOPS]
Random Read 4KB (QD=32) : 2.512 MB/s [ 613.4 IOPS]
Random Write 4KB (QD=32) : 1.251 MB/s [ 305.5 IOPS]
The choice is clear here, but my card is pretty old...yours may fare better. Sandisk cards are generally known for balanced performance.
As for the different results...I dunno. The eMMC partitions should be all the same, it's all on the same flash after all. The only thing I can think of is filesystem differences, but the internal partitions are all ext3, right?
As sad as it makes me to say it, zRAM...isn't very good at the moment. It seems to slow the phone a bit while enabled, for an effectively minimal amount of extra memory. You'd probably be better off increasing minfree thresholds to keep things killed when they're no longer needed, rather than stressing the memory management even more just to keep a couple more apps "loaded".
@LuH
Well, i don't use CM (it doesn't support lapdock), but I use on stock zRam - I saved ~4.5MB (6.9MB compressed to 2.5MB) ... but I read on internet, that zRam is faster than Swap
Fervi
Failed to send the attachment before, giving now. Anyways, probably will try your suggestion to do it from computer later.
Septfox said:
Double the write speed isn't "outperforming"? :v
Click to expand...
Click to collapse
Well, I'm not really concerned by swapping out - that usually takes place when the phone is at rest. I specifically want it to wake up fast -> read speed is the bottleneck and there it's not as big a difference.
Septfox said:
As for the different results...I dunno. The eMMC partitions should be all the same, it's all on the same flash after all. The only thing I can think of is filesystem differences, but the internal partitions are all ext3, right?
Click to expand...
Click to collapse
Well, it looks as though the smaller the partition, the worse the performance is. No idea why. The biggest (and fastest), "Internal SD card" or Media storage or whatever it's called at different system, the one mounted as /sdcard, is exFAT, others are mostly ext3 (preinstall, cache, system and data) and webtop is ext4.
Septfox said:
As sad as it makes me to say it, zRAM...isn't very good at the moment. It seems to slow the phone a bit while enabled, for an effectively minimal amount of extra memory. You'd probably be better off increasing minfree thresholds to keep things killed when they're no longer needed, rather than stressing the memory management even more just to keep a couple more apps "loaded".
Click to expand...
Click to collapse
Exactly, I need hundreds of MBs, not single megabytes, to outweigh the performance loss.
LuH said:
Well, I'm not really concerned by swapping out - that usually takes place when the phone is at rest. I specifically want it to wake up fast -> read speed is the bottleneck and there it's not as big a difference.
Click to expand...
Click to collapse
Swapping should be happening every time the phone starts running out of memory. So, uh, pretty much every other second.
Run an app > OOM > store "oldest" objects in RAM to pagefile/swap partition > load latest app into RAM > user does something in-app requiring a service provider or some other additional data being loaded > OOM > vicious cycle continues
LuH said:
Well, it looks as though the smaller the partition, the worse the performance is. No idea why. The biggest (and fastest), "Internal SD card" or Media storage or whatever it's called at different system, the one mounted as /sdcard, is exFAT, others are mostly ext3 (preinstall, cache, system and data) and webtop is ext4.
Click to expand...
Click to collapse
Oh right, I guess the internal "SD" would be exFAT or some other FAT variant, since it's treated as a removable card.
Write speed being lower on smaller flash partitions makes sense, if they already have data in them, kind of.
If a write is attempted on a page within a flash block which already has data in it, you have to go through the whole read-erase-modify-write process, dragging overall speed down...
Unless our flash supports TRIM, which would pre-emptively erase blocks while the filesystem is idle; I'm pretty sure it unfortunately doesn't. So it's rare that an app writing files is going to happen upon a nice, big contiguous area of already-cleared blocks that can be simply written to.
But then, /cache is almost certainly empty (or minimally filled), so it makes no sense for writes on it to be slow.
*shrugs* I guess you could try formatting it and see if the write speed improves.
LuH said:
Exactly, I need hundreds of MBs, not single megabytes, to outweigh the performance loss.
Click to expand...
Click to collapse
zRAM is 256mb at default, and you can probably count it being effectively double that at least, once things are compressed into it.
It just...doesn't seem to work very quickly. YMMV though. It's enabled by default on the last few CM12 nightlies, so if you've updated recently (well, and are using 12), it's already on.
If you want it to be bigger/smaller, the value isn't baked in; utilities such as Kernel Aduitor can resize it. I tried increasing it to 500mb just to see if I could break something, and the phone...seemed to run slightly better for some reason. So that was a thing.
And reiteration: it's worthwhile to modify minfree settings. At least in Lollipop, if you keep free memory floating above 200mb, it runs much better. Apps will need to relaunch more, but relaunching is usually a lot faster than letting free memory sink to the 160-170mb range that stock values allow, and waiting while the memory manager chokes.
Empty App: 200 and Hidden App: 160 is adequate.
And speaking of the memory manager, joojoobee's kernel has a bunch of patches merged in that aren't in the nightlies yet, which improve memory handling somewhat (phone still starts choking under 200mb, but it's usable).
On the performance side:
Have any of you had any positive long term experiences with swap enabled? While swap gave me the ability to run several huge tasks all at once, in the long run it made my system very unstable. Things would crash out of random, the phone would take ages to wake up from sleep sometimes etc.
I have now upgraded to cm12.1 and disabled my script again.

Categories

Resources