• Joe Thornber's avatar
    dm cache: add stochastic-multi-queue (smq) policy · 66a63635
    Joe Thornber authored
    The stochastic-multi-queue (smq) policy addresses some of the problems
    with the current multiqueue (mq) policy.
    
    Memory usage
    ------------
    
    The mq policy uses a lot of memory; 88 bytes per cache block on a 64
    bit machine.
    
    SMQ uses 28bit indexes to implement it's data structures rather than
    pointers.  It avoids storing an explicit hit count for each block.  It
    has a 'hotspot' queue rather than a pre cache which uses a quarter of
    the entries (each hotspot block covers a larger area than a single
    cache block).
    
    All these mean smq uses ~25bytes per cache block.  Still a lot of
    memory, but a substantial improvement nontheless.
    
    Level balancing
    ---------------
    
    MQ places entries in different levels of the multiqueue structures
    based on their hit count (~ln(hit count)).  This means the bottom
    levels generally have the most entries, and the top ones have very
    few.  Having unbalanced levels like this reduces the efficacy of the
    multiqueue.
    
    SMQ does not maintain a hit count, instead it swaps hit entries with
    the least recently used entry from the level above.  The over all
    ordering being a side effect of this stochastic process.  With this
    scheme we can decide how many entries occupy each multiqueue level,
    resulting in better promotion/demotion decisions.
    
    Adaptability
    ------------
    
    The MQ policy maintains a hit count for each cache block.  For a
    different block to get promoted to the cache it's hit count has to
    exceed the lowest currently in the cache.  This means it can take a
    long time for the cache to adapt between varying IO patterns.
    Periodically degrading the hit counts could help with this, but I
    haven't found a nice general solution.
    
    SMQ doesn't maintain hit counts, so a lot of this problem just goes
    away.  In addition it tracks performance of the hotspot queue, which
    is used to decide which blocks to promote.  If the hotspot queue is
    performing badly then it starts moving entries more quickly between
    levels.  This lets it adapt to new IO patterns very quickly.
    
    Performance
    -----------
    
    In my tests SMQ shows substantially better performance than MQ.  Once
    this matures a bit more I'm sure it'll become the default policy.
    Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
    Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
    66a63635
dm-cache-policy-smq.c 39.3 KB