{"id":740,"date":"2018-01-06T14:57:54","date_gmt":"2018-01-06T14:57:54","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=740"},"modified":"2018-01-06T14:57:54","modified_gmt":"2018-01-06T14:57:54","slug":"low-memory-and-the-rainy-day-fund","status":"publish","type":"page","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=740","title":{"rendered":"Low memory, and the rainy day fund"},"content":{"rendered":"<p>Just like any other piece of software, Orchids consumes memory. \u00a0Monitoring signatures can involve using a growing amount of memory over time.<\/p>\n<p>You can get some information on memory consumption by running run Orchids with the\u00a0<code>-v1<\/code> flag. \u00a0In that case, Orchids will tell you what signatures are costly in terms of number of threads created. \u00a0A signature that creates\u00a0<em>n<\/em> threads (at most) after reading\u00a0<em>n<\/em> events can be expected to also use memory proportional to the number of events.<\/p>\n<p>However, machines have finite memory. \u00a0If Orchids just ran its algorithm blindly, it would eventually use up all the memory the machine has. \u00a0An attacker, knowing that, could just feed events to the machine so that Orchids would consume as much memory as possible, leading to a so-called denial-of-service attack.<\/p>\n<p>Orchids has two ways to mitigate that.<\/p>\n<ul>\n<li>First, Orchids runs within a\u00a0<em>memory limit<\/em>. \u00a0That is set by the\u00a0<code>MaxMemorySize<\/code> directive in <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=68\">orchids.conf<\/a>. \u00a0Orchids will never consume more that the memory you set this way.<\/li>\n<li>Second, Orchids uses a\u00a0<em>rainy day fund<\/em>. \u00a0The problem with a mere memory limit is that, once you have used up all the memory allowed by the <code>MaxMemorySize<\/code> directive, there is simply no memory left to do any work, and Orchids would in principle abort.<br \/>\nThe idea of the rainy day fund is as follows. \u00a0On start up, Orchids preallocates a dummy block of memory. \u00a0The size of that block of memory is specified by the <code>RainyDayFund<\/code> directive\u00a0in <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=68\">orchids.conf<\/a>.<br \/>\nWhenever Orchids reaches its memory limit, it will enter a so-called <em>low memory mode<\/em>. \u00a0In that mode, Orchids will starting eating up some memory from the rainy day fund, while measuring how much memory each thread will consume.<br \/>\nIf Orchids ever consumes more than a fixed amount of the rainy day fund (fixed to 75% for now), then it enters\u00a0<em>critical memory mode<\/em>. \u00a0In that mode, Orchids deallocates the index tables that help it execute fast, and kills enough threads to recuperate enough memory. \u00a0Once that is done, it reallocates as much of the rainy day fund as it can, attempting to go back to normal mode.<\/li>\n<\/ul>\n<p>Critical memory mode does a lot of nasty things. \u00a0By deallocating index tables, Orchids is slowed down. \u00a0By killing threads,\u00a0 some attacks will go undetected. \u00a0However, this is better than just letting Orchids abort\u2014and no longer detect anything.<\/p>\n<p>The strategy that Orchids uses to kill threads in critical memory mode is experimental, and subject to change. \u00a0The risk is that an attacker might know that strategy, and exploit it so as to hide some attacks to Orchids. \u00a0Keeping the strategy secret makes no sense, if only because the Orchids source is public.<\/p>\n<p>For now, the strategy is as follows: kill the most recent threads. \u00a0That is it.<\/p>\n<p>The important point is that that strategy does not kill the threads that monitor long-standing attack candidates. \u00a0The opposite strategy, killing the oldest threads, would be all too easy to exploit for attackers: start some activity that Orchids can monitor, then drown Orchids into a flow of events, so as to make sure to induce a critical memory situation: if Orchids killed the oldest threads, the attacker could be sure he could proceed undetected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just like any other piece of software, Orchids consumes memory. \u00a0Monitoring signatures can involve using a growing amount of memory over time. You can get some information on memory consumption by running run Orchids with the\u00a0-v1 flag. \u00a0In that case, Orchids will tell you what signatures are costly in terms of number of threads created. &hellip; <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=740\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Low memory, and the rainy day fund<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-740","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=740"}],"version-history":[{"count":1,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/740\/revisions"}],"predecessor-version":[{"id":741,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/740\/revisions\/741"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}