From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4E16EFB5.4000700@domain.hid> Date: Fri, 08 Jul 2011 13:53:25 +0200 From: Gilles Chanteperdrix MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai-help] Anti-memory-fragmentation tricks for my Xenomai process? List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jeremy Friesner Cc: xenomai@xenomai.org On 07/08/2011 07:48 AM, Jeremy Friesner wrote: > This all works well, but there is one minor issue where I'd like to > improve things: after running for a while, the allocation and > deallocation of 128kB buffers, interspersed with smaller > allocations/deallocations, causes fragmentation in the process's > heap, with the end result that the process appears to be using a lot > more memory than it actually has allocated. This doesn't cause real > problems (AFAICT), but because the GUI for the system has a RAM Usage > Indicator (that gets its info from /proc/meminfo, and displays total > memory-usage as a percentage of physical RAM), users are prone to > wonder why so much RAM is being used even when the program is idle. > The heap fragmentation makes it look like there is a memory leak, > even when there technically isn't. The size allocated by a process is more accurately measured with /proc/self/maps or /proc/self/smaps than with /proc/meminfo. For the 128k buffers, you can mmap/munmap anonymous memory, this way, you will only consume what you use. Malloc also has a threshold above which it uses mmap, maybe you can change that threshold to be 128KiB (I think it is 4MiB by default). See mallopt documentation. -- Gilles.