• Dave Chinner's avatar
    xfs: active perag reference counting · c4d5660a
    Dave Chinner authored
    We need to be able to dynamically remove instantiated AGs from
    memory safely, either for shrinking the filesystem or paging AG
    state in and out of memory (e.g. supporting millions of AGs). This
    means we need to be able to safely exclude operations from accessing
    perags while dynamic removal is in progress.
    
    To do this, introduce the concept of active and passive references.
    Active references are required for high level operations that make
    use of an AG for a given operation (e.g. allocation) and pin the
    perag in memory for the duration of the operation that is operating
    on the perag (e.g. transaction scope). This means we can fail to get
    an active reference to an AG, hence callers of the new active
    reference API must be able to handle lookup failure gracefully.
    
    Passive references are used in low level code, where we might need
    to access the perag structure for the purposes of completing high
    level operations. For example, buffers need to use passive
    references because:
    - we need to be able to do metadata IO during operations like grow
      and shrink transactions where high level active references to the
      AG have already been blocked
    - buffers need to pin the perag until they are reclaimed from
      memory, something that high level code has no direct control over.
    - unused cached buffers should not prevent a shrink from being
      started.
    
    Hence we have active references that will form exclusion barriers
    for operations to be performed on an AG, and passive references that
    will prevent reclaim of the perag until all objects with passive
    references have been reclaimed themselves.
    
    This patch introduce xfs_perag_grab()/xfs_perag_rele() as the API
    for active AG reference functionality. We also need to convert the
    for_each_perag*() iterators to use active references, which will
    start the process of converting high level code over to using active
    references. Conversion of non-iterator based code to active
    references will be done in followup patches.
    
    Note that the implementation using reference counting is really just
    a development vehicle for the API to ensure we don't have any leaks
    in the callers. Once we need to remove perag structures from memory
    dyanmically, we will need a much more robust per-ag state transition
    mechanism for preventing new references from being taken while we
    wait for existing references to drain before removal from memory can
    occur....
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarAllison Henderson <allison.henderson@oracle.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    c4d5660a
bmap.c 22.3 KB