This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: malloc pre-allocated too much memory
- From: Steve Munroe <sjmunroe at us dot ibm dot com>
- To: Victor Hsieh <victor at csie dot org>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Thu, 17 Feb 2005 10:54:36 -0600
- Subject: Re: malloc pre-allocated too much memory
libc-alpha-owner@sources.redhat.com wrote on 02/17/2005 10:31:38 AM:
> Hi,
>
> I'm running a service with very small memory usage (less than 500
KB)
> but a large amount of servicing processes (more than 20 thousand).
>
> Since we always work hard to reduce the memory usage, we've found
that
> gnu libc's malloc seems to pre-allocate about 128 KB of memory. (We
found
> this phenomenon because we add additional memory to the machine, but the
> number of processes grew up in FreeBSD but Linux.) But in most case we
> won't use that much, I think 5 KB are really enough for each process. So
> there are a large ratio of unused memory. I would like to ask either
any
> suggestion, solution to reduce the pre-allocation, or any other good
> idea about this problem.
>
These are the default settings from malloc.c:
#define DEFAULT_MMAP_THRESHOLD (128 * 1024)
#define DEFAULT_MMAP_MAX (65536)
#define DEFAULT_TRIM_THRESHOLD (128 * 1024)
#define DEFAULT_TOP_PAD (0)
You can also adjust these values at runtime using #include <malloc.h>
#define MY__MMAP_THRESHOLD (1024 * 8)
#define MY__MMAP_MAX (0)
#define MY__TRIM_THRESHOLD (1024 * 8)
#define MY__TOP_PAD (0)
mallopt (M_MMAP_THRESHOLD, MY__MMAP_THRESHOLD);
mallopt (M_MMAP_MAX, MY__MMAP_MAX);
mallopt (M_TRIM_THRESHOLD, MY__TRIM_THRESHOLD);
mallopt (M_TOP_PAD, MY__TOP_PAD);
Steven J. Munroe
Linux on Power Toolchain Architect
IBM Corporation, Linux Technology Center