Memory Usage in opkg

Thomas Wood thomas at openedhand.com
Wed May 21 13:11:28 CEST 2008


Hi,

Over the last two and a half days I've been fixing all the memory leaks
discovered by running libopkg_test. I have reduced the directly lost and
indirectly lost memory to 0 bytes. The reachable memory at exit has been
reduced to 29kB (down from ~13MB), with the remaining blocks belonging
to libgpgme and libcurl which does not appear to be freed by their
respective de-initialisation routines.

Having had such a detailed look at the code, I am fairly further
optimisation work is possible in terms of both memory usage and speed.

Some interesting statistics:

* I've add some 65 additional free and deinit statements
* ... of which 52 are additional free() calls alone
* 18 files changed, mostly in libopkg, but also one in libbb
* Total of 184 insertions(+), 25 deletions(-)


Reports from valgrind
---------------------

 ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 65 from 1)
 malloc/free: in use at exit: 29,064 bytes in 2,013 blocks.
 malloc/free: 1,145,726 allocs, 1,143,713 frees, 1,443,951,146 bytes allocated.
 For counts of detected errors, rerun with: -v
 searching for pointers to 2,013 not-freed blocks.
 checked 390,804 bytes.

 LEAK SUMMARY:
    definitely lost: 0 bytes in 0 blocks.
      possibly lost: 0 bytes in 0 blocks.
    still reachable: 29,064 bytes in 2,013 blocks.
         suppressed: 0 bytes in 0 blocks.
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-reachable=yes


Graph from massif
-----------------
 (MB in use vs. MB (de)allocated)

    MB
13.04^             #                                 .                        
     |             #                                 :                        
     |            :#                                ::                        
     |           .:# @                             ::: :                      
     |           ::# @                            .::: :.                     
     |          @::# @    . ..                    :::: ::  .. ,.     ,:       
     |         :@::# @:  .:@::  :                ::::: :@  :::@:   .:@:.      
     |        .:@::# @: .::@:::::.              .::::: :@. :::@::::::@::      
     |       ,::@::# @: :::@::::::             .:::::: :@: :::@::::::@:::     
     |       @::@::# @: :::@::::::.            ::::::: :@: :::@::::::@::.     
     |      ,@::@::# @: :::@:::::::           .::::::: :@: :::@::::::@:::     
     |     ,@@::@::# @: :::@:::::::.         .:::::::: :@: :::@::::::@::::    
     |     @@@::@::# @: :::@::::::::         ::::::::: :@: :::@::::::@::::.   
     |    .@@@::@::# @: :::@::::::::         ::::::::: :@: :::@::::::@:::::   
     |    :@@@::@::# @: :::@:::::::::      . ::::::::: :@: :::@::::::@::::::  
     |    :@@@::@::# @: :::@:::::::::.     : ::::::::: :@: :::@::::::@:::::.  
     |   ::@@@::@::# @: :::@::::::::::     : ::::::::: :@: :::@::::::@::::::, 
     |  .::@@@::@::# @: :::@::::::::::    :: ::::::::: :@: :::@::::::@::::::@ 
     |  :::@@@::@::# @: :::@:::::::::::  .:: ::::::::: :@: :::@::::::@::::::@:
     | ,:::@@@::@::# @: :::@:::::::::::. ::: ::::::::: :@: :::@::::::@::::::@.
   0 +----------------------------------------------------------------------->MB
     0                                                                   94.44

Number of snapshots: 76
 Detailed snapshots: [1, 5, 6, 7, 10, 13 (peak), 14, 19, 32, 47, 53, 63, 73]


-- 
OpenedHand Ltd.

Unit R Homesdale Business Center / 216-218 Homesdale Road /
Bromley / BR1 2QZ / UK             Tel: +44 (0)20 8819 6559

Expert Open Source For Consumer Devices - http://o-hand.com/
------------------------------------------------------------





More information about the opkg-devel mailing list