View Single Post
Posts: 310 | Thanked: 383 times | Joined on Jan 2010
#1
Hey everyone,

I've been using my phone as a wireless media server for friends (with Samba + wifi hotspot). While it worked brilliantly for reads, writes were causing all kinds of weird issues, and absolutely destroyed interactivity on the phone itself.

Later, while copying several 400mb files from internal storage to my SD card, it actually froze, and rebooted. I suspect dsme was swapped out and couldn't respond quickly enough to avoid the watchdog.

Anyway, I sat down and thought about the problem, and set about to improve interactivity under I/O load. This is my current configuration, and I find it vastly improves responsiveness:

Code:
    echo 3 > /proc/sys/vm/dirty_ratio
    echo 3 > /proc/sys/vm/dirty_background_ratio
    echo 100 > /proc/sys/vm/dirty_writeback_centisecs 
    echo 100 > /proc/sys/vm/dirty_expire_centisecs 
    echo 4096 > /proc/sys/vm/min_free_kbytes 
    echo 50 > /proc/sys/vm/swappiness 
    echo 200 > /proc/sys/vm/vfs_cache_pressure 
    echo 8 > /proc/sys/vm/page-cluster
    echo 4 > /sys/block/mmcblk0/queue/nr_requests
    echo 4 > /sys/block/mmcblk1/queue/nr_requests
Quick explanation:

Generally speaking, Linux is tuned for rotating media, not flash memory. The VM and I/O schedulers try to group I/Os together in a sensible manner, to reduce disk thrashing.

Of course, it's meaningless on the n900; there is no penalty for discontinous I/O.

So what I've done is:

- Reduce the time dirty buffers and pages are allowed to remain dirty; they should be eligible for flushing almost immediately.

- Reduce the amount of VM allowed to stay dirty; I/Os block once this threshold is met.

- Increase the minimum amount of free physical memory. The kernel will always try to leave 4mb free (yes, wasted) so that large allocations can take place even under high memory pressure (without swapping). When used, the kernel prioritizes its replacement by freeing other memory (through swapping or flushing writes).

- Reduce the willingness of the system to needlessly swap. This one is somewhat contentious (no pun intended); if your phone doesn't favor maintaining cache and free memory, swap-outs can be exceptionally long, when required, to make room for things like the Phone app. However, due to the overall improvement in interactivity, I find it acceptable. I've never come close to missing a call.

- Prefer to free disk cache over program data. The onboard storage (and even microsd) is quite fast for reads, and has no rotational latency. Since we're almost always under pressure for RAM, let's prefer to keep data we know we'll need over VFS cache. Helps to prevent large files (ie. videos) from overwhelming program data.

- Set the swap page size to 256k to match the SD card or internal flash device.

- .. and finally:

The most important change was reducing (essentially eliminating) the device I/O queues. The main purpose of I/O queueing is to allow the system to make intelligent read/write decisions based on a large number of elements requested (nearly) concurrently, such as contiguous streaming of data collected across multiple writes.

This doesn't really provide any benefit for us though! There is no additional latency associated with discontinuous writes, so why let the I/O queues build up?

Reducing them to 4 causes I/Os to block, rather than queue. This means you're less likely to encounter a situation where the queue is slammed by a large background process (ie. copying a 400mb file), and something you do in the foreground requires immediate I/O to continue, because the longest you'll have to wait is 4 I/Os!

Anyway, if you want to give it a try, just paste those commands into your terminal as root.

I'd advise against making them permanent until more people try it out.

And if you're a VFS maintainer and notice an error in my logic please point it out as well!

Last edited by nightfire; 2011-02-17 at 16:07.
 

The Following 93 Users Say Thank You to nightfire For This Useful Post:
-L-, abill_uk, anapospastos, ArnimS, Arrancamos, attila77, Bartus, Benson, bobh, Bundyo, cddiede, ceevee, cfh11, Char, cheve, clasificado, corduroysack, Creamy Goodness, Dark_Angel85, debernardis, elie-7, Estel, EugeneS, ezmendriz, F2thaK, fasza2, fms, frostbyte, fusi, fw190, gabby131, Gucky66, HellFlyer, Helmuth, joerg_rw, juise-, jurop88, kevloral, kinggo, kmare, kopele, ktchiu, leetnoob, Lehto, lma, Manatus, Marshall Banana, MartinK, mathiasp, mece, mehulrajput, Mentalist Traceur, mikec, moepda, mpi, mrojas, mscion, nashith, Necc, OVK, pedrolucasbp, pelago, peterleinchen, pillar, qole, rabarkar, rebhana, reinob, RobbieThe1st, saned, sbock, scribbles, stlpaul, Stonik, stopgap, Switch_, theonelaw, Tiboric, tokag, trompkins, tswindell, uppercase, uvatbc, vdx29, Venemo, wumpwoast, Xagoln, ysss, Zaerc, zero, zillertal