|
From: Andrei S. <and...@gm...> - 2008-05-28 06:29:45
|
Hello, I am a GSoC student doing performance work for GNOME and I make use of Valgrind's massif a lot in my work. I want to ask you about the possibility of determining the lifetime of allocations during a program's execution. What I want to do is determine those allocations that have short lifetime and try to replace them with something else, perhaps static buffers, the main goal being to reduce the memory fragmentation in GNOME. >From what I noticed, Massif doesn't say anything about deallocations (free / delete), maybe I'm wrong ? Please let me know what I could do. Thank you for your time. -- Andrei Soare |
|
From: Nicholas N. <nj...@cs...> - 2008-05-28 07:56:50
|
On Wed, 28 May 2008, Andrei Soare wrote: > I am a GSoC student doing performance work for GNOME and I make use of > Valgrind's massif a lot in my work. > > I want to ask you about the possibility of determining the lifetime of > allocations during a program's execution. What I want to do is determine > those allocations that have short lifetime and try to replace them with > something else, perhaps static buffers, the main goal being to reduce the > memory fragmentation in GNOME. > >> From what I noticed, Massif doesn't say anything about deallocations (free / > delete), maybe I'm wrong ? > > Please let me know what I could do. Massif tracks deallocations, but you're right that it doesn't really say anything about them, or about allocation lifetimes. You could definitely track object lifetimes with a Valgrind tool, and Massif might be a good place to start because it has a lot of allocation-tracking infrastructure, but I expect you'd need to make substantial modifications to it. Nick |
|
From: Andrei S. <and...@gm...> - 2008-05-28 08:06:35
|
I suspected that. However, I have no idea how and what I must modify and I would really appreciate some hints. On Wed, May 28, 2008 at 10:56 AM, Nicholas Nethercote < nj...@cs...> wrote: > Massif tracks deallocations, but you're right that it doesn't really say > anything about them, or about allocation lifetimes. > > You could definitely track object lifetimes with a Valgrind tool, and > Massif might be a good place to start because it has a lot of > allocation-tracking infrastructure, but I expect you'd need to make > substantial modifications to it. > > Nick > -- Andrei Soare |
|
From: Nicholas N. <nj...@cs...> - 2008-05-28 22:36:06
|
On Wed, 28 May 2008, Andrei Soare wrote: > I suspected that. However, I have no idea how and what I must modify and I > would really appreciate some hints. Look at the code: massif/ms_main.c. Massif is fairly well commented, and the most complicated parts are dealing with snapshots and the XTree structure, all of which you could probably rip out. In particular, look at the "Heap management" and "malloc() et al replacement wrappers" for the code that intercepts malloc/free/etc and does stuff in response. Also, 'ms_instrument' and related functions, as well as 'get_time' are responsible for keeping track of time (either instructions executed, bytes allocated/deallocated, or real time). Then, think what you want your tool to do. I'd start by recording in a table the allocation site, deallocation site, and lifetime of every block allocated, and then at the end present them in order from shortest to longest. Massif already records all live allocated blocks in the 'malloc_list' structure, you could just change the content of the nodes and change it to not remove freed ones. The 'VG_(ssort)' sorting function (include/pub_tool_libcbase.h) might be useful for sorting the results at the end. Once you get that working, I expect you'll find the output is very repetitive. You'll probably want to aggregate results somehow, eg. 100 blocks were allocated at point X that all had a lifetime of N instructions. I expect the appropriate aggregation approach will become clearer once you see what the basic output looks like, and what kinds of patterns occur. Nick |