[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: free memory - use it temporarily



Peter Arremann wrote:
On Sunday 16 November 2008 08:30:51 am Steve West wrote:
I am running Fedora 9 x86 64 bit. I have 8 gigs of memory in the system.I
wrote a program to malloc 4 gigs of memory space. Free shows nearly the
same result before and during the execution of the program. Why does free
not show that 4 gigs where allocated and used? How do I show the true
memory usage?

Steve

What you encounter is a documented, intended behavior. Different people refer to it by different names like delayed allocation or memory overcommit, but it addresses all the same issue. Essentially, there are so many programs out there that ask for memory and never use it, the kernel will overcommit memory. That means that malloc (with few exceptions) will succeed even if you don't really have that memory available. It isn't actually allocated until your process uses it. Change your program to touch every page of the memory you allocated (simple for loop accessing one word in each page is sufficient) and you'll see the memory usage of your program increase steadily. Search google for memory overcommit or delayed allocation. http://opsmonkey.blogspot.com/2007/01/linux-memory-overcommit.html
There is a program to do this already:
yum install numactl
free
memhog 4g
free

This way you can convince the buffers and file cache to be cleared, but sort of pushes stuff into swap.
more fun: ask it for more than ram+swap {ok, that might be bad}.

DaveT.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]