PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/post/2014-08-16-lvcache-a-tool-for-managing-lv/index.html

https://github.com/larsks/blog.oddbit.com
HTML | 308 lines | 227 code | 80 blank | 1 comment | 0 complexity | 532cc545ad7a83178df6b0c9d76b8d93 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>lvcache: a tool for managing LVM caches &middot; The Odd Bit</title>
  7. <meta name="description" content="Until recently I had a bcache based setup on my laptop, but when forced by circumstance to reinstall everything I spent some time looking for alternatives that were less disruptive to configure on an existing system.
  8. I came across Richard Jones&#39; article discussing the recent work to integrate dm-cache into LVM. Unlike bcache and unlike using dm-cache directly, the integration with LVM makes it easy to associate devices with an existing logical volume.">
  9. <meta name="HandheldFriendly" content="True">
  10. <meta name="MobileOptimized" content="320">
  11. <meta name="generator" content="Hugo 0.88.0" />
  12. <meta name="robots" content="index,follow">
  13. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  14. <link rel="stylesheet" href="https://blog.oddbit.com/dist/style.min.81747fa30e7c939c160ea84909a818dc1b99d7e662edf55326bd32a4510c9eb5.css">
  15. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin,cyrillic-ext,latin-ext,cyrillic">
  16. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
  17. <!-- alternate output formats -->
  18. <link rel="stylesheet" href="/css/oddbit.css">
  19. <link rel="stylesheet" href="/css/sx.css">
  20. <link rel="stylesheet" href="/css/pull-request.css">
  21. <link rel="stylesheet" href="/css/archive.css">
  22. <link rel="stylesheet" href="/css/syntax.css">
  23. </head>
  24. <body>
  25. <div id="wrapper">
  26. <header class="site-header">
  27. <div class="container">
  28. <div class="site-title-wrapper">
  29. <h1 class="site-title">
  30. <a title="The Odd Bit" href="https://blog.oddbit.com/">The Odd Bit</a>
  31. </h1>
  32. <a class="button-square" href="https://blog.oddbit.com/rss.xml"><i class="fa fa-rss"></i></a>
  33. <a class="button-square button-social hint--top" data-hint="Twitter" title="Twitter" href="https://twitter.com/larsks" rel="me">
  34. <i class="fa fa-twitter"></i>
  35. </a>
  36. <a class="button-square button-social hint--top" data-hint="Github" title="Github" href="https://github.com/larsks" rel="me">
  37. <i class="fa fa-github-alt"></i>
  38. </a>
  39. <a class="button-square button-social hint--top" data-hint="Stack Overflow" title="Stack Overflow" href="https://stackoverflow.com/users/147356/larsks" rel="me">
  40. <i class="fa fa-stack-overflow"></i>
  41. </a>
  42. </div>
  43. <div class="donate">
  44. If you find something here useful or interesting, you can
  45. <a href="https://www.buymeacoffee.com/oddbit">buy me a coffee</a>!
  46. </div>
  47. <ul class="site-nav">
  48. <li class="site-nav-item">
  49. <a title="Home" href="/">Home</a>
  50. </li>
  51. <li class="site-nav-item">
  52. <a title="Categories" href="/categories">Categories</a>
  53. </li>
  54. <li class="site-nav-item">
  55. <a title="Tags" href="/tags">Tags</a>
  56. </li>
  57. <li class="site-nav-item">
  58. <a title="Archives" href="/archives">Archives</a>
  59. </li>
  60. <li class="site-nav-item">
  61. <a title="Answers" href="/about/stackoverflow/">Answers</a>
  62. </li>
  63. <li class="site-nav-item">
  64. <a title="GPG Key" href="/about/gpg/">GPG Key</a>
  65. </li>
  66. </ul>
  67. </div>
  68. </header>
  69. <div id="container">
  70. <div class="container">
  71. <article class="post-container" itemscope="" itemtype="http://schema.org/BlogPosting">
  72. <header class="post-header">
  73. <h1 class="post-title" itemprop="name headline">lvcache: a tool for managing LVM caches</h1>
  74. <p class="post-date post-line">
  75. <span>Published <time datetime="2014-08-16" itemprop="datePublished">Sat, Aug 16, 2014</time></span>
  76. <span>by</span>
  77. <span itemscope="" itemprop="author" itemtype="https://schema.org/Person">
  78. <span itemprop="name">
  79. <a href="/about/" itemprop="url" rel="author">Lars Kellogg-Stedman</a>
  80. </span>
  81. </span>
  82. </p>
  83. </header>
  84. <div class="post-content clearfix" itemprop="articleBody">
  85. <p>Until recently I had a <a href="http://bcache.evilpiepirate.org/">bcache</a> based setup on my laptop, but when
  86. forced by circumstance to reinstall everything I spent some time
  87. looking for alternatives that were less disruptive to configure on an
  88. existing system.</p>
  89. <p>I came across <a href="http://rwmj.wordpress.com/2014/05/22/using-lvms-new-cache-feature/">Richard Jones' article</a> discussing the recent work to
  90. integrate <a href="https://en.wikipedia.org/wiki/Dm-cache">dm-cache</a> into <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)">LVM</a>. Unlike <em>bcache</em> and unlike using
  91. <em>dm-cache</em> directly, the integration with LVM makes it easy to
  92. associate devices with an existing logical volume.</p>
  93. <p>I have put together a small tool called <a href="https://github.com/larsks/lvcache">lvcache</a> that simplies the
  94. process of:</p>
  95. <ul>
  96. <li>Creating and attaching cache volumes</li>
  97. <li>Detaching and removing cache volumes</li>
  98. <li>Getting cache statistics for logical volumes</li>
  99. <li>Listing the cache status of all logical volumes</li>
  100. </ul>
  101. <p>With <code>lvcache</code> installed, you can run (as root) the following command
  102. to create a new cache volume that is 20% the size of your origin
  103. volume and attach it to the specified origin volume:</p>
  104. <pre><code># lvcache create myvg/home
  105. </code></pre>
  106. <p>You can control the size of the cache LV relative to the origin
  107. volume. To create a cache LV that is 40% the size of the origin
  108. volume:</p>
  109. <pre><code># lvcache create -% 40 myvg/home
  110. </code></pre>
  111. <p>You can query <code>dm-setup</code> for cache statistics with the <code>status</code>
  112. command (the <code>-H</code> translates raw bytes counts into human readable
  113. numbers with SI suffixes):</p>
  114. <pre><code># lvcache status -H myvg/home
  115. +-----------------------+------------------+
  116. | Field | Value |
  117. +-----------------------+------------------+
  118. | cached | True |
  119. | size | 32G |
  120. | cache_lv | home_cache |
  121. | cache_lv_size | 6G |
  122. | metadata_lv | home_cache_cmeta |
  123. | metadata_lv_size | 8M |
  124. | cache_block_size | 128 |
  125. | cache_utilization | 0/98304 |
  126. | cache_utilization_pct | 0.0 |
  127. | demotions | 0 |
  128. | dirty | 0 |
  129. | end | 62914560 |
  130. | features | 1 |
  131. | md_block_size | 8 |
  132. | md_utilization | 200/2048 |
  133. | md_utilization_pct | 9.765625 |
  134. | promotions | 0 |
  135. | read_hits | 0 |
  136. | read_misses | 0 |
  137. | segment_type | cache |
  138. | start | 0 |
  139. | write_hits | 0 |
  140. | write_misses | 0 |
  141. +-----------------------+------------------+
  142. </code></pre>
  143. <p>Because <code>lvcache</code> is using the <a href="http://cliff.readthedocs.org/en/latest/">cliff</a> framework, it is very easy to
  144. extract individual values from this list for graphing or monitoring
  145. purposes:</p>
  146. <pre><code># lvcache status tank.home -f value -c md_utilization_pct
  147. 9.765625
  148. </code></pre>
  149. <p>Or:</p>
  150. <pre><code># lvcache status tank.home -f shell
  151. cached=&quot;True&quot;
  152. size=&quot;32G&quot;
  153. cache_lv=&quot;nova_cache&quot;
  154. cache_lv_size=&quot;6G&quot;
  155. metadata_lv=&quot;nova_cache_cmeta&quot;
  156. metadata_lv_size=&quot;8M&quot;
  157. cache_block_size=&quot;128&quot;
  158. cache_utilization=&quot;0/98304&quot;
  159. cache_utilization_pct=&quot;0.0&quot;
  160. demotions=&quot;0&quot;
  161. dirty=&quot;0&quot;
  162. end=&quot;62914560&quot;
  163. features=&quot;1&quot;
  164. md_block_size=&quot;8&quot;
  165. md_utilization=&quot;200/2048&quot;
  166. md_utilization_pct=&quot;9.765625&quot;
  167. promotions=&quot;0&quot;
  168. read_hits=&quot;0&quot;
  169. read_misses=&quot;0&quot;
  170. segment_type=&quot;cache&quot;
  171. start=&quot;0&quot;
  172. write_hits=&quot;0&quot;
  173. write_misses=&quot;0&quot;
  174. </code></pre>
  175. <p>This is a very rough tool right now, but it seems to get the job done
  176. on my system. If you do find this useful, let me know!</p>
  177. </div>
  178. <footer class="post-footer clearfix">
  179. <p class="post-tags">
  180. <span>Tagged:</span>
  181. <a href="https://blog.oddbit.com/tag/lvm/">lvm</a>,
  182. <a href="https://blog.oddbit.com/tag/cache/">cache</a>
  183. </p>
  184. <div class="share">
  185. <a class="icon-twitter" href="https://twitter.com/share?text=lvcache%3a%20a%20tool%20for%20managing%20LVM%20caches&url=https%3a%2f%2fblog.oddbit.com%2fpost%2f2014-08-16-lvcache-a-tool-for-managing-lv%2f"
  186. onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
  187. <i class="fa fa-twitter"></i>
  188. <span class="hidden">Twitter</span>
  189. </a>
  190. </div>
  191. </footer>
  192. <script src="https://utteranc.es/client.js"
  193. repo="larsks/blog.oddbit.com"
  194. issue-term="pathname"
  195. label="comment"
  196. theme="github-light"
  197. crossorigin="anonymous"
  198. async>
  199. </script>
  200. </article>
  201. </div>
  202. </div>
  203. </div>
  204. <footer class="footer">
  205. <div class="container">
  206. <div class="site-title-wrapper">
  207. <h1 class="site-title">
  208. <a title="The Odd Bit" href="https://blog.oddbit.com/">The Odd Bit</a>
  209. </h1>
  210. <a class="button-square button-jump-top js-jump-top" href="#">
  211. <i class="fa fa-angle-up"></i>
  212. </a>
  213. </div>
  214. <p class="footer-copyright">
  215. <span>&copy; 2022 / Powered by <a href="https://gohugo.io/">Hugo</a></span>
  216. </p>
  217. <p class="footer-copyright">
  218. <span><a href="https://github.com/roryg/ghostwriter">Ghostwriter theme</a> By <a href="http://jollygoodthemes.com">JollyGoodThemes</a></span>
  219. <span>/ <a href="https://github.com/jbub/ghostwriter">Ported</a> to Hugo By <a href="https://github.com/jbub">jbub</a></span>
  220. </p>
  221. </div>
  222. </footer>
  223. <script src="https://blog.oddbit.com/js/jquery-1.11.3.min.js"></script>
  224. <script src="https://blog.oddbit.com/js/jquery.fitvids.js"></script>
  225. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  226. <script src="https://blog.oddbit.com/js/scripts.js"></script>
  227. </body>
  228. </html>