We have moved to a new Sailfish OS Forum. Please start new discussions there.
37

Howto: Make disk IO more responsive (for example during btrfs balance)

Tracked by Jolla (Rejected)

asked 2015-05-09 14:01:14 +0200

00prometheus gravatar image

updated 2015-06-23 15:04:57 +0200

If you are having problems with the phone becoming laggy or unresponsive during heavy disk IO (downloading/installing many or large packages, running btrfs balance, etc) this is for you. Using this, my phone performs a btrfs balance in the background without any performance impact at all. It is done by an easy kernel tweak to the disk scheduler that gives much better flash-storage responsiveness during heavy disk IO.

[background] The default disk scheduler is optimized for spinning disks. It tries to batch together transfers so that it runs as long a sequence of sectors as possible before changing to another transfer. This is because shifting back and forth between different disk locations (a seek operation) is extremely slow on a spinning disk. The disadvantage is that two simultaneous transfers do not "share bandwidth"; one transfer will hog the disk for a considerable time, locking all other transfers in queue.

With flash, the penalty for a seek operation is negligible, and several transfers can easily take turns accessing the disk, rapidly changing back and forth between all simultaneous transfers. That way all tasks immediately get to do their disk IO without waiting for large transfers to complete and the phone feels much more responsive during large disk operations.

There are three schedulers to choose from in the Jolla kernel, the default "cfq" scheduler, the "deadline" scheduler and the "noop" scheduler. The deadline scheduler attempts to guarantee the next transfer in queue to get a time-slice within a certain time, giving real-time constraints. The noop scheduler simply doesn't schedule at all. I have seen many recommend the noop scheduler for flash, but in my experience the deadline scheduler, in particular with tighter time-constraints than default, gives better results than the noop scheduler. Mainly I prefer the deadline scheduler over the noop scheduler because it guarantees responsiveness when there are large operations going on (such as btrfs balance), and for me responsiveness is more important than shaving a few percent off total execution time (I hate it when I get jitter and lag). [/background]

Howto:

Make sure you have developer mode active on your phone, then enter:

devel-su

your password

echo deadline > /sys/block/mmcblk0/queue/scheduler
echo 1 > /sys/block/mmcblk0/queue/iosched/fifo_batch
echo 10 > /sys/block/mmcblk0/queue/iosched/read_expire
echo 50 > /sys/block/mmcblk0/queue/iosched/write_expire

If you have an sd-card in your phone, enter the same for mmcblk1 to make it more responsive too:

echo deadline > /sys/block/mmcblk1/queue/scheduler
echo 1 > /sys/block/mmcblk1/queue/iosched/fifo_batch
echo 10 > /sys/block/mmcblk1/queue/iosched/read_expire
echo 50  > /sys/block/mmcblk1/queue/iosched/write_expire

You can put that in a script and run from your startup if you don't want to re-enter every time you reboot the phone.

edit retag flag offensive close delete

Comments

1

What about fine tunning CFQ? Is that possible?

Kollin ( 2015-05-09 14:59:10 +0200 )edit
1

Of course! :-) You'll find the instructions in Linus's git-repository: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/block/cfq-iosched.txt?id=HEAD

00prometheus ( 2015-05-09 15:01:57 +0200 )edit
2

Wow, this should really be a default, imho. Who can make this into a patch?

lispy ( 2015-05-12 09:28:44 +0200 )edit

A very useful improvement .

richardski ( 2015-05-16 11:46:14 +0200 )edit

My script:

#bin/bash 
echo deadline > /sys/block/mmcblk0/queue/scheduler &&  echo 1 > /sys/block/mmcblk0/queue/iosched/fifo_batch && echo 10 > /sys/block/mmcblk0/queue/iosched/read_expire &&  echo 50 > /sys/block/mmcblk0/queue/iosched/write_expire && echo deadline > /sys/block/mmcblk1/queue/scheduler && echo 1 > /sys/block/mmcblk1/queue/iosched/fifo_batch && echo 10 > /sys/block/mmcblk1/queue/iosched/read_expire && echo 50  > /sys/block/mmcblk1/queue/iosched/write_expire
Kollin ( 2015-05-19 23:47:39 +0200 )edit

2 Answers

Sort by » oldest newest most voted
12

answered 2015-06-22 20:12:34 +0200

coderus gravatar image

to /etc/udev/rules.d/95-ioscheduler.rules

KERNEL=="mmcblk[0-1]", ATTR{queue/scheduler}="deadline"
KERNEL=="mmcblk[0-1]", ATTR{queue/iosched/fifo_batch}="1"
KERNEL=="mmcblk[0-1]", ATTR{queue/iosched/read_expire}="10"
KERNEL=="mmcblk[0-1]", ATTR{queue/iosched/write_expire}="50"
edit flag offensive delete publish link more

Comments

1

Now this should become the new default, shouldn't it? I mean what do we have the scheduler set to cfq if we have only flash memory?

MoritzJT ( 2015-06-22 20:26:53 +0200 )edit

i know nothing about this, sorry. you should ask some other person.

coderus ( 2015-06-22 20:28:02 +0200 )edit

Thanks @coderus! I haven't figured out systemd enough to know where to put this properly, so right now I am calling a script from a pre-existing startup file (Alien-Dalvik startup). This is much cleaner and nicer!

00prometheus ( 2015-06-22 21:52:50 +0200 )edit

Coderus thanks. Work after reboot.

Schturman ( 2015-06-22 21:59:17 +0200 )edit

This file 95-ioscheduler.rules does not exist by default ? Why not make it downloadable, so that we could just copy it to the right folder ?

Upp15 ( 2015-06-23 09:07:28 +0200 )edit
1

answered 2015-05-10 11:40:49 +0200

Upp15 gravatar image

updated 2015-05-11 11:29:01 +0200

If the above is true, then this should be made default by Jolla!?

I looked at one of those scheduler files in my phone, and there was the following line:

noop deadline [cfq]

That does not exactly match to the instructions above ?

(btw, there's a typo in the first echo of the second block in the instructions, the file name should be 'scheduler')

edit flag offensive delete publish link more

Comments

Hei,

Actually, both hase this setting.

LVPVS out.

LVPVS ( 2015-05-11 14:57:57 +0200 )edit
1

What you are seeing are the possible schedulers compiled into your kernel, with the scheduler currently active marked by square brackets (i.e. the cfq scheduler,which is the default spinning-disk scheduler). You are right about the typo, thanks for that, fixing!

00prometheus ( 2015-05-12 01:39:57 +0200 )edit

Ok, and if there's only one scheduler, it doesn't have to be in brackets (like after that echo command would be the case) ?

Presumably this would do the same:

noop [deadline] cfq

?

Upp15 ( 2015-05-12 09:13:25 +0200 )edit
2

No, /sys/block/mmcblk0/queue/scheduler is a special kernel "file", it isn't really a file on your disk. It is an interface to interact with the kernel through file-system commands (there are many other such files, for example under /proc). So when you read the contents of the file, you get the current settings. When you write the word "deadline" to the file, the scheduler is set to use the deadline module, but if you read the contents again, it will still show all three options, only now the word "deadline" will have brackets around it. Try it! Setting the scheduler is not dangerous in any way (though there are other files which are, so be a bit careful).

00prometheus ( 2015-05-12 13:06:40 +0200 )edit

Ok, now I understand (coming from Windows background I easily get confused in Linux world ...).

Thanks for the explanation!

Upp15 ( 2015-05-12 13:35:15 +0200 )edit
Login/Signup to Answer

Question tools

Follow
15 followers

Stats

Asked: 2015-05-09 14:01:14 +0200

Seen: 3,367 times

Last updated: Jun 23 '15