1 =============================
2 Guidance for writing policies
3 =============================
5 Try to keep transactionality out of it. The core is careful to
6 avoid asking about anything that is migrating. This is a pain, but
7 makes it easier to write the policies.
9 Mappings are loaded into the policy at construction time.
11 Every bio that is mapped by the target is referred to the policy.
12 The policy can return a simple HIT or MISS or issue a migration.
14 Currently there's no way for the policy to issue background work,
15 e.g. to start writing back dirty blocks that are going to be evicted
18 Because we map bios, rather than requests it's easy for the policy
19 to get fooled by many small bios. For this reason the core target
20 issues periodic ticks to the policy. It's suggested that the policy
21 doesn't update states (eg, hit counts) for a block more than once
22 for each tick. The core ticks by watching bios complete, and so
23 trying to see when the io scheduler has let the ios run.
26 Overview of supplied cache replacement policies
27 ===============================================
32 This policy is now an alias for smq (see below).
34 The following tunables are accepted, but have no effect::
36 'sequential_threshold <#nr_sequential_ios>'
37 'random_threshold <#nr_random_ios>'
38 'read_promote_adjustment <value>'
39 'write_promote_adjustment <value>'
40 'discard_promote_adjustment <value>'
42 Stochastic multiqueue (smq)
43 ---------------------------
45 This policy is the default.
47 The stochastic multi-queue (smq) policy addresses some of the problems
48 with the multiqueue (mq) policy.
50 The smq policy (vs mq) offers the promise of less memory utilization,
51 improved performance and increased adaptability in the face of changing
52 workloads. smq also does not have any cumbersome tuning knobs.
54 Users may switch from "mq" to "smq" simply by appropriately reloading a
55 DM table that is using the cache target. Doing so will cause all of the
56 mq policy's hints to be dropped. Also, performance of the cache may
57 degrade slightly until smq recalculates the origin device's hotspots
58 that should be cached.
63 The mq policy used a lot of memory; 88 bytes per cache block on a 64
66 smq uses 28bit indexes to implement its data structures rather than
67 pointers. It avoids storing an explicit hit count for each block. It
68 has a 'hotspot' queue, rather than a pre-cache, which uses a quarter of
69 the entries (each hotspot block covers a larger area than a single
72 All this means smq uses ~25bytes per cache block. Still a lot of
73 memory, but a substantial improvement nonetheless.
78 mq placed entries in different levels of the multiqueue structures
79 based on their hit count (~ln(hit count)). This meant the bottom
80 levels generally had the most entries, and the top ones had very
81 few. Having unbalanced levels like this reduced the efficacy of the
84 smq does not maintain a hit count, instead it swaps hit entries with
85 the least recently used entry from the level above. The overall
86 ordering being a side effect of this stochastic process. With this
87 scheme we can decide how many entries occupy each multiqueue level,
88 resulting in better promotion/demotion decisions.
91 The mq policy maintained a hit count for each cache block. For a
92 different block to get promoted to the cache its hit count has to
93 exceed the lowest currently in the cache. This meant it could take a
94 long time for the cache to adapt between varying IO patterns.
96 smq doesn't maintain hit counts, so a lot of this problem just goes
97 away. In addition it tracks performance of the hotspot queue, which
98 is used to decide which blocks to promote. If the hotspot queue is
99 performing badly then it starts moving entries more quickly between
100 levels. This lets it adapt to new IO patterns very quickly.
105 Testing smq shows substantially better performance than mq.
110 The cleaner writes back all dirty blocks in a cache to decommission it.
115 The syntax for a table is::
117 cache <metadata dev> <cache dev> <origin dev> <block size>
118 <#feature_args> [<feature arg>]*
119 <policy> <#policy_args> [<policy arg>]*
121 The syntax to send a message using the dmsetup command is::
123 dmsetup message <mapped device> 0 sequential_threshold 1024
124 dmsetup message <mapped device> 0 random_threshold 8
128 dmsetup create blah --table "0 268435456 cache /dev/sdb /dev/sdc \
129 /dev/sdd 512 0 mq 4 sequential_threshold 1024 random_threshold 8"
130 creates a 128GB large mapped device named 'blah' with the
131 sequential threshold set to 1024 and the random_threshold set to 8.