You are not logged in.
If this is not the appropriate place for this topic, feel free to move it around;)
In this topic started by flipper T , I asked about auto changing disk schedulers on kernel change
That is why I start this topic, as I have already forgotten to change the elevator once or twice, I like to prevent that from happening.
.
Now I was curious about the possibility to let there be a check when a kernel id chosen, to append a pre chosen scheduler, bfq, cfq, noop etc.
I thought of doing it with bash, but I think it's impossible cause there is no bash at that point, but am not sure.
WonderWoofy thought about using udev, which is a much better idea, cause it is started pretty early.
But I think udev is also not early enough.
I took a look at dmesg to see at what point the scheduler and udev were applied
[ 0.733952] BFS CPU scheduler v0.430 by Con Kolivas.
[ 0.740604] systemd-udevd[77]: starting version 204In fact just before udev. So my question is, if I want this to work, in what direction must I go? EFI or a module?
Thanks
Last edited by qinohe (2013-06-02 23:13:33)
Offline
BFS is for the CPU, not I/O.
Try googling:
http://www.cyberciti.biz/faq/linux-chan … -harddisk/
http://askubuntu.com/questions/78682/ho … -scheduler
http://www.linuxhowtos.org/System/iosched.htm
Last edited by brebs (2013-05-26 18:51:28)
Offline
@brebs, so I brought this qeustion up in the thread qinohe linked to above. I use a udev rule to apply a different scheduler to different types of media. So I use something like this:
## set scheduler for non-rotating disks
ACTION=="add", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"
# set scheduler for rotating disks
ACTION=="add", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"But I wanted to know if there was a way to have udev also poll for the booted kernel, so that I could have it select bfq if it happened to be booted from a CK kernel, and then use one of cfq, noop, or deadline othewise.
I think this is what qinohe is actually asking, and you are right that he has confused bfs with bfq. What he means is bfq.
@qinohe, this would explain why the scheduler was applied before udev started, because that message you are referring to in dmesg is actually the application of the cpu scheduler and not the I/O scheduler.
Offline
to have udev also poll for the booted kernel, so that I could have it select bfq if it happened to be booted from a CK kernel, and then use one of cfq, noop, or deadline othewise.
Put it in a BASH startup script, which does a bit of uname checking.
Just have Udev call a script, rather than try to do it all with Udev's "ATTR" ![]()
Offline
Yes this is true, and for all intents and purposes it would certainly work. Though these days, I have started using "systemd --user" so I actually don't use the CK kernel anymore, as the bfs patch turns off a needed cgroup functionlaity in order to have the user sessions.
So for qinohe, I am sure that this would be a reasonable solution, and would work quite nicely. But for me, it has become more of a curiosity as to whether there is some udev detectable difference in the /sys heirarchy between a booted CK kernel and a stock kernel.
Last edited by WonderWoofy (2013-05-26 19:14:41)
Offline
You mean "intents and purposes" ![]()
/proc/sys/kernel/rr_interval only exists with the BFS scheduler.
Offline
You mean "intents and purposes"
Yes, that is what I meant. That is interesting with the /proc. That I did not know. Now is that something that is handlable by udev? I was under the impression that udev polled for things under /sys only, and the /proc filesystem does its own thing.
Offline
BFS is for the CPU, not I/O.
Try googling:
http://www.cyberciti.biz/faq/linux-chan … -harddisk/
http://askubuntu.com/questions/78682/ho … -scheduler
http://www.linuxhowtos.org/System/iosched.htm
I feel stupid, I think I know what I'm asking , just posted the wrong scheduler, yes, I mean bfq!
@WonderWoofy, yes that is exactly what I want.
But now my next question, how to implement it! Yesterday I wrote my first bash script, I don't even know if it works;)
Should I take WonderWoofy's way and use the udev rule, or do as brebs said, and use a bash script, which I will paste;
#!/bin/bash
if [uname -r = linux-ck];
then echo bfq > /sys/block/sda/queue/scheduler
fi
else
if [uname -r = linux];
then echo cfq > /sys/block/sda/queue/scheduler
fiHe, now don't judge me to hard;)
Offline
Should I take WonderWoofy's way and use the udev rule, or do as brebs said, and use a bash script
I would do a combination of both if you are looking to have different I/O schedulers for different devices. But if it is simply the desire to set bfq globally for the CK kernel or a different scheduler globally for other kernels, then I think this can all be diregarded in favor of a kernel command line option. That is, with the CK kernel you woulduse elevator=bfq, while with the others you would use elevator=deadline|noop. If cfq is desired, then no setting is required, as that is the default. In fact, I think that with the CK kernel, bfq is actually the default there (at least the one built by graysky), so maybe no command line arg is required there either.
BTW, you should probably make the "uname -r" a variable, the use that in the test. Having a plain "uname -r" is not going to actually do anything, It is giong to try to equate "uname -r" as an actual string. It won't run the command. You could use "$(uname -r) in the test to make it evaluate the result of the uname -r command as well.
Last edited by WonderWoofy (2013-05-26 20:02:02)
Offline
qinohe wrote:Should I take WonderWoofy's way and use the udev rule, or do as brebs said, and use a bash script
I would do a combination of both if you are looking to have different I/O schedulers for different devices.
It's only for the SSD, the HD is static cfq
But if it is simply the desire to set bfq globally for the CK kernel or a different scheduler globally for other kernels, then I think this can all be diregarded in favor of a kernel command line option. That is, with the CK kernel you woulduse elevator=bfq, while with the others you would use elevator=deadline|noop. If cfq is desired, then no setting is required, as that is the default. In fact, I think that with the CK kernel, bfq is actually the default there (at least the one built by graysky), so maybe no command line arg is required there either.
Exact , I just want the change to happen automagicly at kernel change, but bfq needs interaction, as it is dormant by default, that says the wiki!
BTW, you should probably make the "uname -r" a variable, the use that in the test. Having a plain "uname -r" is not going to actually do anything, It is giong to try to equate "uname -r" as an actual string. It won't run the command. You could use "$(uname -r) in the test to make it evaluate the result of the uname -r command as well.
I get back on this, my bash 'foo' is not good , bad even as you see, gona try to sort this out in the days to come, I really need to give myself some more scripting experience, as a present ![]()
Offline
If it is only for the SSD, then I would use a udev rule to match a non-rotational device with a kernel name of /dev/sd[a-z] and then have it RUN+="/your/script/here"
So a combination of the two.
Last edited by WonderWoofy (2013-05-26 20:41:02)
Offline
So this is not possible?
I had this rules, just changed the kernel, and added an extra line!
# set bfq scheduler for non-rotating disks with linux ck-kernel
ACTION=="add|change", KERNEL=vmlinuz-linux-ck="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq"
# set cfq scheduler for non-rotating disks with linux-kernel
ACTION=="add|change", KERNEL=vmlinuz-linux="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="cfq"
# set cfq scheduler for rotating disk
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"Offline
I don't think that this is how the "KERNEL=" option is meant to be used. Are you saying you ahve tried this?
Offline
I suggest:
ACTION=="add|change", KERNEL=="sd[a-z]", RUN+="/root/bin/iodrive %k"Then do the fancy work in that iodrive script. Don't forget to chmod 700 it.
Edit: Added %k, to pass the drive to the script.
Last edited by brebs (2013-05-27 07:07:58)
Offline
I don't think that this is how the "KERNEL=" option is meant to be used. Are you saying you ahve tried this?
He, after reading some of this guide, I see! And no no I didn't have the guts to try!
I suggest:
ACTION=="add|change", KERNEL=="sd[a-z]", RUN+="/root/bin/iodrive %k"Then do the fancy work in that iodrive script. Don't forget to chmod 700 it.
Edit: Added %k, to pass the drive to the script.
Ha thanks, like you suggested before, not to try and use 'ATTR' to do that.
I have a look later on today!
Offline
So, I have done some reading about this, and came up with the next little script.
Maybe it can be made smaller, but lets get this to work first;)
#!/bin/bash
if [[ "$(uname -r) | grep *-ARCH" ]] ; then
var1="echo cfq > /sys/block/sda/queue/scheduler"
echo "$var1"
fi
if [[ "$(uname -r) | grep *-ck" ]] ; then
var2="echo bfq > /sys/block/sda/queue/scheduler"
echo "$var2"
fiI ran
bash -x SSDwhich gave the following output, does it look OK?
++ uname -r
+ [[ -n 3.9.4-1-ARCH | grep *-ARCH ]]
+ var1='echo cfq > /sys/block/sda/queue/scheduler'
+ echo 'echo cfq > /sys/block/sda/queue/scheduler'
echo cfq > /sys/block/sda/queue/scheduler
++ uname -r
+ [[ -n 3.9.4-1-ARCH | grep *-ck ]]
+ var2='echo bfq > /sys/block/sda/queue/scheduler'
+ echo 'echo bfq > /sys/block/sda/queue/scheduler'
echo bfq > /sys/block/sda/queue/schedulerOffline
Your use of the test (ie. "[" and "]") is a bit wrong here. The first one, you are not really testing it against any conditions, and the second you would need to be putting the stuff you are testing in backticks or in a $(command) so that it is run before the test takes place. I don't want to just write a script for you, as it would take away the learning process, but start with this. Make the thing you are trying to test (the kernel version) the variable. So in this case, it might be something like this:
_kernel=$(uname -r | cut -d'-' -f3)With the CK kernel, this would result in "CK" and with the official kernel it would be "ARCH". So you would then test this quoted variable against those things:
[[ "$_kernel" = "CK" ]]; then ... Start with that knowledge and work your way through it. I assume you can look through some other scripts and figure out an if/else statement pretty easily. Just know that the test command will throw a 0 if it is equal and a 1 if it is not. That exit code determines whether or not it will proceed with the "then" or not.
Edit: There is also probably a better way to test for the kernel version, as the "cut" part depends on the version string being the same exact format every time. So it is using the "-" as the delimiter and taking the third part of split up by that delimit assumption. So you are assuming there is going to be a version number, a pkgrel, and then the appending of descriptive thing at the end (I'm not sure what you would call that).
Last edited by WonderWoofy (2013-05-28 14:34:55)
Offline
I'm glad you don't hand the answer;), for sure I like to really understand this.
But reading through your answer only made it more complicated, which always seems to happen when I learn something new.
Now still I'm going to sort this, maybe not today or this week, but I will!
If you would happen to have some advice on a good guide/book, there hundreds / thousands of them, difficult to say what is really a good one!
Offline
I didn't really learn the little bit of scripting I know from any book. I mostly just read through scripts when I wanted to modify or change some behavior, then went on the internets and googled the parts I didn't understand. I have to agree with ewaller that a good way to learn how to code/script is to read good code or script. It may not make total sense at first, but try to pick up on what you know and use that as a jumping point to delve deeper into the parts you don't know. I think a great place to start looking through some well written bash scripts are on your own machine. The Arch Linux devs do some pretty amazing scripting, and everyone has mkinitpcio on their machine. There is also netctl and/org netcfg, and if you have netcfg, then there is openresolv on your system, as well as dhcpcd.
Start learning my friend!
Offline
FYI: To do a test based on the outcome of a command, you simply add if before it:
if uname -r | grep -q *-ARCH"
...You need to make sure to hide the output though, as I did by adding the -q flag to grep.
That said, WonderWoofy is right about using a variable for your tests here. For the variable, I suggest storing the full 'uname -r' string, then using bash paramater expansion to parse it down:
_kernel=$(uname -r)
...
if [[ ${_kernel##*-} = ARCH ]]Last edited by alphaniner (2013-05-28 16:59:51)
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
Why not just set the default scheduler with elevator=bfq or elevator=cfq in the kernel parameters?
I suggested this earlier. But I this is mainly for the idea that you might want a scheduler 'A' for a SSD, and scheduler 'B' for a rotational with the Arch kernel, but scheduler 'C' if a rotational with the CK kernel (since it offers an additional elevator option). Or at least something to that effect. I agree if you want bfq across all drives then setting it on the kernel command line is hte way to go. For me this has just become a hypothetical.
Offline
I didn't really learn the little bit of scripting I know from any book. I mostly just read through scripts when I wanted to modify or change some behavior, then went on the internets and googled the parts I didn't understand. I have to agree with ewaller that a good way to learn how to code/script is to read good code or script. It may not make total sense at first, but try to pick up on what you know and use that as a jumping point to delve deeper into the parts you don't know. I think a great place to start looking through some well written bash scripts are on your own machine. The Arch Linux devs do some pretty amazing scripting, and everyone has mkinitpcio on their machine. There is also netctl and/org netcfg, and if you have netcfg, then there is openresolv on your system, as well as dhcpcd.
Start learning my friend!
Hehe, yes I start again! But I needed to really bend my head around it, and still not all the pieces fell into place, but that will probably take time, and a lot of practice.
Maybe the part about learning from a good script could be true, but I really needed to have some basic info about bash, glue that to the fact that I'm not native English speaker, well you get a nice soup!, bashsoup I guess;) WellI didi what you suggested, see later on!
@alphaniner, it just might have helped me a lot, we'll see later!
Thanks for that info page, I already read a lot of it!
@falconindy, yes the basic idee behind this is,
the rotational drive will always have cfq as scheduler.
The non-rotational disk will change to, bfq=CK and to cfq=ARCH
The change is done by the next script, hoppefully!)
Well, this is what I have so far;
#!/bin/bash
_kernel=$(uname -r | cut -d'-' -f3)
if [ "$_kernel"="ARCH" ]; then
echo "cfq > /sys/block/sda/queue/scheduler"; fi
if [ "$_kernel"="CK" ]; then
echo "bfq > /sys/block/sda/queue/scheduler"; fiAm I working in the right direction?
Offline
Instead of sda you should use $1 (i.e. the first parameter), which will be the %k in the RUN+= string in the udev rule I posted above.
Offline
I am not sure if this is necessary... but in every script i have seen, there is whitespace between the parameters in the test brackets. So it would be [ "$_kernel" = "CK" ]. Maybe it is just for readability, but this is what I have always seen.
Brebs is right about using a variable in place of sda. You may have only one drive, but if you had more then there is the chance that it might not end up being sda. So "$1" is the first parameter, which means that if you had a command with an argument, (say $ echo "hello" ) then that $1 would represent the first argument (in the example it would be "hello"). If you had three arguments to the command, then they could be represented as $1, $2, and $3.
Oh and the echo lines are misquoted. In that case it would actually print "bfq > /sys/block/sda/queue/scheduler". So you want the echo "bfq" to be redirected (>) into that path. Having the double quotes around that whole thing would group bfq with the path, which is not what you are trying to do. It is a good idea to get in the habit of quoting things, but in this case it isn't actually necesary since you are echoing a string with no white space. If you wanted it to print "hello world" then it would then be necessay to do echo "hello world" so that the command knows that those two words are grouped together as one argument.
Offline