• Andreas Gruenbacher's avatar
    gfs2: Revise glock reference counting model · 767fd5a0
    Andreas Gruenbacher authored
    In the current glock reference counting model, a bias of one is added to
    a glock's refcount when it is locked (gl->gl_state != LM_ST_UNLOCKED).
    A glock is removed from the lru_list when it is enqueued, and added back
    when it is dequeued.  This isn't a very appropriate model because most
    glocks are held for long periods of time (for example, the inode "owns"
    references to its inode and iopen glocks as long as the inode is cached
    even when the glock state changes to LM_ST_UNLOCKED), and they can only
    be freed when they are no longer referenced, anyway.
    
    Fix this by getting rid of the refcount bias for locked glocks.  That
    way, we can use lockref_put_or_lock() to efficiently drop all but the
    last glock reference, and put the glock onto the lru_list when the last
    reference is dropped.  When find_insert_glock() returns a reference to a
    cached glock, it removes the glock from the lru_list.
    
    Dumping the "glocks" and "glstats" debugfs files also takes glock
    references, but instead of removing the glocks from the lru_list in that
    case as well, we leave them on the list.  This ensures that dumping
    those files won't perturb the order of the glocks on the lru_list.
    
    In addition, when the last reference to an *unlocked* glock is dropped,
    we immediately free it; this preserves the preexisting behavior.  If it
    later turns out that caching unlocked glocks is useful in some
    situations, we can change the caching strategy.
    
    It is currently unclear if a glock that has no active references can
    have the GLF_LFLUSH flag set.  To make sure that such a glock won't
    accidentally be evicted due to memory pressure, we add a GLF_LFLUSH
    check to gfs2_dispose_glock_lru().
    Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
    767fd5a0
super.c 39.5 KB