cache-policies.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Guidance for writing policies
  2. =============================
  3. Try to keep transactionality out of it. The core is careful to
  4. avoid asking about anything that is migrating. This is a pain, but
  5. makes it easier to write the policies.
  6. Mappings are loaded into the policy at construction time.
  7. Every bio that is mapped by the target is referred to the policy.
  8. The policy can return a simple HIT or MISS or issue a migration.
  9. Currently there's no way for the policy to issue background work,
  10. e.g. to start writing back dirty blocks that are going to be evicte
  11. soon.
  12. Because we map bios, rather than requests it's easy for the policy
  13. to get fooled by many small bios. For this reason the core target
  14. issues periodic ticks to the policy. It's suggested that the policy
  15. doesn't update states (eg, hit counts) for a block more than once
  16. for each tick. The core ticks by watching bios complete, and so
  17. trying to see when the io scheduler has let the ios run.
  18. Overview of supplied cache replacement policies
  19. ===============================================
  20. multiqueue
  21. ----------
  22. This policy is the default.
  23. The multiqueue policy has three sets of 16 queues: one set for entries
  24. waiting for the cache and another two for those in the cache (a set for
  25. clean entries and a set for dirty entries).
  26. Cache entries in the queues are aged based on logical time. Entry into
  27. the cache is based on variable thresholds and queue selection is based
  28. on hit count on entry. The policy aims to take different cache miss
  29. costs into account and to adjust to varying load patterns automatically.
  30. Message and constructor argument pairs are:
  31. 'sequential_threshold <#nr_sequential_ios>' and
  32. 'random_threshold <#nr_random_ios>'.
  33. The sequential threshold indicates the number of contiguous I/Os
  34. required before a stream is treated as sequential. The random threshold
  35. is the number of intervening non-contiguous I/Os that must be seen
  36. before the stream is treated as random again.
  37. The sequential and random thresholds default to 512 and 4 respectively.
  38. Large, sequential ios are probably better left on the origin device
  39. since spindles tend to have good bandwidth. The io_tracker counts
  40. contiguous I/Os to try to spot when the io is in one of these sequential
  41. modes.
  42. cleaner
  43. -------
  44. The cleaner writes back all dirty blocks in a cache to decommission it.
  45. Examples
  46. ========
  47. The syntax for a table is:
  48. cache <metadata dev> <cache dev> <origin dev> <block size>
  49. <#feature_args> [<feature arg>]*
  50. <policy> <#policy_args> [<policy arg>]*
  51. The syntax to send a message using the dmsetup command is:
  52. dmsetup message <mapped device> 0 sequential_threshold 1024
  53. dmsetup message <mapped device> 0 random_threshold 8
  54. Using dmsetup:
  55. dmsetup create blah --table "0 268435456 cache /dev/sdb /dev/sdc \
  56. /dev/sdd 512 0 mq 4 sequential_threshold 1024 random_threshold 8"
  57. creates a 128GB large mapped device named 'blah' with the
  58. sequential threshold set to 1024 and the random_threshold set to 8.