Skip to content

Commit 9d1b404

Browse files
jthornbersnitm
authored andcommitted
dm cache policy smq: distribute entries to random levels when switching to smq
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 <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 4e781b4 commit 9d1b404

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/md/dm-cache-policy-smq.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,11 @@ static void smq_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
13591359
spin_unlock_irqrestore(&mq->lock, flags);
13601360
}
13611361

1362+
static unsigned random_level(dm_cblock_t cblock)
1363+
{
1364+
return hash_32_generic(from_cblock(cblock), 9) & (NR_CACHE_LEVELS - 1);
1365+
}
1366+
13621367
static int smq_load_mapping(struct dm_cache_policy *p,
13631368
dm_oblock_t oblock, dm_cblock_t cblock,
13641369
uint32_t hint, bool hint_valid)
@@ -1369,7 +1374,7 @@ static int smq_load_mapping(struct dm_cache_policy *p,
13691374
e = alloc_particular_entry(&mq->cache_alloc, from_cblock(cblock));
13701375
e->oblock = oblock;
13711376
e->dirty = false; /* this gets corrected in a minute */
1372-
e->level = hint_valid ? min(hint, NR_CACHE_LEVELS - 1) : 1;
1377+
e->level = hint_valid ? min(hint, NR_CACHE_LEVELS - 1) : random_level(cblock);
13731378
push(mq, e);
13741379

13751380
return 0;

0 commit comments

Comments
 (0)