• Dave Chinner's avatar
    xfs: add a lru to the XFS buffer cache · 430cbeb8
    Dave Chinner authored
    Introduce a per-buftarg LRU for memory reclaim to operate on. This
    is the last piece we need to put in place so that we can fully
    control the buffer lifecycle. This allows XFS to be responsibile for
    maintaining the working set of buffers under memory pressure instead
    of relying on the VM reclaim not to take pages we need out from
    underneath us.
    
    The implementation introduces a b_lru_ref counter into the buffer.
    This is currently set to 1 whenever the buffer is referenced and so is used to
    determine if the buffer should be added to the LRU or not when freed.
    Effectively it allows lazy LRU initialisation of the buffer so we do not need
    to touch the LRU list and locks in xfs_buf_find().
    
    Instead, when the buffer is being released and we drop the last
    reference to it, we check the b_lru_ref count and if it is none zero
    we re-add the buffer reference and add the inode to the LRU. The
    b_lru_ref counter is decremented by the shrinker, and whenever the
    shrinker comes across a buffer with a zero b_lru_ref counter, if
    released the LRU reference on the buffer. In the absence of a lookup
    race, this will result in the buffer being freed.
    
    This counting mechanism is used instead of a reference flag so that
    it is simple to re-introduce buffer-type specific reclaim reference
    counts to prioritise reclaim more effectively. We still have all
    those hooks in the XFS code, so this will provide the infrastructure
    to re-implement that functionality.
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    430cbeb8
xfs_buf.h 13.7 KB