{"id":1277,"date":"2017-05-05T12:33:07","date_gmt":"2017-05-05T12:33:07","guid":{"rendered":"http:\/\/10sa.com\/sql_stories\/?p=1277"},"modified":"2017-05-06T11:59:43","modified_gmt":"2017-05-06T11:59:43","slug":"data-alignment","status":"publish","type":"post","link":"http:\/\/10sa.com\/sql_stories\/?p=1277","title":{"rendered":"Data alignment in block devices"},"content":{"rendered":"<p>CentOS 7<\/p>\n<pre language=bash>\r\n[root@]# cat \/etc\/redhat-release \r\nCentOS Linux release 7.3.1611 (Core) \r\n<\/pre>\n<p>Problem:<br \/>\nmkfs.xfs warning: device is not properly aligned<\/p>\n<pre language=\"bash\">\r\n[root@]# parted -a optimal \/dev\/mapper\/mpathb mkpart primary  0% 100%\r\n[root@]# parted \/dev\/mapper\/mpathb align-check opt 1\r\n1 aligned\r\nparted \/dev\/mapper\/mpathb p\r\nModel: Linux device-mapper (multipath) (dm)\r\nDisk \/dev\/mapper\/mpathb: 21.5GB\r\nSector size (logical\/physical): 512B\/512B\r\nPartition Table: gpt\r\nDisk Flags: \r\n\r\nNumber  Start   End     Size    File system  Name     Flags\r\n 1      <span style='color:#dd2020'>33.6MB<\/span>  21.5GB  21.4GB               primary\r\n[root@]# mkfs.xfs \/dev\/mapper\/mpathb1\r\n<span style='color:#dd2020'>warning: device is not properly aligned<\/span> \/dev\/mapper\/mpathb1\r\nUse -f to force usage of a misaligned device\r\n<\/pre>\n<p>Why it happened?<\/p>\n<pre language=bash>\r\n[root@]# blkid -i \/dev\/mapper\/mpathb\r\nDEVNAME=\/dev\/mapper\/mpathb\r\nMINIMUM_IO_SIZE=8192\r\nOPTIMAL_IO_SIZE=<span style='color:#dd2020'>33553920<\/span>\r\nPHYSICAL_SECTOR_SIZE=512\r\nLOGICAL_SECTOR_SIZE=512\r\n<\/pre>\n<p>Cause OPTIMAL_IO_SIZE is huge.<br \/>\nYou can find which devices are touched by this problem:<\/p>\n<pre language=bash>\r\n[root@]# find \/sys\/devices\/ -name optimal_io_size | xargs  tail -n 1 \r\n<\/pre>\n<p>You can test if that is the cause by mounting file with 0 zero value:<\/p>\n<pre>\r\n[root@]# echo 0 > \/tmp\/zero\r\n[root@]# mount --bind \/tmp\/zero \/sys\/devices\/virtual\/block\/dm-2\/queue\/optimal_io_size\r\n<\/pre>\n<p>What is optimal_io_size? Storage vendors can also supply &#8220;I\/O hints&#8221; about a device&#8217;s preferred<br \/>\nminimum unit for random I\/O (&#8216;minimum_io_size&#8217;) and streaming I\/O<br \/>\n(&#8216;optimal_io_size&#8217;).  For example, these hints may correspond to a RAID<br \/>\ndevice&#8217;s chunk size and stripe size respectively. <a href=\"https:\/\/people.redhat.com\/msnitzer\/docs\/io-limits.txt\">https:\/\/people.redhat.com<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Vital_Product_Data\">VPD (vital product data)<\/a><\/p>\n<p>How to solve the problem globally for LVM? Disable data_alignment_detection in configuration. <\/p>\n<pre language=\"bash\">\r\n[root@]# grep align \/etc\/lvm\/lvm.conf | grep -v '^\\s#'\r\nmd_chunk_alignment = 1\r\ndata_alignment_detection = <span style='color:#20dd20; font-weight: bold'>0<\/span>\r\ndata_alignment = 0\r\ndata_alignment_offset_detection = 1\r\n<\/pre>\n<p>What is the root cause?<br \/>\nVPD and kernel<br \/>\nhttps:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/torvalds\/linux.git\/commit\/?id=09b6b51b0b6c1b9bb61815baf205e4d74c89ff04<br \/>\n unsigned skip_vpd_pages:1;\t\/* do not read VPD pages *\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CentOS 7 [root@]# cat \/etc\/redhat-release CentOS Linux release 7.3.1611 (Core) Problem: mkfs.xfs warning: device is not properly aligned [root@]# parted -a optimal \/dev\/mapper\/mpathb mkpart primary 0% 100% [root@]# parted \/dev\/mapper\/mpathb align-check opt 1 1 aligned parted \/dev\/mapper\/mpathb p Model: Linux device-mapper (multipath) (dm) Disk \/dev\/mapper\/mpathb: 21.5GB Sector size (logical\/physical): 512B\/512B Partition Table: gpt Disk Flags: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19,18],"tags":[],"_links":{"self":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/1277"}],"collection":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1277"}],"version-history":[{"count":16,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/1277\/revisions"}],"predecessor-version":[{"id":1294,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/1277\/revisions\/1294"}],"wp:attachment":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1277"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}