What is the PREEMPTION option good for?



PREEMPTION may be needed for correctness, including for very low latency
switching to high priority tasks, but it is a pessimization for most
things that I tried (mainly makeworld), and the details of the
pessimizations indicate that it doesn't actually give correctness either.

Makeworld in a certain SMP configuration here takes 853+-5 seconds without
PREEMPTION or IPI_PREEMPTION, and 863+-5 seconds with PREEMPTION and
IPI_PREEMPTION (both without KSE; KSE gives another pessimization in
the 5-10 second range).

Most of the difference is caused by pgzero becoming too active with
PREEMPTION. The behaviour with PREEMPTION under SMP is similar to
that under both UP and SMP when the PREEMPTION ifdef was first added
to vm_zeroidle.c a couple of years ago. pgzero is active for about 3
times as long (18 seconds instead of 6 for my current makeworld
benchmark. This reduces the reported system time by even more than
the extra time spent in pagezero, but for some reason (probably cache
thrashing, though pgzero uses nontemporal writes on the benchmark
machine) it increases the real time by about the same amount as the
extra time spent in pgzero.

A couple of years ago, pgzero did this even for !SMP because it had a
very broken priority so it rarely (never?) got preempted. Now its
preemption is broken similarly under SMP with PREEMPTION but without
IPI_PREEMPTION, since it takes an IPI to preempt it in many cases.
Its code is:

% for (;;) {
% if (vm_page_zero_check()) {
% vm_page_zero_idle();
% #ifndef PREEMPTION
% if (sched_runnable()) {
% mtx_lock_spin(&sched_lock);
% mi_switch(SW_VOL, NULL);
% mtx_unlock_spin(&sched_lock);
% }
% #endif

without PREEMPTION, it yields voluntarily, and this works fine. With
PREEMPTION and !SMP, it gets preempted, and this works not so fine (it
has slightly higher overheads). With PREEMPTION and SMP and >1 CPU
but no IPI_PREEMPTION, this cannot work, and even with IPI_PREEMPTION
it doesn't work now in practice (IPI_PREEMPTION gives a small pessimization
due to more context switches without significantly affecting the time
spent in pgzero).

If PREEMPTION should actually be best here, why doesn't the main idle
thread depend on it?

Does anyone have an example where PREEMPTION makes a useful difference?

Bruce
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • [patch] preempt-smp.patch, 2.6.8-rc3-mm2
    ... > SMP issues in a sufficient way. ... It does the loop counting within ... the loop counter every time we disable preemption. ... this patch in essence recognizes the fact that the current preemption ...
    (Linux-Kernel)
  • Re: What is the PREEMPTION option good for?
    ... suspiciously active on heavy loaded SMP web servers (even complained on ... I'll try disabling PREEMPTION and see how it goes. ... to RELENG_4 for interrupt latency. ... interrupt priorities don't work right -- ...
    (freebsd-arch)
  • Re: question about preemption code
    ... SMP in maybe_preempt_in_ksegrp. ... #ifdef PREEMPTION ... priority is lower than PRI_MAX_ITHD. ...
    (freebsd-hackers)
  • Re: 5.2-CURRENT constantly crashing
    ... Although I'm really not sure what's causing it. ... with SMP (although I haven't seen it with SMP and no PREEMPTION). ... >> software disk write buffer. ...
    (freebsd-current)
  • Re: ArcNet and 2.6.8.1
    ... Is preemption safe enough to ensure SMP safe or would I ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)