FORUMS
Remove All Ads from XDA

Tweak Android for Performance, and increase battery by Saving Power Usage with Sysctl

3,181 posts
Thanks Meter: 6,088
 
Post Reply Email Thread
Here I will post tweaks as I find them to optimize Android.

When echoing in the following sysctl settings they do not remain after reboot, so we can adb remount then create a sysctl.conf file on our pc's with these settings, then ./adb push sysctl.conf /etc/ then the kernel should apply the settings every reboot

For examples of a sysctl.conf use google: Sysctl.conf Examples

Open a Terminal and Execute these commands as root

Tweak virtual memory to conserve power when running on battery:
Code:
echo 0 > /proc/sys/vm/swappiness #can be ignored if you dont use swap
echo 0 > /proc/sys/vm/dirty_expire_centisecs #can be ignored if you dont use swap
echo 0 > /proc/sys/vm/dirty_writeback_centisecs #can be ignored if you dont use swap
echo 60 > /proc/sys/vm/dirty_background_ratio
echo 95 > /proc/sys/vm/dirty_ratio
Tweak virtual memory for running on Charger

Code:
echo 0 > /proc/sys/vm/swappiness #can be ignored if you dont use swap
echo 3000 > /proc/sys/vm/dirty_expire_centisecs #can be ignored if you dont use swap
echo 500  > /proc/sys/vm/dirty_writeback_centisecs #can be ignored if you dont use swap
echo 10   > /proc/sys/vm/dirty_background_ratio
echo 40   > /proc/sys/vm/dirty_ratio
Detecting apps/services that hog the battery/cpu:
Also while on battery, you should stop all applications that don't really stay idle when you're not using them, if you want to find which apps arent really staying idle you can:
Code:
strace -p $(pidof yourapp) # for all your running applications 
ps aux | awk '{print$10,$11}' | sort -n # will list all running softs sorted by used cpu time
By default when Linux runs out of memory it goes through the process list and starts killing off processes that it thinks are using too much memory. This sysctl makes Linux kill the runaway process that made the system run out of memory instead, which is usually what you want.(this will also reduce cpu time and increase battery usage).
Code:
sysctl -w vm.oom_kill_allocating_task=1
Credit: ccpp0
vfs_cache_pressure to 10 , gives more mem to cache fs dentry and inode to save cpu
At the default value of vfs_cache_pressure = 100 the kernel will attempt to reclaim dentries and inodes at a "fair" rate with respect to pagecache and swapcache reclaim. Decreasing vfs_cache_pressure causes the kernel to prefer to retain dentry and inode caches. Increasing vfs_cache_pressure beyond 100 causes the kernel to prefer to reclaim dentries and inodes.
Code:
sysctl -w vm.vfs_cache_pressure=10

I'll be adding more tweaks for sysctl and basic cmd line tweaks as I find them, also these tweaks would be good integrated into roms, apps, and a power-save widget if anyone wants to get creative.
The Following 3 Users Say Thank You to defconoi For This Useful Post: [ View ] Gift defconoi Ad-Free
 
 
8th June 2009, 09:46 AM |#2  
Senior Member
Thanks Meter: 166
 
Donate to Me
More
a few questions
do i enter this into the terminal emulator? also does this only need to be entered in one time? thank you in advance for any help.
8th June 2009, 09:50 AM |#3  
robpet2's Avatar
Senior Member
Flag Virginia
Thanks Meter: 77
 
More
great find.. will keep my eye on this thread
8th June 2009, 11:01 AM |#4  
defconoi's Avatar
OP Senior Member
Flag SCHUYLKILL HAVEN
Thanks Meter: 6,088
 
Donate to Me
More
Smile
Quote:
Originally Posted by david1171

do i enter this into the terminal emulator? also does this only need to be entered in one time? thank you in advance for any help.

yes you can enter it in via terminal emulator or ./adb shell, the echo'd settings are not permanent and will reset after reboot, so use the settings to test, then follow the directions to create a /etc/sysctl.conf file to make the settings permanent after you feel comfortable with the settings(if you notice improvement)
defcon
8th June 2009, 11:32 AM |#5  
free-sidux's Avatar
Senior Member
Thanks Meter: 11
 
More
Wow, this is cool, thank you!

Could you maybe add some more comments, I don't really understand what the single commands do. Or some place, where the function of e.g. "dirty_expire_centisecs" is explained?

One more precise question though: If I don't have a swap file on sd, does the tweaking of the swappiness still change anything?

Greetings!
8th June 2009, 11:36 AM |#6  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by free-sidux

Wow, this is cool, thank you!

Could you maybe add some more comments, I don't really understand what the single commands do. Or some place, where the function of e.g. "dirty_expire_centisecs" is explained?

One more precise question though: If I don't have a swap file on sd, does the tweaking of the swappiness still change anything?

Greetings!


there is no swap space on G1, so settings related to the swap can be ignored.

echo 0 > /proc/sys/vm/dirty_expire_centisecs
echo 0 > /proc/sys/vm/dirty_writeback_centisecs

never writes out dirty pages ?
8th June 2009, 11:46 AM |#7  
defconoi's Avatar
OP Senior Member
Flag SCHUYLKILL HAVEN
Thanks Meter: 6,088
 
Donate to Me
More
Quote:
Originally Posted by free-sidux

Wow, this is cool, thank you!

Could you maybe add some more comments, I don't really understand what the single commands do. Or some place, where the function of e.g. "dirty_expire_centisecs" is explained?

One more precise question though: If I don't have a swap file on sd, does the tweaking of the swappiness still change anything?

Greetings!

http://tinyurl.com/nlb9ws

Note: The value of vm.swappiness=0 states that no swap space will be used at all, basically it can be ignored if you dont use swap though
8th June 2009, 11:52 AM |#8  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by defconoi

http://tinyurl.com/nlb9ws

Note: The value of vm.swappiness=0 states that no swap space will be used at all, basically it can be ignored if you dont use swap though


set vfs_cache_pressure to 10 , gives more mem to cache fs dentry and inode to save cpu "wa".
9th June 2009, 11:16 AM |#9  
Member
Thanks Meter: 0
 
More
how do i create a Sysctl.conf file with this script?
i tried the link of examples but all i could find was info about it.

everything else works but when i try
sysctl vm.block_dump=1

i get sysctl: error: 'vm.block_dump=1' is an unknown key

any ideas?
9th June 2009, 03:04 PM |#10  
defconoi's Avatar
OP Senior Member
Flag SCHUYLKILL HAVEN
Thanks Meter: 6,088
 
Donate to Me
More
actually ya know what I think we can just disable sysctl all together in menuconfig->Filesystems->Pseudo Filesystems->Proc->Sysctl Support when compiling a new kernel and setting these tweaks right in the kernel.
Says in menuconfig"As it is generally a good thing, you should say Y here unless
building a kernel for install/rescue disks or your system is very
limited in memory
."
So I think we can gain some memory disabling this since we dont really need it
9th June 2009, 03:19 PM |#11  
defconoi's Avatar
OP Senior Member
Flag SCHUYLKILL HAVEN
Thanks Meter: 6,088
 
Donate to Me
More
Talking disable /dev/mem
Also I think we can disable the Memory Device Driver, /dev/mem, it says it can be disabled for security conscious and can be disabled on memory tight systems, which we are definitely memory tight plus there's just no valid app that uses /dev/mem on actual memory.
Other popular users of /dev/mem are rootkits and the like.
(note: mmap access of memory via /dev/mem was already not allowed since
a really long time)

People who want to use /dev/mem for kernel debugging can enable the config
option.
Post Reply Subscribe to Thread

Tags
hacks, sysctl, tweaks

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes