Skip to content

Conversation

edwintorok
Copy link
Contributor

Polling mode is a performance optimization in tapdisk, where it would busy poll the PV ring for the next request, instead of going to sleep and waiting for an event channel to wake it up when the next request arrives. When the guest supplies us with a steady sequence of IO requests this is quicker (it avoids a lot of syscalls), at the expense of consuming more Dom0 CPU.
Once polling mode is entered if there are no requests for polling-duration microseconds, then polling mode is exited.

The wakeup granularity is 4ms on the 4.19 kernel (which also matches CONFIG_HZ=250).
The default polling duration is 1ms, but we may not be able to reliably handle such low timeouts.
On newer kernels we seem to hit the 1ms polling duration timeout all the time, which results in tapdisk entering and exiting polling mode very often. This is in fact a lot slower than just staying in event mode, or permanently staying in polling mode when measured with a Phoronix SQLite benchmark.

Testing showed that a 6ms value results in good benchmark results (~40% faster than the default event based), and a 3ms value in bad benchmark results (50% slower than event based).

Increase the default polling duration to be a multiple of the wakeup granularity on 4.19, which should work with both 4.19 kernels and newer.

Eventually we should measure what is the optimal value where the overhead of entering/exiting polling mode is no longer greater than staying in event mode. (This is similar to how entering and exiting C modes need to take into account enter and latencies, except in this case those latencies are not known).

Polling mode is a performance optimization in tapdisk, where it would busy poll
the PV ring for the next request, instead of going to sleep and waiting for an
event channel to wake it up when the next request arrives.
When the guest supplies us with a steady sequence of IO requests this is
quicker (it avoids a lot of syscalls), at the expense of consuming more Dom0
CPU.
Once polling mode is entered if there are no requests for polling-duration
microseconds, then polling mode is exited.

The wakeup granularity is 4ms on the 4.19 kernel (which also matches
CONFIG_HZ=250).
The default polling duration is 1ms, but we may not be able to reliably handle
such low timeouts.
On newer kernels we seem to hit the 1ms polling duration timeout all the time,
which results in tapdisk entering and exiting polling mode very often.
This is in fact a lot slower than just staying in event mode, or permanently
staying in polling mode when measured with a Phoronix SQLite benchmark.

Testing showed that a 6ms value results in good benchmark results (~40% faster
than the default event based), and a 3ms value in bad benchmark results (50% slower than event based).

Increase the default polling duration to be a multiple of the wakeup granularity on 4.19,
which should work with both 4.19 kernels and newer.

Eventually we should measure what is the optimal value where the overhead of
entering/exiting polling mode is no longer greater than staying in event mode.
(This is similar to how entering and exiting C modes need to take into account
enter and latencies, except in this case those latencies are not known).

Signed-off-by: Edwin Török <[email protected]>
@edwintorok
Copy link
Contributor Author

The tapdisk change is in xapi-project/blktap#429, although this can go in ahead of that one (if tapdisk never enter polling mode due to the bug with newer kernels, then the change here has no effect)

@edwintorok edwintorok added this pull request to the merge queue Aug 4, 2025
Merged via the queue into xapi-project:master with commit ebeb717 Aug 4, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants