Now, let’s get down to what sysctl.conf does and how it works.
Min Free KBytes (vm.min_free_kbytes) - This is used to force the Linux VM to keep a minimum number of kilobytes free. The VM uses this number to compute a pages_min value for each lowmem zone in the system. Each lowmem zone gets a number of reserved free pages based proportionally on its size. Default is 2048kb.
Dirty Ratio (vm.dirty_ratio) and Dirty Background Ratio (vm.dirty_background_ratio) control how often the kernel writes data to "disk" (in our case the internal microSD system card, not the removable microSD card). When your apps write data to disk, Linux actually doesn't write the data out to the disk right away, it actually writes the stuff to system memory and the kernel handles when and how the data is actually going to be flushed to the disk. These values represent a percentage, the higher the percentage, the longer it waits to flush, the lower the percentage, the more often flushes will occur. Now remember, we are dealing with solid state storage, not the traditional disk platter and spindle. So we are actually able to delay flushes a little longer with solid state versus a traditional hard drive disk.
VFS Cache Pressure (vm.vfs_cache_pressure) -Now here is where it gets interesting! File system cache (dentry/inode) is really more important than the block cache above in dirty ratio and dirty background ratio, so we really want the kernel to use up much more of the RAM for file system cache, this will increas the performance of the system without sacrificing performance at the application level. The default value is 100, as a percentage, and what you want to do is lower the value to tell the kernel to favor the file system cache and not drop them aggressively.
Oom Allocating Task (vm.oom_kill_allocating_task) (enable or disable, generally in Linux this value is either a "1" or a "0," representing as on or off.) -This enables or disables killing the OOM-triggering task in out-of-memory (oom) situations. If this is set to zero, or disabled, the OOM killer will scan through the entire task list and select a task based on heuristics to kill. This normally selects a rogue memory-hogging task that frees up a large amount of memory when killed. If this is set to non-zero, or enabled, the OOM killer simply kills the task that triggered the out-of-memory condition. This avoids the expensive task list scan, which can take mass amounts of time and "hang" or freeze the system.
This information has been pulled from the following sites:
http://www.imoseyon.com/2011/05/dxd2-tweaks-new-version-man-its-been.html (newest)
imoseyon: Sysctl tweaking for faster, longer lasting Android (deprecated)
imoseyon: sysctl (and minfree) tweaks revisited (deprecated)
/proc/sys/vm | LinuxInsight (deprecated)
sysctl (and minfree) tweaks revisited
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):
I personally run my Droid X with the following:
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_cachesMy personal recommendation for most people (no manual flushing should be required):
vm.dirty_ratio = 90If 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_background_ratio = 55
vm.vfs_cache_pressure = 20
vm.dirty_ratio = 90Btw, you can schedule cache purge using Tasker/sl4a, or you can use cron.
vm.dirty_background_ratio = 70
vm.vfs_cache_pressure = 1
Sysctl tweaking for faster, longer lasting Android
In this post, let's focus on three settings: vm.dirty_ratio, vm.dirty_backgroud_ratio, and vm.vfs_cache_pressure.
vm.dirty_ratio and vm.dirty_background_ratio control how often kernel writes data to "disk" (well in our case the microSD card). When your apps write data to disk, Linux actually doesn't write the data out to disk right away, it actually writes the stuff to system memory and the kernel handles when/how the data is actually going to be flushed to disk.
I dunno - how much difference can it actually make? We're not talking about traditional hard drives with spindles, we're talking about solid state stuff. I suppose there could be a slight savings in battery life and increase in performance if you delay the data flush as much as you can.
I ended up with:
vm.dirty_ratio = 90Now vm.vfs_cache_pressure is much more interesting. File system cache (dentry/inode) is really more important than the block cache above, so we really want the kernel to use up much of the RAM for them. The default value is 100, and what you want to do is lower that value to tell the kernel to favor the file system cache and not drop them aggressively.
vm.dirty_background_ratio = 70
You can also take it a step further and set it to 1 (lowest possible without being dangerous). With the value of 1 the kernel will drop cache only when it's completely out of memory.
The problem is if you lower the value too much, after a day or two your device may start getting sluggish because the amount of RAM available to the applications continue to shrink to the point where they are starved for memory. So I came up with a solution to manually drop caches nightly!vm.vfs_cache_pressure = 1
And what I do to ensure that the caches are dropped nightly is to run the following sl4a scripts via tasker. Cron would be better but busybox on android doesn't seem to support it yet.echo 3 > /proc/sys/vm/drop_caches
# tells kernel to drop all file system caches
(It also reverts the dirty settings because I don't care if my phone writes to disk aggresively while i'm sleeping and it's being charged.)
su -c 'echo 3 > /proc/sys/vm/drop_caches;\And the following script at wakeup time:
sysctl -w vm.dirty_background_ratio=3;\
sysctl -w vm.dirty_ratio=15'
su -c 'echo 3 > /proc/sys/vm/drop_caches;\Finally, here's what my sysctl.conf file looks like:
sysctl -w vm.dirty_background_ratio=70;\
sysctl -w vm.dirty_ratio=90'
# cat /etc/sysctl.confI've been running at the above settings for a few days now, and the phone has been faster than ever with zero ill effects. Your mileage may vary of course.
# shouldn't matter - no swap is used
vm.swappiness = 0
# try to keep at least 4MB in memory
vm.min_free_kbytes = 4096
# favor block cache
vm.dirty_ratio = 90
vm.dirty_background_ratio = 70
# extremely favor file cache
vm.vfs_cache_pressure = 1
# reboot when OOM happens
vm.panic_on_oom = 2
# wait 5 sec before rebooting when OOM
kernel.panic = 5
# currently experimenting
kernel.shmmax = 268435456
kernel.shmall = 16777216



최근 덧글