You are not logged in.

#1 2019-08-08 08:04:28

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Making certain processes meaner with renice.

Revisiting launching certain files with a better nice value. Have babbled about this before, though for whatever reason like so many other 2dork gnu/Nix projects ended up putting it on the back burner and never really exploring it fully.

Nice value, is basically how "nice" a process is compared to others, in sharing cpu(s) access. It ranges from -20 to 19(positive 19.) With -20 (minus 20) having the best niceness value. Meaning it's actually the least "nice" when it comes to using available cpu(s) resources. Other processes with a lower priority (are nicer. smile ) Will wait in line for cpu access, while those with higher one's want to cut to the front of the line when wanting cpu-time.

Ok let's list out the nice values of all running processes and check them out. Am going to do so with the following.

ps -eo pid,ppid,ni,comm

Scrolling down this list, we see that some of them already have a nice value of -20, these are important processes, which are given priority when it comes to accessing cpu(s) resources. Such as some of the kworker's (kernel worker processes.) and scrolling down on my system, by default pulseaudio gets a nice value of -11 (minus eleven.) While for majority seems the system default is 0/zero. By my understanding this should mean all processes with that 0 nice value get equal treatment by the kernel in access to cpu's. Why I'm interested in this, originally the driving thought is that I may want some of my prefered processes (like Firefox or say a media player or whatever) to get faster access to available cpu cycles. Hopefully increasing their performance by some extent.

With that in mind I dorked with this, was looking through an old tweak file and came accross some babblings about trying this and am sharing some of the key junk I'd found prior to abandoning this, here goes. Ok now, there's a snag involved here, which at the moment haven't invested the time in figuring out and can't remember the relevant info on how I did it first time around, errrr ok now here goes. The problem is I believe someone has to be root to give a process lower than 0, so in trying to recall how I was doing it, came up with this what I'm going to consider slightly dirty hack, I gave my user the right to renice processes without requiring I/they enter a password in /etc/sudoers.d.

I've babbled about this before, though long and short of it, is that creating files in etc/sudoers.d is now the approved way of allowing users to add commands without say needing to enter password. In that location I created a file named myrules, so the path to it is /etc/sudoers.d/myrules and these are the contents.

# Adding some sudo commands I don't need passwd for.
myusername ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /usr/bin/renice

The last one is the one I added that's of interest to this babble, looked up the path to the renice command on this OS, with "which renice" and it told me that turns out to be /usr/bin/renice, so I added that to the myrules file in the above location, so my user can execute the renice command giving a nice value lower than 0, without need of a password. This might not be the best security approach though, as my user can renice the hades out of pretty much every process on the OS, at any value they please. Though do note, that the processes involved are still launched as-under my user, they aren't running with elevated privileges or as root-etc. Ok having said that getting on with the rest of this niceness babble.

Using Firefox as an example am going to create a real barebones script to handle this renice noise when Firefox is launched by my keybind in rc.xml.

#!/bin/sh
/home/myusername/.browser/quantum/firefox -p "quantum" &
sudo renice -5 $(pgrep firefox)

Now to explain the contents of that sucker. I have pretty much always run Firefox from a direct download from Mozilla and in this case, the first part there is the path to it, the firefox binary that's kept in my users /home directory. I've got a .dot directory named .browser, cause I don't want a directory named browser sitting in plain sight in my /home. Then further, I renamed the folder extracted from the Mozilla download to be named quantum(it's normally just called firefox.) Inside of that is the binary to actually launch Firefox, it's named firefox, sheesh and finally the -p "quantum" part is used because that's the name of the profile I set-up and want this browser to use when I launch it. The & is just saying, after running this part of the command, run what's after it too. Which is clearly "sudo renice -5 $(pgrep firefox) Which is the part that renice's Firefox to a nice value of -5 and the pgrep part get's the PID = process id of Firefox, letting the rest of it know which process I want that renice value to be applied to.

Also note, that I created another .dot directory in my users /home called .bin (again cause I don't want a directory named bin just sitting their visible in home and the script I made above there I've named firefox.sh. One more thing has to be done, have to make the script executable, in this case, in thunar I click my way into the .bin directory, select "open a terminal here" so that it's(I'm in the current working directory) and then in that terminal "chmod +x firefox.sh" to make the script executable. Ok next up, time to edit rc.xml to add a keybind, that will run this script when I press that key-combo to launch Firefox.

We navigate to rc.xml at the following location /home/yourusername/.config/openbox and there it is, open rc.xml in your favorite text-editor and find a place to slap in your keybind, which in my case looks as follows.

    <keybind key="Control-Up">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Browser</name>
        </startupnotify>
        <command>/home/myusername/.bin/firefox.sh</command>
      </action>
    </keybind>

You add the path to the script you want to run between the <command> and </command> tags. Save the file and last thing to do is restart openbox, ie: "openbox --exit" to logout/logbackin. Hit the Control + UP arrow keys to launch firefox by running that script and check it's nice value with "ps -eo pid,ppid,ni,comm |grep firefox" which the output shows me ...

2052     1  -5 firefox-bin

Thusly yeppers, Firefox now has a nice value of -5. Overall am not super happy with this, it's kinda hacky and mainly the thing about allowing a user to set a nice value of whatever they want without need of a password doesn't make me all warm and tingly inside but just noting this cause it's interesting and wanted to share. There's also I believe a command called ionice with can boost (or obviously lower) a processes access to disk i/o. Haven't really dorked with this overmuch but can see some possibly cool applications for this type of junk. All comments, criticisms etc welcomed fellow nixers.

Last edited by BLizgreat! (2019-08-08 10:17:14)

Offline

#2 2019-08-08 08:58:38

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Making certain processes meaner with renice.

Why not just:

nice -5 firefox

Online

#3 2019-08-08 09:06:23

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

^ Really good point. Mostly ended up with that hack cause I did a crappy job of documenting what I'd found about this and came up with that hack to work around.

Have to test something real quick. Bbl and Vll! smile

Offline

#4 2019-08-08 09:52:05

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

Well the proper syntax for doing this another-better way is alluding me. Tried putting the whole command with and without quotes, double and single, just the relevant part of the command with & w/o sudo. Nope, wouldn't work. Plus many of the attempts messed up sudo, so had to switch to root user to fix it.

Went back to using the method outlined in the OP. Arghhh, think nice is used for launching a process with a certain nice value, whereas renice applies to an already running process. In that script am launching Firefox with the Mozilla profile I want it to use, as normal user and then have to have elevated privs to give it a nice value lower than 0.

Sure there are better ways for this, just burnt out on messing with it for now. Arghhhh n Vll! smile

Last edited by BLizgreat! (2019-08-08 09:55:32)

Offline

#5 2019-08-09 05:57:11

ohnonot
...again
Registered: 2015-09-29
Posts: 4,165
Website

Re: Making certain processes meaner with renice.

I think renice is necessary because:
nice is not allowed to change niceness, needs superuser privileges; however it would then also start the process in question with su privileges.

Offline

#6 2019-08-09 06:32:20

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Making certain processes meaner with renice.

ohnonot wrote:

I think renice is necessary because:
nice is not allowed to change niceness,.

True

needs superuser privileges;

Not here (Buster)

however it would then also start the process in question with su privileges

Shouldn't, but I haven't tested.

Online

#7 2019-08-10 02:45:26

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

Yeah if you wanted to use nice, to lower a process below 0, you'd have to use sudo and it'd be running as root.
"nice -5 processname" increases its nice value. It'd be nice value 5, have to use double hyphens to lower it, "nice --5 processname".

Last edited by BLizgreat! (2019-08-10 02:52:04)

Offline

#8 2019-08-10 06:54:52

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

Typed this out last night and didn't get around to posting it.

Also additional, as some information comes back to me (plus a refresher course of course. smile ), apparently something like "nice -5 firefox" would actually increased it's nice value from 0 to 5(positive 5) which is not what I was going for, whereas "sudo nice --5 firefox" would lower the effected process by 5 to be -5, as by default it'll start with 0, so 0 -5 = -5 there. In other words use double hyphens to lower (--) a single hyphen increases it. You can decrease the nice value for a process as simple user all the way up to 19 ( which again is actually the value that gives a process the least favorable nice value and lowest nice priority.) So "nice -19 processname" would take a process from 0 to a nice value of 19, the lowest/worst nice value. Whereas renice doesn't work that way. We can all thank the grey neckbeards for this type of thing, though yep, we should. With nice increasing a processes nice value to 19 actually lowers it, while lowering it beyond 0 into negative numbers actually increases it. big_smile

Also to add to my headache in this case, Firefox is not actually installed and recognized by the OS's package management tools, it's independent of them and running from a location I've choosen, /home. Did set it as default x-www-browser on the system but typing "firefox" doesn't do anything on the system, winds up with "not found etc." Anyway, remembered while dorking through notes, had comes across a couple other options which could solve this on a desktop users system. Though never got around to trying them, apparently there could be existing daemons to do this kind of thing, one is called "renicer" and the other "auto nice daemon", have no idea if these are any good or if even still around and maintained.

Now if it were a server-etc, would likely just set up a @boot or @reboot crontab to apply whatever nice/ionice-etc values to important processes and lower ones for things I wouldn't want interfering with them in terms of system resources. However on a personal user system, not quite so straightforward. This babble will somewhat work for apps/processes a particular person chooses to give some preference in terms of access to resources though. Of course as usual not necessarily that easy are other factors, depending upon what someone is trying to do. Such as relevant kernel config options. Long time taken to compiling my own kernels. Opting for config settings like making kernels fully preemptive vs the voluntary that's the usual stock default, junk like increasing the timer interupt frequency, personally am opting for 300hz, most desktop distro kernels default to 250hz. This basically means the kernel looks around for something it should be doing 250 times a second. On the other hand some supposedly "performance desktop kernels" have this set to 1000hz (1,000 times per sec.) and some "real time" applications might need it jacked up that high to function better. Whereas to me seems kind of strange that it's such of big jump. 250/300 or 1000hz. I don't do audio development though, so opt for the conservative in that config option, a small boost over stock but not 750hz difference.

Just saying like most things gnu/Nix isn't necessarily so simple. Works both ways, some things a user might want to be nicer, some huge backup script or whatever running and bogging down other processes a user wants running. May want to lower it's nice value, so it gets access but not such preference to other (more desirable processes) the user is running. As again you can increase niceness all the way up to 19 without needing any sudo/root privileges. Though lowering any process beyond 0 does require it. With the aforementioned dorkishness a user can add rc.xml/menu.xml etc commands that will allow them to give a given process more favorable nice values lower than 0 anyway. From a security standpoint, don't consider this much of an issue, a person would have to have physical access to my pc with me logged in and know what the hell renicing xyz would even matter (not persistent once pc is shutdown/rebooted anyway) or remote access via some compromise (with username + password) in which case somebody would be mega-screwed anyway and if they've/whoever got the ability to do that, they can do a helluva lot more than bother renicing processes.

Overall still don't so much like it but view it as a moot point. May eventually get around to seeing what some of those daemons can do for this. Long way from an expert in any of this or related and likely will never bother getting to be either. big_smile

Ps, dontcha guys miss the good ole WOB= wall of babble #! days? tongue

Last edited by BLizgreat! (2019-08-10 06:57:18)

Offline

#9 2019-08-12 08:06:37

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,081
Website

Re: Making certain processes meaner with renice.

^ yes, actually. Though please don't be angry if I don't always read every word...


John
--------------------
( a boring Japan blog, idle Twitterings and GitStuff )
In case you forget, the rules.

Offline

#10 2019-08-12 11:34:00

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

So mad right now! Messing around John-san the wobs can cause eye bleed. smile Where do you stand on this overall concept? Think there could be some performance gains to be had but atm don't have anything solid.

Offline

#11 2019-08-13 06:03:20

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,081
Website

Re: Making certain processes meaner with renice.

Er... maybe...
Looking forward to hearing how it works out. smile


John
--------------------
( a boring Japan blog, idle Twitterings and GitStuff )
In case you forget, the rules.

Offline

#12 2019-08-13 12:12:28

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

Yeah atm constrained as to how much I can test this. Should equal some benefit, provided a user doesn't go overboard with it. Just telling os/kernel I want these processes to get some degree of preference over others. Really doubt it can amount to serious performance gains. Same time going with the logical, enough small tweaks can add up to noticeable improvement. Mostly just wanted to share the dorkish concept, as think it's interesting and the Uber geekdom no doubt didn't implement these options for no reason.

Offline

#13 2019-08-25 06:30:10

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

In the never ending effort to find or recover gnu/nix tweaks, was revisiting this. The part applicable to this babble is they mention a daemon which they say automatically does this type of thing called Ananicy.

Archwiki is always worth a visit. Another one that while offtopic thought is really interesting is under the turn off cpu mitigations section. States doing so can boost some Intel chips performance up to 50%! Am not saying do this just worth sharing.

VlAw! = Viva la Archwiki! smile

Offline

#14 2019-08-25 06:48:03

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

Afterthought babble, believe ionice may only work with the CFQ i/o scheduler. And mean to show another possible benefit of this type of junk.

Was dorking away and noticed my old laptop fan blasted into hyperdrive wth, popped open a terminal and ran top. Find and then updatedb(of the mlocate fame) were smashing my cpu's! Eventually tracked them down to scripts in aptdaily and settled it by just making them non-executable so they won't run anymore but that situation is a good illustration of where limiting a processes cpu priority makes sense. Though in that Archwiki resource they also mention a prog called cpulimit (never used it as yet) that could be relevant.

Vll!

Last edited by BLizgreat! (2019-08-25 06:50:20)

Offline

#15 2019-10-26 07:42:57

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,217

Re: Making certain processes meaner with renice.

Update on this nonsense:

Believe I'd set(renice'ed)Firefox to a value of -3 making it meaner. Result appeared to be a bunch of cpu choppiness + spikes. Haven't done it justice though or really even dorked with it, shrugs. Still think there's potential, atm too lazy to really do the experimentation required to find any secret-sauce.

VLL! smile

Offline

Board footer

Powered by FluxBB