Memory/CPU Usage with adb top

Search This thread

us1111

Senior Member
Jun 19, 2007
186
2
Hi,

I was curious why the Hero sometimes is blazing fast, and sometimes so incredible slow. That is why I decided to root the device to see what's going on in the device with top and other tools...

This is what is showing up, right after booting the device (sorted on memory usage and not showing kernel processes:

Code:
  PID CPU% S  #THR     VSS     RSS UID      Name
  123  12% S    12 239468K  43276K nobody   com.htc.launcher
   67   5% S    50 212448K  35532K system   system_server
  119   0% S    14 140420K  24796K misc     android.process.acore
   36   0% S     1  72644K  21680K root     zygote
  121   0% S    18 120660K  21200K radio    com.android.phone
  383   0% S    15 118140K  20328K app_40   com.htc.android.mail
  214   0% S    13 109376K  17696K app_3    com.google.process.gapps
  258   3% S     8 108124K  17636K app_5    com.android.mms
  363   0% S     9 182892K  16784K app_25   com.android.calendar
  336   0% S     8  95792K  16384K app_22   com.htc.android.psclient
  301   0% S     7 102784K  15392K app_12   com.google.android.apps.maps:FriendS
ervice
  486   0% S     5 177860K  15364K app_78   org.koxx.pure_calendar
  271   0% S     8  95904K  15264K app_6    android.process.media
  346   0% S     8  97212K  15120K app_15   com.htc.dcs
  495   0% S     6 110632K  15056K app_68   com.tunewiki.lyricplayer.android:pla
yer
  460   0% S     6  96336K  14688K app_41   com.htc.android.footprints
  477   0% S     6  95972K  14496K app_24   com.htc.album
  390   0% S     6 102280K  13956K app_25   com.htc.calendar
  176   0% S     7 100340K  13928K app_26   com.htc.socialnetwork.provider
  443   0% S     5  94192K  13912K app_53   net.rgruet.android.g3watchdog
  448   0% S     6  96240K  13616K app_59   com.biggu.shopsavvy
  293   0% S     5  93400K  13492K app_9    com.htc.htctwitter
  469   0% S     6 100004K  13488K system   com.android.settings
  328   0% S     6  94660K  13316K app_17   com.htc.android.worldclock
  249   0% S     5  93420K  13280K app_80   com.socialnmobile.hangulkeyboard
  524   0% S     6  94024K  13248K app_48   com.htc.htclocationservice
  376   0% S     6  93772K  13204K app_32   com.htc.providers.uploads
  515   0% S     6  94324K  12620K app_13   com.google.android.gm
  318   0% S     6  92960K  12460K app_21   com.htc.provider.weather
  306   0% S     8  94976K  12140K app_19   com.htc.provider.settings
  431   0% S     5  92016K  11708K app_73   com.rechild.advancedtaskkiller
  417   0% S     6  99156K  11684K app_45   com.google.android.partnersetup
   37   0% S     9  29752K   5360K media    /system/bin/mediaserver
  100   0% S     2   3124K   1156K wifi     /system/bin/wpa_supplicant
   35   0% S     9  11068K   1152K radio    /system/bin/rild
   38   0% S     1   1180K    740K bluetoot /system/bin/dbus-daemon
   41   0% S     1   1196K    580K compass  /system/bin/akm8973
  131   0% S     1    856K    428K dhcp     /system/bin/dhcpcd
   33   0% S     1    852K    400K root     /system/bin/vold
  538   4% R     1    916K    376K shell    top
  537   0% S     1    740K    332K shell    /system/bin/sh
   39   0% S     1    800K    308K root     /system/bin/installd
   32   0% S     1    808K    268K system   /system/bin/servicemanager
   34   0% S     1    668K    268K root     /system/bin/debuggerd
    1   0% S     1    292K    204K root     /init
   43   0% S     4   3332K    164K shell    /sbin/adbd

What I don't understand is why for example tunewiki has a memory intensive task in resident memory while i've never started it up. Also these processes I maybe (almost) never use , why on earth start them for me?:
com.android.mms
com.htc.htctwitter
com.biggu.shopsavvy

Also the android calendar seems unnessesary because of the HTC calendar?

Why is the system keeping these processes in memory when they are not used? That seems like a waste of memory to me..

I know Android has a particular view on proces lifecycle management, however when I start a program, it may not use many CPU cycles but it does use and keep memory for itself...
 

lux209

Senior Member
Jul 20, 2008
63
6
I read somewhere that when a program/process is not used the memory is "unloaded" on the internal memory to free up some space, and reloaded when you use the program again.

But i can be wrong, I don't remember where I saw that.
 

us1111

Senior Member
Jun 19, 2007
186
2
Yeah... But top tells me otherwise.. I think the application stays resident (RSS) but CPU cycles are kept to a minimum. I think this is design when you leave an application with no service:

- Stop CPU cycles
- Leave memory footprint until needed otherwise
 

lux209

Senior Member
Jul 20, 2008
63
6
sorry my previous message was not clear (and my english is quite bad)

What I remember is that the process is still active (so you can see it with top) but the memory (RAM) is unloaded and saved on the internal storage. When you start the process again it just reload the data to the RAM
 

kiz

Senior Member
Dec 24, 2008
87
0
Edinburgh
Why are you worried about memory usage? These days many operating systems pre-fetch apps so they load quicker. I imagine Android has just selected certain apps to pre-fetch. Remember, empty RAM is wasted RAM!

I would be more concerned with cpu cycles if I were you.
 

us1111

Senior Member
Jun 19, 2007
186
2
Why are you worried about memory usage? These days many operating systems pre-fetch apps so they load quicker. I imagine Android has just selected certain apps to pre-fetch. Remember, empty RAM is wasted RAM!

I would be more concerned with cpu cycles if I were you.

pre-fetching apps is somewhat different than keeping programs in RSS. What I see in top is that programs stay in resident memory, which is not easely reclaimable. It then will take (a lot) of CPU cycles to free up and re-fill this memory, so there is a relation...

What I do see in practice is that android is sometimes slow and sometimes quite fast, without changing anything obvious. I was/am looking for a reason for this symptom.

That is why I rooted the thing to be able to see some low level system stat's. In top I see that a lot of programs stay in resident memory which is normaly not good in linux/unix land..
If there is an detail design of how Android does this, I would really like to see it (and hope that i'll understand it). By the way, I have seen the presentation of process lifecycle management, but this describes inactive applications as "saved" which i presume is not keeping it in memory.


And indeed emtpty ram will probably never happen with a linux kernel because of caching an buffering...
 
Last edited:

us1111

Senior Member
Jun 19, 2007
186
2
just use taskiller app all the time

Hmm.. i would like to approach it a more scientific way.. A good OS should not need you to do that..

http://linux.derkeiler.com/Mailing-Lists/Kernel/2009-01/msg05142.html

As I can see it, tuning could be done in the init.rc scripts and in particular this section which adresses the out of memory (oom) killer:

Code:
# Define the oom_adj values for the classes of processes that can be
# killed by the kernel.  These are used in ActivityManagerService.
    setprop ro.FOREGROUND_APP_ADJ 0
    setprop ro.VISIBLE_APP_ADJ 1
    setprop ro.SECONDARY_SERVER_ADJ 2
    setprop ro.HOME_APP_ADJ 4
    setprop ro.HIDDEN_APP_MIN_ADJ 7
    setprop ro.CONTENT_PROVIDER_ADJ 14
    setprop ro.EMPTY_APP_ADJ 15

# Define the memory thresholds at which the above process classes will
# be killed.  These numbers are in pages (4k).
    setprop ro.FOREGROUND_APP_MEM 1536
    setprop ro.VISIBLE_APP_MEM 2048
    setprop ro.SECONDARY_SERVER_MEM 4096
    setprop ro.HOME_APP_MEM 4096
    setprop ro.HIDDEN_APP_MEM 5120
    setprop ro.CONTENT_PROVIDER_MEM 5632
    setprop ro.EMPTY_APP_MEM 6144

# Write value must be consistent with the above properties.
# Note that the driver only supports 6 slots, so we have HOME_APP at the
# same memory level as services.
    write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15

    write /proc/sys/vm/overcommit_memory 1
    write /proc/sys/vm/min_free_order_shift 4
    write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,563
2,6144

    # Set init its forked children's oom_adj.
    write /proc/1/oom_adj -16
 
Last edited:

jhietter

Member
May 8, 2007
25
0
I'm wondering the same thing lately as I try to speed up my Droid. With OSMonitor's new cpu graph in the notification area, I noticed my cpu usage was very high a good deal of the time. So I rebooted and watched it stay at 99% for a while. I went to watch the processes and it was tunewiki, mixzing and camera (android.media) taking up all the cpu. I hadn't started any of them. Tunewiki was over 90% for several minutes. I would understand an initial scan, but it's been installed for over 24 hours so I don't know what the hell it could still be doing. I have about 14GB of music on the SD right now, so I'm wondering if it has to scan through that on every reboot.
 

BlueHawk

Senior Member
Aug 17, 2009
351
61
Toronto
I wouldn't get too hung up about memory usage. The most important thing that will chew battery and slow down your device is CPU. And that is going to be up to the app developer and how they design things. Ideally, you want to write your program so that it doesn't run all the time - that is, it has a sleep state. If all your apps play nice and sleep when they are put in the background, your OS can then go into a hibernate mode when not being used by you (not tapping on the keyboard or doing other things interactively with it). This saves battery because hibernate allows halting the CPU cycles (when the CPU is awake, when it is not doing anything related to any app, it will be executing the equivalent of a NOP, which still chews battery). Also, if you have programs that don't allow a sleep (or rarely) , other apps get starved of cycles, hence you see a slow down.

As for your question as to why you have other processes at boot, some apps are written to start at boot. That was how the developer intended it to work. And some of these things, you don't want to kill. Some of these are even part of the core Android or HTC Sense, and if you kill it, Android will die an ugly death - try killing HTC Checkin and see how your Hero takes that!

If your system needs RAM, it will start swapping inactive app data out of active memory onto the swap. Use "free" in busybox, to gauge if anything got moved out to swap.
 

erasmux

Retired Recognized Developer
May 22, 2010
1,437
455
This issue has been covered in great detail and length throughout this thread:

http://xdaforums.com/showthread.php?t=622666

I think most recent ROMs use higher values for the low memory killer. The trick is to find values that will on the one hand keep as much free memory for fast loading of new apps and disk caching. But on the other hand, you don't want apps too close to fast - i.e. switch from your browser to check an SMS and return to find it has been killed and needs to reload. Even worse, since the hero has a relatively low amount of physical memory, it is pretty easy to reach values which kill background services like your SMS program and then you start missing messages....

I will also say, that to the best of my knowledge, you are wrong that apps you never used open up. It might not kill apps which are not in use any more, but any app which see there was loaded for a reason. For example for the calender, I assume HTC's calender app still uses the stock calender under the hood - try to remove it and see what happens.
 

stefpaul

Senior Member
Jun 27, 2010
354
33
bucharest
This issue has been covered in great detail and length throughout this thread:

http://xdaforums.com/showthread.php?t=622666

I think most recent ROMs use higher values for the low memory killer. The trick is to find values that will on the one hand keep as much free memory for fast loading of new apps and disk caching. But on the other hand, you don't want apps too close to fast - i.e. switch from your browser to check an SMS and return to find it has been killed and needs to reload. Even worse, since the hero has a relatively low amount of physical memory, it is pretty easy to reach values which kill background services like your SMS program and then you start missing messages....

I will also say, that to the best of my knowledge, you are wrong that apps you never used open up. It might not kill apps which are not in use any more, but any app which see there was loaded for a reason. For example for the calender, I assume HTC's calender app still uses the stock calender under the hood - try to remove it and see what happens.

In my option, for the little hero to run Sense 2.1 you need a lite version (Salsa Lite), so you can use whatever you like... But it seems that from the lack of processor power, hero lags.

On the other hand, if you want a new version of android, a stock version is more of use, but if you miss Sense(like i do), you get bored of it.

@ erasmux => can you make a .zip file that removes recent applications in the Sense 2.1 status bar, i think it's one of the sources that make the rom laggy...
 

erasmux

Retired Recognized Developer
May 22, 2010
1,437
455
In my option, for the little hero to run Sense 2.1 you need a lite version (Salsa Lite), so you can use whatever you like... But it seems that from the lack of processor power, hero lags.

On the other hand, if you want a new version of android, a stock version is more of use, but if you miss Sense(like i do), you get bored of it.

@ erasmux => can you make a .zip file that removes recent applications in the Sense 2.1 status bar, i think it's one of the sources that make the rom laggy...

I am not currently actively supporting any Android 2.3+ Sense ROMs. If and when I release future Sense ROMs, I will see if I find the time for this.