132 lines · plain
1=============================2Guidance for writing policies3=============================4 5Try to keep transactionality out of it. The core is careful to6avoid asking about anything that is migrating. This is a pain, but7makes it easier to write the policies.8 9Mappings are loaded into the policy at construction time.10 11Every bio that is mapped by the target is referred to the policy.12The policy can return a simple HIT or MISS or issue a migration.13 14Currently there's no way for the policy to issue background work,15e.g. to start writing back dirty blocks that are going to be evicted16soon.17 18Because we map bios, rather than requests it's easy for the policy19to get fooled by many small bios. For this reason the core target20issues periodic ticks to the policy. It's suggested that the policy21doesn't update states (eg, hit counts) for a block more than once22for each tick. The core ticks by watching bios complete, and so23trying to see when the io scheduler has let the ios run.24 25 26Overview of supplied cache replacement policies27===============================================28 29multiqueue (mq)30---------------31 32This policy is now an alias for smq (see below).33 34The following tunables are accepted, but have no effect::35 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>'41 42Stochastic multiqueue (smq)43---------------------------44 45This policy is the default.46 47The stochastic multi-queue (smq) policy addresses some of the problems48with the multiqueue (mq) policy.49 50The smq policy (vs mq) offers the promise of less memory utilization,51improved performance and increased adaptability in the face of changing52workloads. smq also does not have any cumbersome tuning knobs.53 54Users may switch from "mq" to "smq" simply by appropriately reloading a55DM table that is using the cache target. Doing so will cause all of the56mq policy's hints to be dropped. Also, performance of the cache may57degrade slightly until smq recalculates the origin device's hotspots58that should be cached.59 60Memory usage61^^^^^^^^^^^^62 63The mq policy used a lot of memory; 88 bytes per cache block on a 6464bit machine.65 66smq uses 28bit indexes to implement its data structures rather than67pointers. It avoids storing an explicit hit count for each block. It68has a 'hotspot' queue, rather than a pre-cache, which uses a quarter of69the entries (each hotspot block covers a larger area than a single70cache block).71 72All this means smq uses ~25bytes per cache block. Still a lot of73memory, but a substantial improvement nonetheless.74 75Level balancing76^^^^^^^^^^^^^^^77 78mq placed entries in different levels of the multiqueue structures79based on their hit count (~ln(hit count)). This meant the bottom80levels generally had the most entries, and the top ones had very81few. Having unbalanced levels like this reduced the efficacy of the82multiqueue.83 84smq does not maintain a hit count, instead it swaps hit entries with85the least recently used entry from the level above. The overall86ordering being a side effect of this stochastic process. With this87scheme we can decide how many entries occupy each multiqueue level,88resulting in better promotion/demotion decisions.89 90Adaptability:91The mq policy maintained a hit count for each cache block. For a92different block to get promoted to the cache its hit count has to93exceed the lowest currently in the cache. This meant it could take a94long time for the cache to adapt between varying IO patterns.95 96smq doesn't maintain hit counts, so a lot of this problem just goes97away. In addition it tracks performance of the hotspot queue, which98is used to decide which blocks to promote. If the hotspot queue is99performing badly then it starts moving entries more quickly between100levels. This lets it adapt to new IO patterns very quickly.101 102Performance103^^^^^^^^^^^104 105Testing smq shows substantially better performance than mq.106 107cleaner108-------109 110The cleaner writes back all dirty blocks in a cache to decommission it.111 112Examples113========114 115The syntax for a table is::116 117 cache <metadata dev> <cache dev> <origin dev> <block size>118 <#feature_args> [<feature arg>]*119 <policy> <#policy_args> [<policy arg>]*120 121The syntax to send a message using the dmsetup command is::122 123 dmsetup message <mapped device> 0 sequential_threshold 1024124 dmsetup message <mapped device> 0 random_threshold 8125 126Using dmsetup::127 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 the131 sequential threshold set to 1024 and the random_threshold set to 8.132