📜 ⬆️ ⬇️

HDD is dedicated to: pacify the application, voracious on disk time

Root of all evil


For a long time I had a problem - the system was very slow after the start. I have a laptop with a hard disk (HDD) and Ubuntu 14.04 .
As it turned out, the reason lay in the program alone - the Dropbox daemon. Dropbox is an online file storage, and its daemon is a program that synchronizes files located in a specific folder with online storage. At the start, the daemon starts to read its cache. It takes me not one hundred megabytes, and you should not delete it manually - there is a chance to lose data. Considering that I have a hard disk — a device with mechanical parts — the demon started consuming the time to access it so much that it became unrealistic to use a computer and run applications until it was loaded. Remove it from startup and run manually? An unpleasant solution, I already have things that I have to start at the start myself (for example, iotop, it does not start without root privileges). It was necessary to find a way to make the application less voracious on the disk .

ionice to help us. Or not?


The first thing I heard about this topic was the ionice utility. It allows you to change the priority of disk access for a given process. According to the manual , there are three classes of I / O priority. I was interested in idle , because, as I understood from the description, it neutralizes the gluttony of the application, always skipping forward processes of other priority classes. It seemed to be a hat, and all that had to be done was:
ionice -c3 -p $ (pgrep dropbox)

Made by The effect is zero. How so? Okay, dig further.

Schedulers, or “I didn't understand anything, but it sounds cool.”


As it turned out , the default ionice on my system does not function at all, since the CFQ scheduler must be enabled. And by default, the deadline scheduler is enabled in new Ubuntas. I will not go into details of how they differ, for he himself did not drive to the end. In general, I read a brief explanation of this case , and then I change the scheduler with the team (or rather, I added this command to /etc/rc.local so that the GFQ scheduler would automatically be exposed at the start):
echo cfq> / sys / block / sda / queue / scheduler

The note
By the way, in the “comments” section of the manual , it is noted that support for classes and priorities works on CFQ. But since no one reads up to it anyway ... XD

Something in the system has slightly changed. The load indicator at the start of the system began to rise above 11, and the processor load began to consist mostly of wait. I'm not sure that this means everything in the long term, but the problem remains - switching to CFQ and the subsequent application of ionice to the dropbox process on system performance at the start did not produce any noticeable effect: neither positive nor negative.

Well, who launches so many threads ?! About the specifics of the Dropbox daemon.


I was already disappointed, but then I noticed that only one dropbox process is shown in the top , and iotop shows several. And by the way, why is the process ID column called PID in the top, and the TID in the iotop? What is the difference between them? The answer quickly found . In my case, the most important discovery: the Dropbox daemon runs several threads for its business. Lots of threads. It turned out that more than a dozen. And sometimes they start reading the disc several times at a time. So where are these brakes! And ionice did not work because, by assigning a priority class to the main process, it does not pass this priority class to the child threads. Therefore, as they were with the standard priority class, they stayed with it.
Well, as the British say, we will use bodging . In our opinion, "crutches". Make a script that will detect the dropbox process and all its child threads, take their identifiers (PID or TID, in this case, ionice is isofull until the light bulb does n’t make much difference), and assign idle class to everyone from time to time (in case dropbox kills part of child threads and / or creates new ones).
#!/bin/bash while true do #    TIDS=( $(ps -L --pid $(pgrep -x dropbox) -o tid=) ) for i in "${TIDS[@]}" do echo $i #  idle ionice -c3 -p $i done sleep 5 done 

Add to autorun, reboot.
And it all worked almost as if there was no Dropbox daemon at all. Eureka!
')
Results
Thus, you can work with any process that consumes a lot of disk time. It is enough to set the priority with the help of ionice and not to forget about the pitfalls, in particular:



What other things to consider? Tell us about your experience in the comments.

Source: https://habr.com/ru/post/282828/


All Articles