• Dave Chinner's avatar
    xfs: implement percpu cil space used calculation · 7c8ade21
    Dave Chinner authored
    Now that we have the CIL percpu structures in place, implement the
    space used counter as a per-cpu counter.
    
    We have to be really careful now about ensuring that the checks and
    updates run without arbitrary delays, which means they need to run
    with pre-emption disabled. We do this by careful placement of
    the get_cpu_ptr/put_cpu_ptr calls to access the per-cpu structures
    for that CPU.
    
    We need to be able to reliably detect that the CIL has reached
    the hard limit threshold so we can take extra reservations for the
    iclog headers when the space used overruns the original reservation.
    hence we factor out xlog_cil_over_hard_limit() from
    xlog_cil_push_background().
    
    The global CIL space used is an atomic variable that is backed by
    per-cpu aggregation to minimise the number of atomic updates we do
    to the global state in the fast path. While we are under the soft
    limit, we aggregate only when the per-cpu aggregation is over the
    proportion of the soft limit assigned to that CPU. This means that
    all CPUs can use all but one byte of their aggregation threshold
    and we will not go over the soft limit.
    
    Hence once we detect that we've gone over both a per-cpu aggregation
    threshold and the soft limit, we know that we have only
    exceeded the soft limit by one per-cpu aggregation threshold. Even
    if all CPUs hit this at the same time, we can't be over the hard
    limit, so we can run an aggregation back into the atomic counter
    at this point and still be under the hard limit.
    
    At this point, we will be over the soft limit and hence we'll
    aggregate into the global atomic used space directly rather than the
    per-cpu counters, hence providing accurate detection of hard limit
    excursion for accounting and reservation purposes.
    
    Hence we get the best of both worlds - lockless, scalable per-cpu
    fast path plus accurate, atomic detection of hard limit excursion.
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    7c8ade21
xfs_log_cil.c 55.8 KB