{"id":2196,"date":"2010-11-15T14:56:43","date_gmt":"2010-11-15T04:56:43","guid":{"rendered":"http:\/\/www.flamingspork.com\/blog\/?p=2196"},"modified":"2014-10-08T09:16:08","modified_gmt":"2014-10-07T23:16:08","slug":"limiting-functions-to-32k-stack-in-drizzle-and-scoped_ptr","status":"publish","type":"post","link":"https:\/\/www.flamingspork.com\/blog\/2010\/11\/15\/limiting-functions-to-32k-stack-in-drizzle-and-scoped_ptr\/","title":{"rendered":"Limiting functions to 32k stack in Drizzle (and scoped_ptr)"},"content":{"rendered":"<p>I wonder if this comes under &#8220;Code Style&#8221; or not&#8230;<\/p>\n<p>Anyway, <a href=\"http:\/\/inaugust.com\/\">Monty<\/a> and I finished getting <a href=\"http:\/\/www.drizzle.org\">Drizzle<\/a> ready for adding &#8220;\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf-Wframe-larger-than=32768&#8221; as a standard compiler flag. This means that no function within the Drizzle source tree can use greater than 32kb stack &#8211; it&#8217;s a compiler warning &#8211; and with -Werror, it means that it&#8217;s a build error.<\/p>\n<p>GCC is not perfect at detecting stack usage, but it&#8217;s pretty good.<\/p>\n<p>Why have we done this?<\/p>\n<p>Well, there is a little bit of recursion in the server&#8230; and we can craft queries to blow a small stack (not so good). On MacOS X, the default thread stack size is only 512kb. This gives not many frames if 32kb stack is a even remotely common.<\/p>\n<p>I found some interesting places to throw a lot of things on the stack too &#8211; that would be rather far down on a callchain &#8211; leading to the possibility of blowing up in really strange ways.<\/p>\n<p>We&#8217;d love to make it 16kb&#8230;. but that&#8217;s a fair bit more work, so something for the future.<\/p>\n<p>We&#8217;ve used the Boost scoped_ptr to address a bunch of these situations as it provides pretty much minimal code change for the same effect (except that memory is dynamically allocated instead of as part of the stack frame).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wonder if this comes under &#8220;Code Style&#8221; or not&#8230; Anyway, Monty and I finished getting Drizzle ready for adding &#8220;\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf-Wframe-larger-than=32768&#8221; as a standard compiler flag. This means that no function within the Drizzle source tree can use greater than &hellip; <a href=\"https:\/\/www.flamingspork.com\/blog\/2010\/11\/15\/limiting-functions-to-32k-stack-in-drizzle-and-scoped_ptr\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[76,75],"tags":[314,633,70,86,386],"class_list":["post-2196","post","type-post","status-publish","format-standard","hentry","category-code","category-drizzle-work-et-al","tag-boost","tag-code","tag-drizzle","tag-gcc","tag-stack"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5a6n8-zq","jetpack-related-posts":[{"id":3741,"url":"https:\/\/www.flamingspork.com\/blog\/2014\/05\/25\/caring-about-stack-usage\/","url_meta":{"origin":2196,"position":0},"title":"Caring about stack usage","author":"Stewart Smith","date":"2014-05-25","format":false,"excerpt":"It may not be surprising that there's been a few projects over the years that I've worked on where we've had to care about stack usage (to varying degrees). For threaded userspace applications (e.g. MySQL, Drizzle) you get a certain amount of stack per thread - and you really don't\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2323,"url":"https:\/\/www.flamingspork.com\/blog\/2011\/03\/17\/things-ive-done-in-drizzle\/","url_meta":{"origin":2196,"position":1},"title":"Things I&#8217;ve done in Drizzle","author":"Stewart Smith","date":"2011-03-17","format":false,"excerpt":"When writing my Dropping ACID: Eating Data in a Web 2.0 Cloud World talk for LCA2011 I came to the realisation that I had forgotten a lot of the things I had worked on in MySQL and MySQL Cluster. So, as a bit of a retrospective as part of the\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1587,"url":"https:\/\/www.flamingspork.com\/blog\/2009\/04\/08\/using-dtrace-to-find-out-why-solaris-is-so-slow-and-if-its-actually-solaris\/","url_meta":{"origin":2196,"position":2},"title":"Using Dtrace to find out if the hardware or Solaris is slow (but really just working around the problem)","author":"Stewart Smith","date":"2009-04-08","format":false,"excerpt":"A little while ago, I was the brave soul tasked with making sure Drizzle was working properly and passing all tests on Solaris and OpenSolaris. Brian recently blogged about some of the advantages of also running on Solaris and the SunStudio compilers - more warnings from the compiler is a\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1405,"url":"https:\/\/www.flamingspork.com\/blog\/2009\/02\/18\/fun-with-387\/","url_meta":{"origin":2196,"position":3},"title":"Fun with the 387","author":"Stewart Smith","date":"2009-02-18","format":false,"excerpt":"Filed\u00c2\u00a0 GCC bug 39228: #include <stdio.h> #include <math.h> int main() { \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 double a= 10.0; \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 double b= 1e+308; \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 printf(\"%d %d %dn\", isinf(a*b), __builtin_isinf(a*b), __isinf(a*b)); \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 return 0; } mtaylor@drizzle-dev:~$ gcc -o test test.c mtaylor@drizzle-dev:~$ .\/test 0 0 1 mtaylor@drizzle-dev:~$ gcc -o test test.c -std=c99 mtaylor@drizzle-dev:~$ .\/test 1 0\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1738,"url":"https:\/\/www.flamingspork.com\/blog\/2009\/10\/14\/return-of-the-top-5-mysql-wishlist-and-looking-at-drizzle\/","url_meta":{"origin":2196,"position":4},"title":"Return of the &#8220;Top 5 MySQL Wishlist&#8221; and looking at Drizzle","author":"Stewart Smith","date":"2009-10-14","format":false,"excerpt":"It's coming up on a year since I started working full time on Drizzle. So, I got a bit reflective... Have we done things that I (and others) really wanted done? Back in 2007, I wrote my top 5 wishlist for the MySQL Server. I am not going to pretend\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1908,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/05\/05\/haildb-hudson-compiler-warnings-and-cppcheck\/","url_meta":{"origin":2196,"position":5},"title":"HailDB, Hudson, compiler warnings and cppcheck","author":"Stewart Smith","date":"2010-05-05","format":false,"excerpt":"I've integrated HailDB into our Hudson setup (haildb-trunk on Hudson). I've also made sure that Hudson is tracking the compiler warnings. We've enabled more compiler warnings than InnoDB has traditionally been compiled with - this means we've started off with over 4,300 compiler warnings! Most of those are not going\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/2196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/comments?post=2196"}],"version-history":[{"count":2,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/2196\/revisions"}],"predecessor-version":[{"id":3844,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/2196\/revisions\/3844"}],"wp:attachment":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/media?parent=2196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/categories?post=2196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/tags?post=2196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}