Wednesday, February 9, 2011

sysctl (and minfree) tweaks revisited

(This is a follow up to my first post).

First of all, I believe tweaking minfree is just as important, if not more, than sysctl.  Android tends to behave badly when there's very little free memory.  When you're running your device with say less than 20-30MB of free RAM, a misbehaving app or two could invoke kernel's OOM killer and cause the device to become unstable, then eventually reboot or freeze.

For that reason, I don't like the default value of 25MB minfree.  (minfree, btw, is android's memory management system).  From my experience, I think at least 80MB minfree is required for your device to run fast and stable.  In general I recommend Rubix's minfree setting (20480 blocks x 4 will give you 80MB): 

echo "2048,3072,6144,15360,17920,20480"  > /sys/module/lowmemorykiller/parameters/minfree

I personally run my Droid X with the following: 

echo "256,512,1024,5120,13000,20000" > /sys/module/lowmemorykiller/parameters/minfree

Both should be fine.  Be sure that the last two numbers are at least 13000 and 20000.

Now back to sysctl.  Personally, I haven't had to manually drop caches at all.  In fact, my phone will probably run fine indefinitely without having to purge (longest i've run it without rebooting was 5 days, but it's really hard not to reboot your phone when you tweak it as much as i do - the kernel will automatically drop caches when it think it needs more memory). But I'm not a heavy user (i don't play games),  your mileage will vary of course, and you may need to purge every once in while.   To purge page, dentry and inode caches, use this command:
sync; echo 3 > /proc/sys/vm/drop_caches
My personal recommendation for most people (no manual flushing should be required):
vm.dirty_ratio = 90
vm.dirty_background_ratio = 55
vm.vfs_cache_pressure = 20
If you are willing to play around with manual or timed flushing I think you can squeeze a little more performance and battery life with:
vm.dirty_ratio = 90
vm.dirty_background_ratio = 70
vm.vfs_cache_pressure = 1
Btw, you can schedule cache purge using Tasker/sl4a, or you can use cron.

11 comments:

  1. sorry for the noobiness but would this work in adb?

    cd C:\androidsdk\tools
    adb shell

    *daemon starts successfully*

    echo "256,512,1024,5120,13000,20000" > /sys/module/lowmemorykiller/parameters/minfree

    then would i just disconnect the usb? I tried this and adb just reprinted the echo command and didn't seem to do anything.

    ReplyDelete
  2. hmmm i don't use adb because i think telnet is waaaayyy better. Looks like adb shell should work though. Try "cat /sys/module/lowmemorykiller/parameters/minfree" to see if your values took.

    ReplyDelete
  3. How would you feel about setting up sysctl on a Droid X

    I have this as my settings,

    Min Free KBytes :4096
    Dirty Ratio:90
    Dirty Background ratio: 70
    VFS Cache pressure: 1
    and on a loaded ROM Liberty 1.5 Oom allocating task is checked.

    ReplyDelete
  4. Matt,

    I have a droid X and those are the settings I use.

    ReplyDelete
  5. Thank you, I am now using these settings now. I appreciate your response. I have another question i was thinking of purchasing the Droid X overclock app Dev by Jrummy16, what are some good settings to set your processor at for battery life as well as peformance? I want to overclock but i am kinda worried about burning out the processor and all that goes along with overclock but do you have any suggestions?

    ReplyDelete
  6. Every Droid X is different as far as how overclockable it is, so you'll need to experiment. I would definitely recommend overclocking the highest frequency and undervolting the rest, especially the lowest. Mine settings are: 300/22, 600/33, 900/48, 1200/63.

    I wouldn't worry about burning out the processor unless you plan on keeping the phone for 10 years. ;)

    ReplyDelete
  7. IM A NOOB AND IM CONFUSED AS TO APPLYING THE SETTINGS FOR THE ECHO COMMAND. DO I JUST HAVE TO TYPE THAT IN TE? AND REBOOT?

    ReplyDelete
  8. James, I think it might be easier to flash one of my zips. http://www.imoseyon.com/2011/02/i-got-zip.html

    ReplyDelete
    Replies
    1. wwill it work for galaxy s3 ? anyway thanks for the explanation

      Delete