N900 Kernel Memory (and more) Optimizations

So I’ve begun trying out some of the optimizations I’ve been using on my Debian machines for the past 8 or 9 years, on my N900. While I would have loved to see 512MB or more, the size we have is very usable as is. So in order to help you maximize the performance of your N900 I’ve compiled a list of simple (and completely reversible) optimizations that I’ve been using for a while that are relatively safe, but I’m not responsible for anything malafashion that happens. I’m using the Community Power-Kernel by Tom Tanner that I discussed in my previous article. It’s patched to the hilt already, but the changes listed below are extremely noticeable.

pengwings Most tweaks consist of tuning caches controlled by the kernel VM and I’m using values that are optimized for perceived performance. What happens in the background, happens, but I want my UI to be as fluid and responsive as possible. No more screen tearing, no more jagged responses. So sit down, strap in and let’s give our penguins some wings…

 

 

echo 30 > /proc/sys/vm/swappiness - The N900 is notoriously slow when doing multiple disk reads or writes. So I lower the “desire” for it to swap out pages. Less paging means more data will be stuck in RAM, so adjust it accordingly if you find yourself running out of memory. I run a cronjob that drops buffer cache containing pagecache, dentries and inodes, to clear out unused dirty pages (sync; echo 3 > /proc/sys/vm/drop_caches).

echo 0 > /proc/sys/vm/page-cluster - When it does swap out, I don’t want it doing huge operations and temporarily freeze the UI due to slow IO bus coupled with the use of CFQ scheduler instead of NOOP.

echo 1 > /proc/sys/vm/laptop_mode - But I do want it to smartly schedule when it’s going to write, so I’m not trying to write to disk when my device is in sleep mode. This might also help with reducing sporadic writes and saving the flash module.

echo 1 > /proc/sys/vm/oom_kill_allocating_task – Instead of killing “lower” priority or idle processes, I’d prefer whichever application tripped an Out-Of-Memory error, to be killed. The tasks I have in background are there for a reason.

echo 0 > /proc/sys/vm/dirty_expire_centisecsThis tells the kernel how often to look for modified/dirty pages in RAM that needs to be written to disk.

echo 0 > /proc/sys/vm/dirty_writeback_centisecsThis tells the kernel how old modified/dirty pages need to be, before they can be considered for flushing.

echo 60 > /proc/sys/vm/dirty_background_ratioThis is the lowest (percent) amount of memory where a dirty page flush can stop.

echo 95 > /proc/sys/vm/dirty_ratioThis is the highest (percent) amount of memory that can be stored before a force flush happens.

echo 0 > /proc/sys/net/ipv4/tcp_timestampsI disable timestamps so the processor has less data to deal with when traffic comes in. Packets can be resent if they’re OOB or clocked wrong.

echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_saveI also disable saving threshold metrics. Just ‘cause I’m gangster like that.

 

So that’s a couple of relatively safe and stable steps you can take to significantly boost your N900 performance and response time. Feel free to call me a fool for some of the values I’m using. I’ll consider your argument.

The heavy-hitters in the Android community have been tuning their kernels for quite a while and giving users awesome experience with their full customized and pre-cooked ROMS. It’s about time we catch-up to their supremeness dontchathink?

9 comments:

Chris said...

Trying these out as we speak.

Say, is there a way to get these settings to load automatically on startup? I'm guessing come boot time these settings go back to default?

Simon said...

Yes, after a reboot these will revert back. You have 2 option; /etc/init.d/rcS sets some of the values, look towards the end of the script. Or you can stash them in
a shell script and call it during boot using an entry in /etc/event.d/

Do this at your own risk though.

Anonymous said...

Very interesting post, Simon, as always.

I plan on trying these out, what is the best way to actually gauge performance on how well the N900 is doing? Is there a way to log statistics (perhaps from TOP or HTOP)?

David Hulbert said...

If anyone needs the original values:

Nokia-N900-02-8:~# cat /proc/sys/vm/swappiness
100
Nokia-N900-02-8:~# cat /proc/sys/vm/page-cluster
5
Nokia-N900-02-8:~# cat /proc/sys/vm/laptop_mode
0
Nokia-N900-02-8:~# cat /proc/sys/vm/oom_kill_allocating_task
0
Nokia-N900-02-8:~# cat /proc/sys/vm/dirty_expire_centisecs
500
Nokia-N900-02-8:~# cat /proc/sys/vm/dirty_writeback_centisecs
500
Nokia-N900-02-8:~# cat /proc/sys/vm/dirty_background_ratio
10
Nokia-N900-02-8:~# cat /proc/sys/vm/dirty_ratio
40
Nokia-N900-02-8:~# cat /proc/sys/net/ipv4/tcp_timestamps
1
Nokia-N900-02-8:~# cat /proc/sys/net/ipv4/tcp_no_metrics_save
0

Anonymous said...

made the mods about 12 last nite, reboot and they are still there. It's a heck of a lot more responsive.

Anonymous said...

It's absolutely awesome.
Please tell me, how often do you run that cron job you referred to?
Thanks a lot for all that :)

Dagui said...

Yes, could you please detail the cron job? Will the device get slower when it runs? Will there be any stability problem if the cron job is not running while using this custom settings?

Denis said...

hmm. is the "performance boost" measurable ?
care to provide numbers ?

Anonymous said...

Are you sure you don't have the description of "dirty_expire_centisecs" & "dirty_writeback_centisecs" mixed up?

Thanks for all of this btw
J

Post a Comment