{"id":611,"date":"2015-06-13T14:24:46","date_gmt":"2015-06-13T14:24:46","guid":{"rendered":"http:\/\/www.tech-g.com\/?p=611"},"modified":"2025-02-21T15:02:09","modified_gmt":"2025-02-21T15:02:09","slug":"over-provisioning-ssd-in-linux","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2015\/06\/13\/over-provisioning-ssd-in-linux\/","title":{"rendered":"Over provisioning SSD in linux"},"content":{"rendered":"\n<p>Over provisioning a Samsung 1TB 850 EVO<\/p>\n\n\n\n<p>Mind you, Don&#8217;t follow this tutorial step by step unless you have a 1TB Samsung 850 EVO, if you have a smaller disk, you need to adapt the numbers to your SSD \ud83d\ude09<\/p>\n\n\n\n<p>Over provisioning a flash disk is simply some un-partitioned space a the end of the disk, but you need to tell the SSD&#8217;s controller about that free space that it can use to do it&#8217;s housekeeping, You also need to find out if the Tejun Heo&#8217;s on-demand HPA unlocking patch applies to your distro, if it does, you need to get kernel patching first.<\/p>\n\n\n\n<p>First of all, the controller will usually use the cache RAM to so the over provisioning, or at least this is what i understood from some text on the Samsung website, you can make things faster by allowing it to use FLASH space while it deletes a 1.5MB flash area to put the data in.<\/p>\n\n\n\n<p>1- How big should the over provisioning area be ?<\/p>\n\n\n\n<p>Samsung recommends 10% of the disk&#8217;s space. Somewhere hidden in a PDF on their websites, they explain that OP space should be anywhere between 7% and 50% ! we will use 10 as our writing patterns are not that harsh. but mind you, a database that alters a few rows every second can probably make the most use of such OP space.<\/p>\n\n\n\n<p>2- Won&#8217;t that 10% wear out before the rest ?<\/p>\n\n\n\n<p>No, there is a mapping function inside the controller where that space is in fact wherever the controller thinks is appropriate, the wear leveling algorithm kicks in at a stage after the logical stage of partitions etc&#8230; it is blind to the file system or the over provisioning area, it will simply remap any address you give it to a random address that is not already mapped, at flash erase, those mappings are deleted, and other areas of the disk will be assigned to that area, i have no idea whether it uses a random algorithm, or simply has a record of flash chip usage (At the size of the sample, that won&#8217;t make any difference.)<\/p>\n\n\n\n<p>3- Are you sure we are informing the controller and not just telling Linux what the last address is ?<\/p>\n\n\n\n<p>Sure I&#8217;m sure, ask the controller DIRECTLY yourself with the command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">smartctl -i \/dev\/sdb\n<\/pre>\n\n\n\n<p>Before the operation we are doing in this article, it will say 1000204886016, and after it will say<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">User Capacity:    900,184,411,136 bytes [900 GB]\n<\/pre>\n\n\n\n<p>Meaning that now, the disk&#8217;s S.M.A.R.T. attribute tells us that this much is available for the user after the over provisioning operation<\/p>\n\n\n\n<p>So, how do we over provision in linux<\/p>\n\n\n\n<p>See the last secrot of your ssd,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hdparm -N \/dev\/sdb\n<\/pre>\n\n\n\n<p>In my case, my samsung 850 EVO has the following, notice that the number is repeated twice. x out of x is the same, and HPA is disabled..<\/p>\n\n\n\n<p>max sectors = 1953525168\/1953525168, HPA is disabled<\/p>\n\n\n\n<p>Now, 1953525168 * 512 = 1,000,204,886,016 (1 TB !)<\/p>\n\n\n\n<p>Now, we want to set a maximum address, anything after this address is a PROTECTED AREA, that the controller knows about, I will multiply the number above with 0.9 to get the maximum address, take the integer part alone<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hdparm -Np1758172678 --yes-i-know-what-i-am-doing \/dev\/sdb (As hdparm -Np1758172678 \/dev\/sdb will ask you if you know what you are doing)\n\n setting max visible sectors to 1758172678 (permanent)\n max sectors   = 1758172678\/1953525168, HPA is enabled\n<\/pre>\n\n\n\n<p>Now again, hdparm -N \/dev\/sdb<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">max sectors = 1758172678\/1953525168, HPA is enabled\n<\/pre>\n\n\n\n<p>Now, to make sure we are not suffering that dreaded bug, let&#8217;s reboot the system and check again after that, I am using debian Jessie, so it is unlikely that i am affected<\/p>\n\n\n\n<p>Yup, hdparm -N \/dev\/sdb still gives us a smaller maximum address than the actual physical<\/p>\n\n\n\n<p>Now, we seem to be ready to talk fdisk business.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fdisk \/dev\/sdb\n<\/pre>\n\n\n\n<p>Now, if you O (Clean), then P, you should get a line such as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Disk \/dev\/sdb: 838.4 GiB, 900184411136 bytes, 1758172678 sectors\n<\/pre>\n\n\n\n<p>This means that FDISK understands.and asking it to create (the n command) will yeild this<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/dev\/sdb1 2048 1758172677 1758170630 838.4G 83 Linux\n<\/pre>\n\n\n\n<p>Arent we happy people.<\/p>\n\n\n\n<p>Now, lets mount with trim support, and enjoy all the beutiful abilities an SSD will bless us with.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tune2fs -o journal_data_writeback \/dev\/sdb1\ntune2fs -O ^has_journal \/dev\/sdb1\n<\/pre>\n\n\n\n<p>NOTE: in the event that you are presented with an error such as the following<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/dev\/sde:\n setting max visible sectors to 850182933 (permanent)\nSG_IO: bad\/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 04 51 40 01 21 04 00 00 a0 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n max sectors   = 1000215216\/1000215216, HPA is disabled\n<\/pre>\n\n\n\n<p>The most likely cause is the SATA controller (Try executing the hdparm -Np command using a different SATA controller), another possible cause of errors is that some disks require being trimmed before this action<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over provisioning a Samsung 1TB 850 EVO Mind you, Don&#8217;t follow this tutorial step by step unless you have a 1TB Samsung 850 EVO, if you have a smaller disk, you need to adapt the numbers to your SSD \ud83d\ude09 Over provisioning a flash disk is simply some un-partitioned space a the end of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,215,9,182],"tags":[],"class_list":["post-611","post","type-post","status-publish","format-standard","hentry","category-hard-disks","category-hdparm","category-pc-hardware","category-ssd"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=611"}],"version-history":[{"count":7,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/611\/revisions"}],"predecessor-version":[{"id":2997,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/611\/revisions\/2997"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}