2013-03-01 22:45:51 +00:00
|
|
|
Guidance for writing policies
|
|
|
|
=============================
|
|
|
|
|
|
|
|
Try to keep transactionality out of it. The core is careful to
|
|
|
|
avoid asking about anything that is migrating. This is a pain, but
|
|
|
|
makes it easier to write the policies.
|
|
|
|
|
|
|
|
Mappings are loaded into the policy at construction time.
|
|
|
|
|
|
|
|
Every bio that is mapped by the target is referred to the policy.
|
|
|
|
The policy can return a simple HIT or MISS or issue a migration.
|
|
|
|
|
|
|
|
Currently there's no way for the policy to issue background work,
|
2016-04-21 01:11:25 +00:00
|
|
|
e.g. to start writing back dirty blocks that are going to be evicted
|
2013-03-01 22:45:51 +00:00
|
|
|
soon.
|
|
|
|
|
|
|
|
Because we map bios, rather than requests it's easy for the policy
|
|
|
|
to get fooled by many small bios. For this reason the core target
|
|
|
|
issues periodic ticks to the policy. It's suggested that the policy
|
|
|
|
doesn't update states (eg, hit counts) for a block more than once
|
|
|
|
for each tick. The core ticks by watching bios complete, and so
|
|
|
|
trying to see when the io scheduler has let the ios run.
|
|
|
|
|
|
|
|
|
|
|
|
Overview of supplied cache replacement policies
|
|
|
|
===============================================
|
|
|
|
|
2015-06-17 15:43:38 +00:00
|
|
|
multiqueue (mq)
|
|
|
|
---------------
|
2013-03-01 22:45:51 +00:00
|
|
|
|
2016-02-10 10:18:10 +00:00
|
|
|
This policy is now an alias for smq (see below).
|
2013-03-01 22:45:51 +00:00
|
|
|
|
2016-02-10 10:18:10 +00:00
|
|
|
The following tunables are accepted, but have no effect:
|
2013-10-24 18:10:28 +00:00
|
|
|
|
2013-12-09 12:53:05 +00:00
|
|
|
'sequential_threshold <#nr_sequential_ios>'
|
|
|
|
'random_threshold <#nr_random_ios>'
|
|
|
|
'read_promote_adjustment <value>'
|
|
|
|
'write_promote_adjustment <value>'
|
|
|
|
'discard_promote_adjustment <value>'
|
2013-03-01 22:45:51 +00:00
|
|
|
|
2015-06-17 15:43:38 +00:00
|
|
|
Stochastic multiqueue (smq)
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
This policy is the default.
|
|
|
|
|
|
|
|
The stochastic multi-queue (smq) policy addresses some of the problems
|
|
|
|
with the multiqueue (mq) policy.
|
|
|
|
|
|
|
|
The smq policy (vs mq) offers the promise of less memory utilization,
|
|
|
|
improved performance and increased adaptability in the face of changing
|
2016-04-21 01:11:25 +00:00
|
|
|
workloads. smq also does not have any cumbersome tuning knobs.
|
2015-06-17 15:43:38 +00:00
|
|
|
|
|
|
|
Users may switch from "mq" to "smq" simply by appropriately reloading a
|
|
|
|
DM table that is using the cache target. Doing so will cause all of the
|
|
|
|
mq policy's hints to be dropped. Also, performance of the cache may
|
|
|
|
degrade slightly until smq recalculates the origin device's hotspots
|
|
|
|
that should be cached.
|
|
|
|
|
|
|
|
Memory usage:
|
2016-04-21 01:11:25 +00:00
|
|
|
The mq policy used a lot of memory; 88 bytes per cache block on a 64
|
2015-06-17 15:43:38 +00:00
|
|
|
bit machine.
|
|
|
|
|
2017-11-27 15:02:40 +00:00
|
|
|
smq uses 28bit indexes to implement its data structures rather than
|
2015-06-17 15:43:38 +00:00
|
|
|
pointers. It avoids storing an explicit hit count for each block. It
|
2016-04-21 01:11:25 +00:00
|
|
|
has a 'hotspot' queue, rather than a pre-cache, which uses a quarter of
|
2015-06-17 15:43:38 +00:00
|
|
|
the entries (each hotspot block covers a larger area than a single
|
|
|
|
cache block).
|
|
|
|
|
2016-04-21 01:11:25 +00:00
|
|
|
All this means smq uses ~25bytes per cache block. Still a lot of
|
2015-06-17 15:43:38 +00:00
|
|
|
memory, but a substantial improvement nontheless.
|
|
|
|
|
|
|
|
Level balancing:
|
2016-04-21 01:11:25 +00:00
|
|
|
mq placed entries in different levels of the multiqueue structures
|
|
|
|
based on their hit count (~ln(hit count)). This meant the bottom
|
|
|
|
levels generally had the most entries, and the top ones had very
|
|
|
|
few. Having unbalanced levels like this reduced the efficacy of the
|
2015-06-17 15:43:38 +00:00
|
|
|
multiqueue.
|
|
|
|
|
2016-04-21 01:11:25 +00:00
|
|
|
smq does not maintain a hit count, instead it swaps hit entries with
|
|
|
|
the least recently used entry from the level above. The overall
|
2015-06-17 15:43:38 +00:00
|
|
|
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:
|
2016-04-21 01:11:25 +00:00
|
|
|
The mq policy maintained a hit count for each cache block. For a
|
2017-11-27 15:02:40 +00:00
|
|
|
different block to get promoted to the cache its hit count has to
|
2016-04-21 01:11:25 +00:00
|
|
|
exceed the lowest currently in the cache. This meant it could take a
|
2015-06-17 15:43:38 +00:00
|
|
|
long time for the cache to adapt between varying IO patterns.
|
|
|
|
|
2016-04-21 01:11:25 +00:00
|
|
|
smq doesn't maintain hit counts, so a lot of this problem just goes
|
2015-06-17 15:43:38 +00:00
|
|
|
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:
|
2016-04-21 01:11:25 +00:00
|
|
|
Testing smq shows substantially better performance than mq.
|
2015-06-17 15:43:38 +00:00
|
|
|
|
2013-03-01 22:45:52 +00:00
|
|
|
cleaner
|
|
|
|
-------
|
|
|
|
|
|
|
|
The cleaner writes back all dirty blocks in a cache to decommission it.
|
|
|
|
|
2013-03-01 22:45:51 +00:00
|
|
|
Examples
|
|
|
|
========
|
|
|
|
|
|
|
|
The syntax for a table is:
|
|
|
|
cache <metadata dev> <cache dev> <origin dev> <block size>
|
|
|
|
<#feature_args> [<feature arg>]*
|
|
|
|
<policy> <#policy_args> [<policy arg>]*
|
|
|
|
|
|
|
|
The syntax to send a message using the dmsetup command is:
|
|
|
|
dmsetup message <mapped device> 0 sequential_threshold 1024
|
|
|
|
dmsetup message <mapped device> 0 random_threshold 8
|
|
|
|
|
|
|
|
Using dmsetup:
|
|
|
|
dmsetup create blah --table "0 268435456 cache /dev/sdb /dev/sdc \
|
|
|
|
/dev/sdd 512 0 mq 4 sequential_threshold 1024 random_threshold 8"
|
|
|
|
creates a 128GB large mapped device named 'blah' with the
|
|
|
|
sequential threshold set to 1024 and the random_threshold set to 8.
|