[TIP] Enable swap - Desire General

After using A2SD to format a swap partition it is not active.
So to enable it, do the following:
Install ROM Manager trough market.
Start ROM Manager and select the first option "Flash ClockworkMod Recovery".
Turn off your device.
Turn on device with volume down pressed.
Press volume down, selection will switch to RECOVERY then press power button.
At the black screen with red triangle press volume up and power button.
Press volume down, selection will switch to Apply sdcard:update.zip and then press power button.
Open a console, navigate to the android SDK tools folder.
Type "adb mount /system", without the quotes doh!
Type "adb shell".
At the shell copy paste the following commands one by one and press enter after pasting them.
echo "#!/system/bin/sh" > /system/etc/init.d/05userinit
echo "swapon -a" >> /system/etc/init.d/05userinit
echo "/dev/block/mmcblk0p3 swap swap" >> /system/etc/fstab
chmod +x /system/etc/init.d/05userinit
chmod g-w /system/etc/init.d/05userinit
chmod o-w /system/etc/init.d/05userinit
chmod g-w /system/etc/fstab
chmod o-w /system/etc/fstab
exit
Now you are back at the normal command prompt, type "adb reboot".
Device will reboot, when its done open a terminal and type "free".
It should show swap space allocated.
And with some programs in memory you can see swap being used:
adb shell
free
total used free shared buffers
Mem: 407860 399940 7920 0 872
Swap: 249596 16596 233000
Total: 657456 416536 240920
Altho it was just using a small bit of swap, this obviously helps.
I was running two benchmarks, had maps open and a radio stream playing.
Quadrant showed my Desire rating at 559 while I was trying to get the phone to actually USE the swap space ...
Btw this is my first Android phone, but I have a rich linux background since 1998. Let's try Android 2.2 as this would boost the benchmark quite notably I recon!

For the most part, swap is not a good idea on Android, because is prevents Androids internal process management from operating efficiently. In some cases, swap can increase performance but in general use it doesn't.
Regards,
DAve

I have to disagree that enabling swap prevents memory management from being effective.
Altho enabling swap "might" degrade the lifetime of your SD card, it still holds memory which is not in use for some time.
You can confirm this by booting up the phone with swap enabled, check the free command and you will notice swap space not being used at all for a fairly long time and even using some applications.
After roughly a day usage, battery is still not empty (Im amazed by this HTC phone!) and swap space is being used by quite abit! Its using over 120mb right now and I still have roughly 10mb free normal memory. Programs still load near instantly and thus tells me swap management works like it should.
To perform a sanity check I started Maps again, free memory dropped to 3mb and some swap was freed. Which confirms that I had not used Maps for the whole day (was sleeping in bed lol) and when it started requested memory which was swapped away and obviously released when it was needed again.
Benchmarks tell me the same story, phone is scoring higher numbers than I tested earlier but this is due to me trying to fill swap during the benchmarks earlier this day. 571 compared to 559, it's not alot but it is "some".
To make a long story short, swap increased performance only when memory is being used too much. Will the performance be noticeable? Probably marginal, but you might notice the difference when your phone has been on for a few days straight. Because the longer you use it, more memory will be used and more unused parts of memory will be swapped.
You might also notice the swap increase when using lots of apps at the same time, mostly using multiple webpages and Maps at the same time.
Some arguments about SD cards being slow, this is only true for writes and not reads.

After further investigation and testing ...
The memory manager from Android could even be optimised for swap.
The current state makes absolutely no use of available swap space, except when memory get filled and then it will start swapping.
In fact it makes TERRIBLE use of swap space ...
You can test this yourself pretty easily yourself. Just open as many applications as you can to fill swap space and leave the phone running for a few hours. If you are like me you are playing with it, testing and/or whatnot you like todo.
After a few hours your swap space will be well filled, in my case around 120mb.
Now I run Advanced Task Killer to kill everything that was running, now swap space used dropped to around 30-40mb and I have almost 100mb free memory ... (free 96924).
Now I reboot the phone and check again after killing all tasks, result is .... rebooting to make an acurate post ... 61528.
So that is roughly 35mb of swapped memory which WAS inuse by Android, HTC Sence and whatnot that was not needed. Ofcourse if the memory would be needed again, it would simple be put back into memory and as this happens alot with lots of applications running.
I can safely conclude that memory management on the Android can be improved by the use of swap ... if it were actually used properly. The only way now is to use a task killer and see your memory increase over time, which is great as my Desire shows absolutely now slow downs or choppyness at all.
On the other hand, testing without swap enabled showed that the memory would increase after bootup too. But not close to 100mb, more like 70mb.
Another point to defeat the point against using swap, the swapped memory is placed on SD and SD write speeds are usualy slow. The slow write speed however does not matter if the memory is not filled already and the to be swapped memory was not inuse for a given time. The other way round when the memory is indeed needed again, SD reads are usualy much faster than writing and as it is such a small amount the read is faster than one would notice.
So when I get time for it, I'll dive into the kernel source. See if we can get a better memory/swap manager going for our already snappy fast phones and make them even faster!

double post :s

sfjuocekr said:
I have to disagree that enabling swap prevents memory management from being effective.
Click to expand...
Click to collapse
If you use swap, you are effectively telling Android you have more memory than you actually have. Therefore, it doesn't reach a memory low condition until you've used up swap, which means it doesn't start killing processes.
Use of swap practically mandates the use of a task killer to kill processes that
Android task management would have usually killed to keep the phone operating smoothly.
Regards,
Dave

You aren't telling Android that you have more memory, there is memory and there is swap.
If Android's process manager doesn't kill processes because it thinks you have more memory, it's clearly stupid as it doesn't know the difference between swap and memory. Besides that both memory and swap are reported independenty.
After 17 hours uptime my phone still holds around 35mb in swap and around 40-50mb free memory, so Androids process/memory manager can clearly be improved to facilitate swap space.

Hi sfjuocekr,
first of all thanks for your little tutorial.
I just wanted to know, that method is still working? I mean on CM7 etc.
And will stay after updating the ROM (e.g. nightlies) or has to be done again every time?
Then, in your case the swap partition was mmcblk0p3, but it's not always like that and should be checked right?

Related

At startup and in general, how much program memory should be in use?

I know there's probably no right answer for this, but i feel like my program memory is always very high and am wondering if that could be what contributes to my poor battery life.
I just started my phone and it says using 28.8MB out of 48.8 (which is lower than sometimes). One of the things that bothers me is when i run a few programs but then close them i don't always see the memory usage drop back down to below that 30MB mark. Sometimes it'll stay up at 35 even with all programs not running. I'm wondering what levels other people are seeing and if mine is high, why?
BTW, I am running K's WM6.0 on an 8525 of Radio 1.47.30.10
Im running MRH 4.5.1 which uses CRCs R9.1 and with my phone on for the last 24-36 hours I just closed all the running apps and checked my memory and Im at 27.35 MB in use and 21.33 MB free.
So compared to mine, yes yours does seem a little bit high, especially since I can launch stuff and fill up the memory but as soon as I close it all down Im right back to around 28 MB in use.
Depends on programs you've got installed and whether or not they are set to startup automatically.
After a reboot I am using 23.35 MB of ram.
Search in the /Windows/Startup folder and delete what you don't want to startup automatically.
Also keep in mind that every folder, start menu, settings, you open will use up some memory. For example if you go to Start/Settings and wait for it to load. Then click on the System Tab, you will notice it takes 1 second or so to open. If go back to the Personal Tab, and then click on the System Tab a 2nd time,,, you will notice it loads immediately. This is because all the "icons" are loaded into your memory. Same thing when you click on your Start Menu the 1st time, there is a slight delay. Then when you reopen it, it opens immediately.
This is common knowledge but closing an App with the X doesn't always actually close it. I recommend downloading a good task manager that allows you to view memory usage and processes. I'm using Task Manager 3.0 by Fdcsoft.
Then lastly, their is an app by Oxios called CloseApps 1.40,,, this will free up some memory even after you have ever application closed. I just used it to get the version number and I didn't have any app running. It just now freed up 3300kb of memory for me.

89% active memory causes sloth

Does anyone know why my memory usage seems to hover around 80%, even though I don't believe I have any extra running programs, AND I have a 4GB micro SD card in that is not filled at all.
The problem: My connection seems to be very slow, and some games won't open because of not enough "available memory" Then they'll open 2 minutes later, no problem.
Ideas?
What ROM are you running? What do you have installed? What tweaks have you performed?
Clueless
When I tap the upper right hand corner to see if any programs are open, the memory icon says 78% - 83% constantly.
That's all I know. How do I check on what RAM I have?
What carrier are you on?
ROM and RAM are two separate terms, google them if you have questions about what they mean.
Try the following CABs to improve %s. Install and restart, let me know if you see a difference. You might also want to download cleanRAM or SK Tools to clear your RAM occasionally.
http://forum.xda-developers.com/showpost.php?p=4799948&postcount=17
Your probably doing something with your phone, but this cab should help if you don't want to flash anything else. This cab does improve a decent amount of RAM, hopefully you find your answer, good luck.

[Q] My Phone Memory just went from ~220 to +400 after reboot. What just happend?

I was helping my friend fixing an iPhone and I removed my sim card to test it on the iPhone (shut off the phone before removing!) - it worked on the iPhone and I put it back in my own and booted it up. For some reason it did not do its famous Quick Boot (it booted as if I had removed the battery! Does it also do this when removing the sim card?!)
Since day 1 of my phone I've been using Simple Task Manager, and I've got a task-killer widget I press frequently to kill whatever might be running in the background. Since day 1, it had always told me:
Boost Completed.
Memory Freed: x.xmb
Available Memory: 210-220mb.
Now, when I click the widget, 'Available Memory' is showing 400-410mb. So... Like the topic says, what just happend?
I'm not sure about the memory thing but I know that using a Task Killer uses more battery and CPU than just letting an app or process sit idle in the background. Android does a good job of task management itself. See below for info:
http://lifehacker.com/?_escaped_fra...ed-what-they-do-and-why-you-shouldnt-use-them
http://geekfor.me/faq/you-shouldnt-be-using-a-task-killer-with-android/
all that happend it that you did a full reboot.
All apps and services were closed,
then when booted barely any memory is used because barrely anything has cached.
for example, when using the browser a lot, it wil start to cach and if you kill it you free that memory.
there are other part in the phone who also cach and you might not close with your killer.
i have the same thing.
normally i'm around 200 mb memory, but i leave open things like my contacts list and whatsapp ect.
when i do a full reboot (no quick boot tricks) all the apps havent started using memory yet.
using the quick boot is just using sleep mode and doesnt close all apps and services.

[Q] Clearing RAM

Whenever i clear the ram on the phone, it seems to move all the applications on my home screen around, making me put them into their places all over again. Anybody know why this is happening?
bump
bump
Well this is awkward a bit
Try to use the stock ram cleaner & tbh i never encounter that issue atall
Sent from my GT-N7100 using Tapatalk 2
that;s the one im using, the stock ram cleaner, when you hold down the home button, bottom left and click on RAM then clear memory. That's when it happens :S
http://www.youtube.com/watch?v=zCh7z5EwYF8
Know the Difference Between Good and Bad High RAM Usage
"Sometimes people like to panic when their computer's resources seem to be maxed out. While CPUs and hard disks may suffer from high usage, RAM doesn't necessarily slow down your computer when it appears to be running low."
http://lifehacker.com/5958598/know-the-difference-between-good-and-bad-high-ram-usage
Whether your RAM is full of cached files or completely empty, it's all available for programs that really need it. Cached data in your RAM is marked as low-priority, and it's instantly discarded as soon as the memory is needed for something else. Because this data can be instantly discarded when necessary, there's no disadvantage to using the RAM for cache. (The one potential disadvantage is users who don't understand what's going on becoming confused.)
Empty RAM is useless. It's not any faster for the computer to write data to empty RAM, nor does empty RAM use less power. In fact, assuming you're launching a program that may already be present in your RAM's file cache, programs will load much faster when your RAM is used rather than when it's empty.
LLanito said:
Whenever i clear the ram on the phone, it seems to move all the applications on my home screen around, making me put them into their places all over again. Anybody know why this is happening?
Click to expand...
Click to collapse
You mean to say it refreshes the whol3 screen after you clear ram?
sent from: The New S-Pen
tbh, when i cleared the ram, it would remove dolphin browser and the stock msg app into the all app folders for some reason. si id have to put them back to their place every time.
MohJee said:
http://www.youtube.com/watch?v=zCh7z5EwYF8
Click to expand...
Click to collapse
hahahahah wtf

Why are zram and swap hogging my RAM?

Lately my G4 has suddenly locked up several times, usually when unlocking. Everything would slow to a crawl (several minutes for anything to respond) or freeze entirely until I rebooted (which sometimes required pulling the battery).
I installed Cool Tool to diagnose the problem and found that it happens when free RAM gets under about 180MB. kswapd kicks in with several hundred MB/s of I/O (I saw it over 1000 once). I'm not sure what it's doing with that much I/O, but of course it makes everything grind to a screeching halt.
Looking in Kernel Adiutor (sic), ZRAM is set to 700MB and swappiness (who puts swap on a flash storage device anyway?) is 80. Both seem very high to me. Why using 700MB of precious RAM food for a virtual, compressed (slow!) swap file, and swap so often? I adjusted them to. 250MB and 20 respectively. As expected I now have way more free RAM (average ~600MB, up from ~300), things seem more responsive and I haven't had any lockup (but I only did this a few hours ago, so too early to know if it really fixed the problem).
Anyone know why these were set to such large numbers? Anyone else have this issue and if so, does this tweak help?
Mine was 40 in swappiness but zram value stick to 700mb
That's odd. I wonder if some process adjusts it on the fly when RAM is low?
Just had another "freeze" with ~200MB free. Again kswapd doing a bunch of I/O and slowing everything else down. Wasn't nearly as bad this time though. Less I/O going on, things were sluggish but not completely frozen, was able to open the recent apps menu and hit Clear All to free up a ton of memory and get things running smoothly again. Maybe need to tweak OOM killer and swappiness settings more so I don't have dozens of old aops/tabs hanging around hogging memory.
RenaKunisaki said:
Just had another "freeze" with ~200MB free. Again kswapd doing a bunch of I/O and slowing everything else down. Wasn't nearly as bad this time though. Less I/O going on, things were sluggish but not completely frozen, was able to open the recent apps menu and hit Clear All to free up a ton of memory and get things running smoothly again. Maybe need to tweak OOM killer and swappiness settings more so I don't have dozens of old aops/tabs hanging around hogging memory.
Click to expand...
Click to collapse
are we both the odd bunch? this is the first time I've come across someone else experiencing the same issues as me! switched from a Samsung to an LG, 3GB to 4GB device respectively, and still experiencing this from time to time.

Categories

Resources