blob: 66c2774c0c64c0e8bf3a9aadc2a6f1b8102b5a12 [file] [log] [blame]
Joe Thornberf2836352013-03-01 22:45:51 +00001Guidance for writing policies
2=============================
3
4Try to keep transactionality out of it. The core is careful to
5avoid asking about anything that is migrating. This is a pain, but
6makes it easier to write the policies.
7
8Mappings are loaded into the policy at construction time.
9
10Every bio that is mapped by the target is referred to the policy.
11The policy can return a simple HIT or MISS or issue a migration.
12
13Currently there's no way for the policy to issue background work,
14e.g. to start writing back dirty blocks that are going to be evicte
15soon.
16
17Because we map bios, rather than requests it's easy for the policy
18to get fooled by many small bios. For this reason the core target
19issues periodic ticks to the policy. It's suggested that the policy
20doesn't update states (eg, hit counts) for a block more than once
21for each tick. The core ticks by watching bios complete, and so
22trying to see when the io scheduler has let the ios run.
23
24
25Overview of supplied cache replacement policies
26===============================================
27
28multiqueue
29----------
30
31This policy is the default.
32
Joe Thornber01911c12013-10-24 14:10:28 -040033The multiqueue policy has three sets of 16 queues: one set for entries
34waiting for the cache and another two for those in the cache (a set for
35clean entries and a set for dirty entries).
36
Joe Thornberf2836352013-03-01 22:45:51 +000037Cache entries in the queues are aged based on logical time. Entry into
38the cache is based on variable thresholds and queue selection is based
39on hit count on entry. The policy aims to take different cache miss
40costs into account and to adjust to varying load patterns automatically.
41
42Message and constructor argument pairs are:
Joe Thornber78e03d62013-12-09 12:53:05 +000043 'sequential_threshold <#nr_sequential_ios>'
44 'random_threshold <#nr_random_ios>'
45 'read_promote_adjustment <value>'
46 'write_promote_adjustment <value>'
47 'discard_promote_adjustment <value>'
Joe Thornberf2836352013-03-01 22:45:51 +000048
49The sequential threshold indicates the number of contiguous I/Os
50required before a stream is treated as sequential. The random threshold
51is the number of intervening non-contiguous I/Os that must be seen
52before the stream is treated as random again.
53
54The sequential and random thresholds default to 512 and 4 respectively.
55
56Large, sequential ios are probably better left on the origin device
57since spindles tend to have good bandwidth. The io_tracker counts
58contiguous I/Os to try to spot when the io is in one of these sequential
59modes.
60
Joe Thornber78e03d62013-12-09 12:53:05 +000061Internally the mq policy maintains a promotion threshold variable. If
62the hit count of a block not in the cache goes above this threshold it
63gets promoted to the cache. The read, write and discard promote adjustment
64tunables allow you to tweak the promotion threshold by adding a small
65value based on the io type. They default to 4, 8 and 1 respectively.
66If you're trying to quickly warm a new cache device you may wish to
67reduce these to encourage promotion. Remember to switch them back to
68their defaults after the cache fills though.
69
Heinz Mauelshagen8735a812013-03-01 22:45:52 +000070cleaner
71-------
72
73The cleaner writes back all dirty blocks in a cache to decommission it.
74
Joe Thornberf2836352013-03-01 22:45:51 +000075Examples
76========
77
78The syntax for a table is:
79 cache <metadata dev> <cache dev> <origin dev> <block size>
80 <#feature_args> [<feature arg>]*
81 <policy> <#policy_args> [<policy arg>]*
82
83The syntax to send a message using the dmsetup command is:
84 dmsetup message <mapped device> 0 sequential_threshold 1024
85 dmsetup message <mapped device> 0 random_threshold 8
86
87Using dmsetup:
88 dmsetup create blah --table "0 268435456 cache /dev/sdb /dev/sdc \
89 /dev/sdd 512 0 mq 4 sequential_threshold 1024 random_threshold 8"
90 creates a 128GB large mapped device named 'blah' with the
91 sequential threshold set to 1024 and the random_threshold set to 8.