{"id":2335,"date":"2014-03-04T13:15:29","date_gmt":"2014-03-04T12:15:29","guid":{"rendered":"http:\/\/vizZzion.org\/blog\/?p=2335"},"modified":"2014-03-04T13:48:10","modified_gmt":"2014-03-04T12:48:10","slug":"are-your-qt-builds-going-oom","status":"publish","type":"post","link":"https:\/\/vizZzion.org\/blog\/2014\/03\/are-your-qt-builds-going-oom\/","title":{"rendered":"Are your Qt builds going OOM?"},"content":{"rendered":"<p>If you&#8217;re, like me, regularly building Qt, you probably have noticed a decent hunger for memory, especially when linking Webkit. This part of the build can take well over  8GB of RAM, and when it fails, you get to do it over again.<\/p>\n<p>The unfortunate data point is that my laptop only has 4GB, which is enough for most (but one) cases. Short of buying a new laptop, here&#8217;s a trick how you can get through this part of the build: Create a swap file. Creating a swapfile increases your virtual memory. This won&#8217;t make it fast, but it at least gives Linux a chance to not run out of memory and kill the &#8216;ld&#8217; process. Creating a swapfile is actually really easy under Linux, you just have to know your toolbox. Here&#8217;s the quick run-down of steps:<\/p>\n<p>First, create an empty file:<\/p>\n<pre>\r\nfallocate -l 4096M \/home\/swapfile\r\n<\/pre>\n<p>Using the fallocate syscall (which works for newer kernels, but only for btrfs, ext4, ocfs2, and xfs filesystems), this can be done fast. In this example, I have enough space on my home partition, so I decided to put the swapfile there. It&#8217;s 4GB in size, which should be plenty of virtual memory to finish even the greediest of builds &#8212; your mileage may vary. If you&#8217;re not able to use fallocate, you&#8217;ll need a bit more patience and dd.<\/p>\n<p>As your swap should never be readable by anybody else than root, change its permissions:<\/p>\n<pre>\r\nchmod 600 \/home\/swapfile\r\n<\/pre>\n<p>Next, &#8220;format&#8221; the swapfile:<\/p>\n<pre>\r\nmkswap \/home\/swapfile\r\n<\/pre>\n<p>Then, add it to your virtual memory pool:<\/p>\n<pre>\r\nswapon \/home\/swapfile\r\n<\/pre>\n<p>You can now check with tools like `free` or `top` (tip: use the much nicer `htop` if you&#8217;re into fancy) that your virtual memory actually increased. Once your build is done, and you need your disk-space back, that&#8217;s easy as pie:<\/p>\n<pre>\r\nswapoff \/home\/swapfile\r\nrm \/home\/swapfile\r\n<\/pre>\n<p>If you want to make this permanent (so it&#8217;ll survive a reboot), add a line like the following to your fstab:<\/p>\n<pre>\r\n\/home\/swapfile none swap defaults 0 0\r\n<\/pre>\n<p>This is just a really quick tip, more details on this process can be found in the excellent <a href=\"https:\/\/wiki.archlinux.org\/index.php\/swap\">Arch Wiki<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re, like me, regularly building Qt, you probably have noticed a decent hunger for memory, especially when linking Webkit. This part of the build can take well over 8GB of RAM, and when it fails, you get to do it over again. The unfortunate data point is that my laptop only has 4GB, which&hellip; <a class=\"more-link\" href=\"https:\/\/vizZzion.org\/blog\/2014\/03\/are-your-qt-builds-going-oom\/\">Continue reading <span class=\"screen-reader-text\">Are your Qt builds going OOM?<\/span> <span class=\"meta-nav\" aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,29,25,35],"tags":[],"class_list":["post-2335","post","type-post","status-publish","format-standard","hentry","category-english","category-kde","category-linux","category-qt"],"_links":{"self":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/2335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/comments?post=2335"}],"version-history":[{"count":4,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/2335\/revisions"}],"predecessor-version":[{"id":2339,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/2335\/revisions\/2339"}],"wp:attachment":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/media?parent=2335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/categories?post=2335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/tags?post=2335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}