maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   Massive interactivity improvement under high I/O load! (https://talk.maemo.org/showthread.php?t=69973)

nightfire 2011-02-17 01:58

Massive interactivity improvement under high I/O load!
 
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! :)

Creamy Goodness 2011-02-17 02:28

Re: Massive interactivity improvement under high I/O load!
 
what do you mean by causing the I/O to block, does it return a failure status on the request?

Mentalist Traceur 2011-02-17 03:12

Re: Massive interactivity improvement under high I/O load!
 
No, it forces I/O attempting processes to write out the dirty pages during their time slot, as I understand it.

So during the milliseconds-to-seconds that there's too many dirty pages, the CPU ignores I/O requests and instead spends those time slots writing out the dirty pages. If the gap between dirty_ratio and dirty_background_ratio is somewhat small, and the gap between flushes is reasonably small, it shouldn't cause too many issues on a human-perceptibility level.

I am not that knowledgeable on kernel parameters on the VM system though, so feel free to correct me, anyone who knows better.

TiagoTiago 2011-02-17 03:15

Re: Massive interactivity improvement under high I/O load!
 
How does this compare to Swappolube?

nightfire 2011-02-17 03:25

Re: Massive interactivity improvement under high I/O load!
 
Never heard of swappolube... :)

In any case, like Mentalist Traceur said, blocking I/O doesn't result in a failure, it just means the process read()s, write()s, etc.. won't return immediately, but only once there's sufficient room in the (now very small) queue.

The benefit is that some desktop application that needs to read a config file doesn't risk ended up at queue position 100, waiting for 99 I/Os to complete, because cp, tar, or samba wasn't able to burst all those writes through (write() blocked quickly).

epitaph 2011-02-17 03:45

Re: Massive interactivity improvement under high I/O load!
 
I've written tune-up tools. I've other parametres. U may find it interesting. What are the original values?

nightfire 2011-02-17 03:54

Re: Massive interactivity improvement under high I/O load!
 
Quote:

Originally Posted by epitaph (Post 948616)
I've written tune-up tools. I've other parametres. U may find it interesting. What are the original values?

Thanks.. I'll check em out.

I actually don't have the original values anymore.. :p They were quite different, though. If anyone wants to check, just run this (root not required):

Code:

echo -n "dirty_ratio: " ; cat /proc/sys/vm/dirty_ratio
echo -n "dirty_background_ratio: " ; cat /proc/sys/vm/dirty_background_ratio
echo -n "dirty_writeback_centisecs: " ; cat /proc/sys/vm/dirty_writeback_centisecs
echo -n "dirty_expire_centisecs: " ; cat /proc/sys/vm/dirty_expire_centisecs
echo -n "min_free_kbytes: " ; cat /proc/sys/vm/min_free_kbytes
echo -n "swappiness: " ; cat /proc/sys/vm/swappiness
echo -n "vfs_cache_pressure: " ; cat /proc/sys/vm/vfs_cache_pressure
echo -n "onboard_nr_requests: " ; cat /sys/block/mmcblk0/queue/nr_requests
echo -n "sd_nr_requests: " ; cat /sys/block/mmcblk1/queue/nr_requests


epitaph 2011-02-17 04:00

Re: Massive interactivity improvement under high I/O load!
 
U should try ur settings with cutetube and avatar trailer hd. Looks very promising. I want to try it later.

The min_free_kbytes value is not that different from the original.

Bratag 2011-02-17 04:02

Re: Massive interactivity improvement under high I/O load!
 
As requested. As a side point. If this does what we think it does - then the issues with transmission essentially locking up the phone (ok really slowing it down) will be mitigated to some extent.

Code:

dirty_ratio: 95

dirty_background_ratio: 60

dirty_writeback_centisecs: 0

dirty_expire_centisecs: 0

min_free_kbytes: 2039

swappiness: 30

vfs_cache_pressure: 100

onboard_nr_requests: 128

sd_nr_requests: 128


nightfire 2011-02-17 04:06

Re: Massive interactivity improvement under high I/O load!
 
Quote:

Originally Posted by Bratag (Post 948625)
As requested. As a side point. If this does what we think it does - then the issues with transmission essentially locking up the phone (ok really slowing it down) will be mitigated to some extent.

Exactly. I'm actually able to place phone calls, browse, and launch programs while writing at 8mb/sec! It was totally unusable before.


All times are GMT. The time now is 00:01.

vBulletin® Version 3.8.8