[CompCache] Setting compcache to full RAM size - G1 Android Development

I've always run compcache on my ROMs when possible and I recently had the idea that setting the full amount of RAM to compcache could be an interesting test. The theory being that it may be slightly slower overall to have ramzswap compressing pages, but minfree would have heaps of memory to play with and apps would never quit, so multitasking would be faster as no apps are writing out to /data and then having to relaunch when I switch to them again.
I've set compcache with the init script like so
Code:
insmod /system/lib/compcache/ramzswap.ko;
rzscontrol /dev/block/ramzswap0 -i -d 98304;
busybox swapon /dev/block/ramzswap0;
And Linux reports the swap is working
Code:
# free
total used free shared buffers
Mem: 107332 105972 1360 0 8
Swap: 98296 48940 49356
Total: 205628 154912 50716
But no matter what I do, even if I launch a heap of apps, I can never get swap usage above the ~48Mb RAM seen here.
Furthermore, apps like Auto Killer and Free Memory only report I have 102Mb RAM total.
What's going on here? Why does Android think it only has 100Mb when free is reporting near on 200Mb total? Why does compcache only fill up halfway and no more? Does this mean that ~48Mb RAM is the "sweet spot" for compcache and any more is pointless?
The phone does feel faster when switching between apps but I could just be imagining it. Out of interest this is a 32B Magic running Dwang 1.17.1, which is basically just Donut AOSP with a faster framework and kernel.
Any ideas/help/suggestions would be appreciated?

Swap is never, ever, regarded by the system as real memory, hence why the system won't report it, since you really only have ~100 mb physical ram.
As to why you're only using 48, I believe that 48 is 1/2 96, so it probably means pages are being compressed 2:1, so the full memory is being compressed and dumped into RAM, and it only occupies 48 MB, leaving you 48 free for other processes.
Again, remember comcapche is swap, not real memory.

jubeh said:
Swap is never, ever, regarded by the system as real memory, hence why the system won't report it, since you really only have ~100 mb physical ram.
As to why you're only using 48, I believe that 48 is 1/2 96, so it probably means pages are being compressed 2:1, so the full memory is being compressed and dumped into RAM, and it only occupies 48 MB, leaving you 48 free for other processes.
Again, remember comcapche is swap, not real memory.
Click to expand...
Click to collapse
I don't think that that analysis is quite right....
First off, you MUST maintain SOME amount of real memory available... otherwise it'll crash in a spectacular way. I believe that the linux kernel itself may have a safety feature that maintains a certain minimum amount of physical ram available. There ARE certain things that the linux kernel will not be willing to swap, such as ITSELF.
Just imagine what would happen if the kernel swapped itself..... any attempt to do this wouldn't end well. Especially if it tried to swap its ENTIRE self since the kernel MUST be in memory in order for it to run.
There is also the swappiness setting... it controls the system's tendency to swap.
And finally, there is the possibility that you may simply not be starting enough processes to consume the full memory!
So imagine this; you have your compcache set for a certain size. It grows to that size and then finally, the kernel says "screw you, you can't have any more memory!" blows an error back to compcache, which complains back to the kernel "sorry, swap is screwed." Yep.... the kernel tells compcache which tells the kernel rather than the kernel just knowing.
You definitely don't want this happening.

Note: I can forsee some serious stability problems that this could result in related to the low memory process killer. Specifically, your compcache grows to its maximum allowed size, you start an application, the low memory process killer figures that you've got plenty of memory available, doesn't kill anything off, tries to start some application, crashes spectacularly when the kernel complains back that it doesn't have any memory. I don't know if this would happen with a stock low memory process killer, but definitely would with the swap hacks added....

lbcoder said:
Note: I can forsee some serious stability problems that this could result in related to the low memory process killer. Specifically, your compcache grows to its maximum allowed size, you start an application, the low memory process killer figures that you've got plenty of memory available, doesn't kill anything off, tries to start some application, crashes spectacularly when the kernel complains back that it doesn't have any memory. I don't know if this would happen with a stock low memory process killer, but definitely would with the swap hacks added....
Click to expand...
Click to collapse
92 MB of compcache doesn't really need 92MB of compcache... that's the point of being compcache.
Compcache file in RAM grows when cache gets stuffed inside compcache.
Setting a low swappiness will cause compcache to just swap what's needed.
And even with full compcache, in the end you end up having around 140 mb (or so) free ram. 92mb of compcache that takes like 50mb and 42 extra mb of normal ram.
I think this idea is great (I was just too lazy to try yet...). Instead of dalvik vm having to free up memory it can stuff some more mb in compcache. should be faster.
I didn't really think my post through... but I hope some of you understood some of the things I wanted to communicate xD

domenukk said:
92 MB of compcache doesn't really need 92MB of compcache... that's the point of being compcache.
Compcache file in RAM grows when cache gets stuffed inside compcache.
Setting a low swappiness will cause compcache to just swap what's needed.
And even with full compcache, in the end you end up having around 140 mb (or so) free ram. 92mb of compcache that takes like 50mb and 42 extra mb of normal ram.
I think this idea is great (I was just too lazy to try yet...). Instead of dalvik vm having to free up memory it can stuff some more mb in compcache. should be faster.
I didn't really think my post through... but I hope some of you understood some of the things I wanted to communicate xD
Click to expand...
Click to collapse
Interesting in theory, but if you actually read what I said, you would note that this is entirely IMPOSSIBLE and would crash spectacularly if not for and in some cases in SPITE of certain safety features built into the kernel.
Note: If you have 70 MB worth of data that CAN'T be swapped, that leaves 20 MB ***PEAK*** available to compcache.
It is neither fair nor sensible to think of all memory as being equal. Running processes ***MUST*** have REAL MEMORY.

A little off-topic, but this discussion (the possibility of REAL "compressed" memory) sparked a thought/question:
Would/could KSM* bring any benefit to Android? (Not sure if the KSM module can even compile/work on ARM)
I know KSM is normally used for detecting and sharing duplicate pages among KVM guests, but I wonder how many pages in a typical running Android installation are duplicated, and thus candidates for sharing/de-duplication.
*I can't posts links yet, so those that don't know what KSM is, will just have to google for it.

lbcoder said:
There ARE certain things that the linux kernel will not be willing to swap, such as ITSELF.
Click to expand...
Click to collapse
I was under the impression the kernel keeps itself in RAM and then reports free memory to the rest of the OS. This is why the phone physically has 192Mb RAM, but only reports 96Mb free (or 107Mb with RAM hack). Perhaps my understanding of Linux/Android memory reporting is not correct?
lbcoder said:
It is neither fair nor sensible to think of all memory as being equal. Running processes ***MUST*** have REAL MEMORY.
Click to expand...
Click to collapse
I think this is likely what is happening. Home, Phone, System and other processes with a low oom are refusing to swap out as they are still running. If the compcache allocation in RAM is dynamic as domenukk says, then those processes are occupying enough RAM that the ramzswap allocation can only grow to ~48Mb as I am seeing. I didn't think of this.
Nor have I tweaked swappiness. It's currently set to 60 (default) so I'd assume it's not too fussy with paging out. I will try playing with this at 10 and 100 to see if I can force anything more into swap or if it's less willing to swap.
brainbone said:
*I can't posts links yet, so those that don't know what KSM is, will just have to google for it.
Click to expand...
Click to collapse
I do not know either, but here are some links people may wish to look at
http://fedoraproject.org/wiki/Features/KSM
http://lwn.net/Articles/306704/
http://lwn.net/Articles/330589/
http://www.linux-kvm.com/content/using-ksm-kernel-samepage-merging-kvm

Ok I am not at all experienced in this area but this is just a suggestion. You say that you can only get 48mb of swap to be compressed at a time. If those 48mb were uncompressed, then that would occupy the 98mb you alloted to it. If you set the cc at say 128mb, then in (my) theory up to 64mb of it the actual ram would be used. I don't know how much sense I'm making but not sure exactly how to explain it. If you don't get it I'll try explaining my logic a little more in depth.

mejorguille said:
If you set the cc at say 128mb, then in (my) theory up to 64mb of it the actual ram would be used.
Click to expand...
Click to collapse
It appears you are right. Even with swappiness set to 100 and opening every app on my phone I'm not able to fill more than half of 128Mb compcache before minfree stats gracefully closing processes:
Code:
/opt/android-sdk-linux_86/tools$ ./adb shell free
total used free shared buffers
Mem: 107332 105956 1376 0 32
Swap: 131064 65520 65544
Total: 238396 171476 66920

Super Jamie said:
It appears you are right. Even with swappiness set to 100 and opening every app on my phone I'm not able to fill more than half of 128Mb compcache before minfree stats gracefully closing processes:
Code:
/opt/android-sdk-linux_86/tools$ ./adb shell free
total used free shared buffers
Mem: 107332 105956 1376 0 32
Swap: 131064 65520 65544
Total: 238396 171476 66920
Click to expand...
Click to collapse
I rock=p
So what's your performance like, compared to say 32mb cc or no cc at all?

It's different but I like it.
There is sometimes a slight (<2 second) pause when launching a new app (I assume this is compcache compressing old pages to swap to make way for the new app) however once the app is up and running, it almost never "exits" so switching between previously-launched apps is noticeably faster than without compcache. I run HelixLauncher Donut and it's never closed and re-launched while I've been trying this, however it did sometimes with 32Mb cc and quite often without cc at all.
I had 5 day uptime last week with 96Mb compcache (rebooted whilst testing another app for a friend) so I don't think stability is an issue. The CM wiki indicates performance with cc is better upon boot then gradually declines, even if that is the case, rebooting my phone once a week is no big issue.
Unless I run into any major issues, I'll be keeping my phone with large compcache

Super Jamie said:
I was under the impression the kernel keeps itself in RAM and then reports free memory to the rest of the OS. This is why the phone physically has 192Mb RAM, but only reports 96Mb free (or 107Mb with RAM hack). Perhaps my understanding of Linux/Android memory reporting is not correct?
I think this is likely what is happening. Home, Phone, System and other processes with a low oom are refusing to swap out as they are still running. If the compcache allocation in RAM is dynamic as domenukk says, then those processes are occupying enough RAM that the ramzswap allocation can only grow to ~48Mb as I am seeing. I didn't think of this.
Nor have I tweaked swappiness. It's currently set to 60 (default) so I'd assume it's not too fussy with paging out. I will try playing with this at 10 and 100 to see if I can force anything more into swap or if it's less willing to swap.
I do not know either, but here are some links people may wish to look at
http://fedoraproject.org/wiki/Features/KSM
http://lwn.net/Articles/306704/
http://lwn.net/Articles/330589/
http://www.linux-kvm.com/content/using-ksm-kernel-samepage-merging-kvm
Click to expand...
Click to collapse
ksm sound cool. As every app runs inside dalvik vm. Not sure though... somebody should ask cyanogen
I am happy thatlarge compcache works out so well for you.
BTW doesn't cyanogenmod 5 count the whole swap as real memory since test4 or so?
Oh and overclocking ondemand to as high as possible will speed up app opening and switching a lot while on compcache

domenukk said:
doesn't cyanogenmod 5 count the whole swap as real memory since test4 or so?
Click to expand...
Click to collapse
It's counted as available "swap" memory, but not "real" ram. Pages stored in "real" ram (memory that the cpu can directly execute code in) still need to be freed up (moved to swap) before previously swapped pages can be moved back in to "real" memory to be executed.
domenukk said:
ksm sound cool.
Click to expand...
Click to collapse
The beauty of KSM is that it does no "swapping". It simply combines 4KB pages that are identical -- so instead of two identical 4KB pages using 8KB of ram, they only take 4KB. The code is executed in place.
KSM would, however, still require swap. If at any time a virtual shared 4KB page is written to, it needs to be copied to a free page to avoid corrupting the virtual page it was a duplicate of before the write. Swap is needed to ensure that there will always be enough available free pages when this happens.
domenukk said:
As every app runs inside dalvik vm.
Click to expand...
Click to collapse
KSM is not dependent on a VM, but the existence of VMs (java or otherwise) increases the likelihood of duplicate pages.
domenukk said:
Not sure though... somebody should ask cyanogen
Click to expand...
Click to collapse
I'd certainly be interested in cyanogen's thoughts on this, but I'm sure there are others that would be able to chime in as well.
Relevant excerpt from kernel.org/doc/ols/2009/ols2009-pages-19-28.pdf
KSM and embedded
KSM is suitable to be run on embedded systems too; the important thing is not to register in KSM regions that won’t likely have equal pages. For each virtual page scanned, KSM has to allocate some rmap_item and tree_item, so while these allocations are fairly small, they can be noticeable if lots of virtual areas are scanned for no good.
Furthermore, these KSM internal rmap/tree data structures are not allocated in high memory. To avoid early out of memory conditions, it is especially important to limit the amount of lowmem allocated on highmem 32bit systems that might have more than 4GB of memory, but these shouldn’t fit in the embedded category in the first place.
Click to expand...
Click to collapse

Super Jamie said:
I was under the impression the kernel keeps itself in RAM and then reports free memory to the rest of the OS. This is why the phone physically has 192Mb RAM, but only reports 96Mb free (or 107Mb with RAM hack). Perhaps my understanding of Linux/Android memory reporting is not correct?
Click to expand...
Click to collapse
Memory reporting is a tricky thing.
But in general, when RAM is allocated to HARDWARE, it is NOT REPORTED.
The chunk of the 192 that is not reported is assigned PRIMARILY to the RADIO. Another chunk is assigned to the GPU. Still more is assigned to the AUDIO HARDWARE.
The part used by the kernel itself IS reported. The most trivial empirical evidence to prove this to you is that when you change KERNELS, it doesn't affect the total system memory, despite your KNOWING that different kernels use different amounts of RAM.
Another bit of empirical proof is that activating COMPCACHE does not reduce the total physical ram reported. And yes, COMPCACHE is part of the kernel...
Now here's another concept of crash and burn: IF everything in memory could be cached in compcache, then what would stop compcache from caching compcache in a horrible infinite memory sucking loop? That would be very very bad, LOL.
I think this is likely what is happening. Home, Phone, System and other processes with a low oom are refusing to swap out as they are still running. If the compcache allocation in RAM is dynamic as domenukk says, then those processes are occupying enough RAM that the ramzswap allocation can only grow to ~48Mb as I am seeing. I didn't think of this.
Click to expand...
Click to collapse
NOW you're getting the idea! Running processes, kernel, etc., all need physical RAM (though actually those processes you mention most definitely CAN be swapped...), and therefore you CAN'T make the ENTIRE RAM into compcache!
Nor have I tweaked swappiness. It's currently set to 60 (default) so I'd assume it's not too fussy with paging out. I will try playing with this at 10 and 100 to see if I can force anything more into swap or if it's less willing to swap.
Click to expand...
Click to collapse
Just beware of possible crash-and-burn

Super Jamie said:
It appears you are right. Even with swappiness set to 100 and opening every app on my phone I'm not able to fill more than half of 128Mb compcache before minfree stats gracefully closing processes:
Code:
/opt/android-sdk-linux_86/tools$ ./adb shell free
total used free shared buffers
Mem: 107332 105956 1376 0 32
Swap: 131064 65520 65544
Total: 238396 171476 66920
Click to expand...
Click to collapse
That doesn't actually follow from what you've posted here.
What follows is that 105956-(65520/2)=73196 of what occupies your memory can't be swapped (kernel, running processes, etc.).

lbcoder said:
What follows is that 105956-(65520/2)=73196 of what occupies your memory can't be swapped (kernel, running processes, etc.).
Click to expand...
Click to collapse
Do you know why swap constantly "settles" at almost exactly half usage regardless of what size compcache I set?
For example, I set 64Mb compcache yesterday and rebooted. Just using my phone normally (browser, genie widget, music) I have this:
Code:
total used free shared buffers
Swap: 63992 32096 31896
Does this mean I am effectively reducing the amount of RAM the phone has for the kernel, "foreground app", "visible app" and "secondary servers" (to use the minfree terms), whilst at the same time allowing more "hidden app" and lower processes to swap out instead of terminating gracefully?

This disturbs me
-------------------------------------
Sent via the XDA Tapatalk App

brainbone said:
I'd certainly be interested in cyanogen's thoughts on this, but I'm sure there are others that would be able to chime in as well.
Click to expand...
Click to collapse
He doesn't know much about it, yet. But he seems inerested.
Attached a short conversation over #twitter
# Dominik domenuk
@cyanogen Is ksm any good 2 save RAM? probably not - you would have already done it http://lwn.net/Articles/329123/
# Steve Kondik cyanogen
@domenuk I don't know too much about it, I think its meant for sharing between distinct virtual machines
@domenuk it could have a lot of potential though
# Dominik domenuk
@cyanogen basically yes. But he states its also for normal apps. I have no idea to what extend android apps have similar memory, though...
# Steve Kondik cyanogen
@domenuk a lot, Android is all about IPC and shared memory. I wouldn't be surprised if the Dalvik people are thinking about it.
Click to expand...
Click to collapse

Here is a way to make Android use more than 50 percent of a swap partition. I am not sure how it will act with compcache... Should be the same... Run the following commands from a terminal or add them following to your userinit.sh file:
Code:
su
echo 80 > /proc/sys/vm/swappiness
echo 150 > /proc/sys/vm/vfs_cache_pressure
!!WARNING!! - Messing with VM settings can cause data loss and system instability... Not liable for damages...
Using the above the "free" output is:
Code:
total used free shared buffers
Mem: 97708 95168 2540 0 356
Swap: 125296 88756 36540
Total: 223004 183924 39080
While we are at it... If anyone is willing... they can try this as well:
echo 1 > /proc/sys/vm/oom_kill_allocating_task
Reference : Article to Linux Insight
Been having pretty good results with it...
Here is a link to the rest of the vm settings...
Linux Insight article listing vm settings
L8r

Related

Some questions about compcache

I've just installed compcache on my Cyanogen ROM, and preliminary farting around gives me the impression "this is frelling epic". I can have some big apps running, all at once, flick between them without reloads, and go back to the home screen instantly.
So here's the question: why is the ext2 partition needed? If compcache does it magic by creating a ramdisk that has compression enabled, and then using that for swap, why does it need any changes to your SD card at all? (I've made the changes, I have my ext2 partition - I'd just like to understand WHY).
Also, has anyone done any empirical testing on battery life with compcache versus swappper? My gut feeling (although this is not based on any proper analysis) is that swapper has made my battery take a real nose-dive, and I've seen people on the Dream boards say compcache has the same or worse effect. How are people finding it on their Magics?
I have had swapper for a while and it does not appear to have any effect on my battery thus far. I've heard of people running both compcache and swapper. Is there a good tutorial out there on setting compcache up? The one I found was kinda outdated and listed support roms that were WAY outdated. I wouldn't mind trying both in conjunction with each other.
I found this over in the Dream forums
http://forum.xda-developers.com/showthread.php?t=537236
but it does presuppose that you're running Cyanogen.
I've actually bumped up my "swap" with Compcache to 64Mb. Rationale is that the Dream has less RAM than we do (even us poor relation 32B RAM-cripped Magic owners). Loaded Google Mail, Exchange Mail, Pacman, Teeter, and loaded up icanhascheezburger.com on the browser (the latter usually being a sure-fire way of prompting a pause for reloading when going back to the home screen). There was no more than half a second delay switching from app to app once they'd all loaded and they all seemed to stay in memory rather than the oldest one used dropping out and needing a reload. If the battery life holds up I'm very pleased.
Just to verify, Swapper is for using a swap on a SD while Compcache utilizes space on the built in ram for a swap. Is this correct?
Gimpeh said:
Just to verify, Swapper is for using a swap on a SD while Compcache utilizes space on the built in ram for a swap. Is this correct?
Click to expand...
Click to collapse
As I understand it, yes. So basically Compcache will grab (say) 32Mb of your RAM and uses it as swap. Which would make no sense (because why would you swap to RAM - just use the RAM as RAM!) except Compcache compresses what gets swapped. Your 32Mb thus becomes 96Mb or more (I'm seeing compression factors of 70-odd %). What I don't personally get is why Compcache needs an ext2 (linux) partition on your SD card.

not clear to me from search what is current state of swap && / || CCache

Can anyone direct me to a guide somewhere?
I'd like to make an ext partition? Or would I? Is Swapper 2 just as fast? Tradoffs? Anyone run into their sd card wearing out yet?
bueler?
The message you have entered is too short. Please lengthen your message to at least 10 characters.
The consensus seem to be "do not use" except as 'last resort', and only needed on phones with 256MB or less of mem.
I wrote this, and I am waiting for a technical review from some experts in this field.
http://forum.xda-developers.com/showthread.php?t=897823
kschang said:
The consensus seem to be "do not use" except as 'last resort', and only needed on phones with 256MB or less of mem.
I wrote this, and I am waiting for a technical review from some experts in this field.
http://forum.xda-developers.com/showthread.php?t=897823
Click to expand...
Click to collapse
I have 256MB ram
At the moment, Compcache is good enough, but I can't help but wonder how much better it could be with swap instead of Compcache.
edit: "For example, If you have a 256MB system (shows as 262MB due to 1024 vs. 1000 KB size difference) and have 130MB of apps and data/cache loaded, then that leaves about 130MB for the system to actually RUN programs. That sounds like a lot, but in reality that is not enough, since the system itself takes 50-80MB, and services will take up another 30-50MB, leaving almost nothing. "
quick review, you don't appear to be differentiating between RAM and Flash? Having more apps installed shouldn't increase RAM usage at all. Unless I gravely misunderstand the Android OS, if I install a new program, it resides in the system flash, not the RAM, until I run it, at which point it gets loaded to RAM. When the system needs memory and no swap or Compcache is in use, it writes the state of the application to the flash and removes it from RAM.
What the swap does is similar to what compcache does-- compresses apps that are currently in RAM, and moves them to the swap space. In the case of Compcache, this is in the RAM. But since you're compressing it, background apps don't take nearly as much RAM, and you get an app switching speedboost because the processor can uncompress the compcache'd program, "move" it to RAM, compress the currently running program in RAM, and "move" it to the compcache. Forgive me if you already said this, I can't read the entire thing at the moment.
As for swap, I'm not sure if the processor compresses before going to the hard swap file, I don't think that it does-- when android starts getting low on RAM, it moves what was in RAM, to the swap on the SD-card. Since it does this when the system is low on RAM, and not when the system runs out of RAM, you never notice it. Reading the app back from the SD card happens almost instantaneously, because the sd cards can be read from at a speed of at least 20MB/s, maybe more. When you're restoring an app to RAM, 20MB/s is plenty.
edit2: I'm sorry but this guide is too vague to be anything more than moderately informative. Comments like:
-"CompCache, or "compressed cache", is handled by the Linux kernel. It takes a portion of your memory, and use it as a cache space, but compressed. By using on-the-fly compression it is able to make your memory appear to be a bit larger than it actually is. However, the result is slower performance.
This is usually NOT tweakble without mod ROM such as Cyanogen Mod. The kernel also must support this feature, and not all do. This also slows your phone. "
-"...swap space by either creating a swap file or a swap partition. This adds a lot of read/write action to your SD card and may substantially decrease its usable life."
-"This really slows your phone."
People wouldn't be doing these things for no reason. Compcache does not "make your memory appear a bit larger", when it at least doubles the amount of usable RAM-- when you allocate 60MB, if you average 75% compression (I usually see between 65% and 80%), do you know how much RAM this effectively nets you? Over at least 60MB extra, usually about 80! So my phone goes from having 256MB ram to having 340 effectively. Having your processor overclocked minimizes any slowdown from the compression/decompression; I haven't noticed any slowdown, and having the "extra" RAM definitely has made my phone more able to multitask.
You basically discourage users from doing ANYTHING like swapping, compcaching, etc to their phone, saying it "slows it down" and "can substantially decrease your SD Card's life". My experience has been otherwise regarding slowing it down, and regarding the SD card, the only part that would actually go bad is the swap partition. If you put that at the end of the drive, when it goes bad, you'll know, and you can just move the partition back 300MB and put your 300MB swap there. We haven't heard of any users' cards going bad from this yet. Also, if you have a class 6+ SD Card, they implement wear leveling on the card, so you don't need to worry about wearing out any individual bits.
Sorry, I'm just not digging it.
rancur3p1c said:
I have 256MB ram
Click to expand...
Click to collapse
Me too, me too...
At the moment, Compcache is good enough, but I can't help but wonder how much better it could be with swap instead of Compcache.
Click to expand...
Click to collapse
So try it. With CM612, I have CompCache AND Swap (through Swapper2 / 128 MB) turned on. It slows down every once in a while but my programs don't crash any more.
edit: "For example, If you have a 256MB system (shows as 262MB due to 1024 vs. 1000 KB size difference) and have 130MB of apps and data/cache loaded, then that leaves about 130MB for the system to actually RUN programs. That sounds like a lot, but in reality that is not enough, since the system itself takes 50-80MB, and services will take up another 30-50MB, leaving almost nothing. "
quick review, you don't appear to be differentiating between RAM and Flash? Having more apps installed shouldn't increase RAM usage at all. Unless I gravely misunderstand the Android OS, if I install a new program, it resides in the system flash, not the RAM, until I run it, at which point it gets loaded to RAM. When the system needs memory and no swap or Compcache is in use, it writes the state of the application to the flash and removes it from RAM.
Click to expand...
Click to collapse
At first I thought the same way you did, until I started looking in "diskusage".
According to diskusage, there is no separate RAM. 256MB is 256MB. App storage is where everything goes, and what's left is used to load services and such. The numbers I added up matches. I have 256 MB phone. 100 is for apps, which leaves about 150-160. System itself takes 50-80 (acore, gapps, phone, system...) then add a few services and you're down to 30-40 MB free to actually run the programs. The numbers seem to match up to what's shown at the bottom of "Manage Services".
I know it's weird, but perusal of Android developers kit doesn't contradict this understanding.
What the swap does is similar to what compcache does-- compresses apps that are currently in RAM, and moves them to the swap space. In the case of Compcache, this is in the RAM. But since you're compressing it, background apps don't take nearly as much RAM, and you get an app switching speedboost because the processor can uncompress the compcache'd program, "move" it to RAM, compress the currently running program in RAM, and "move" it to the compcache. Forgive me if you already said this, I can't read the entire thing at the moment.
As for swap, I'm not sure if the processor compresses before going to the hard swap file, I don't think that it does-- when android starts getting low on RAM, it moves what was in RAM, to the swap on the SD-card. Since it does this when the system is low on RAM, and not when the system runs out of RAM, you never notice it. Reading the app back from the SD card happens almost instantaneously, because the sd cards can be read from at a speed of at least 20MB/s, maybe more. When you're restoring an app to RAM, 20MB/s is plenty.
edit2: I'm sorry but this guide is too vague to be anything more than moderately informative. Comments like:
-"CompCache, or "compressed cache", is handled by the Linux kernel. It takes a portion of your memory, and use it as a cache space, but compressed. By using on-the-fly compression it is able to make your memory appear to be a bit larger than it actually is. However, the result is slower performance.
This is usually NOT tweakble without mod ROM such as Cyanogen Mod. The kernel also must support this feature, and not all do. This also slows your phone. "
-"...swap space by either creating a swap file or a swap partition. This adds a lot of read/write action to your SD card and may substantially decrease its usable life."
-"This really slows your phone."
People wouldn't be doing these things for no reason. Compcache does not "make your memory appear a bit larger", when it at least doubles the amount of usable RAM-- when you allocate 60MB, if you average 75% compression (I usually see between 65% and 80%), do you know how much RAM this effectively nets you? Over at least 60MB extra, usually about 80! So my phone goes from having 256MB ram to having 340 effectively. Having your processor overclocked minimizes any slowdown from the compression/decompression; I haven't noticed any slowdown, and having the "extra" RAM definitely has made my phone more able to multitask.
Click to expand...
Click to collapse
It also seriously depends on your SD card. I've read reports on Phandroid that said class 6 or 8 microSD cards would provide almost lag-free swaps, but that's on a G1 (which is already a slow phone).
You basically discourage users from doing ANYTHING like swapping, compcaching, etc to their phone, saying it "slows it down" and "can substantially decrease your SD Card's life". My experience has been otherwise regarding slowing it down, and regarding the SD card, the only part that would actually go bad is the swap partition. If you put that at the end of the drive, when it goes bad, you'll know, and you can just move the partition back 300MB and put your 300MB swap there. We haven't heard of any users' cards going bad from this yet. Also, if you have a class 6+ SD Card, they implement wear leveling on the card, so you don't need to worry about wearing out any individual bits.
Sorry, I'm just not digging it.
Click to expand...
Click to collapse
Constantly reading and writing the file will cause that area to get much heavier use and eventually cause it to fail the bootup "checking SD card". The only question is how much life is taken away.
I am running my Droid on 24% CompCache AND 128MB Swap right now. Occasional lag but otherwise runs quite well. It's also overclocked to 1.2 GHz with P3Droid's kernel. So I do practice somewhat of what I preach...
so if I have 512MB of ROM, and 256MB of RAM, and I fill up my ROM with programs, how much RAM do I have?
I don't follow how what you said can be.
SD Card writes-- SanDisk guarantees theirs for 100K writes to any given sector...that's good enough for the swap to not be a problem in the near future IMHO.
let's put it this way...
Here's the specs of Moto Droid from Motorola itself (http://developer.motorola.com/products/droid/)
RAM 256 MB
FLASH ROM 512 MB
USER STORAGE AVAILABLE (MAX) 256 MB
So the REST of the ROM clearly is to hold the Android OS itself. The actual programs you can load for running? 256MB. That's app storage.
I've always wondered if there's a way to read the actual ROM contents and enumerate that... But that's for another topic.
Found this useful post: boot process of Android OS
http://www.androidenea.com/2009/06/android-boot-process-from-power-on.html
Furthermore, I noticed that the "built-in" apps (i.e. bloatware) are actually just stuff left in the "system" dir which can only be accessed with root permission. So they are NOT store in "ROM" per se, but more like "part of boot rom".
I have to find explanation on how an app is loaded, but that helps...
Aha, so that's the term they used... Application Lifecycle.
http://www.youtube.com/watch?v=ITfRuRkf2TM
Okay, I take back what I said. Apps are loaded into RAM, but HOW things are allocated wasn't that clear.
From what I understand, apps, when they are killed by system, some exit gracefully by writing their instance "state" (data and cache) to app storage. Some just exits.
Browser will write the URL, for example. When the browser is "resumed", the process is loaded, then the instance loads back the URL and it's as if nothing happened.
I'll have to revise the paper, AND I haven't figured out what to say about swap and compcache yet.
Made some corrections.
On 256MB machine, 30MB is used by deep system buffers (not part of OS), another 32 for OS cache, so about 190 or so is available the OS itself to load apps and services, and just the default gapps, system, phone, and so on is about 60MB. So a fresh clean phone should ahve no more than 120-130 MB free. If you load a couple apps with autostart services, it'll quickly drop below 50MB.
http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android
Another piece of the puzzle... The numbers at the bottom of "Manage Services" is as explained below:
(quoting from http://android-developers.blogspot.com/2010/02/service-api-changes-starting-with.html )
"Finally, along the bottom of the screen are some obscure numbers. If you know how to interpret them, this gives you a lot of information on the memory status of your device:
* Avail: 38MB+114MB in 25 says that the device has 38MB of completely free (or likely used for unrequired caches) memory, and has another 114MB of available memory in 25 background processes it can kill at any time.
* Other: 32MB in 3 says that the device has 32MB of unavailable memory in 3 unkillable processes (that is, processes that are currently considered to be foreground and must be kept running)"
The order is reversed in Android OS 2.2. Mine says
Other: 75MB in 5 Avail: 18MB + 20 MB in 3
Which should mean 75MB in 5 unterminable tasks, 18 MB free (or can be freed easily), plus another 20 MB used by 3 processes that can be killed to free up.
ProCrank says...
39911K System_server
15756K acore
12982K swiftkey
10136K DIY Screensaver (lock screen)
9392K Phone (system)
9093K ATKfroyo
6834K Terminal
3984K JuiceDefender
3785K Screebl
3482K system MMS
3329 SeePU
3244K Bluetooth
3199K SetCPU
1979K Zygote (which is Dalvik init)
1425K Mediaserver
and the rest is native system code well under 1MB in size.
If you add System_server, Phone, Zygote, Acore, and foreground app (terminal and procrank) you get about 75MB. It would be nice if that screen TELLS you which program it considers to be unterminable, but, oh well...

[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 ZRAM?

I had a search about and really I am only looking for confirmation as to whether this is accurate or not...
CALIBAN666 said:
I think its better to Post this here,when its not better,than sorry!!!
-----------------------------------------------------------------
Once a brief statement for those who are not traveling so long in the Android scene:
ZRAM = ramzswap = Compcache
In order to explain more precisely ZRAM first need other terms are more clearly defined:
Swap can be compared with the swap file on Windows. If the memory (RAM) to complete the PC the data that are being used not actively outsource (eg background applications) so as to re-evacuate RAM free. To this data is written to a hard disk. If required, this data is then read back from there easily. Even the fastest SSD is slower than the RAM. On Android, there is no swap!
In ZRAM unnecessary storage resources are compressed and then moved to a reserved area in the fixed RAM (ZRAM). So a kind of swap in memory.
This Ram is more free because the data then only about 1/4 of the former storage requirements have. However, the CPU has to work in more because they compress the data has (or unpack again when they are needed). The advantage clearly lies in the speed. Since the swap partition in RAM is much faster than this is a swap partition on a hard drive.
In itself a great thing. But Android does not have a swap partition, and therefore brings Android ZRAM under no performance gain as would be the case with a normal PC.
In normal PC would look like this:
Swap = swap file (on disk) -> Slow
ZRAM (swap in RAM) -> Faster than swap
RAM -> Quick
With Android, there is no swap partition, and therefore brings ZRAM also no performance boost.
The only thing that brings ZRAM is "more" RAM. Compressed by the "enlarged" so to speak of the available memory. That's on devices with little RAM (<256MB) also pretty useful. The S2 has 1GB but the rich, and more than. There must not be artificially pushed up to 1.5 GB.
After you activate the ZRAM also has 2 disadvantages. The encoding and decoding using CPU time, which in turn has higher power consumption.
Roughly one can say (For devices with more than 512MB RAM):
Without ZRAM: + CPU Performance | + Battery | RAM
With ZRAM: CPU Performance |-Battery | + RAM
For devices with too little RAM so it makes perfect sense. But who shoots the S2 already be fully complete RAM and then still need more?
Check whether you can ZRAM runs in the terminal with
free or cat / proc / meminfo
I hope it helps to understand zRam!!!!
Click to expand...
Click to collapse
Taken from here
That looks accurate, but it's a little hard to understand. A basic explanantion of zRAM is that zRAM compresses an actual block of RAM in order to have more RAM available to the system. If you make the compression too high with zRAM then your device will actually go slower as a result. An example of going over the top would be adding 256MB of RAM using zRAM on a phone that only has 768MB RAM (that's almost a 50% compression rate because ~600MB is available to the user). zRAM also requires the CPU to compress and decompress the data.
Zram is not ram. It is a virtual memory, also known as swap space, which lives in the ram. Virtual memory is the part where the system stores memory fragments which are not accessed, making more room for apps to store information in the ram. Most Pcs work with virtual memory on disk, but Linux has a zram feature, aka CompCache, which can hold unused pages in a compressed manner in memory, thus makes more ram available by compressing unaccessed pages.
Sent from my HTC Sensation Z710e using xda premium
so this ZRAM tweak is only useful for devices with low RAM's isn't it? well thanks for the info i dont wanna sacrifice batt life for some unnoticeable effect on my s3
once zram is enabled ....how do u remove the partition completely from.the ram after disabling it?
I noticed that my galaxy s duos comes with zram . However I wish to disable the partition and instead use swap partition in /cache .
So....how do I completely remove the partition space in ram?
Thank you .
Virtual Memory
Raven2k said:
Zram is not ram. It is a virtual memory, also known as swap space, which lives in the ram. Virtual memory is the part where the system stores memory fragments which are not accessed, making more room for apps to store information in the ram. Most Pcs work with virtual memory on disk, but Linux has a zram feature, aka CompCache, which can hold unused pages in a compressed manner in memory, thus makes more ram available by compressing unaccessed pages.
Sent from my HTC Sensation Z710e using xda premium
Click to expand...
Click to collapse
Sorry but you have a wrong concept of "Virtual Memory".
Google "virtual memory wiki" for the full article.
All programs have access only to their own "virtual" memory space of 4GB on 32bit OS'
But internally to the OS, that full virtual address space is divided on pages of 4KB each.
The OS manages all programs pages, if not enought RAM is available, it starts writing pages to the Page File / Swap partition.
When a program tries to read or write from its virtual memory address which page is not on physical memory, the OS launches a Page Fault Exception, takes over execution and reads the faulty page from storage (page file or swap partition) to physical memory, and if necessary writes another page to storage to make room for the requested page. Then it resumes the program execution.
From the article. Android does not have a Swap partition, but it compresses pages to ZRAM.
geno83 said:
Sorry but you have a wrong concept of "Virtual Memory".
Google "virtual memory wiki" for the full article.
All programs have access only to their own "virtual" memory space of 4GB on 32bit OS'
But internally to the OS, that full virtual address space is divided on pages of 4KB each.
The OS manages all programs pages, if not enought RAM is available, it starts writing pages to the Page File / Swap partition.
When a program tries to read or write from its virtual memory address which page is not on physical memory, the OS launches a Page Fault Exception, takes over execution and reads the faulty page from storage (page file or swap partition) to physical memory, and if necessary writes another page to storage to make room for the requested page. Then it resumes the program execution.
From the article. Android does not have a Swap partition, but it compresses pages to ZRAM.
Click to expand...
Click to collapse
True but not completely.
Android doesn't require ZRAM nor swap to work. It is a linux fraction but it doesn't act like linux completely.
Could anybody tell me the best way to improve ram efficiency without sacrificing batt
Thread cleaned. Either post relevant replies or don't post.
Right now, I have a full ZRAM. How does RAM handles it?
Sent from my Moto G4 Plus using XDA Labs

Can you change ZRAM with root on stock kernel?

Hi all,
With this Xiaomi device SoC source code was never released so only stock kernel can be used. Is it possible to turn on ZRAM and change ZRAM values with it still if I was to gain root?
Many thanks
LaurenceGough said:
Hi all,
With this Xiaomi device SoC source code was never released so only stock kernel can be used. Is it possible to turn on ZRAM and change ZRAM values with it still if I was to gain root?
Many thanks
Click to expand...
Click to collapse
You already have zRAM enabled by default. AFAIK modern Android devices don't use a swap partition (except RAM+ features).
see your zRAM:
Code:
su
cat /proc/swaps
adjust your zRAM:
Code:
su
swapon --help
the size of your zRAM is defined in
/vendor/etc/*fstab*
WoKoschekk said:
You already have zRAM enabled by default. AFAIK modern Android devices don't use a swap partition (except RAM+ features).
see your zRAM:
Code:
su
cat /proc/swaps
adjust your zRAM:
Code:
su
swapon --help
the size of your zRAM is defined in
/vendor/etc/*fstab*
Click to expand...
Click to collapse
Thanks very much, that command is super useful and no amount of Googling I did could find it!
/vendor/etc/*fstab* reports:
"/dev/block/zram0 none swap defaults zramsize=55%"
This sounds like ZRAM should be enabled at 2.2GB.
The problem with this device is the swap partition is reported as always 2252MB, yet even with the "RAM" boost turned on or off the "swap" partition is reported as the exact same size. I suspected based on the really, really poor memory related performance it is disk based SWAP... Anything more than 2-3 simple apps and they reload constantly like they were fully closed when switching apps. All power saving features are turned off.
P.S I am not rooted just yet, I was just trying to see if I could improve my performance as the CPU is quite strong but memory is the issue.
Thanks again
Edit:
I just ran /vendor/etc/*fstab* again after enabling "RAM boost" and restarting, it says it's on in the app switch view (+2GB) but the output is the exact same of this file, I am not sure if this is to be expected or not. Performance is exactly the same so I guess it's just another MIUI bug?
This "SWAP" partition is also not always full usually only 1GB out of the 2GB in use. Checking against a Pixel 7, it's 3GB of ZRAM (reported as SWAP, but of course no RAM boost or SWAP exists on Pixels) it's fully utilized almost always despite having double the physical RAM.
LaurenceGough said:
at 2.2GB
Click to expand...
Click to collapse
LaurenceGough said:
always 2252MB
Click to expand...
Click to collapse
we calculate with base 2!
=> 1024^2 = MiB = 1.048.576 Byte
=> 1.048.576 x 2258 = 2.367.684.608 Byte = 2,2GiB!!
=> 2258MiB = 2,2GiB
There is no partition or used storage for zRAM/swap on your device. Consider that zRAM is compressed with lz4 (=50% compression). So, 1GiB RAM storage needs only 512MiB zRAM storage. The (de)compression is done by the kernel.
zRAM (and also swap) can't boost your system. These partitions are only used for cached data. Before your kernel deletes this data to clear RAM storage it gets compressd and stored in the zRAM area. It's the most useless data.
zRAM is a dynamic partition on your RAM. If RAM only needs 128MiB zRAM then zRAM won't be greater than 128MiB. It never increases to the full available size until it's really needed. If fsrab states "55%" than 55% is the maximum size of zRAM in your RAM and not a persistent size that is always occupied.
Don't change anything regarding to the RAM management as Android is nearly perfect handling thas by itself. You can only make it worse.
Thanks again. The issue I'm facing is that just a few basic apps struggle to run when multitasking, I have disabled all power saving features and MIUI optimisations / powerkeeper daemon but when switching apps or webpages they very often reload fully. I am certain this is an issue with low memory, and I know 4GB is not a lot of memory these days, but I thought I could run more than two tabs in a web browser, and more than a few simple apps without them reloading.
My understanding of zRAM is that it compresses RAM as you say, whilst this taxes the CPU more it should be able to compress more data into the RAM, effectively allowing more apps / webpages (pages) to stay available to use, rather than being killed by the low memory killer dameon lmkd.
Is my understanding correct that this 55% zRAM would provide an extra ~3.3GB or so of compressed RAM, making the total addressable RAM approx ~5.3GB?
If the 2GB of "RAM boost" or SWAP as it should be called if I am correct was working I'd expect it to be able to keep a few more apps or tabs running in memory and prevent a full reload? Is there any way I could check if this is running correctly without root? I know SWAP partitions are not ideal and they have a few downsides but I think this phone has relatively fast storage for its price range.
I am on the lookout for a device with more RAM but it'd be nice to understand a bit more about this situation and learn.
LaurenceGough said:
making the total addressable RAM approx ~5.3GB?
Click to expand...
Click to collapse
Your RAM storage remains 4096MiB. The swapped data in zRAM is compressed and can't processed until it gets decompressed. All data in zRAM actually should have been deleted and this storage isn't acting as additional RAM storage increasing your performance per se.
Apart from that Android's RAM management always uses 60-70% under normal conditions. For peaks, due to some heavy memory using apps, it can increase to 80-90% while at the same time zRAM increases, too. It's correlating. You can't force RAM to swap everthing into zRAM for having 2-3GB available. That's not the meaning of zRAM.

Categories

Resources