{"id":80,"date":"2007-04-10T20:09:47","date_gmt":"2007-04-11T04:09:47","guid":{"rendered":"http:\/\/jaredrobinson.com\/blog\/?p=80"},"modified":"2007-04-10T20:09:47","modified_gmt":"2007-04-11T04:09:47","slug":"glibc-malloc-hooks-and-tlsf","status":"publish","type":"post","link":"https:\/\/jaredrobinson.com\/blog\/glibc-malloc-hooks-and-tlsf\/","title":{"rendered":"glibc malloc hooks and TLSF"},"content":{"rendered":"<p>Recently, I was asked to constrain the memory usage of an application on Linux. Glibc provides hooks for [malloc, free, etc](http:\/\/www.gnu.org\/software\/libc\/manual\/html_node\/Hooks-for-Malloc.html). By the way, the hook functions are responsible to guarantee thread safety &#8212; glibc doesn&#8217;t do it automatically. I used the malloc hooks in combination with a memory manager that a colleague found: TLSF. There are two implementations:<\/p>\n<p>* [http:\/\/tlsf.baisoku.org\/](http:\/\/tlsf.baisoku.org\/) (public domain)<br \/>\n* [http:\/\/rtportal.upv.es\/rtmalloc\/](http:\/\/rtportal.upv.es\/rtmalloc\/) (GPL)<\/p>\n<p>There are benefits and caveats when using a custom memory allocator. TLSF was meant to shine for real-time use, because the overhead of malloc and free are O(1) constant-time operations. On the other hand, TLSF isn&#8217;t thread-safe.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I was asked to constrain the memory usage of an application on Linux. Glibc provides hooks for [malloc, free, etc](http:\/\/www.gnu.org\/software\/libc\/manual\/html_node\/Hooks-for-Malloc.html). By the way, the hook functions are responsible to guarantee thread safety &#8212; glibc doesn&#8217;t do it automatically. I used the malloc hooks in combination with a memory manager that a colleague found: TLSF. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaredrobinson.com\/blog\/glibc-malloc-hooks-and-tlsf\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;glibc malloc hooks and TLSF&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,17],"tags":[],"class_list":["post-80","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming","category-tech"],"_links":{"self":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/80","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":0,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}