{"id":2248,"date":"2016-04-30T01:01:54","date_gmt":"2016-04-29T23:01:54","guid":{"rendered":"http:\/\/possiblelossofprecision.net\/?p=2248"},"modified":"2021-05-15T11:46:37","modified_gmt":"2021-05-15T09:46:37","slug":"creating-a-zfs-pool-on-ram-backed-block-devices","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=2248","title":{"rendered":"Creating a zfs pool on RAM backed block devices"},"content":{"rendered":"<p>Especially for performance benchmarks it can be quite handy to have a zfs pool that&#8217;s not limited by the speed of the underlying hard drives or other block devices (like <a href=\"http:\/\/en.wikipedia.org\/wiki\/ISCSI\">iSCSI<\/a> or <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fibre_Channel\">fibre channel<\/a>). The Linux kernel has a nice <a href=\"http:\/\/lxr.free-electrons.com\/source\/drivers\/block\/brd.c\">block device driver<\/a> that let&#8217;s you create virtual block devices that are RAM backed. To list the available options, use <code>modinfo<\/code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# modinfo brd\r\n&#x5B;...]\r\nparm:           rd_nr:Maximum number of brd devices (int)\r\nparm:           rd_size:Size of each RAM disk in kbytes. (int)\r\nparm:           max_part:Num Minors to reserve between devices (int)\r\n<\/pre>\n<p>To create <strong>three<\/strong> virtual block devices with a size of <strong>2GiB<\/strong> each for example, load the <code>brd<\/code> module with the following options<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# modprobe brd rd_nr=3 rd_size=2097152\r\n<\/pre>\n<p>which will create three devices named <code>\/dev\/ramN<\/code>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# ls -lah \/dev\/ram*\r\nbrw-rw---- 1 root disk 1, 0 Apr 30 00:34 \/dev\/ram0\r\nbrw-rw---- 1 root disk 1, 1 Apr 30 00:34 \/dev\/ram1\r\nbrw-rw---- 1 root disk 1, 2 Apr 30 00:34 \/dev\/ram2\r\n<\/pre>\n<p>Note that the default value for the <code>rd_nr<\/code> parameter is <strong>16<\/strong>, which would result in 16 <code>\/dev\/ramN<\/code> devices being created. However, the memory is still available until those virtual block devices are actually used.<\/p>\n<p>Creating a zfs pool on these RAM backed block devices works just as with any other block device:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# zpool create tank ram0 ram1 ram2\r\n# zpool status\r\n  pool: tank\r\n state: ONLINE\r\n  scan: none requested\r\nconfig:\r\n\r\n        NAME        STATE     READ WRITE CKSUM\r\n        tank        ONLINE       0     0     0\r\n          ram0      ONLINE       0     0     0\r\n          ram1      ONLINE       0     0     0\r\n          ram2      ONLINE       0     0     0\r\n\r\nerrors: No known data errors\r\n\r\n# zpool list\r\nNAME   SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT\r\ntank  5,95G   224K  5,95G         -     0%     0%  1.00x  ONLINE  -\r\n<\/pre>\n<p>Reading from and writing to a filesystem on this RAM backed pool should be quite fast<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# zfs create tank\/fs\r\n# dd if=\/dev\/zero of=\/tank\/fs\/testfile.img bs=1M count=5k\r\n5120+0 records in\r\n5120+0 records out\r\n5368709120 bytes (5,4 GB) copied, 2,51519 s, 2,1 GB\/s\r\n<\/pre>\n<p>Since the actual performance (throughput as well as IOPS) is heavily depending on the actual hardware, your mileage may vary here, of course. Please also keep in mind that writing zeros to a file with <code>dd<\/code> is a quick and easy way to get a first ballpark number, it is not a proper performance benchmark however. You might want to have a look at <a href=\"http:\/\/www.coker.com.au\/bonnie++\/\">bonnie++<\/a> et al. for that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Especially for performance benchmarks it can be quite handy to have a zfs pool that&#8217;s not limited by the speed of the underlying hard drives or other block devices (like iSCSI or fibre channel). The Linux kernel has a nice block device driver that let&#8217;s you create virtual block devices that are RAM backed. To list the available options, use&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=2248\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[76,75],"class_list":["post-2248","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-linux","tag-zfs"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2248"}],"version-history":[{"count":6,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2248\/revisions"}],"predecessor-version":[{"id":2254,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2248\/revisions\/2254"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}