Review Request 116577: Call malloc_trim() when deleting a dialog

Vishesh Handa me at vhanda.in
Wed Mar 12 13:58:39 UTC 2014



> On March 3, 2014, 8:51 p.m., Martin Gräßlin wrote:
> > recommendation: look at kwin/main.cpp kdemain()
> 
> David Edmundson wrote:
>     Thanks.
>     
>     Copy and pasted for lazy:
>     
>     #ifdef M_TRIM_THRESHOLD
>         // Prevent fragmentation of the heap by malloc (glibc).
>         //
>         // The default threshold is 128*1024, which can result in a large memory usage
>         // due to fragmentation especially if we use the raster graphicssystem. On the
>         // otherside if the threshold is too low, free() starts to permanently ask the kernel
>         // about shrinking the heap.
>     #ifdef HAVE_UNISTD_H
>         const int pagesize = sysconf(_SC_PAGESIZE);
>     #else
>         const int pagesize = 4*1024;
>     #endif // HAVE_UNISTD_H
>         mallopt(M_TRIM_THRESHOLD, 5*pagesize);
>     #endif // M_TRIM_THRESHOLD
>     
>     
>     From what I understand there are two schools of thought:
>     1) set the options to cleanup more aggressively
>     2) whenever we delete a load of stuff we say "hey, we're probably super fragmented now. Can you tidy up my memory please."
>     
>     For a Plasma use-case, I think 2 maybe work better as we can know when we close an applet or dialog. 
>

I'm not sure which option is better. While (2) makes more sense since we do have that information, it means additional code and remembering to call it. Maybe we can just be more aggressive with memory and see if it has some noticeable side affects?


- Vishesh


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/116577/#review51820
-----------------------------------------------------------


On March 3, 2014, 7:52 p.m., David Edmundson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/116577/
> -----------------------------------------------------------
> 
> (Updated March 3, 2014, 7:52 p.m.)
> 
> 
> Review request for Plasma.
> 
> 
> Repository: plasma-framework
> 
> 
> Description
> -------
> 
> Call malloc_trim() when deleting a dialog
> 
> A dialog will typically contain lots and lots of tiny objects.
> 
> Tiny mallocs are not returned to the system immediately and are left for
> us to re-use.
> 
> When we delete a dialog it would be a good time to release these.
> 
> This fixes the memory growth when repeatedly opening and closing the
> widget explorer.
> 
> TBH: I don't /fully/ understand malloc_trim, but it does seem this patch makes a difference.
> 
> Also I think maybe this would be better being in the destructor of KDeclatarive::QMLObject as well?
> or maybe we should tune the malloc options so it behaves better in general.
> 
> 
> Diffs
> -----
> 
>   src/declarativeimports/core/dialog.cpp 61e8d93 
> 
> Diff: https://git.reviewboard.kde.org/r/116577/diff/
> 
> 
> Testing
> -------
> 
> The following test (courtesy of Martin K) http://paste.kde.org/pjreffopt creates 10 dialogs, waits 5 seconds and deletes them.
> 
> Before: Memory usage in ksysguard goes up to 125Mb and stays there indefinitely.
> After:Memory usage in ksysguard goes up to 125Mb and when the dialogs are removed goes back down to 35Mb
> 
> 
> Thanks,
> 
> David Edmundson
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20140312/ad0c88ea/attachment-0001.html>


More information about the Plasma-devel mailing list