r/linuxquestions • • 6d ago

Run processes at the lowest priority possible

Hi all! I have a little question for you.

Let's say my machine has 4 cores (4 physical and logical cores, no hyper-threading). I want to run 5 cpu-bound processes, but one of them should get CPU only when there's some to spare. I'm expecting seeing in top something like this:

process-1   99.9% cpu
process-2   99.9% cpu
process-3   99.9% cpu
process-4   99.9% cpu
process-5    0.4% cpu

All my processes are commands started from different terminals on my desktop.

On Ubuntu 22.04 (Linux 5.15.0) I can achive this setting sysctl kernel.sched_autogroup_enabled=0 and running my process 5 with nice -n 19. Works great.

Now I'm moving to Ubuntu 26.04 (Linux 7.0.0) and this doesn't work anymore, all my processes get 80% CPU no matter the niceness value.

I tried running process 5 with chrt --idle 0 , it has some effect but nowhere near what I'd like.

Why I want to to this? Because I regularily run many different cpu-bound workloads in different terminals, and I want some of them finish as soon as possible (normal priority), and others can last longer and I prefer them not to interfere (lowest priority) as long as there are normal priority processes running.

Is there a way to have truly low priority processes on recent kernels?

Edit: I don't have necessarily one normal-priority process for each core. For example, this is another possible use case where 5 processes take all the 4-core pie and a sixth process eats the crumbles:

process-1   79.9% cpu
process-2   79.9% cpu
process-3   79.9% cpu
process-4   79.9% cpu
process-5   79.9% cpu
process-6    0.5% cpu
2 Upvotes

9 comments sorted by

3

u/polymath_uk_ 6d ago

You can pin processes to CPU cores (if you write the software yourself) which would be the thing to do for the first 4 processes. Process 5 can be unpinned and run with nice 19 meaning that it will only consume CPU from any of the 4 cores if those cores are not busy. For software you don't write yourself, see u/ipsirc 's comment.

2

u/beertown 6d ago

I have a varying amount of processes, not necessarily 1 per CPU like in my example, I should have mention this. Thanks for your hint, I'll look into it anyway.

1

u/Difficult-Value-3145 3d ago

You could still write like a process queue of some sort at least for like long running processes if your planning on using the computer while those processes are running you might want to leave one open for short running prosseses . I might actually try this

3

u/ol-gormsby 6d ago

You can constrain a process to get no more than a set amount of memory and a set percentage of CPU, but that doesn't sound like what you're after.

systemd-run --scope -p MemoryLimit=500M -p CPUQuota=50% process-name

It's strange that "nice" values aren't working especially when they used to work. What does "top" report? If your low-priority process is getting a lot of resources, it might be because the other processes aren't demanding it? Is there a bottleneck somewhere, where a process is waiting on I/O or something else?

1

u/beertown 6d ago

Thank you but yes, that's not what I'm looking for. I just want nomal-priority processes take all the available CPU, and the leftovers to go to the low-priority processes. This is what I get in Ubuntu 22.04, but not in Ubuntu 26.04.

top reports an equal distribution of CPU usage, no matter the nice value. I run strictly cpu-bound code, with negligible IO and small RAM footprint. You can try yourself: python -c "x = 9**9**9" consumes 1 full core for a long time, nice -n 19 python -c "x = 9**9**9" is the same with the highest niceness.

2

u/Difficult-Value-3145 6d ago edited 6d ago

I really want to know the cause of this is it a Linux issue or just Ubuntu cause this is taking control from the user and I'm not a fan unless it's op in.

I just did a bit of checking and if the actual bottleneck is IO then the lower priority process might get runtime as the higher priority process is blocked by IO speed . Ionice will give a program higher IO priority I'm gonna keep reading some stuff I may post if I. Find anything else out.

Edit : chrt manpage let's you both see and modify realtime prossese properties Might be why you want

1

u/beertown 6d ago

IO is a negligible part of the workload, think of my case as strictly cpu-bound. Thank you for your suggestion, I'll read chrt manpage.