[IDEA] Smart Swapper - G1 Android Development

I was thinking the other day about people opinions about using swaps and what the swappiness should be set to. I thought about how at sometimes during heavy use a higher swappiness would help while at other times it could slow things down. I was wondering if it would be possible to make a "smart" Swapper app that ran in the background and automatically adjusted the swappiness according to how much free memory is needed. For example when the phone is idle in your pocket swappiness would be at 10 but then as your started to browse the web or use GPS it would increase swappiness to allow you to have more free memory. Feel free to tell me why this is not practical or possible, it was just a thought I had.

I don't this its a case of being impossible
the question is why?
if your phone is 'sleeping' it probably isn't doing much with swap, so reducing swappiness won't achieve anything.
increasing swappiness when your phone comes to some load threshold will only increase the 'load' on swap as all of a sudden you want to dump more stuff from real memory into swap
tbh I don't understand why so many are obsessed with swap.
my advice , keep swappiness at default, and as for size of swap, large
why large?
good question, as you never really fill more than 40mb..
the reason for 'large' is 'wear levelling' your swap takes a hammering, if this partition is large then each block is going to have less writes on it than a smaller swap partition over a given period of time, thus increasing the life span of your sd card.

Agreed, playing with swappiness doesn't really help a whole lot.
One of the bigger issues (imo) is how once you have swap turned on the kernel will swap inactive pages out in order to make room for IO caching. If your device is sleeping, a lot of pages are suddenly inactive.
While at first it might seem like you'd want the ram to make up for a slow SD card, swapping out to the same device in order to make room for cache is counterintuitive. Unfortunately there is no way to cap the total amount of ram that can be used for cache. The logic is that unused ram and inactive pages can be put to better use to speed up IO.....except on devices with extremely limited ram and IO like most smartphones.
It's pretty unlikely that anything like that will make it back into the linux kernel any time soon. :\

Then again you never know Lunix is open sourced as well as android anything is possible

The idea is correct, but as said, it isn't possible. Don't count on any linux changes in the future on this. On the other hand, i think there is a possibility, but this should be calculated.
Swapiness is set on boot, right? If i change it when running my phone, would this make any difference on further use?
Now my suggestion is, find out what swapiness is ideal. When the program can calculate the ideal swapiness level, based on how much RAM is used over time, this would be nice? It would write this level down in a userinit, and when you reboot the phone, it would use this level as a reference point on swapiness.
Only downside is that you can't figure out the ideal swapiness, it depends on the phone, apps and personal preference.
Anyone has comments on this idea?

Related

Best swapper settings for performance?

Hello again all. I have been using Fatal1ty's Hero builds for a while now which are fantastic Thank you again Fatal1ty. But no matter what i seem to set swapper to it makes the phone run really slow. When I actually disable swapper is when this build runs the smoothest for me. Was wondering what settings everyone here uses for swapper to get the performance increase from it.
currently is set to the following
/sdcard/swapfile.swp
65mb
20 swapiness
i have tried 20 60 and 100 swapiness with upto 256 mb and really didn't seem to help. just wondering what settings that everyone else uses to have it run more speedy. Also I was wondering if it is possible to put to system memory like in the space for applications although I think that may be a bad idea depending on type of memory as will more then likely make that memory fail with all the read / write cycles

Autokiller memory opimizer (not a task killer)

What is the verdict on these memory optimizer type apps?
http://andrs.w3pla.net/autokiller/faq
I can't recommend Autokiller highly enough on Samsung Froyo phones. It was a must use, even with Voodoo, on my old SGS i9000, and the same thing on my Droid Charge.
True story: just this morning I was ready to throw my Charge against the wall in frustration. Ever since upgrading to EE4 the damn thing was LAG LAG LAG city, even with Voodoo. Phone was snappy as heck after a reboot, but after a couple of hours use, it started to lag, and then would get so laggy it was almost unusable. Seriously, opening apps would take 10 second. Auto-rotate the screen took 4-5 seconds.
I enabled Autokiller, set it "aggressive" and the phone's a speed demon again.
Try it, can't hurt your phone with it, might help it exponentially.
waiting for the phones built in lowmem killer is useless, use autokiller and you will notice an immediate improvement in phone response time. heres a point for ya, without it installed i have 78mb ram free,,,with installed 158ram. thats huge. for a phone. plus they dev just updated to reduce memory usage of the app itself, plus there are tweaks in the settings menu to make the IO scheduler more aggressive, improve sd card reads, battery life, wifi, networ,...its layered man. and free....whats more to love. the only other way i have found to improve phone speed feelwise is with kangfucius kernel and set that terd up to 1500hz with cfq. shazaam.
elucid said:
What is the verdict on these memory optimizer type apps?
http://andrs.w3pla.net/autokiller/faq
Click to expand...
Click to collapse
Basically what you're doing is tweaking the settings for how Android frees up your memory. In theory, it should be good, because the defaults that were picked with the Android release aren't going to be appropriate for everyone. Just be careful not to be too aggressive or you might start losing functionality you want, such as alarms or background email checks.
chadness said:
Basically what you're doing is tweaking the settings for how Android frees up your memory. In theory, it should be good, because the defaults that were picked with the Android release aren't going to be appropriate for everyone. Just be careful not to be too aggressive or you might start losing functionality you want, such as alarms or background email checks.
Click to expand...
Click to collapse
Good point on not being too aggressive. The higher you set it, the more sticky sports ate pushed out of memory, so with the settings I have right now the phone kills some things that in the oat would have been running when I went back to them. I'm going to drop down from aggressive to strict and see if that's a better balance for how I use the phone.
Sent from my SCH-I510 using Tapatalk
Call me crazy but...
Android is linux based right? I.E. it uses a linux kernel? I was under the impression that was true. If so, unless you're running into the problem of completely filling RAM and having to wait for stuff to be cleared, this kind of thing will not help you!
Linux intentionally leaves commonly used items in RAM in order to decrease access time. It is perfectly normal for such a system to run at 70-80% memory usage. It is, in fact, a GOOD thing, because it means more memory is actually being put to a potentially useful purpose.
That being said, if you're actually running out of RAM I suppose something like this could help.
slight23 said:
Android is linux based right? I.E. it uses a linux kernel? I was under the impression that was true. If so, unless you're running into the problem of completely filling RAM and having to wait for stuff to be cleared, this kind of thing will not help you!
Linux intentionally leaves commonly used items in RAM in order to decrease access time. It is perfectly normal for such a system to run at 70-80% memory usage. It is, in fact, a GOOD thing, because it means more memory is actually being put to a potentially useful purpose.
That being said, if you're actually running out of RAM I suppose something like this could help.
Click to expand...
Click to collapse
Yes, yes, I frequently give the "in linux free memory is wasted memory" whenever people want to use some taskkiller app because they want a lot of free memory. This isn't about shooting for some high free memory number because we're Windows minded and think we need a lot of free memory, this is about finding the right settings for Android's own memory manager to keep the phone responsive. There's been something about my Samsung phones (except the Nexus S) where they just get laggy as hell with the stock memory manager settings.
As described above, my phone was almost unusable after a couple of hours booted up until I enabled Autokiller. Maybe something I'm running has memory leak; could be, but I pretty much run the same apps on all my phones, and the HTCs and Nexus S don't get laggy like the i9000 and Charge do.
This app, or the one named MinFreeManager really help. In the early days of the i9000 on MoDaCo site we were using the cat command to tweak the settings manually in our efforts to find a way to stop RFS lag before Voodoo came along.
I just installed this yesterday and configured it for strict mode. I also enabled all of the advanced system tweaks and so far I haven't noticed much if any difference, perhaps it depends on your individual usage and what apps, launcher, etc you're using. I'm going to leave it on and see how it goes though.
Any still using this? Any want to share what settings they use?

[Q] Can Swap on NAND kill the NAND itself?

Can Swap on NAND kill the NAND itself?een covered several times already on different forums,
but I am still seeking for some accurate clarifications regarding whether or not a Swap partition on NAND can eventually kill the NAND itself.
I have a kindle-fire fire with CM9 and unfortunately I have noticed a high ram consumption by ICS. I tried the 99V6_supercharger script as someone already suggested, but unfortunately that didn't help much.
I'm always left out with few megabytes of free ram with just the stock browser and Gmail and plume opened, and if I open few more the OS becomes unusable due to lack of free ram.
So basically my question is, should I create a 500mb swap partition in NAND? Will it damage and eventually kill the NAND itself?
Thanks
anyone?
The short answer is "no, not in your phone's normal lifetime and under normal usage". AFAIK, NAND memory is based on the very same technology that micro-SD cards are made from.
While this may have been true in the very early days of static memory chips, just recently (a few months back) a study proved that it would take I don't remember exactly how many (but it was in the tens of millions order of magnitude) write cycles to "kill" all the cells of a NAND chip (allowing the wear-levelling algorithms to spread the data elsewhere, and then killing those cells in turn) and make it unreliable enough.
If you were running a supercalculator farm making very heavy disk-intensive calculations, it would take more than 2 years of continous 27/7 writing to completely kill such a memory -or a modern SSD device.
And who uses a phone for more than 2 years nowadays ?
(plus, if you actually set up a swap partition on your device, you'll notice that unless you increase the parameter proc.kern.vm.swappiness to more than 30, your device actually doesn't swap that much, nor does it swap continously. Oh, and 500Mb for a swap partition is overkill for a phone : it will seldom use more than 128Mb, the necessary quantity for two dalvik VMs with the default size of 64Mb that's set on most Gingerbread devices nowadays. )
(EDIT2 : but if you're still worried, I got a suggestion : get ahold of a class-10 micro-SD card -don't be stingy on the quality, go for the higher-value brands like Samsung or Corsair/Kingston- and set up the swap area over this. If it breaks down, you ust swap a new one in and you're back on track.. )

[Q] Making Swapfile on Gtab 7+?

hi guys,..
i want to ask is there any way i can make swapfile on gtab 7+ running hc 3.2? or there is no posibility to make swapfile on honeycomb? i've tried to make the swapfile using dd command from terjinal, but somehow im stucked on setting permission for the file, the file i've created always have special permission that i can't change to rw-r-r, it always stayed rw-rSw-r, im a newbie on linux things, and willing to learn.
any help really appreciate.
thanks.
Okay, you say that you're a newbie to linux. That's fair and reasonable. I'm going to try and teach you some things by way of asking questions. They might sound like I'm attacking you, but I'm not...
Do you know you are trying to create a swap file? What do you hope to gain by doing so?
Is this one of those mythical magical things that someone claims will make the tablet run 50395920 times faster, allow it to brew coffee, and make your car get better fuel mileage?
...and some answers...
Within the android environment, a swap file is a BAD THING. The entire system is designed to drop stuff out of memory if/when it needs more memory, and the overhead of a swapfile will cause more harm than good.
Take care
Gary
garyd9 said:
Within the android environment, a swap file is a BAD THING. The entire system is designed to drop stuff out of memory if/when it needs more memory, and the overhead of a swapfile will cause more harm than good.
Click to expand...
Click to collapse
It's not that dramatic. Most of "the overhead of a swapfile" is overhead you're already committing to by utilizing a VMM (Virtual Memory Manager). The Dalvik VM doesn't do a whole lot of its own memory management so implementing a swapfile at the OS level, which is what the OP is looking to do, wouldn't have a huge impact on performance.
The only time where you'd have any real overhead of maintaining a swapfile is when memory is full and the OS pages out memory to disk. But remember that the alternative is to close down the process and run some garbage collection. Both are intensive actions - swapfile is I/O intensive while GC is CPU and memory intensive - so you're really trading one source of overhead for another.
To answer the OP's question, it sounds like you haven't rooted the tab. You would need to be root in order to change the perms as you described. If you are rooted, make sure you're using the right command to set permissions - I haven't tried this specifically on Android but from my *nix experience, the command you want is chmod 644 <path to file>
---------- Post added at 09:24 PM ---------- Previous post was at 08:39 PM ----------
Almost forgot, what kernel are you using?
im using stock kernel 2.6.36, kk6 rooted. i've tried to chmod the swapfile, but still cant change the permission, i usually use root explorer to change the permission, but now it doesn't take effect. the file permission r8 now is rw-rwSr--, the "S" thing is making the swap cant be aplied (i guess).
back there when i use optimus (gingerbread), swapfile is default from stock rom. is it have something to do with honeycomb?
thanks for your reply.
garyd9 said:
Okay, you say that you're a newbie to linux. That's fair and reasonable. I'm going to try and teach you some things by way of asking questions. They might sound like I'm attacking you, but I'm not...
Do you know you are trying to create a swap file? What do you hope to gain by doing so?
Is this one of those mythical magical things that someone claims will make the tablet run 50395920 times faster, allow it to brew coffee, and make your car get better fuel mileage?
...and some answers...
Within the android environment, a swap file is a BAD THING. The entire system is designed to drop stuff out of memory if/when it needs more memory, and the overhead of a swapfile will cause more harm than good.
Take care
Gary
Click to expand...
Click to collapse
thanks m8 for your lighten up of linux, i really appreciate it. just from my experient when im using optimus (gingerbread) i never felt lack of memory when using multitasking (it only has 512mb ram). but now when i using gtab (with 1gb ram or 778mb?) first it fast on multitasking but about 10 minute later it getting slower, when i check with task manager, it only has 80mb left??
is it me or is it gingerbread have better ram management than honeycomb, and so if it is, im trying to make swapfile in hope that its getting better. i use v6 supercharger, kill all proccess when it turn to standby by automatic, overclocking to 1,6ghz, but still i can make the ram more efficient when running on multitasking.
hope you understand for what im going to achieve.
thanks.
h2g2 said:
It's not that dramatic.
Click to expand...
Click to collapse
Are you suggesting that using an OS-level "generic" swapfile on flash memory is better or even equivalent to using a system/purpose built solution?
The linux kernel has no way to know if the memory its swapping out is even needed anymore. The android system, however, does know this - and will often discard allocations.
Let's say you run two applications: email and the browser. The browser has several pages loaded with flash, and lots of memory intensive stuff going on. Also in memory is the code that syncs your email in the background and several other "non critical" services (such as SMS, latitude, etc.) and a few critical services (such as some wifi support, display support, framework, etc.)
Keep in mind that if android requests memory, and there's a swapfile, the kernel will claim it has memory backed by swap... So given a large enough swapfile, the kernel will never tell android that it's running short on memory...
Given the above situation, the user now wants to run Angry Birds. There isn't enough physical RAM to support all of the above in memory AND Angry Birds. What will happen?
If there's no swapfile, android will see there isn't enough RAM to support it, and simply drop the browser and email client from memory, but keep the services in memory. Angry birds loads, and the user is happy.
IF there IS a swapfile, however, then android will see that there is RAM to support AB along with everything else in memory, and just load Angry Birds. When that happens, the linux kernel will have to swap pages of memory out to the flash memory. The KERNEL doesn't know the difference between the email client, the email service, the browser, or any other "non-critical" service. All those memory pages are flagged the same. So, perhaps the browser gets swapped out. (wasted cycles - it could have been discarded.) The email client is retained in RAM, but the email service is swapped out to flash. Angry Birds loads. 5 minutes later, Angry Birds freezes and gets jumpy... why? Because the email service has to be swapped back into RAM, and something else swapped out in its place. This time it was latitude. A few minutes later, latitude wants to update your position, so the same thing happens. What gets swapped this time?
Why spend the cycles swapping things in and out of RAM? There is plenty of memory on these devices to support all the services and memory hungry games. If some game has a memory leak, you SHOULD be getting errors from running out of memory and NOT blissfully swapping things to flash.
I'm not going to tell people how to use their devices. I'm going to try and give them advice, but I certainly can't force people to take it. As a matter of fact, I'll even encourage the technical minded to explore and break things to learn on their own.
However, when a person asks the question I see in the OP, and admits that they are new to linux, then I suspect that they aren't technically minded and exploring, but blindly following the "suggestion" of someone else who promises all kinds of silly things. It reminds me of someone who disabled kernel panic reboots and claimed that it was a tweak to make the system more stable... and had many people actually believing that.
There's a good reason why google hasn't enabled swapping, and there's even less of a reason with devices that come with 1GB of RAM.
Take care
Gary
---------- Post added at 01:45 AM ---------- Previous post was at 01:25 AM ----------
danielkaboom said:
is it me or is it gingerbread have better ram management than honeycomb, and so if it is, im trying to make swapfile in hope that its getting better. i use v6 supercharger, kill all proccess when it turn to standby by automatic, overclocking to 1,6ghz, but still i can make the ram more efficient when running on multitasking.
hope you understand for what im going to achieve.
thanks.
Click to expand...
Click to collapse
First of all, try the same thing without that "supercharger" script. I've made clear my thoughts on that. In this case, using that script may or may not be allowing HC to do what its designed to do in regards to memory management. I'm not saying you should delete it - but to run tests without it.
If you are running low on FREE memory, that's not a bad thing. What good is the memory doing if it's not being used? Android will let an unused application linger in RAM as long as they wants so long as nothing else needs that RAM. As soon as something else needs that RAM, those unused apps will be purged (garbage collection.)
Having a swap file directly contradicts any effort to purge things from memory. A swapfile will encourage the system to swap things to flash as virtual memory. Sure, your "free memory" number might be bigger, but it will slow the system down when it's swapping things out to and in from flash memory. (A blunt question Are you chasing numbers or actual performance?
How do you expect to make memory MORE efficient by always having it be unused? Memory that's not being used is wasted. If my desktop machine (that has 16GB of RAM) has only 6GB being used, then I have 10GB of RAM wasted. I'd rather that memory be used to store an application I might go back to using, or used as cache. Completely unused RAM is completely wasted RAM.
I understand that you might be caught up in the whole thing with overclocking, having as much free RAM as possible, and having nice benchmark numbers. The thing is.. NONE OF THAT MATTERS.
Want higher benchmark numbers? I can make you a kernel that will give you insanely high numbers. Your device will suck for actual use, but you'll get high benchmarks.
Want a big "free RAM" number? Never run any apps, never get email, don't do anything at all with the device. It'll be an expensive paperweight, but you'll always have lots of free (and completely wasted) RAM.
Try this: make a backup of your system and then go back to stock. Use your tablet in a factory state for a few days. Then root it and disable some of the things that might be chewing the battery. Don't overclock, don't install scripts, and don't install a custom kernel. Use the device like that for a while. Actually USE the device - don't benchmark it, check task managers, etc. Just use it.
Now, how does it feel? No script, kernel, or anything else will make a dramatic performance increase. They can (and often do) make things slower, however. (That's why I'm very careful about modifications I make to my kernel...)
After using it stock for a few days, come back and tell us what you think - what you wish would be better in actual day to day use. (Again, benchmarks and numbers don't mean much...)
Take care
Gary
yes Gary,...to be honest, im blindly follow every1 that claims can tweaks or anything like tha, but when i tested it and using it, if its making my device getting "better" i kept it, if its making it worse than before, i let go.
in my opinion, slow, fast or faster is relative, it depends on every1 needs. for me loading game such as finalstrike hd in 5 sec is fast, but maybe different to others by loading it 20-30 sec is acceptable.
but if you said swapfile is bad and will only making it worse, then i'll accept that, but after im testing it. for me, sugar is not sweet until my tounge said so, no offence.
again, thanks Gary for the explanation, thanks for opening my mind.
edit : ill try to follow your instruction first.
You should do what you feel like, but please don't get caught up in lots of people telling you that they have magic bullets to fix things (that really aren't even broken.)
That being said, you are having a technical problem and I just can't resist information sharing.
What directory are you trying to create the file in? /sdcard (or /mnt/sdcard) won't work.
Try /data
(/mnt/sdcard == /sdcard.. and they will force certain permissions via fuse/vold.) Unlike GB, with HC /data and /mnt/sdcard use the same space. (/mnt/sdcard is actually a fuse from /data/media.) (In GB, /data space was very limited. That's not the case with HC.)
Gary
still failed,...:
- create a file in /data (named swapfile.swp), using terminal
# dd if=/dev/zero of=/data/swapfile.swp bs=1024 count=128000
- check from root explorer, the file is now created.
# mkswap /data/swapfile.swp
# swapon /data/swapfile.swp
swapon /data/swapfile.swp = Function not implemented
any sugestion?
edit : the permission is now can be change to rw-r--r--(thx Gary)..but its still failed to swapon,..
edit 2 : from what i've read from other pages and sites,..is it because "kernel not support"?
garyd9 said:
Are you suggesting that using an OS-level "generic" swapfile on flash memory is better or even equivalent to using a system/purpose built solution?
Click to expand...
Click to collapse
There is no "system/purpose built solution" - the Dalvik VM uses the Linux kernel VMM functions for low level memory management (http://developer.android.com/guide/basics/what-is-android.html).
The linux kernel has no way to know if the memory its swapping out is even needed anymore. The android system, however, does know this - and will often discard allocations.
Click to expand...
Click to collapse
Yes it does. The VMM knows which pages are active, which are inactive, and - if an application has called free() on a pages it previously malloc()'d, it will know which pages are expired.
In fact, the VMM will often know more than the Dalvik VMs because each application runs in its own Dalvik thread with its own dedicated heap. Any individual Dalvik instance will only know the disposition of the heap for its own application.
The VMM, on the other hand, has visibility of all Dalvik threads and will know which threads are idle and which are active, which Dalvik threads have run garbage collection and free()'d a portion of their heap, etc.
Keep in mind that if android requests memory, and there's a swapfile, the kernel will claim it has memory backed by swap... So given a large enough swapfile, the kernel will never tell android that it's running short on memory...
Click to expand...
Click to collapse
No, it won't. That's not how the swapfile works. What you're describing is more akin to memory-mapped file I/O, which is related (in that the VMM plays a role in managing that address space) but not at issue (it's a completely separate operation from memory allocation and de-allocation).
Memory is requested by giving the kernel a malloc() command. The VMM will then check its page cache (the size of which is constrained by physical memory - regardless of whether there is a swapfile or not) and look for available space. If space isn't available, then the VMM will look for pages marked as expired. If there aren't enough expired pages, it will look for inactive pages (pages allocated by processes that are idle or supsended).
At this point, the VMM will either 1) discard the contents of the expired and/or inactive pages until enough free pages are available (if no swapfile is available) or 2), write the contents of the expired and/or inactive pages to the swapfile before discarding them until enough free pages are available.
Note that the presence or absence of the swapfile has no bearing on what pages are chosen. And again, regardless of whether there is a swapfile or not, if there aren't enough expired and/or inactive pages to get rid of, malloc() returns a null pointer. In otherwords, you will get out of memory errors even with a giant swapfile.
Given the above situation, the user now wants to run Angry Birds. There isn't enough physical RAM to support all of the above in memory AND Angry Birds. What will happen?
If there's no swapfile, android will see there isn't enough RAM to support it, and simply drop the browser and email client from memory, but keep the services in memory. Angry birds loads, and the user is happy.
IF there IS a swapfile, however, then android will see that there is RAM to support AB along with everything else in memory, and just load Angry Birds. When that happens, the linux kernel will have to swap pages of memory out to the flash memory. The KERNEL doesn't know the difference between the email client, the email service, the browser, or any other "non-critical" service. All those memory pages are flagged the same. So, perhaps the browser gets swapped out. (wasted cycles - it could have been discarded.) The email client is retained in RAM, but the email service is swapped out to flash. Angry Birds loads. 5 minutes later, Angry Birds freezes and gets jumpy... why? Because the email service has to be swapped back into RAM, and something else swapped out in its place. This time it was latitude. A few minutes later, latitude wants to update your position, so the same thing happens. What gets swapped this time?
Click to expand...
Click to collapse
So bearing in mind that the Linux kernel VMM is ultimately responsible for choosing what gets dropped or swapped out of memory and also bearing in mind that only inactive or expired pages are eligible to be dropped/swapped, we can see that the situation you describe will never happen.
The behavior of, from the user's perspective, what applications get shoved out of active memory (regardless of whether they end up in the swapfile or in /dev/null) doesn't change. In the same way that the Linux VMM will never drop pages associated with an active process (such as the email sync service, the Wifi driver, etc), the Linux VMM will likewise never swap these pages out either.
Why spend the cycles swapping things in and out of RAM? There is plenty of memory on these devices to support all the services and memory hungry games. If some game has a memory leak, you SHOULD be getting errors from running out of memory and NOT blissfully swapping things to flash.
Click to expand...
Click to collapse
Consider the scenario you spelled out previously - without the swapfile, the pages associated with the Browser app will get dropped and make room for Angry Birds. Good news: Angry Birds starts up faster.
With the swapfile, the pages associated with the Browser app will get swapped out to make room for Angry Birds. This will take longer since there's some file I/O involved. Bad news: Angry Birds starts up slower.
So what's the use case for the swapfile? What if you want to go back to the browser again? Without the swapfile, the Browser is gone. You have to launch it - the application binary needs to be read off disk, executed, the heap has to be re-allocated, re-initialized, and program data needs to be populated. The page you wanted is gone - you need to fetch that again. More waiting while it downloads from the server and the HTML code is rendered on the screen.
In this scenario, reading the heap back into memory from the swap file is actually more efficient than recreating it - even if you ignore the obvious benefit of not having to relaunch the app and reload the page, there's substantial overhead associated with relaunching the app.
So that's the use case - maybe it's not applicable to you if (although maybe someone who wants to go back and forth between Angry Birds and a cheat guide on a G1 might appreciate this) but if you are multitasking across several memory-intensive apps, then the benefit of not having to re-invent the wheel, so to speak, to recover the application state can outweigh the cost of paging the application state out to disk.
I'm not going to tell people how to use their devices. I'm going to try and give them advice, but I certainly can't force people to take it. As a matter of fact, I'll even encourage the technical minded to explore and break things to learn on their own.
However, when a person asks the question I see in the OP, and admits that they are new to linux, then I suspect that they aren't technically minded and exploring, but blindly following the "suggestion" of someone else who promises all kinds of silly things. It reminds me of someone who disabled kernel panic reboots and claimed that it was a tweak to make the system more stable... and had many people actually believing that.
Click to expand...
Click to collapse
I have no problem with dissuading people of the notion that some hack is going to instantly and unequivocally make their system better. But I think the proper response, especially on a forum like this, is to present the facts of the matter and not just a knee-jerk contrarion reaction. Simply dismissing the swapfile as a "BAD THING" doesn't really help the OP learn more about it, at the very least.
I'm with you on disabling kernel panic reboots, though. That's just stupid.
There's a good reason why google hasn't enabled swapping, and there's even less of a reason with devices that come with 1GB of RAM.
Click to expand...
Click to collapse
Maybe, maybe not. Android 2.1 and earlier didn't implement JIT. Android 2.2 and earlier didn't implement EXT4. Android 2.3 and earlier didn't implement GPU-accelerated UI compositing. Android 3.2 and earlier didn't implement ASLR. Does that mean these were considered undesirable by Google at one point in time? Or were they always on Google's list of things they wanted to do and they just hadn't gotten around to them yet?
---------- Post added at 01:56 AM ---------- Previous post was at 01:41 AM ----------
danielkaboom said:
still failed,...:
- create a file in /data (named swapfile.swp), using terminal
# dd if=/dev/zero of=/data/swapfile.swp bs=1024 count=128000
- check from root explorer, the file is now created.
# mkswap /data/swapfile.swp
# swapon /data/swapfile.swp
swapon /data/swapfile.swp = Function not implemented
any sugestion?
edit : the permission is now can be change to rw-r--r--(thx Gary)..but its still failed to swapon,..
edit 2 : from what i've read from other pages and sites,..is it because "kernel not support"?
Click to expand...
Click to collapse
Yes, the kernel needs to have swapfs support. If you've ever played around with EXT4 kernels or ROMs that required EXT4 kernels, for example, it's kind of the same idea.
It sounds like the stock GT7+ kernel does not have this so you will need to find a custom kernel that does. I'm going to go out on a limb and guess that garyd9's kernel does not support swapfs.
Without the kernel, you're out of luck.
Regarding your situation on your Tab, it sounds like you've got an app or two that's misbehaving. Have you tried throwing up a CPU monitor? It would be useful to know whether the slowdown is caused by the CPU getting busy, and whether this load is from a single app or not.
Thank you for explaining that. Are there any examples, other than the one you mentioned, in which Android would benefit from a swapfile?
reading both pros and cons about swapfile really makes my head spinning,... im trying to understand it little by little. thanks guys for the explanation.
and yeah, guess im run out of luck,..(cause i don't have enough skill to make the kernel on my own,..sigh).
thanks.
danielkaboom said:
reading both pros and cons about swapfile really makes my head spinning,... im trying to understand it little by little. thanks guys for the explanation.
and yeah, guess im run out of luck,..(cause i don't have enough skill to make the kernel on my own,..sigh).
thanks.
Click to expand...
Click to collapse
It is a complicated issue with lots of tradeoffs in both directions.
I'm still curious as to the specifics of your problems, though. Garyd9 is correct in saying that creating a swapfile may not help your particular issue but that doesn't mean there isn't some other way to fix it. We just need more information about what's going on on your tablet.
---------- Post added at 05:49 PM ---------- Previous post was at 05:29 PM ----------
nyarltep said:
Thank you for explaining that. Are there any examples, other than the one you mentioned, in which Android would benefit from a swapfile?
Click to expand...
Click to collapse
Fundamentally, it breaks down to a store vs. recalculate issue - do you store memory pages to the swap file and incur the storage I/O overhead or do you discard it and recalculate it later and incur the cpu and memory I/O overhead? All of these resources are in short supply on the GT7+.
A swapfile works best with applications that maintain steady states that can easily be swapped out and back in as needed. A swapfile is least effective for active background processes.
If, for example, you're running out of memory running too many apps in the background - think clients for sync services, streaming media, system monitoring, etc. - a swapfile is not going to help.
However, if you're running into situations where you are switching between multiple apps such as document viewers/editors, and are finding that you need to reload documents as the apps get silently killed in the background, a swapfile could potentially help.
The only real way to know is to test it but without a kernel with swapfs support for the GT7+, it's impossible to say for certain.
from the opinion, i guess using swapfile for backround process is useless, but using it to switching task (for example : im using browser with lot of pages and beside that im doing some paperwork on office aplication) will help a bit, am i r8? if its r8, then im willing to try using swapfile, because i already freeze/uninstall some aplication that running on backround but still give me lags, when i did the example above.
but again, im running out of luck,..until Garyd9 or any1 else kind enough to make kernel that support swapfs,...
thanks for both of you, for your effort to answering my noob question.
regards,
dan
PS : Gary, i've tried your instruction, and yes it makes my daily use better,...though im still curious using swap,...hehehe.
danielkaboom said:
from the opinion, i guess using swapfile for backround process is useless, but using it to switching task (for example : im using browser with lot of pages and beside that im doing some paperwork on office aplication) will help a bit, am i r8? if its r8, then im willing to try using swapfile, because i already freeze/uninstall some aplication that running on backround but still give me lags, when i did the example above.
but again, im running out of luck,..until Garyd9 or any1 else kind enough to make kernel that support swapfs,...
Click to expand...
Click to collapse
Background processes are fine to swap out if they're steady state, it's active background processes that aren't going to benefit from a swapfile.
However, the lags you're experiencing may continue to persist depending on what is causing those lags. A swapfile won't help if you've got a poorly-optimized app running, particularly one that is not efficient with memory allocations. It also won't help if the lags are caused by a Dalvik thread performing garbage collection on its heap (whether the app on that thread is efficient in its memory allocations or not).
My educated guess is that if you are experiencing lags while using an active, foreground application, then this is not a problem that will be fixed with a swapfile. On the other hand, if you are experiencing lags launching new applications or bringing background apps into the foreground, these types of lags may be reduced with the use of a swapfile though the only way to know for sure is to test it.
I don't have time for an indepth reply to h2g2, but I'll reply simply:
You seem to be knowledgable enough to recompile a kernel - so please feel free to pull my kernel sources and initramfs, turn on swapping (samsung has it disabled by default), and try it. Keep an eye on the swapping and memory stats, as well as what's being swapped, etc... You might be surprised.
(If I had time, I'd do the same.. I've been wrong before and I might be wrong again... )
In either case, Daniel, I'm glad that turning off all that excess crap helps. As much as we all complain about this tablet, it actually runs pretty good without many modifications. If you read the changes I've made in the p6210 kernel, you'll see that I really haven't done much to it. The most invasive change was adding stuff that Samsung didn't have in there (such as UV.)
Take care
Gary
garyd9 said:
I don't have time for an indepth reply to h2g2, but I'll reply simply:
You seem to be knowledgable enough to recompile a kernel - so please feel free to pull my kernel sources and initramfs, turn on swapping (samsung has it disabled by default), and try it. Keep an eye on the swapping and memory stats, as well as what's being swapped, etc... You might be surprised.
(If I had time, I'd do the same.. I've been wrong before and I might be wrong again... )
Click to expand...
Click to collapse
Just to be clear, I have no real stake in this except to make sure that the technical facts about the swapfile are presented properly. In much the same way that you've been frustrated hearing about people recommending that they disable kernel panic reboots, I also am frustrated when people have a knee-jerk "swapfile = terrible" reaction that is largely based on FUD.
That said, you're right, I should just test it myself when I've got some free time.
Dusted off my old Nexus One, loaded up a clean install of CM7 and installed a kernel with CONFIG_SWAP=y. I decided to go with a swap partition on my sd card rather than a swapfile but the effect should be the same.
I haven't had time to do extensive testing but so far but I can confirm that swap is working and I haven't yet noticed a major perceptible impact to performance of the device.
Code:
# free
total used free shared buffers
Mem: 403240 379288 23952 0 60
-/+ buffers: 379228 24012
Swap: 62696 27948 34748
# grep "pswp" /proc/vmstat
pswpin 192
pswpout 7059
---------- Post added at 01:37 PM ---------- Previous post was at 12:49 PM ----------
Been switching back and forth between apps for a while now, paying particular attention to apps like Google Earth and the Browser that load up lots of data.
One particular test that seemed to stress the memory subsystem was using the "Print this page" on multi-page articles on graphics-heavy sites like, e.g. Anandtech (had the Snapdragon S4 review up). With swap enabled, there was a delay of 1-2 seconds when switching back to the browser (no doubt from reading the appropriate pages back into memory) but without the swapfile, the session was gone and the page needed to be reloaded, which took much longer than 1-2 seconds.
Some caveats:
1) I used a rather small swap partition (64MB) compared to the amount of memory available on the device (512MB for the N1). This means that I didn't need to do too much tweaking to the lowmemorykiller settings.
2) I set swappiness to 100, which is intentionally a bit heavy-handed (default seems to be 60).
3) I did not tweak other settings such as dalvik.vm.heapsize, vfs.
_cache_pressure, page-cluster and, as mentioned in #1, lowmemorykiller/parameters/minfree.
Code:
# free
total used free shared buffers
Mem: 403240 390824 12416 0 36
-/+ buffers: 390788 12452
Swap: 62696 59684 3012
# grep "pswp" /proc/vmstat
pswpin 6061
pswpout 31228
h2g2 said:
Dusted off my old Nexus One, loaded up a clean install of CM7 and installed a kernel with CONFIG_SWAP=y. I decided to go with a swap partition on my sd card rather than a swapfile but the effect should be the same.
I haven't had time to do extensive testing but so far but I can confirm that swap is working and I haven't yet noticed a major perceptible impact to performance of the device.
Code:
# free
total used free shared buffers
Mem: 403240 379288 23952 0 60
-/+ buffers: 379228 24012
Swap: 62696 27948 34748
# grep "pswp" /proc/vmstat
pswpin 192
pswpout 7059
---------- Post added at 01:37 PM ---------- Previous post was at 12:49 PM ----------
Been switching back and forth between apps for a while now, paying particular attention to apps like Google Earth and the Browser that load up lots of data.
One particular test that seemed to stress the memory subsystem was using the "Print this page" on multi-page articles on graphics-heavy sites like, e.g. Anandtech (had the Snapdragon S4 review up). With swap enabled, there was a delay of 1-2 seconds when switching back to the browser (no doubt from reading the appropriate pages back into memory) but without the swapfile, the session was gone and the page needed to be reloaded, which took much longer than 1-2 seconds.
Some caveats:
1) I used a rather small swap partition (64MB) compared to the amount of memory available on the device (512MB for the N1). This means that I didn't need to do too much tweaking to the lowmemorykiller settings.
2) I set swappiness to 100, which is intentionally a bit heavy-handed (default seems to be 60).
3) I did not tweak other settings such as dalvik.vm.heapsize, vfs.
_cache_pressure, page-cluster and, as mentioned in #1, lowmemorykiller/parameters/minfree.
Code:
# free
total used free shared buffers
Mem: 403240 390824 12416 0 36
-/+ buffers: 390788 12452
Swap: 62696 59684 3012
# grep "pswp" /proc/vmstat
pswpin 6061
pswpout 31228
Click to expand...
Click to collapse
little of my understanding, if a swapfile is made in an external sd, the sd card must have good r/w capability (minimum required a class 6 sd card), what if the swapfile is made in internal sd (since GTab have 12gb planted chip memory), what is the effect?
and so,....would you be kind enough to build a kernel for GTab 7+ that support swapfile? and if you do, can you do with a flashable zip (which i can flash it through cwm recovery?
so i can answer my own question : swap or not to swap?
and of course if you have spare time
thanks
dan
danielkaboom said:
little of my understanding, if a swapfile is made in an external sd, the sd card must have good r/w capability (minimum required a class 6 sd card), what if the swapfile is made in internal sd (since GTab have 12gb planted chip memory), what is the effect?
and so,....would you be kind enough to build a kernel for GTab 7+ that support swapfile? and if you do, can you do with a flashable zip (which i can flash it through cwm recovery?
so i can answer my own question : swap or not to swap?
and of course if you have spare time
thanks
dan
Click to expand...
Click to collapse
I'm using a Class 2 8GB MicroSDHC card from Sandisk on my Nexus One for testing and it seems to be fine. I'd recommend using an external SD because it's replaceable and swap I/O will wear out your flash faster so you're better off segregating it.
I took a look at the state of the kernel source for the GTab7+ at the moment and it looks like the Samsung sources are out of date and a kernel built from the current sources won't run properly on the LA3 firmware (Garyd9 notes this in the thread for his kernel as well) so right now, building a custom kernel is a nonstarter for me because the LA3 firmware fixed some pretty major shutdown issues for me on my Tab.
Perhaps when the ICS sources are released, I'll take another look.

[Q]What is VM heap size and how it works!?

I've been seeing This CM7 and wanted to know what this was?!
I'm always reading how people say that xxMB is the best size.
But what is it? And how it works?
What's it for? What's the right size for a Galaxy S?
VeryCoolAlan said:
I've been seeing This CM7 and wanted to know what this was?!
I'm always reading how people say that xxMB is the best size.
But what is it? And how it works?
What's it for? What's the right size for a Galaxy S?
Click to expand...
Click to collapse
This setting is simply the maximum amount of heap space (read: memory) a single instance of the Dalvik VM (read: application) can obtain.
Don't read anything into the "benchmarks" performed. This setting should have little effect on overall system performance. The only scenario where it would be beneficial to increase the maximum heap size would be if you have an application that is very close to using up all of its available heap space, which would force it to run garbage collection frequently, which would use up CPU cycles. It is possible that lowering the maximum heap size could be beneficial in that it might prevent an application from obtaining more memory than it needs (by forcing it to garbage collect sooner), but that all depends on how the Dalvik VM is implemented and is really beyond my knowledge.
The heap (in Java) stores dynamically allocated variables, such as objects. Like Rueben_ said, when the heap is running low on memory, the JVM will run garbage collection. Garbage collection uses processing cycles, which will slow down your phone. In case you're wondering, the other place in memory where things are stored is called the stack, which stores arguments and parameters.
Oh okay
So how do you how much memory to put it for at Max?
Sent from my SGH-T959 using xda premium
mrinehart93 said:
In case you're wondering, the other place in memory where things are stored is called the stack, which stores arguments and parameters.
Click to expand...
Click to collapse
I do believe the stack is reserved for storage of CPU data (typically, the contents of its registers) before it switches toanother context (or thread, which means loading a different set of data in its registers).
The memory zone where data from user apps (and the Dalvik VM is one of those, albeit a über-app of sorts since it runs all the other apps) is stored is rather just called "the heap". At least that's the way I learned it
daxdax89 said:
So is it better to put higher or lower heap size for games?
Click to expand...
Click to collapse
There is no right answer for this as you should have gathered from reading the answers you were given.
It all depends on how you use your phone.
Try out different settings with games and you'll see which suits your usage best.
Go on - Live on the edge a little lol...
daxdax89 said:
So is it better to put higher or lower heap size for games?
Click to expand...
Click to collapse
For the Vibrant if you use big apps then put the VM at like 128 or or something like that.
If you have small flashlight apps then use it at 32-96
Sent from my SAMSUNG-SGH-I747 using xda premium
Say, this seems to be a "magic bullet" for devices with modest memory sizes to keep apps from swamping the available memory. For my 1 GB Lollipop device, setting dalvik.vm.heapsize to "96m" improved the performance of the device. I was able to cycle between many memory-heavy applications without getting bogged down.
Be careful! Forgetting the "m" at the end, or setting the number too low will send your device into an endless garbage-collection, essentially locking you out. I set it too low myself, had to pop the battery, then quickly raise the value after reboot (before the "system_server" app got itself above the limit I had set), rebooting again to apply the new value. For a fair indication of a lower limit, look at the memory consumption of the "system_server" app. Set it above that to give it some headroom. Make sure you have a recovery plan before messing with this value!

Categories

Resources