dm cache policy smq: distribute entries to random levels when switching to smq
authorJoe Thornber <ejt@redhat.com>
Thu, 15 Sep 2016 13:36:24 +0000 (09:36 -0400)
committerMike Snitzer <snitzer@redhat.com>
Thu, 22 Sep 2016 15:15:03 +0000 (11:15 -0400)
For smq the 32 bit 'hint' stores the multiqueue level that the entry
should be stored in.  If a different policy has been used previously,
and then switched to smq, the hints will be invalid.  In which case we
used to put all entries in the bottom level of the multiqueue, and then
redistribute.  Redistribution is faster if we put entries with invalid
hints in random levels initially.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-cache-policy-smq.c

index f3cec4e6333ccf8f6ddf2542a5cdfd272e50a0a9..c33f4a6e1d7d087a086b492a3b3cc61d13049acd 100644 (file)
@@ -1359,6 +1359,11 @@ static void smq_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
        spin_unlock_irqrestore(&mq->lock, flags);
 }
 
+static unsigned random_level(dm_cblock_t cblock)
+{
+       return hash_32_generic(from_cblock(cblock), 9) & (NR_CACHE_LEVELS - 1);
+}
+
 static int smq_load_mapping(struct dm_cache_policy *p,
                            dm_oblock_t oblock, dm_cblock_t cblock,
                            uint32_t hint, bool hint_valid)
@@ -1369,7 +1374,7 @@ static int smq_load_mapping(struct dm_cache_policy *p,
        e = alloc_particular_entry(&mq->cache_alloc, from_cblock(cblock));
        e->oblock = oblock;
        e->dirty = false;       /* this gets corrected in a minute */
-       e->level = hint_valid ? min(hint, NR_CACHE_LEVELS - 1) : 1;
+       e->level = hint_valid ? min(hint, NR_CACHE_LEVELS - 1) : random_level(cblock);
        push(mq, e);
 
        return 0;