I have written a C program, in which I continuously allocate memory(of 1 MB size) using malloc. I do not free this memory. While this program is running, I call the linux free command and expect that, the Memory used should increase gradually and Memory free should decrease. But this does not expect. The Free command output remains almost constant. Any idea why the memory allocated using malloc are not showing in the Memory used ?
Why Linux Free command is not showing less free memory when I run a process which keeps on allocating memory
1.8k Views Asked by user3404785 At
2
There are 2 best solutions below
0
Sunil Bojanapally
On
Malloc'ed memory isn't mapped into process memoryspace unless you touch it. This memory will only be ready when the it get a pagefault in the allocated memory, the memory should be mapped in.
For example you can check top, for VIRT column which has complete view of assigned memory by malloc but RES is the real memory usage till that point of time where may not all the malloc memory is mapped.
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4841 esunboj 20 0 1350m 457m 49m S 25 12.9 43:04.26 firefox
Related Questions in LINUX
- How do I recursively find and replace only in files named index.php on Linux webserver?
- passing text with \n as one argument in shell
- kernel module does not print packet info
- How to send ESC/POS commands to thermal printer in Linux
- (x64 Nasm) Writeline function on Linux
- How do I set the Hive user to something different than the Spark user from within a Spark program?
- Default priority of thread with SCHED_FIFO
- Calling a python function with options from shell script
- How to split a directory into parts without compressing or archiving?
- Cross compile simple standard C program on Linux for Mac
- How to offload NAPI poll function to workqueue
- python netifaces - How to get currently used network interface
- Unexpected output from function
- mingw-64 conflicting declarations when cross-compiling
- Different behavior of async with Visual Studio 2013(Windows8.1) and GCC 4.9(Ubuntu14.10)
Related Questions in MEMORY
- DataTable does not release memory
- Impala Resource Estimation for queries with Group by
- Is there any way to get a lru list in Linux kernel?
- C# console application - Unhandled exception while finding the Available and free Ram space.Getting exact answer in windows forms application
- Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in PHP
- C# equivalent of Java Memory mapping methods
- How to figure out the optimal fetch size for the select query
- Creating two arrays with malloc on the same line
- Using parse.com and having allocation memory issue
- error reading variable: cannot access memory at address
- CentOS memory availability
- Correct idiom for freeing repr(C) structs using Drop trait
- Find Ram/Memory manufacturer in Linux?
- Profiling memory usage on App Engine
- Access Violation: 0xC0000005, why is this happening?
Related Questions in MALLOC
- Malloc confusion
- Creating two arrays with malloc on the same line
- C program crashes when I tried to set an element of type char* in my struct to a specific string?
- Allocating a struct and saving a string in it
- C Define size of array inside main for a struct
- Random double free or invalid next_size
- Accessing char array inside struct showing out of bounds error
- Simple malloc function in c
- Malloc( ) - Decision between a new page(s) request or re-cycling previously allocated memory
- C/CUDA: Only every fourth element in CudaArray can be indexed
- Dynamically creating a 2D array of pointers using malloc in C
- Cannot free fileName char * after fclose
- function to get 2d-arrays from stack and heap
- Why do I get a still reachable block after mallocing a char*?
- copying function pointer throws error in one function pointer
Related Questions in FREE-COMMAND
- Linux "free -m": Total, used and free memory values don't add up
- Using sar command results in wrong memory statistics on Fedora 22
- What is available and free memory in response of free command on Linux?
- how to extract the remaining memory from free using awk?
- Free Memory in Linux?
- Two commands in one line
- Linux amount of swap displayed by "free" is different from "smem"
- How to calculate memory utilization percentage in linux machine?
- How do I reconcile 'top' and 'free -m''s memory usage reporting in linux?
- Linux free shows high memory usage but top does not
- Is there something like the Linux free command on Android?
- What is equivalent of Linux's 'free' command on FreeBSD v8.1
- Linux free command meaning
- My server's total memory doesn't match with USED + FREE memory. I'm using linux free command
- Understanding buffers/cache in linux `free -m`
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
When you call
mallocit in turn requests memory from the kernel (viasbrkormmap) and the OS just casually gives it the memory, without actually allocating it for the process. This is an optimistic strategy; in effect the OS "hopes" the process will never even use the memory.When the process eventually writes (or reads) from the memory, it faults and the OS says "ok FINE, if you insist" and actually allocates the memory.
You can see this by gradually writing to the memory:
One side effect of this is that you can easily allocate more memory with
mallocthan the system has. By writing to it you will eventually hit a limit and your process wil be killed.