Skip to contentSkip to conversation

allow non root users to set io priority "idle" ?

DISCUSSION dragoran 5 participants 18 messages Aug 6, 2007 – Aug 8, 2007

lore
Share & tools
lore

dragoran

author
#0 lore raw

Its possible to set the io priority using tools like ionice and syscalls.
But this works only as root.
Why can't a non root user change the priority of his processes to idle?
I understand that realtime priority requires root but why idle?
For instance the beagle trys to set its priority to idle but fails because it does not run as root.
Any reason for this that I have missed? I can't think of a case where setting the io priority to idle would have a negative impact for other users or the whole system.

P.S:
Please CC me when replying.

#1 lore raw
Quoted 9 lines · dragoran

Its possible to set the io priority using tools like ionice and syscalls. But this works only as root.
Why can't a non root user change the priority of his processes to idle? I understand that realtime priority requires root but why idle? For instance the beagle trys to set its priority to idle but fails because it does not run as root.
Any reason for this that I have missed? I can't think of a case where setting the io priority to idle would have a negative impact for other users or the whole system.

Very low priority can starve others when it holds some kernel resource needed by another task.

Consider three tasks: one very low priority, one high priority: Low priority task holds some kernel resource, middle task eats as much CPU as it gets; high priority task wants to get the resource. High priority will need to wait for low running, which could take a long time. With true SCHED_IDLE (i believe the current implementation is not true) this could be never or at least a very long time.

There are ways to defend against this problem (known as priority inheritance), but the kernel doesn't do them consistently. The same issue could also happen for user space managed resources.

For IO I suppose the same could happen too. e.g. low priority task wants to write out a page and keeps it locked until the IO is finished. High priority task wants to access the page and has to wait until it is unlocked. Middle task generates an endless stream of IO that makes the idle priority writeout never finish.

In general idle priorities are quite risky, even for root.

-Andi

author
#2 lore raw
Quoted 24 lines · Andi Kleen
Quoted 10 lines · dragoran

Its possible to set the io priority using tools like ionice and syscalls. But this works only as root.
Why can't a non root user change the priority of his processes to idle? I understand that realtime priority requires root but why idle? For instance the beagle trys to set its priority to idle but fails because it does not run as root.
Any reason for this that I have missed? I can't think of a case where setting the io priority to idle would have a negative impact for other users or the whole system.

Very low priority can starve others when it holds some kernel resource needed by another task.

Consider three tasks: one very low priority, one high priority: Low priority task holds some kernel resource, middle task eats as much CPU as it gets; high priority task wants to get the resource. High priority will need to wait for low running, which could take a long time. With true SCHED_IDLE (i believe the current implementation is not true) this could be never or at least a very long time.

Quoted 8 lines

There are ways to defend against this problem (known as priority inheritance), but the kernel doesn't do them consistently. The same issue could also happen for user space managed resources.

For IO I suppose the same could happen too. e.g. low priority
task wants to write out a page and keeps it locked until the IO is finished. High priority task wants to access the page and has to wait until it is unlocked. Middle task generates an endless
stream of IO that makes the idle priority writeout never finish.

couldn't this be fixed by bumping idle tasks to middle while they hold a pagelock? ex:
task A - hp
task B - mp
task C - lp (idle)
task C locks a page -> becomes a mp (middle prio) task until its finished task C unlocks the page -> back to idle

Quoted 5 lines

In general idle priorities are quite risky, even for root.

-Andi

#3 lore raw
Quoted 1 line

couldn't this be fixed by bumping idle tasks to middle while they hold a

Usually to high.

But it's all complicated and hasn't been done consistently (there are real time mutexes in the -rt kernel for example, but there are lots of other locks and they have higher overhead too) and it's unclear we really want to do all this complexity anyways.

Also as I said the problem could then still happen in user space which then would all need to be fixed to handle PI too.

In some cases the relationship is also not as simple as a single lock. And for IO handling it would be likely quite hard.

I personally always found idle priorities quite dubious because even if they worked reliable for the CPU they will clear your cache/ load your memory controller and impact all other programs because of this. And for the disk they will cause additional seeks which are also very costly.

-Andi

author
#4 lore raw
Quoted 11 lines · Andi Kleen
Quoted 2 lines

couldn't this be fixed by bumping idle tasks to middle while they hold a

Usually to high.

But it's all complicated and hasn't been done consistently
(there are real time mutexes in the -rt kernel for example, but there are lots of other locks and they have higher overhead too) and it's unclear we really want to do all this complexity anyways.

Also as I said the problem could then still happen in user space which then would all need to be fixed to handle PI too.

Quoted 8 lines

In some cases the relationship is also not as simple as a single lock. And for IO handling it would be likely quite hard.

I personally always found idle priorities quite dubious because
even if they worked reliable for the CPU they will clear your cache/ load your memory controller and impact all other programs because
of this. And for the disk they will cause additional seeks which are also very costly.

ok, thx so that means that the best that can be done for now is to run beagle as best effort with prio 7 (like its done now).

#5 lore raw
In reply to Andi Kleen
Quoted 12 lines · Andi Kleen
Quoted 1 line

couldn't this be fixed by bumping idle tasks to middle while they hold a

Usually to high.

But it's all complicated and hasn't been done consistently (there are real time mutexes in the -rt kernel for example, but there are lots of other locks and they have higher overhead too) and it's unclear we really want to do all this complexity anyways.

Also as I said the problem could then still happen in user space which then would all need to be fixed to handle PI too.

Quoted 8 lines

In some cases the relationship is also not as simple as a single lock. And for IO handling it would be likely quite hard.

I personally always found idle priorities quite dubious because even if they worked reliable for the CPU they will clear your cache/ load your memory controller and impact all other programs because of this. And for the disk they will cause additional seeks which are also very costly.

But that is why the idle priority implementation in CFQ adds a grace period before idle prio tasks are run. So that concern should not be an issue, if so the grace period needs to be enlarged. That at least covers the seek side of things. If idle io tasks run, then the IO load on the system must be very low to zero. Hence other IO relevant resource contention isn't an iissue.

Signature · 1 line
Jens Axboe
author
#6 lore raw

so there is no real reason not to allow it for non root users? removing the check is easy (3 lines) ....
or are there any other issues/problems?

Quoted 33 lines · Jens Axboe
Quoted 12 lines · Andi Kleen
Quoted 1 line

couldn't this be fixed by bumping idle tasks to middle while they hold a

Usually to high.

But it's all complicated and hasn't been done consistently (there are real time mutexes in the -rt kernel for example, but there are lots of other locks and they have higher overhead too) and it's unclear we really want to do all this complexity anyways.

Also as I said the problem could then still happen in user space which then would all need to be fixed to handle PI too.

Quoted 8 lines

In some cases the relationship is also not as simple as a single lock. And for IO handling it would be likely quite hard.

I personally always found idle priorities quite dubious because even if they worked reliable for the CPU they will clear your cache/ load your memory controller and impact all other programs because of this. And for the disk they will cause additional seeks which are also very costly.

But that is why the idle priority implementation in CFQ adds a grace period before idle prio tasks are run. So that concern should not be an issue, if so the grace period needs to be enlarged. That at least covers the seek side of things. If idle io tasks run, then the IO load on the system must be very low to zero. Hence other IO relevant resource contention isn't an iissue.

--
Jens Axboe

author
#7 lore raw

so there is no real reason not to allow it for non root users? removing the check is easy (3 lines) ....
or are there any other issues/problems?

(resend sorry for the top post stupid gmail ;) )

#8 lore raw
Quoted 3 lines · dragoran

so there is no real reason not to allow it for non root users? removing the check is easy (3 lines) ....
or are there any other issues/problems?

Jens was only talking about the seek issue I mentioned I believe; not about the PI problem.

-Andi

#11 lore raw
In reply to Andi Kleen
Quoted 5 lines · Andi Kleen

For IO I suppose the same could happen too. e.g. low priority task wants to write out a page and keeps it locked until the IO is finished. High priority task wants to access the page and has to wait until it is unlocked. Middle task generates an endless stream of IO that makes the idle priority writeout never finish.

I don't think it's a problem for high priority (RT) tasks - it's well known in the real time Linux community that you never, ever do IO from a thread that has to satisfy RT constraints. A correct RT linux app does its IO from a SCHED_NORMAL thread, with *plenty* of buffering, and feeds the RT constrained SCHED_FIFO threads using a lock free ringbuffer.

SCHED_IDLE starving SCHED_NORMAL is an issue of course. But SCHED_IDLE seems a lot more useful for read than write which I would expect to take fewer locks. For example I'd expect Beagle to want to read at SCHED_IDLE but write out its indices at SCHED_NORMAL.

Would it make any sense to allow anyone to set SCHED_IDLE for reads but require root to change IO priority for writes?

Lee

#9 lore raw
In reply to dragoran
Quoted 3 lines · dragoran

so there is no real reason not to allow it for non root users? removing the check is easy (3 lines) ....
or are there any other issues/problems?

Andi already explained to you why it can't be enabled for non-root users. I merely talked about why idle priority works.

Signature · 1 line
Jens Axboe
author
#10 lore raw
Quoted 11 lines · Jens Axboe
Quoted 4 lines · dragoran

so there is no real reason not to allow it for non root users? removing the check is easy (3 lines) ....
or are there any other issues/problems?

Andi already explained to you why it can't be enabled for non-root users. I merely talked about why idle priority works.

ok, I missunderstood you.
shouldn't read mails at 0:18 am ;)

#13 lore raw
In reply to Andi Kleen
Quoted 2 lines · Andi Kleen

Very low priority can starve others when it holds some kernel resource needed by another task.

Nevertheless ordinary users are permitted to lower priority ([re]nice) and resource limits (setrlimit).

Quoted 5 lines

For IO I suppose the same could happen too. e.g. low priority task wants to write out a page and keeps it locked until the IO is finished. High priority task wants to access the page and has to wait until it is unlocked. Middle task generates an endless stream of IO that makes the idle priority writeout never finish.

I don't quite understand. There are a lot of other ways to starve such high-priority process:
1. renice the low-priority process
2. send it a signal
3. ptrace it
4. use something like cpulimit (http://cpulimit.sourceforge.net/) to stall it
....

So I think current behaviour of ionice is inconsistent (and pointless).

P.S.
Please CC me, I'm not subscribed.

Best regards,
Alexei

Signature · 1 line
All science is either physics or stamp collecting.
#12 lore raw
In reply to Lee Revell
Quoted 3 lines

I don't think it's a problem for high priority (RT) tasks - it's well known in the real time Linux community that you never, ever do IO from a thread that has to satisfy RT constraints.

The point here is to protect the system from a potentially malicious user

Quoted 2 lines

which I would
expect to take fewer locks.

Even a single lock is one too much. My example lock -- the page lock bit -- certainly applies to both reads and writes.

-Andi

#14 lore raw
In reply to Sheplyakov Alexei
Quoted 6 lines · Sheplyakov Alexei
Quoted 2 lines · Andi Kleen

Very low priority can starve others when it holds some kernel resource needed by another task.

Nevertheless ordinary users are permitted to lower priority ([re]nice)

Low priority as allowed by renice is ok -- the resource holder will run eventually and the system make progress.

Quoted 3 lines

I don't quite understand. There are a lot of other ways to starve such high-priority process:
1. renice the low-priority process

That requires user action.

e.g. if you google a bit you can find a famous story where the NASA had to do that remotely to solve a PI problem on one of the Mars rovers. But I'm sure they weren't very pleased about it. And not everybody has a JPL control room to patch things up in the backhand.

Quoted 2 lines

2. send it a signal
3. ptrace it

Only root can do these.

-Andi

#17 lore raw
In reply to Sheplyakov Alexei
Quoted 1 line · Sheplyakov Alexei

So I think current behaviour of ionice is inconsistent (and pointless).

It is not, as has been explained more than once in this thread, we cannot allow ordinary users to eg /etc/passwd infinitely. See?

It'd be nice if we could solve this of course, until then true idle io must be a cautious root-only thing. So it may be inconsistent and a bit confusing, but it's definitely not pointless.

Signature · 1 line
Jens Axboe
#15 lore raw
In reply to Andi Kleen
Quoted 5 lines · Andi Kleen
Quoted 3 lines

I don't quite understand. There are a lot of other ways to starve such high-priority process:
1. renice the low-priority process

That requires user action.

As well as lowering IO priority.

Quoted 4 lines
Quoted 2 lines

2. send it a signal
3. ptrace it

Only root can do these.

The original question (unless I'm missing something) was "why _the owner_ of a process is not enabled to lower its IO priority?" The owner of the process certainly can send signal and ptrace it.

Quoted 2 lines

Low priority as allowed by renice is ok -- the resource holder will run eventually and the system make progress.

System (whatever that means) should not depend on random users' processes.

Quoted 2 lines

e.g. if you google a bit you can find a famous story where the NASA had to do that remotely to solve a PI problem on one of the Mars rovers.

Certainly there are a scenarios when lowering priority (CPU or IO) have negative effect. "If it hurts -- then don't do it". However, it is not kernels job to decide if the user is right. If the user asks to do something "stupid" (run his process with idle IO priority, whipe out his home directory, you name it) -- just do that (as long as the action is permitted by the security policy).

P.S.
Please CC me, I'm not subscribed.

Best regards,
Alexei

Signature · 1 line
All science is either physics or stamp collecting.
#16 lore raw
Quoted 3 lines

The original question (unless I'm missing something) was "why _the owner_ of a process is not enabled to lower its IO priority?" The owner of the process certainly can send signal and ptrace it.

Ah I misparsed you.

Sending signals and ptraces is atomic regarding system operations. This means the kernel will finish doing whatever it is doing (or bail out releasing all resources) before processing them. So stopping a process this way can never starve its IO. Ok there are special cases like user space FUSE or NFS servers that can block operations, but these are expected to run as root.

-Andi