Skip to contentSkip to conversation

VM and swap - it's really unusable

2.4.17/18pre Dieter Nützel 53 participants 351 messages Jan 8, 2002 – Jan 29, 2002 Page 2 of 2

Subsystems (6)
lore
Share & tools
lore
#305 lore raw
In reply to Alan Cox

On Wednesday 09 January 2002 13:57, Andrew Morton wrote:
[snip]

Quoted 10 lines

Without LL, Linux cannot reasonably be used for professional audio work that involves real time FX or real time synthesis. The default kernel has worst-case latencies noticeably worse than Windows, and most people are reluctant to use that system already, not just because of instability but latencies also. Its not a matter of it being "a bit of a problem" - the 100msec worst case latencies visible in the standard kernel make it totally implausible that you would ever deploy Linux in a situation where RT FX/synthesis were going to happen.

Quoted 9 lines

By contrast, if we get LL in place, then we can potentially use Linux in "black box"/"embedded" systems designed specifically for audio users; all the flexibility of Linux, but if they choose to ignore most of that, they'll still have a black rack-mounted box capable of doing everything (more mostly everything) currently done by dedicated hardware. As general purpose CPU performance continues to increase, this becomes more and more overwhelmingly obvious as the way forward for audio processing.

I keep on seeing these "Blackbox" apps like Tivo using Linux but the fact remains the average folks cannot get any reasonable kind of A/V
performance and support under Linux. That's what we need.

Needing to save money and get some fast cash (I'm unemployed), yesterday, I swapped out my dual P-III motherboard in my BeOS box
for a Via C-III (700MHz) based system. And I got my first real hiccups
while using the OS when I was playing MP3s and _launching_ the TV program _full screen_(640x480 on 640x480 virtual desktop window).

Obviously, when this stuff is done right, more CPU power can only help, but it still has to be done right. As I am sure that you know, BeOS claims average latency of 250 microseconds.

Signature · 1 line
[email protected].
#306 lore raw
In reply to Ken Brownfield

Andrew Morton wrote:
[...]

Quoted 5 lines

I haven't seen any figures for embedded XP, but it is said that if you bend over backwards you can get 10 milliseconds out of NT4, and 4-5 out of the fabled BeOS. This is one area where we can fairly easily be very much the best. It's low-hanging fruit.

Quoted 8 lines

Internal preemptability is, in my opinion, the best way to deliver this.

I accept your point about it making debugging harder - I would suggest that the preempt code be altered so that it can be disabled at runtime, rather than via a rebuild. I suspect this can be done at zero cost by setting init_task's preempt count to 1000000 via a kernel boot option. And at almost-zero cost via a sysctl.

And with some bad luck, the bug goes away when you do this. The bug of the missing lock...

Helge Hafting

#307 lore raw
In reply to Ken Brownfield
Quoted 4 lines · John Alvord

Incidently human visual perception runs around 200 milliseconds minimum and hearing/touch perception around 100 milliseconds if the signal has to go through the brain. Of course we extend our perceptions with tools/programs etc.

Cool! That means movies don't need to run faster than 5 frames/second. Maybe 10 frames/second for plenty of overkill. No need to look at keyboard and mice any more frequently either, what a relief. (Any why do silly gamers want to go so much higher?)

Sarcasm mode "off" now...just because some experiments show it takes humans a long time to push the correct button when you show them a picture of a banana doesn't mean there is no reason to have a user interface do anything any faster. (I can come up with plenty of examples if you would like.)

OK, now that I have pissed off a big hunk of the folks on the list, let me bring up a different question:

How does all this fit into doing a tick-less kernel?

There is something appealing about doing stuff only when there is stuff to do, like: respond to input, handle some device that becomes ready, or let another process run for a while. Didn't IBM do some nice work on this for Linux? (*Was* it nice work?) I was under the impression that the current kernel isn't that far from being tickless.

A tickless kernel would be wonderful for battery powered devices that could literally shut off when there be nothing to do, and it seems it would (trivially?) help performance on high end power hogs too.

Why do we have regular HZ ticks? (Other than I think I remember Linus saying that he likes them.)

Thanks,

-kb, the Kent who knows more about user interfaces than he does preemption.

#308 lore raw
Quoted 8 lines · Kent Borg

How does all this fit into doing a tick-less kernel?

There is something appealing about doing stuff only when there is stuff to do, like: respond to input, handle some device that becomes ready, or let another process run for a while. Didn't IBM do some nice work on this for Linux? (*Was* it nice work?) I was under the impression that the current kernel isn't that far from being tickless.

Quoted 6 lines

A tickless kernel would be wonderful for battery powered devices that could literally shut off when there be nothing to do, and it seems it would (trivially?) help performance on high end power hogs too.

Why do we have regular HZ ticks? (Other than I think I remember Linus saying that he likes them.)

Feel free to quantify the savings over the current setup with max power saving enabled in the kernel. I just don't see how "wonderful" it would be, given that an idle system currently uses very little battery if you setup the options to save power.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#309 lore raw
Quoted 4 lines

Feel free to quantify the savings over the current setup with max power saving enabled in the kernel. I just don't see how "wonderful" it would be, given that an idle system currently uses very little battery if you setup the options to save power.

IBM have a tickless kernel patch set for the S/390. Here its not battery at stake but VM overhead sending timer interrupts to hundreds of otherwise idle virtual machines

#310 lore raw
In reply to Bill Davidsen
Quoted 11 lines · Bill Davidsen
Quoted 8 lines · Kent Borg

How does all this fit into doing a tick-less kernel?

There is something appealing about doing stuff only when there is stuff to do, like: respond to input, handle some device that becomes ready, or let another process run for a while. Didn't IBM do some nice work on this for Linux? (*Was* it nice work?) I was under the impression that the current kernel isn't that far from being tickless.

Quoted 7 lines
Quoted 6 lines

A tickless kernel would be wonderful for battery powered devices that could literally shut off when there be nothing to do, and it seems it would (trivially?) help performance on high end power hogs too.

Why do we have regular HZ ticks? (Other than I think I remember Linus saying that he likes them.)

I put a patch on sourceforge as part of the high-res-timers investigation the implemented a tick less kernel with instrumentation. It turns out to be overload prone, mostly do to the need to start and stop a "slice" timer on each schedule() call. I, for one, think this issue is dead and rightly so. The patch is still there for those who want to try it. See signature for URL.

Quoted 10 lines

Feel free to quantify the savings over the current setup with max power saving enabled in the kernel. I just don't see how "wonderful" it would be, given that an idle system currently uses very little battery if you setup the options to save power.

--
bill davidsen <[email protected]>
CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.

Signature · 3 lines
George           [email protected]
High-res-timers: http://sourceforge.net/projects/high-res-timers/
Real time sched: http://sourceforge.net/projects/rtsched/
#311 lore raw
In reply to Ken Brownfield

On Wed, Jan 09, 2002 at 12:10:38AM +0000, Alan Cox wrote:

| That is generally not true. Pe-emption is used in user space to prevent
| applications doing very stupid things. Pre-emption in a trusted environment
| can often be most efficient if done by the programs themselves.
| Userspace is not a trusted environment

That's true, but at some point in the future I think the work involved in making sure all new additional kernel code and all new intra-kernel interactions are "tuned" becomes larger than going preemptive all the way down.

Apple had its arguments for cooperative, along the same lines as what you've mentioned I believe. And while I agree that the kernel is a much _more_ trusted environment, I think the possibilities easily remain for abuse given that there are A) more and more people contributing kernel code every day, and B) countless unspeakably evil modules out there.

And the preempt tunability that has been mentioned sounds like it would go a long way.

| Andrew's patches give you 1mS worst case latency for normal situations, that
| is below human perception, and below scheduling granularity. In other words
| without the efficiency loss and the debugging problems you can place the
| far enough latency below other effects that it isnt worth attacking any more.

It sounds like the LL patches are easier and less prone to locking issues with a lot of the benefit. But I can't help but feel that it's not using the right tool for the job. I think the end result of stabilizing a preemptive kernel (in 2.5?) is worth the price, IMHO.

Signature · 2 lines
Ken.
[email protected]
#312 lore raw
Quoted 4 lines

That's true, but at some point in the future I think the work involved in making sure all new additional kernel code and all new intra-kernel interactions are "tuned" becomes larger than going preemptive all the way down.

It makes no difference to the kernel the work is the same in all cases because you cannot pre-empt while holding a lock. Therefore you have to do all the lock analysis anyway

#313 lore raw
In reply to Ken Brownfield
Quoted 5 lines · John Alvord

Incidently human visual perception runs around 200 milliseconds minimum and hearing/touch perception around 100 milliseconds if the signal has to go through the brain. Of course we extend our perceptions with tools/programs etc.

Have you ever tried to play piano with 100 ms latency from pressing the key to sound? I can tell you that it's pretty difficult...

- Jussi Laako

Signature · 2 lines
PGP key fingerprint: 161D 6FED 6A92 39E2 EB5B  39DD A4DE 63EB C216 1E4B
Available at PGP keyservers
#314 lore raw
In reply to Dieter Nützel
Quoted 28 lines · Daniel Phillips
Quoted 7 lines · Andrea Arcangeli
Quoted 3 lines

The preemptible approach is much less of a maintainance headache, since people don't have to be constantly doing audits to see if something changed, and going in to fiddle with scheduling points.

this yes, it requires less maintainance, but still you should keep in mind the details about the spinlocks, things like the checks the VM does in shrink_cache are needed also with preemptive kernel.

Yes of course, the spinlock regions still have to be analyzed and both patches have to be maintained for that. Long duration spinlocks are bad by any measure, and have to be dealt with anyway.

Quoted 8 lines
Quoted 7 lines

Finally, with preemption, rescheduling can be forced with essentially zero latency in response to an arbitrary interrupt such as IO completion, whereas the non-preemptive kernel will have to 'coast to a stop'. In other words, the non-preemptive kernel will have little lags between successive IOs, whereas the preemptive kernel can submit the next IO immediately. So there are bound to be loads where the preemptive kernel turns in better latency *and throughput* than the scheduling point hack.

Quoted 6 lines

The I/O pipeline is big enough that a few msec before or later in a submit_bh shouldn't make a difference, the batch logic in the ll_rw_block layer also try to reduce the reschedule, and last but not the least if the task is I/O bound preemptive kernel or not won't make any difference in the submit_bh latency because no task is eating cpu and latency will be the one of pure schedule call.

Quoted 3 lines

That's not correct. For one thing, you don't know that no task is eating CPU, or that nobody is hogging the kernel. Look at the above, and consider the part about the little lags between IOs.

We agree. Actually "if the task is I/O bound", I meant "if nobody is hogging CPU", I exactly wanted to make the example of no task hogging CPU in general.

Quoted 13 lines
Quoted 8 lines
Quoted 3 lines

Mind you, I'm not devaluing Andrew's work, it's good and valuable. However it's good to be aware of why that approach can't equal the latency-busting performance of the preemptive approach.

I also don't want to devaluate the preemptive kernel approch (the mean latency it can reach is lower than the one of the lowlat kernel, however I personally care only about worst case latency and this is why I don't feel the need of -preempt),

This is exactly the case that -preempt handles well. On the other hand, trying to show that scheduling hacks satisfy any given latency bound is equivalent to solving the halting problem.

Quoted 7 lines

I thought you had done some real time work?

Quoted 3 lines

but I just wanted to make clear that the
idea that is floating around that preemptive kernel is all goodness is very far from reality, you get very low mean latency but at a price.

A price lots of people are willing to pay.

I'm not convinced that all those people knows exactly what they're buying then 8).

Quoted 2 lines

By the way, have you measured the cost of -preempt in practice?

dropping the lock in spin_unlock made a difference in the numbers, so the overhead must be definitely visible, by simply loading the system with threaded kernel computation (like webserving etc..etc..).

Andrea

#315 lore raw
In reply to Dieter Nützel
Quoted 6 lines · Daniel Phillips
Quoted 4 lines · Anton Blanchard
Quoted 2 lines · Andrea Arcangeli [apparently]

So yes, mean latency will decrease with preemptive kernel, but your CPU is definitely paying something for it.

Quoted 6 lines
Quoted 2 lines

And Andrew Morton's work suggests he can do a much better job of reducing latency than -preempt.

That's not a particularly clueful comment, Anton. Obviously, any latency-busting hacks that Andrew does could also be patched into a -preempt kernel.

Yes. The important part is the implicit dropping of the BKL across schedule().

Quoted 4 lines

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Quoted 3 lines

The preemptible approach is much less of a maintainance headache, since people don't have to be constantly doing audits to see if something changed, and going in to fiddle with scheduling points.

Except it doesn't work. The full-on low-latency patch has ~60 rescheduling points. Of these, ~40 involve popping spinlocks. Really, the only significant latency sources which the preemptible kernel solves are generic_file_read() and generic_file_write().

So preemptible kernel needs lock-break to be useful. And then it's basically the same thing, with the same maintainability problems. And believe me, these are considerable. Mainly because the areas which needs busting up exactly coincide with the areas where there has been most churn in the kernel.

Quoted 7 lines

Finally, with preemption, rescheduling can be forced with essentially zero latency in response to an arbitrary interrupt such as IO completion, whereas the non-preemptive kernel will have to 'coast to a stop'. In other words, the non-preemptive kernel will have little lags between successive IOs, whereas the preemptive kernel can submit the next IO immediately. So there are bound to be loads where the preemptive kernel turns in better latency *and throughput* than the scheduling point hack.

Latency yes. Throughout no.

I don't think the "preempt slows down the kernel" argument is very valid really. Let's invert the argument - Linux is multitasking, and that has a cost. There's no reason why certain bits of the kernel need to violate that just to get a bit more throughput. If it really worries you, set HZ=10 and increase all the timeslices, etc.

Now, there *may* be overheads added due to losing the implicit locking which per-CPU data gives you.

The main cost of preempt IMO is in complexity and stability risks.

(BTW: I took a weird oops testing the preempt patch on an SMP NFS client. The fault address was 0x0aXXXXXX. No useful backtrace, unfortunately).

Quoted 3 lines

Mind you, I'm not devaluing Andrew's work, it's good and valuable. However it's good to be aware of why that approach can't equal the latency-busting performance of the preemptive approach.

There's no point in just merging the preempt patch and saying "there, that's done". It doesn't do anything.

Instead, a decision needs to be made: "Linux will henceforth be a low-latency kernel". Now, IF we can come to this decision, then internal preemption is the way to do it. But it affects ALL kernel developers. Because we'll need to introduce a new rule: "it is a bug to spend more than five milliseconds holding any locks".

So. Do we we want a low-latency kernel? Are we prepared to mandate
the five-millisecond rule? It can be done, but won't be easy, and
we'll never get complete coverage. But I don't see the will around here.

-

#316 lore raw
Quoted 2 lines

low-latency kernel". Now, IF we can come to this decision, then internal preemption is the way to do it. But it affects ALL kernel

The pre-empt patches just make things much much harder to debug. They remove some of the predictability and the normal call chain following goes out of the window because you end up seeing crashes in a thread with no idea what ran the microsecond before

Some of that happens now but this makes it vastly worse.

The low latency patches don't change the basic predictability and debuggability but allow you to hit a 1mS pre-empt target for the general case.

Alan

#317 lore raw
Quoted 8 lines · Alan Cox
Quoted 2 lines

low-latency kernel". Now, IF we can come to this decision, then internal preemption is the way to do it. But it affects ALL kernel

The pre-empt patches just make things much much harder to debug. They remove some of the predictability and the normal call chain following goes out of the window because you end up seeing crashes in a thread with no idea what ran the microsecond before

Quoted 6 lines

Some of that happens now but this makes it vastly worse.

The low latency patches don't change the basic predictability and debuggability but allow you to hit a 1mS pre-empt target for the general case.

Yes, it does make things much much harder to debug - but:
* If you get a problem on a preemtive UP kernel, it is likely to be a problem on a SMP too - and those are hard to debug aswell. But the positive aspect is that you get more people that can do the debugging... :-) (One CPU gets delayed with handling a IRQ the other runs into the critical section)
* It is optional at compile time.
And could even be made run time optional / CPU ! Just set a too big value on the counter and it will never reschedule...

/RogerL

Signature · 3 lines
Roger Larsson
Skellefteå
Sweden
#318 lore raw
In reply to Andrew Morton
Quoted 7 lines · Andrew Morton
Quoted 4 lines

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Eh, I disagree here. The right time is the moment a high-priority task becomes runnable. Given your HZ, only a fully preemptible kernel can come close to meeting that.

Quoted 9 lines
Quoted 7 lines

Finally, with preemption, rescheduling can be forced with essentially zero latency in response to an arbitrary interrupt such as IO completion, whereas the non-preemptive kernel will have to 'coast to a stop'. In other words, the non-preemptive kernel will have little lags between successive IOs, whereas the preemptive kernel can submit the next IO immediately. So there are bound to be loads where the preemptive kernel turns in better latency *and throughput* than the scheduling point hack.

Latency yes. Throughout no.

I bet in _many_ (most?) workloads the preemptible kernel turns in better throughput. Anytime there is load on the system, there should be a benefit. I bet the same goes for your patch. I've certainly verified it for both in various loads myself.

Quoted 5 lines

I don't think the "preempt slows down the kernel" argument is very valid really. Let's invert the argument - Linux is multitasking, and that has a cost. There's no reason why certain bits of the kernel need to violate that just to get a bit more throughput. If it really worries you, set HZ=10 and increase all the timeslices, etc.

Very well said. I always find an answer to the "more complexity, more context switching, blah blah" arguments as ultimately being arguments tantamount to "preemptive multitasking sucks".

Quoted 2 lines

Now, there *may* be overheads added due to losing the implicit locking which per-CPU data gives you.

Perhaps, but note what preempt enable and disable statements effectively
are: an inc and a dec. Not even atomic.

Yes, there is a branch on reenable. This may be an interesting change to look into. FWIW, we have a construct that doesn't check for reschedule on reenable, too.

Quoted 4 lines

The main cost of preempt IMO is in complexity and stability risks.

(BTW: I took a weird oops testing the preempt patch on an SMP NFS client. The fault address was 0x0aXXXXXX. No useful backtrace, unfortunately).

Should of sent me the oops :)

Quoted 13 lines
Quoted 3 lines

Mind you, I'm not devaluing Andrew's work, it's good and valuable. However it's good to be aware of why that approach can't equal the latency-busting performance of the preemptive approach.

There's no point in just merging the preempt patch and saying "there, that's done". It doesn't do anything.

Instead, a decision needs to be made: "Linux will henceforth be a low-latency kernel". Now, IF we can come to this decision, then internal preemption is the way to do it. But it affects ALL kernel developers. Because we'll need to introduce a new rule: "it is a bug to spend more than five milliseconds holding any locks".

Quoted 4 lines

So. Do we we want a low-latency kernel? Are we prepared to mandate
the five-millisecond rule? It can be done, but won't be easy, and
we'll never get complete coverage. But I don't see the will around here.

I agree here, but then I do have three points:

- proper lock use that benefits SMP scalability benefits preempt-kernel induced latency improvements. In other words, things like short lock durations, fine-grained locking, and ditching the BKL benefit both worlds.

- with the preemptible kernel in place, we can look at the long-held locks and figure ways to combat them. The preempt-stats patch helps us find them. Then, we can take a lock-break approach. We can look into finer grained locks. We can localize lock the lock if it is global or the BKL. Or we can do something radical like make long-held spinlocks priority-inheriting when preempt-kernel is enabled. In other words, preempt-kernel becomes a framework for proper solutions in the future.

- finally, the usual: it's an option.

Robert Love

#319 lore raw
In reply to Andrew Morton
Quoted 7 lines · Andrew Morton
Quoted 4 lines

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Have we ever considered making rescheduling work like get_user? That is, make current->need_resched be a pointer, and if we need to reschedule, make it an INVALID pointer that causes us to fault and call schedule in its fault path?

Orthogonally, for rescheduling points with locks, we could build a version of the spinlocks that know when they're blocking other processes and can do a spin_yield(&lock) in places where they can safely give up a lock. On single processor, spin_yield could translate to a scheduling point.

Signature · 1 line
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.."
#320 lore raw

Oliver Xymoron wrote:
[...]

Quoted 4 lines

Have we ever considered making rescheduling work like get_user? That is, make current->need_resched be a pointer, and if we need to reschedule, make it an INVALID pointer that causes us to fault and call schedule in its fault path?

Elegant perhaps, but now you take the time to do a completely unnecessary
page fault when rescheduling. This has a cost which is high on some architectures. But the point of rescheduling was to improve interactive performance and io latency.
Every page fault may have to check for this case.

Helge Hafting

#321 lore raw
In reply to Dieter Nützel
Quoted 5 lines · Andrew Morton

There's no point in just merging the preempt patch and saying "there, that's done". It doesn't do anything.

Instead, a decision needs to be made: "Linux will henceforth be a low-latency kernel".

I thought the intention was to make it a config option?

Quoted 9 lines

Now, IF we can come to this decision, then
internal preemption is the way to do it. But it affects ALL kernel developers. Because we'll need to introduce a new rule: "it is a bug to spend more than five milliseconds holding any locks".

So. Do we we want a low-latency kernel? Are we prepared to mandate
the five-millisecond rule? It can be done, but won't be easy, and
we'll never get complete coverage. But I don't see the will around here.

At least the flaming has gotten a little less ;-)

--
Daniel

#322 lore raw
Quoted 4 lines · Daniel Phillips
Quoted 2 lines

Instead, a decision needs to be made: "Linux will henceforth be a low-latency kernel".

I thought the intention was to make it a config option?

It was originally, it is now, and I intend it to be.

Further, since it uses the existing SMP locks, it doesn't introduce new design decisions (the one being protection of implicitly locked per-CPU data on preempt).

Robert Love

#323 lore raw
In reply to Daniel Phillips
Quoted 8 lines · Daniel Phillips
Quoted 5 lines · Andrew Morton

There's no point in just merging the preempt patch and saying "there, that's done". It doesn't do anything.

Instead, a decision needs to be made: "Linux will henceforth be a low-latency kernel".

I thought the intention was to make it a config option?

Irrelevant, it has to be implemented in order to be an option, so the amount of work involved is the same either way. And if you want to make it a runtime setting you add a slight bit of work and overhead deciding if LL is wanted.

I'm not advocating that, but it would allow admins to enable LL when the system was slow and see if it really made a change. Rebooting is bound to change the load ;-)

Quoted 9 lines
Quoted 9 lines

Now, IF we can come to this decision, then
internal preemption is the way to do it. But it affects ALL kernel developers. Because we'll need to introduce a new rule: "it is a bug to spend more than five milliseconds holding any locks".

So. Do we we want a low-latency kernel? Are we prepared to mandate
the five-millisecond rule? It can be done, but won't be easy, and
we'll never get complete coverage. But I don't see the will around here.

Really? You have people working on low latency, people working on preempt, and at least a few of us trying to characterize the problems with large memory and i/o. I would say latency has become a real issue, and you only need enough "will" to have one person write useful code, this is a committee.

Since changes of this type don't need to be perfect and address all cases, just help some and not make other worse, I think we will see improvement in 2.4.xx without waiting for 2.5 or 2.6. No one is complaining that the Linux overall thruput is bad, that network performance is bad, etc. But responsiveness has become an issue, and I'm sure there's enough will to solve it. "Solve" means getting most of the delays to be caused by hardware capacity instead of kernel ineptitude.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#324 lore raw
In reply to Dieter Nützel
Quoted 8 lines · Andrew Morton
Quoted 4 lines · Daniel Phillips

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Oops, sorry, right.

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

And while I'm enumerating differences, the preemptable kernel (in this incarnation) has a slight per-spinlock cost, while the non-preemptable kernel has the fixed cost of checking for rescheduling, at intervals throughout all 'interesting' kernel code, essentially all long-running loops. But by clever coding it's possible to finesse away almost all the overhead of those loop checks, so in the end, the non-preemptible low-latency patch has a slight efficiency advantage here, with emphasis on 'slight'.

--
Daniel

#325 lore raw
Quoted 3 lines · Daniel Phillips

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

The preemptible kernel ALSO has to wait for a scheduling point to roll around, since it cannot preempt with spinlocks held.

Considering this, I don't see much of an advantage to adding kernel preemption.

regards,

Rik

Signature · 4 lines
"Linux holds advantages over the single-vendor commercial OS"
    -- Microsoft's "Competing with Linux" document

http://www.surriel.com/		http://distro.conectiva.com/
#326 lore raw
Quoted 5 lines · Rik van Riel

The preemptible kernel ALSO has to wait for a scheduling point to roll around, since it cannot preempt with spinlocks held.

Considering this, I don't see much of an advantage to adding kernel preemption.

It only has to wait if locks are held and then only until the locks are dropped. Otherwise it will preempt on the next return from interrupt.

Future work would be to look into long-held locks and see what we can do.

Without preempt-kernel, we have none of this: either run until completion or explicit scheduling points.

Robert Love

#327 lore raw
Quoted 10 lines · Robert Love
Quoted 5 lines · Rik van Riel

The preemptible kernel ALSO has to wait for a scheduling point to roll around, since it cannot preempt with spinlocks held.

Considering this, I don't see much of an advantage to adding kernel preemption.

It only has to wait if locks are held and then only until the locks are dropped. Otherwise it will preempt on the next return from interrupt.

So what exactly _is_ the difference between an explicit preemption point and a place where we need to explicitly drop a spinlock ?

Quoted 4 lines

From what I can see, there really isn't a difference.

Future work would be to look into long-held locks and see what we can do.

One thing we could do is download Andrew Morton's patch ;)

Rik

Signature · 4 lines
"Linux holds advantages over the single-vendor commercial OS"
    -- Microsoft's "Competing with Linux" document

http://www.surriel.com/		http://distro.conectiva.com/
#328 lore raw
Quoted 3 lines · Rik van Riel

So what exactly _is_ the difference between an explicit preemption point and a place where we need to explicitly drop a spinlock ?

In that case nothing, except that when we drop the lock and check it is the earliest place where preemption is allowed. In the normal scenario, however, we have a check for reschedule on return from interrupt (e.g. the timer) and thus preempt in the same manner as with user space and that is the key.

Quoted 4 lines
Quoted 2 lines

Future work would be to look into long-held locks and see what we can do.

One thing we could do is download Andrew Morton's patch ;)

That is certainly one option, and Andrew's patch is very good. Nonetheless, I think we need a more general framework that tackles the problem itself. Preemptible kernel does this, yields results now, and allows for greater return later on.

Robert Love

#329 lore raw
In reply to Rik van Riel
Quoted 7 lines · Robert Love
Quoted 3 lines · Rik van Riel

So what exactly _is_ the difference between an explicit preemption point and a place where we need to explicitly drop a spinlock ?

Quoted 5 lines

In that case nothing, except that when we drop the lock and check it is the earliest place where preemption is allowed. In the normal scenario, however, we have a check for reschedule on return from interrupt (e.g. the timer) and thus preempt in the same manner as with user space and that is the key.

One could do:

static inline void spin_unlock(spinlock_t *lock)

{
        __asm__ __volatile__(
                spin_unlock_string
        );

	if (--current->lock_depth == 0 &&
		current->need_resched &&
		current->state == TASK_RUNNING)
		schedule();
}

But I have generally avoided "global" solutions like this, in favour of nailing the _specific_ code which is causing the problem. Which is a lot more work, but more useful.

The scheduling points in bread() and submit_bh() in the mini-ll patch go against this (masochistic) philosophy.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Future work would be to look into long-held locks and see what we can do.

One thing we could do is download Andrew Morton's patch ;)

That is certainly one option, and Andrew's patch is very good. Nonetheless, I think we need a more general framework that tackles the problem itself. Preemptible kernel does this, yields results now, and allows for greater return later on.

We need something which makes 2.4.x not suck.

-

#330 lore raw
In reply to Rik van Riel
Quoted 8 lines · Rik van Riel
Quoted 3 lines · Daniel Phillips

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

The preemptible kernel ALSO has to wait for a scheduling point to roll around, since it cannot preempt with spinlocks held.

Think about the relative amount of time spent inside spinlocks vs regular kernel.

Quoted 2 lines

Considering this, I don't see much of an advantage to adding kernel preemption.

And now?

--
Daniel

#331 lore raw
In reply to Daniel Phillips
Quoted 7 lines · Daniel Phillips

And while I'm enumerating differences, the preemptable kernel (in this incarnation) has a slight per-spinlock cost, while the non-preemptable kernel has the fixed cost of checking for rescheduling, at intervals throughout all 'interesting' kernel code, essentially all long-running loops. But by clever coding it's possible to finesse away almost all the overhead of those loop checks, so in the end, the non-preemptible low-latency patch has a slight efficiency advantage here, with emphasis on 'slight'.

True (re spinlock weight in preemptible kernel) but how is that not comparable to explicit scheduling points? Worse, the preempt-kernel typically does its preemption on a branch on return to interrupt (similar to user space's preemption). What better time to check and reschedule if needed?

Robert Love

#332 lore raw
Quoted 10 lines · Robert Love
Quoted 7 lines · Daniel Phillips

And while I'm enumerating differences, the preemptable kernel (in this incarnation) has a slight per-spinlock cost, while the non-preemptable kernel has the fixed cost of checking for rescheduling, at intervals throughout all 'interesting' kernel code, essentially all long-running loops. But by clever coding it's possible to finesse away almost all the overhead of those loop checks, so in the end, the non-preemptible low-latency patch has a slight efficiency advantage here, with emphasis on 'slight'.

Quoted 5 lines

True (re spinlock weight in preemptible kernel) but how is that not comparable to explicit scheduling points? Worse, the preempt-kernel typically does its preemption on a branch on return to interrupt (similar to user space's preemption). What better time to check and reschedule if needed?

I'm not sure that preempt and low latency really are attacking the same problem. What I am finding is the LL improves overall performance when a process does something which is physically slow, like a find in a directory with 20k files. On the other hand PK makes the response of the system better to changes. In particular I see the DNS servers which have other work running, even backups or reports, are more responsive with PK, as are usenet news servers. I find it hard to measure "feels faster" with either approach, although like the supreme court "I know it when I see it."

I'd like to hope that some of each will get in the main kernel, PK has been stable for me for a while, LL has never been unstable but I've run it less.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#333 lore raw
In reply to Daniel Phillips
Quoted 7 lines · Daniel Phillips
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Daniel Phillips

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Quoted 9 lines
Quoted 2 lines

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Oops, sorry, right.

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

mmhhh. At which cost? And then anyway if I have a spinlock, I still have to wait for a scheduling point to roll around.

#334 lore raw
Quoted 5 lines · Luigi Genoni
Quoted 3 lines · Daniel Phillips
Quoted 2 lines · Andrew Morton
Quoted 1 line · Daniel Phillips

What a preemptible kernel can do that a non-preemptible kernel can't

is:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

reschedule exactly as often as necessary, instead of having lots of

extra

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

schedule points inserted all over the place, firing when *they* think

the

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

time is right, which may well be earlier than necessary.

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Quoted 8 lines
Quoted 5 lines

Oops, sorry, right.

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

mmhhh. At which cost? And then anyway if I have a spinlock, I still have to wait for a scheduling point to roll around.

Did you read the thread? Think about the relative amount of time spent in spinlocks vs the amount of time spent in the regular kernel.

--
Daniel

#335 lore raw
In reply to Dieter Nützel
Quoted 8 lines · Daniel Phillips
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Daniel Phillips

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Quoted 8 lines
Quoted 2 lines

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Oops, sorry, right.

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

That's theory. Practice (ie: instrumentation) says that the preempt patch makes little improvement over conditional yields in generic_file_read() and generic_file_write(). Four lines. Additional yields in wait_for_buffers() (where we move zillions of buffers from BUF_LOCKED to BUF_CLEAN) and in submit_bh() and bread() are cream.

Preemptability is global in its impact, and in its effect. It requires global changes to make it useful. If we're prepared to make those changes (scan_swap_map, truncate_inode_pages, etc) then fine. Go for it. We'll end up with a better kernel.

Quoted 8 lines

And while I'm enumerating differences, the preemptable kernel (in this incarnation) has a slight per-spinlock cost, while the non-preemptable kernel has the fixed cost of checking for rescheduling, at intervals throughout all 'interesting' kernel code, essentially all long-running loops. But by clever coding it's possible to finesse away almost all the overhead of those loop checks, so in the end, the non-preemptible low-latency patch has a slight efficiency advantage here, with emphasis on 'slight'.

As I said: I don't buy the efficiency worries at all. If scheduling pressure is so high that either approach impacts performance, then scheduling pressure is too high. We need to fix the context switch rate and/or speed up context switches. The overhead of conditional_schedule() or preempt will be zilch.

-

#336 lore raw
In reply to Dieter Nützel
Quoted 10 lines · Robert Love
Quoted 7 lines · Daniel Phillips

And while I'm enumerating differences, the preemptable kernel (in this incarnation) has a slight per-spinlock cost, while the non-preemptable kernel has the fixed cost of checking for rescheduling, at intervals throughout all 'interesting' kernel code, essentially all long-running loops. But by clever coding it's possible to finesse away almost all the overhead of those loop checks, so in the end, the non-preemptible low-latency patch has a slight efficiency advantage here, with emphasis on 'slight'.

Quoted 5 lines

True (re spinlock weight in preemptible kernel) but how is that not comparable to explicit scheduling points? Worse, the preempt-kernel typically does its preemption on a branch on return to interrupt (similar to user space's preemption). What better time to check and reschedule if needed?

The per-spinlock cost I was refering to is the cost of the inc/dec per spinlock. I guess this cost is small enough as to be hard to measure, but I have not tried so I don't know. Curiously, none of the people I've heard making pronouncements on the overhead of your preempt patch seem to have measured it either.

--
Daniel

#337 lore raw
Quoted 11 lines · Daniel Phillips
Quoted 5 lines

True (re spinlock weight in preemptible kernel) but how is that not comparable to explicit scheduling points? Worse, the preempt-kernel typically does its preemption on a branch on return to interrupt (similar to user space's preemption). What better time to check and reschedule if needed?

The per-spinlock cost I was refering to is the cost of the inc/dec per spinlock. I guess this cost is small enough as to be hard to measure, but I have not tried so I don't know. Curiously, none of the people I've heard making pronouncements on the overhead of your preempt patch seem to have measured it either.

;-)

If they did I suspect it would be minimal. Andrew's point on complexity and overhead in this manner is exact -- such thinks are just not an issue.

I see two valid arguments against kernel preemption, and I'll be the first to admit them:

- we introduce new problems with kernel programming. specifically, the issue with implicitly locked per-CPU data. honestly, this isn't a huge deal. I've been working on preempt-kernel for awhile now and the problems we have found and fixed are minimal. admittedly, however, especially wrt the future, preempt-kernel may introduce new concerns. I say let's rise to meet them.

- we don't do enough for the worst-case latency. this is where future work is useful and where preempt-kernel provides the framework for a better kernel.

I want a better kernel. Hell, I want the best kernel. In my opinion, one factor of that is having a preemptible kernel.

Robert Love

#338 lore raw
In reply to Dieter Nützel
Quoted 8 lines · Daniel Phillips
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Daniel Phillips

What a preemptible kernel can do that a non-preemptible kernel can't is:
reschedule exactly as often as necessary, instead of having lots of extra schedule points inserted all over the place, firing when *they* think the time is right, which may well be earlier than necessary.

Quoted 9 lines
Quoted 2 lines

Nope. `if (current->need_resched)' -> the time is right (beyond right, actually).

Oops, sorry, right.

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

Yes. It can also fix problematic areas which my testing didn't cover.

Incidentally, there's the SMP problem. Suppose we have the code:

	lock_kernel();
	for (lots) {
		do(something sucky);
		if (current->need_resched)
			schedule();
	}
	unlock_kernel();

This works fine on UP, but not on SMP. The scenario:

- CPU A runs this loop.

- CPU B is spinning on the lock.

- Interrupt occurs, kernel elects to run RT task on CPU B. CPU A doesn't have need_resched set, and just keeps on going. CPU B is stuck spinning on the lock.

This is only an issue for the low-latency patch - all the other approaches still have sufficiently bad worse-case that this scenario isn't worth worrying about.

I toyed with creating spin_lock_while_polling_resched(), but ended up changing the scheduler to set need_resched against _all_ CPUs if an RT task is being woken (yes, yuk).

-

#339 lore raw
In reply to Dieter Nützel
Quoted 7 lines · Andrew Morton
Quoted 3 lines · Daniel Phillips

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

Yes. It can also fix problematic areas which my testing didn't cover.

I bet, with a minor hack, it can help you *find* those problem areas too. You compile the two patches together and automatically log any event along with the execution address, where your explicit schedule points failed to reschedule in time. Sort of like a profile but suited exactly to your problem.

This just detects the problem areas in normal kernel execution, not spinlocks, but that is probably where most of the maintainance will be anyway.

By the way, did you check for latency in directory operations?

Quoted 21 lines

Incidentally, there's the SMP problem. Suppose we have the code:

	lock_kernel();
	for (lots) {
		do(something sucky);
		if (current->need_resched)
			schedule();
	}
	unlock_kernel();

This works fine on UP, but not on SMP. The scenario:

- CPU A runs this loop.

- CPU B is spinning on the lock.

- Interrupt occurs, kernel elects to run RT task on CPU B. CPU A doesn't have need_resched set, and just keeps on going. CPU B is stuck spinning on the lock.

Quoted 7 lines

This is only an issue for the low-latency patch - all the other approaches still have sufficiently bad worse-case that this scenario isn't worth worrying about.

I toyed with creating spin_lock_while_polling_resched(), but ended up changing the scheduler to set need_resched against _all_ CPUs if an RT task is being woken (yes, yuk).

Heh, subtle. Thanks for pointing that out and making my head hurt.

--
Daniel

#340 lore raw
In reply to Dieter Nützel
Quoted 7 lines · Daniel Phillips
Quoted 5 lines · Andrew Morton
Quoted 3 lines · Daniel Phillips

The preemptible kernel can reschedule, on average, sooner than the scheduling-point kernel, which has to wait for a scheduling point to roll around.

Quoted 8 lines
Quoted 2 lines

Yes. It can also fix problematic areas which my testing didn't cover.

I bet, with a minor hack, it can help you *find* those problem areas too. You compile the two patches together and automatically log any event along with the execution address, where your explicit schedule points failed to reschedule in time. Sort of like a profile but suited exactly to your problem.

Well, one of the instrumentation patches which I use detects a scheduling overrun at interrupt time and emits an all-CPU backtrace. You just feed the trace into ksymoops or gdb then go stare at the offending code.

That's the easy part - the hard part is getting sufficient coverage. There are surprising places. close_files(), exit_notify(), ...

Quoted 4 lines

This just detects the problem areas in normal kernel execution, not spinlocks, but that is probably where most of the maintainance will be anyway.

By the way, did you check for latency in directory operations?

Yes. They can be very bad for really large directories. Scheduling on the found-in-cache case in bread() kills that one easily for most local filesystems. There may still be a problem in ext2.

-

#341 lore raw
In reply to Dieter Nützel
Quoted 6 lines · Andrew Morton
Quoted 1 line · Daniel Phillips

By the way, did you check for latency in directory operations?

Yes. They can be very bad for really large directories. Scheduling on the found-in-cache case in bread() kills that one easily for most local filesystems. There may still be a problem in ext2.

A indexed directory won't have that problem - I'll get to finishing off the htree patch pretty soon[1]. In any event, the analogous technique will work:
a schedule point in ext2_bread.

[1] Wli's hash work is happening at a convenient time.

--
Daniel

#342 lore raw
In reply to Dieter Nützel
Quoted 7 lines · Robert Love
Quoted 3 lines · Andrea Arcangeli

"extra schedule points all over the place", that's the -preempt kernel not the lowlatency kernel! (on yeah, you don't see them in the source but ask your CPU if it sees them)

How so? The branch on drop of the last lock? It's not a factor in

exactly, this is the reschedule point I meant. Oh note that it's unlikely also in the lowlatecy patch. Please count the number of time you add this branch in the -preempt, and how many times we add this branch in the lowlat and then tell me who is adding rescheduling points in the kernel all over the place.

Quoted 3 lines

This makes me think the end conclusion would be that preemptive multitasking in general is bad. Why don't we increase the timeslice and and tick period, in that case?

that would increase performance, but we'd lost interactivity.

Quoted 2 lines

One can argue the complexity degrades performance, but tests show otherwise. In throughput and latency. Besides, like I always say, its

which benchmarks? you should make sure the CPU spend all its cycles in the kernel to benchmark the perfrormance degradation (this is the normal case of webserving with a few gigabit ethernet cards using sendfile).

Quoted 1 line

ride. On the other hand, the patch has a _huge_ userbase and you can't

I question this because it is too risky to apply. There is no way any distribution or production system could ever consider applying the preempt kernel and ship it in its next kernel update 2.4. You never know if a driver will deadlock because it is doing a test and set bit busy loop by hand instead of using spin_lock and you cannot audit all the device drivers out there. It is not like the VM that is self contained and that can be replaced without any caller noticing, this instead impacts every single driver out there and you'd need to audit all of them, which is not feasible I think and that should be done by giving everybody the time to test. This is also what makes preempt config option risky, if we go preempt we should force everybody to use it, at least during 2.5, so we get the useful feedback from testers of all the hardware, or nobody could trust -preempt.

NOTE: I trust your work with spinlocks, locks around per-cpu data structures etc.. is perfect, I trust that part, as said it's the driver doing test and set bit that you cannot audit that is the problem here and that makes it potentially unstable, not your changes. And also the per-cpu data structures sounds a little risky (but for example for UP that's not an issue).

Quoted 2 lines

question that. You also can't question the benchmarks that show improvements in average _and_ worst case latency _and_ throughput.

I don't question some benchmark is faster with -preempt, the interesting thing is to find why because it shouldn't be the case, Andrew for example mentioned software raid, there are good reasons for which -preempt could be faster there, so we added a single sechdule point and we just have that case covered in 18pre2aa1, we don't need reschedule points all over the place like in -preempt to cover things like that. It is good to find them out so we can fix those bugs, I consider them bugs :).

Again: I'm not completly against preempt, it can reach an mean latency much lower than mainline (it can reschedule immediatly in the middle of long copy-users for example), so it definitely has a value, it's just that I'm not sure if it worth it.

Andrea

#343 lore raw
In reply to Dieter Nützel
Quoted 9 lines · Andrea Arcangeli
Quoted 5 lines · Daniel Phillips

BTW, I find your main argument confusing. First you don't want -preempt with CONFIG_EXERIMENTAL because it might not get wide enough testing, so you want to enable it by default in the mainline kernel, then you argue it's too risky because everybody will use it and it might break some obscure driver. Sorry, you lost me back there.

the point I am making is very simple: _if_ we include it, it should _not_ be a config option.

That doesn't make any sense to me. Why should _SMP be a config option and not _PREEMPT?

--
Daniel

#344 lore raw
In reply to Dieter Nützel

----- Original Message -----
From: "Andrea Arcangeli" <[email protected]>
To: "Robert Love" <[email protected]>
Cc: "Daniel Phillips" <[email protected]>; "Anton Blanchard" <[email protected]>; "Luigi Genoni" <[email protected]>; "Dieter N?tzel" <[email protected]>; "Marcelo Tosatti" <[email protected]>; "Rik van Riel" <[email protected]>; "Linux Kernel List" <[email protected]>; "Andrew Morton" <[email protected]>
Sent: Wednesday, January 09, 2002 6:24 AM
Subject: Re: [2.4.17/18pre] VM and swap - it's really unusable

Quoted 19 lines · Robert Love
Quoted 7 lines · Andrea Arcangeli
Quoted 4 lines

"extra schedule points all over the place", that's the -preempt kernel not the lowlatency kernel! (on yeah, you don't see them in the source but ask your CPU if it sees them)

How so? The branch on drop of the last lock? It's not a factor in

exactly, this is the reschedule point I meant. Oh note that it's unlikely also in the lowlatecy patch. Please count the number of time you add this branch in the -preempt, and how many times we add this branch in the lowlat and then tell me who is adding rescheduling points in the kernel all over the place.

Quoted 3 lines

This makes me think the end conclusion would be that preemptive multitasking in general is bad. Why don't we increase the timeslice and and tick period, in that case?

Quoted 8 lines

that would increase performance, but we'd lost interactivity.

Quoted 2 lines

One can argue the complexity degrades performance, but tests show otherwise. In throughput and latency. Besides, like I always say, its

which benchmarks? you should make sure the CPU spend all its cycles in the kernel to benchmark the perfrormance degradation (this is the normal case of webserving with a few gigabit ethernet cards using sendfile).

I haven't seen any interactive tests that showed worse results than the
vanilla kernel with the preempt patch. The only cases where it gives a worse performance is in a single tasking environment such as running bonnie or dbench and apps like that that require to throttle the system. This is obviously expected behavior though. Performance degradation might be seen on a per app basis, but when looking at the system as a whole, performance has never degraded with the patch as far as i've seen. Better overall performance is what has lead to better "benchmark" performance on the tests being run by people.

Quoted 15 lines
Quoted 1 line

ride. On the other hand, the patch has a _huge_ userbase and you can't

I question this because it is too risky to apply. There is no way any distribution or production system could ever consider applying the preempt kernel and ship it in its next kernel update 2.4. You never know if a driver will deadlock because it is doing a test and set bit busy loop by hand instead of using spin_lock and you cannot audit all the device drivers out there. It is not like the VM that is self contained and that can be replaced without any caller noticing, this instead impacts every single driver out there and you'd need to audit all of them, which is not feasible I think and that should be done by giving everybody the time to test. This is also what makes preempt config option risky, if we go preempt we should force everybody to use it, at least during 2.5, so we get the useful feedback from testers of all the hardware, or nobody could trust -preempt.

I disagree. Redhat shipped gcc 2.96 when it was producing incompatible
binaries and was buggy as all hell, why not ship a kernel that is "unstable" and "risky" if it promises better performance.
If scheduling points are ugly in 2.4, then they'd be ugly in 2.5. The only solution to the problem you see with it is making 2.5 fully preemptible from the ground up instead of having to add fixes. If nobody wants to do things the hard way (assuming there is a better way), is it better to leave it unfixed rather than fix it? Of course i'm assuming that the idea of a fully preemptible kernel is better than the current version we have now.

Quoted 10 lines

NOTE: I trust your work with spinlocks, locks around per-cpu data structures etc.. is perfect, I trust that part, as said it's the driver doing test and set bit that you cannot audit that is the problem here and that makes it potentially unstable, not your changes. And also the per-cpu data structures sounds a little risky (but for example for UP that's not an issue).

Quoted 2 lines

question that. You also can't question the benchmarks that show improvements in average _and_ worst case latency _and_ throughput.

Quoted 8 lines

I don't question some benchmark is faster with -preempt, the interesting thing is to find why because it shouldn't be the case, Andrew for example mentioned software raid, there are good reasons for which -preempt could be faster there, so we added a single sechdule point and we just have that case covered in 18pre2aa1, we don't need reschedule points all over the place like in -preempt to cover things like that. It is good to find them out so we can fix those bugs, I consider them bugs :).

I think robert love is trying to give the kernel the highest flexibility.
Making it flexible in key areas will improve your worst cases but a lot of the time during normal use it's the multitude of smaller cases that is noticeable.

Quoted 6 lines

Again: I'm not completly against preempt, it can reach an mean latency much lower than mainline (it can reschedule immediatly in the middle of long copy-users for example), so it definitely has a value, it's just that I'm not sure if it worth it.

Andrea

Ok so the medicine is worse than the disease. I take it that you only want
some key points made for rescheduling instead of the full preempt patch by
Robert. That seems logical enough. The only issue i see is that for the
most part people dont like the idea of needing to add scheduling points. So how would the kernel need to be fixed in order to not need them and still be fully preemptible like it's getting in Robert's patch. If it just cant then is it really best to hang out somewhere on the edge of preemptible multitasking because some people are in denial that the kernel needs to be patched so much to work correctly and for the sake of single tasking performance?

Now in just my own opinion i think of linux as a multitasking kernel and as thus it should perform that function as best as possible. If you want to run a single program as fast as possible then absolutely dont run anything
else and nothing can preempt it to degrade it's performance. The fact that
you can run multiple apps and run a single program as fast as possible without degrading it's performance is a bug if those other apps (at the same priority) have to wait longer than they should if we want linux to be a multitasking kernel. Just to sum things up, if there is a way to be fully preemptible without scheduling points linux, then perhaps that should be a major focus for 2.5 instead of picking and choosing (ugly)scheduling points, but if not then the argument about them not being elegant is mute because then the kernel, itself, is far from elegant already, so what exactly are you saving?

- Formerly safemode

#345 lore raw
Quoted 6 lines · Andrea Arcangeli
Quoted 3 lines · Ed Sweetman

Ok so the medicine is worse than the disease. I take it that you only want
some key points made for rescheduling instead of the full preempt patch by
Robert. That seems logical enough. The only issue i see is that for the

Quoted 6 lines

My ideal is to have the kernel to be as low worst latency as -preempt, but without being preemptive. that's possible to achieve, I don't think we're that far.

mean latency is another matter, but I personally don't mind about mean latency and I much prefer to save cpu cycles instead.

hear hear!

The akpm patch is achieving a MUCH better latency than pure -preempt, and only has 40
or so coded preemption points instead of a few hundred (eg every spin_unlock)....

and if with 40 we can get <= 1ms then everybody will be happy; if you want, say, 50 usec
latency instead you need RTLinux anyway. With 1ms _worst case_ latency the "mean" latency
is obviously also very good.......

#346 lore raw
In reply to Ed Sweetman
Quoted 14 lines · Arjan van de Ven
Quoted 6 lines · Andrea Arcangeli
Quoted 4 lines · Ed Sweetman

Ok so the medicine is worse than the disease. I take it that you only
want some key points made for rescheduling instead of the full preempt
patch by Robert. That seems logical enough. The only issue i see is
that for the

Quoted 6 lines

My ideal is to have the kernel to be as low worst latency as -preempt, but without being preemptive. that's possible to achieve, I don't think we're that far.

mean latency is another matter, but I personally don't mind about mean latency and I much prefer to save cpu cycles instead.

Quoted 6 lines

hear hear!

The akpm patch is achieving a MUCH better latency than pure -preempt, and only has 40
or so coded preemption points instead of a few hundred (eg every spin_unlock)....

The difference is that the preemptive kernel mostly uses existing infrastructure. When SMP scalability gets better due to holding locks for a shorter time then the preemptive kernel will improve as well!

AND it can be used on a UP computer to "simulate" SMP and that should help the quality of the total code base...

This is my idea:
* Add the preemptive kernel
* "Remove" reschedule points from main kernel.
note: that reschedule points that does nothing more than test and schedule can be NOOPed since they will never trigger in a preemptive kernel...

Quoted 6 lines

and if with 40 we can get <= 1ms then everybody will be happy; if you want, say, 50 usec
latency instead you need RTLinux anyway. With 1ms _worst case_ latency the "mean" latency
is obviously also very good.......

Worst case latency... is VERY hard to prove if you rely on schedule points. Since they are typically added after the fact...
If the code suddenly end up on a road less travelled...

With preemptive kernel your worst latency is the longest held spinlock. PERIOD.
(you can of cause be delayed by an even higher priority process)
* Make sure that there are no "infinite" loops inside any spinlock.

"infinite" == over ALL or ALL/x of something since someone, somewere
will have ALL close to infinite... (infinity/x is still infinity... :-)
example code is looping through LRU list to find a victim page... once it was not infinite due to the small number of pages...

Note: that akpm patches usually hava a - "do not do this list" with known problem spots (ok, usually in a hard to break spinlocks).

/RogerL

Signature · 3 lines
Roger Larsson
Skellefteå
Sweden
#347 lore raw
In reply to Ed Sweetman
Quoted 11 lines · Arjan van de Ven
Quoted 10 lines · Andrea Arcangeli
Quoted 3 lines · Ed Sweetman

Ok so the medicine is worse than the disease. I take it that you only want
some key points made for rescheduling instead of the full preempt patch by
Robert. That seems logical enough. The only issue i see is that for the

My ideal is to have the kernel to be as low worst latency as -preempt, but without being preemptive. that's possible to achieve, I don't think we're that far.

Quoted 6 lines
Quoted 2 lines

mean latency is another matter, but I personally don't mind about mean latency and I much prefer to save cpu cycles instead.

hear hear!

The akpm patch is achieving a MUCH better latency than pure -preempt,

Can you please point us at the benchmark results that support your claim?

Quoted 3 lines

and only has 40
or so coded preemption points instead of a few hundred (eg every spin_unlock)....

So? The cost of this is, in theory, a dec and a branch normally not taken. Robert hasn't coded it that way in the current incarnation, and personally, I'd rather see the correctness proven before the microoptimizations are done, but that's where it's going in theory. Big deal.

On the other hand, I just did a test for myself that pretty well makes up my mind about this patch. I'm typing this right now on a 64 Meg laptop with a slow disk, dma turned off. On this machine, debian apt-get dist-upgrade is essentially a DoS - once it gets to unpacking packages and configuring, for whatever reason, the machine becomes almost ununsable. Changing windows for example, can take 10-15 seconds. Updatedb, while not quite as bad, is definitely an irritant as far as interactive use goes.

With Robert's patch, the machine is a little sluggish during apt-get, but quite usable. This is a *huge* difference. And during updatedb, well, I hardly notice it's happening, except for the disk light.

So I like this patch. What was your complaint again? If you've got hard numbers and repeatable benchmarks, please trot them out.

--
Daniel

#348 lore raw
In reply to Ed Sweetman
Quoted 3 lines · Roger Larsson

The difference is that the preemptive kernel mostly uses existing infrastructure. When SMP scalability gets better due to holding locks for a shorter time then the preemptive kernel will improve as well!

Ehm. Holding locks for a shorter time is not guaranteed to improve smp scalability. In fact it can completely kill it due to cacheline pingpong effects.

Quoted 7 lines
Quoted 5 lines

and if with 40 we can get <= 1ms then everybody will be happy; if you want, say, 50 usec
latency instead you need RTLinux anyway. With 1ms _worst case_ latency the "mean" latency
is obviously also very good.......

Worst case latency... is VERY hard to prove if you rely on schedule points.

Agreed. It's "worst case" in the soft real time sence. But we've beaten the kernel quite hard during such tests....

Quoted 2 lines

With preemptive kernel your worst latency is the longest held spinlock. PERIOD.

Yes and without the same stuff akpm does that's about 80 to 90 ms right now.

Quoted 2 lines

Note: that akpm patches usually hava a - "do not do this list" with known problem spots (ok, usually in a hard to break spinlocks).

Usually in hardware related parts. Even with -preempt you'll get this. Hopefully only during hardware initialisation, but there are just cases where you need to go WAAAY too far if you want to go below, say, 5ms during device init.

#349 lore raw
In reply to Dieter Nützel
Quoted 8 lines · Daniel Phillips
Quoted 7 lines · Andrea Arcangeli
Quoted 5 lines · Daniel Phillips

BTW, I find your main argument confusing. First you don't want -preempt with CONFIG_EXERIMENTAL because it might not get wide enough testing, so you want to enable it by default in the mainline kernel, then you argue it's too risky because everybody will use it and it might break some obscure driver. Sorry, you lost me back there.

Quoted 4 lines
Quoted 2 lines

the point I am making is very simple: _if_ we include it, it should _not_ be a config option.

That doesn't make any sense to me. Why should _SMP be a config option and not

getting the drivers tested with preempt enable makes lots of sense to me.

Quoted 1 line

_PREEMPT?

SMP in 2.1 wasn't a config option.

Andrea

#350 lore raw
In reply to Dieter Nützel
Quoted 3 lines · Ed Sweetman

Ok so the medicine is worse than the disease. I take it that you only want
some key points made for rescheduling instead of the full preempt patch by
Robert. That seems logical enough. The only issue i see is that for the

My ideal is to have the kernel to be as low worst latency as -preempt, but without being preemptive. that's possible to achieve, I don't think we're that far.

mean latency is another matter, but I personally don't mind about mean latency and I much prefer to save cpu cycles instead.

Andrea