5.2.1 switch Policy

By default, the principal buffer has a switch buffer policy. Under this policy, per-CPU buffers are allocated in pairs: one buffer is active and the other buffer is inactive. When a DTrace consumer attempts to read a buffer, the kernel firsts switches the inactive and active buffers. Buffer switching is done in such a manner that there is no window in which tracing data may be lost. Once the buffers are switched, the newly inactive buffer is copied out to the DTrace consumer. This policy assures that the consumer always sees a self-consistent buffer: a buffer is never simultaneously traced to and copied out. This technique also avoids introducing a window in which tracing is paused or otherwise prevented. The rate at which the buffer is switched and read out is controlled by the consumer with the switchrate option. As with any rate option, switchrate may be specified with any time suffix, but defaults to rate-per-second. For more details on switchrate and other options, see Chapter 10, Options and Tunables.

Under the switch policy, if a given enabled probe would trace more data than there is space available in the active principal buffer, the data is dropped and a per-CPU drop count is incremented. In the event of one or more drops, dtrace displays a message similar to the following example:

dtrace: 11 drops on CPU 0

If a given record is larger than the total buffer size, the record is dropped regardless of buffer policy. You can reduce or eliminate drops by either increasing the size of the principal buffer with the bufsize option or by increasing the switching rate with the switchrate option.

Under the switch policy, scratch space for copyin, copyinstr, and alloca is allocated out of the active buffer.