• Dave Chinner's avatar
    xfs: rework per-iclog header CIL reservation · 31151cc3
    Dave Chinner authored
    For every iclog that a CIL push will use up, we need to ensure we
    have space reserved for the iclog header in each iclog. It is
    extremely difficult to do this accurately with a per-cpu counter
    without expensive summing of the counter in every commit. However,
    we know what the maximum CIL size is going to be because of the
    hard space limit we have, and hence we know exactly how many iclogs
    we are going to need to write out the CIL.
    
    We are constrained by the requirement that small transactions only
    have reservation space for a single iclog header built into them.
    At commit time we don't know how much of the current transaction
    reservation is made up of iclog header reservations as calculated by
    xfs_log_calc_unit_res() when the ticket was reserved. As larger
    reservations have multiple header spaces reserved, we can steal
    more than one iclog header reservation at a time, but we only steal
    the exact number needed for the given log vector size delta.
    
    As a result, we don't know exactly when we are going to steal iclog
    header reservations, nor do we know exactly how many we are going to
    need for a given CIL.
    
    To make things simple, start by calculating the worst case number of
    iclog headers a full CIL push will require. Record this into an
    atomic variable in the CIL. Then add a byte counter to the log
    ticket that records exactly how much iclog header space has been
    reserved in this ticket by xfs_log_calc_unit_res(). This tells us
    exactly how much space we can steal from the ticket at transaction
    commit time.
    
    Now, at transaction commit time, we can check if the CIL has a full
    iclog header reservation and, if not, steal the entire reservation
    the current ticket holds for iclog headers. This minimises the
    number of times we need to do atomic operations in the fast path,
    but still guarantees we get all the reservations we need.
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    31151cc3
xfs_log_cil.c 51.7 KB