glibc's malloc: arenas and memory fragmentation?

From: Ozgun (ozgune_at_gmail.com)
Date: 12/28/04

  • Next message: Juha Laiho: "Re: What did Master Foo mean here?"
    Date: 27 Dec 2004 22:37:55 -0800
    
    

    Hi all -

    We have an application that spawns off four threads at start-up. Our
    memory allocation pattern is basically in spikes: the application is
    idle for a while, and then allocates and frees tens (if not hundreds)
    of MBs in a couple of seconds.

    We set a hard limit on the Data size of the application, and if the
    app. exceeds a certain limit, we process-recycle it. Under glibc 2.2,
    here's what malloc_stats() prints for our application:

    Arena 0:
    system bytes = 102883720
    in use bytes = 91413448
    Arena 1:
    system bytes = 23896064
    in use bytes = 2566048
    Arena 2:
    system bytes = 57393152
    in use bytes = 5984928
    Total (incl. mmap):
    system bytes = 184959368
    in use bytes = 100750856
    max mmap regions = 4
    max mmap bytes = 2912256

    If we don't set a hard limit for the Data size and continue to run the
    program, the Data and Resident Set sizes continue to increase
    (somewhat) linearly with the former increasing 3x-4x faster than the
    later. Under memory debugging tools, our heap allocation appears as 120
    MBs, and stays flat over time.

    We run this application on a box that has 2 GB of RAM. An strace for
    the application shows lots (and lots) of mmap2s() with a few sbrks().
    [sbrk() calls don't hit the 900 MB limit.]

    Is there any way to ask glibc's malloc() to coalesce the memory it has
    allocated (or anything else that would eat less CPU cycles than process
    recycling)? What are some other ways of minimizing the memory
    fragmentation (or could this be anything other than mem.
    fragmentation)?

    Thanks,

    Ozgun.


  • Next message: Juha Laiho: "Re: What did Master Foo mean here?"

    Relevant Pages

    • Re: [PATCH-RFC] cfq: Disable low_latency by default for 2.6.32
      ... Would the number of dirty pages in the page allocation failure message to ... My definition of fragmentation is just the number of fragments / the number of pages: ... it tends to increase when memory is freed, and to decrease when memory is allocated. ... So the async-rampup is getting smacked very hard with allocation failures ...
      (Linux-Kernel)
    • Re: How to release heap memory that is marked as free
      ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
      (microsoft.public.vc.mfc)
    • Re: [PATCH 00/28] Swap over NFS -v16
      ... memory they can consume. ... So we need the extra (skb) ... included in the reserve? ... if the allocation had to dip into emergency reserves, ...
      (Linux-Kernel)
    • Re: CMemoryState & multi-threaded application
      ... released, and interspersed with smaller allocations, *will* cause fragmentation. ... I've sometimes done this by having a thread that wakes up once a minute and traces memory. ... Manager, Process Viewer, etc., since they are largely clueless about storage allocation ...
      (microsoft.public.vc.mfc)
    • Re: Memory leak with CAsyncSocket::Create
      ... read my essay on how storage allocators work. ... Create method is consuming system memory that is not released back to ... The memory consumption is either shown as "Mem Usage" on the Task ... many levels of allocation going ...
      (microsoft.public.vc.mfc)