~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/admin-guide/device-mapper/cache-policies.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 =============================
  2 Guidance for writing policies
  3 =============================
  4 
  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.
  8 
  9 Mappings are loaded into the policy at construction time.
 10 
 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.
 13 
 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
 16 soon.
 17 
 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.
 24 
 25 
 26 Overview of supplied cache replacement policies
 27 ===============================================
 28 
 29 multiqueue (mq)
 30 ---------------
 31 
 32 This policy is now an alias for smq (see below).
 33 
 34 The 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 
 42 Stochastic multiqueue (smq)
 43 ---------------------------
 44 
 45 This policy is the default.
 46 
 47 The stochastic multi-queue (smq) policy addresses some of the problems
 48 with the multiqueue (mq) policy.
 49 
 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.
 53 
 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.
 59 
 60 Memory usage
 61 ^^^^^^^^^^^^
 62 
 63 The mq policy used a lot of memory; 88 bytes per cache block on a 64
 64 bit machine.
 65 
 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
 70 cache block).
 71 
 72 All this means smq uses ~25bytes per cache block.  Still a lot of
 73 memory, but a substantial improvement nonetheless.
 74 
 75 Level balancing
 76 ^^^^^^^^^^^^^^^
 77 
 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
 82 multiqueue.
 83 
 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.
 89 
 90 Adaptability:
 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.
 95 
 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.
101 
102 Performance
103 ^^^^^^^^^^^
104 
105 Testing smq shows substantially better performance than mq.
106 
107 cleaner
108 -------
109 
110 The cleaner writes back all dirty blocks in a cache to decommission it.
111 
112 Examples
113 ========
114 
115 The 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 
121 The syntax to send a message using the dmsetup command is::
122 
123         dmsetup message <mapped device> 0 sequential_threshold 1024
124         dmsetup message <mapped device> 0 random_threshold 8
125 
126 Using 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 the
131         sequential threshold set to 1024 and the random_threshold set to 8.

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php