<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Nov 26, 2013, at 4:20 PM, Eduardo Silva <<a href="mailto:edsiper@gmail.com">edsiper@gmail.com</a>> wrote:<div><blockquote type="cite"><div dir="ltr"><div>On Tue, Nov 26, 2013 at 2:10 PM, Eduardo Silva <span dir="ltr"><<a href="mailto:edsiper@gmail.com" target="_blank">edsiper@gmail.com</a>></span> wrote:</div></div><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr"><div>On Tue, Nov 26, 2013 at 2:01 PM, Jason Evans <span dir="ltr"><<a href="mailto:jasone@canonware.com" target="_blank">jasone@canonware.com</a>></span> wrote:</div></div><div class="gmail_extra"><div class="h5"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div style="word-wrap:break-word"><div>On Nov 26, 2013, at 11:40 AM, Eduardo Silva <<a href="mailto:edsiper@gmail.com" target="_blank">edsiper@gmail.com</a>> wrote:<br>
<div><blockquote type="cite"><div dir="ltr"><div>i am interested into gather memory usage per Linux thread, as i am using jemalloc i think this can be done quering the arenas per thread. if i am correct, do you have some code example that accomplish something similar to this ?</div>
</div></blockquote><br></div></div><div>Threads don't own memory; allocated regions can be shared among threads, and allocation/deallocation can be split between threads. That said, jemalloc does track total volume of allocation and deallocation on a per thread basis, so you can derive the information you want as long as you account for allocated regions that are shared among threads. Take a look at the "thread.allocated" and "thread.deallocated" mallctl() interfaces in the man page:</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span><a href="http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html" target="_blank">http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html</a></div>
<div><br></div><div>There is a relevant test program included with jemalloc:</div><div><br></div><div><span style="white-space:pre-wrap"> </span><a href="https://github.com/jemalloc/jemalloc/blob/dev/test/allocated.c" target="_blank">https://github.com/jemalloc/jemalloc/blob/dev/test/allocated.c</a></div></div></blockquote></div><br></div></div></blockquote></div></div></blockquote><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr">thanks for your help!, thats the info that i need.</div></blockquote></div></div></blockquote><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div class="gmail_extra"><div class="im">
</div></div>
</blockquote></div><br>I have implemented a similar code and its working great. Now an extra question: i would like to spawn a thread to monitor the threads allocation/deallocations, can i access this data from a different thread ?, if so, is there any API or example available ?</div></blockquote></div><br><div>You can call the "thread.allocatedp" and "thread.deallocatedp" mallctl() interfaces from each thread you care about, then pass the pointers to your monitoring thread. You may get stale reads if you read the counters from a different thread since there's no synchronization protecting reads/writes of the counters, but in practice the values you read are unlikely to be substantially out of date, at least on x86/x64 systems.</div><div><br></div><div>Jason</div></body></html>