Recover memory after program exit

Here is my problem: after starting the set of programs, free tells me that after execution, 1 GB less memory. After some searching, I found SO: what really happens when you do not free after malloc , which (as I understand it) makes it clear that missing memory maladaptations should not be a problem. (it is right?)

top does not show any processes that use significant amounts of memory.

How can I find out “what happened” with the memory, that is, what program allocated it and why is it not a free run after ?

Where does free collect information?

(I am running a recent version of Ubuntu)

+4
source share
3 answers

Yes, the memory used by your program is freed up after the exit of your program.

The statistics in “free” are confusing, but the fact is that memory is available for other programs:

http://kevinclosson.wordpress.com/2009/11/17/linux-free-memory-is-it-free-or-reclaimable-yes-when-i-want-free-memory-i-want-free- memory /

http://sourcefrog.net/weblog/software/linux-kernel/free-mem.html

Here is a link to the best event:

http://www.linuxatemyram.com/

+4
source

free (1) is an incorrect designation, it should be more correctly called unused , because this is what it shows. Or perhaps it should be called physicalfree (or rather, the "free" column in the output file should be called "unused").
You will notice that “buffers” and “cached” tend to rise as “free” decreases. The memory does not disappear, it is simply assigned to another "bucket".

The difference between free memory and unused memory is that although both are “free”, unused memory is really like that (without using physical memory), while just “free” memory is often moved to the buffer cache. This, for example, is the case for all executable images and libraries, all that is read-only or read-execute. If the same file is downloaded again, the “free” page is displayed again in the process and data should not be downloaded.

Note that "unused" is actually bad, although it is not immediately obvious (it sounds good, right?). Free (but physically used) memory serves the purpose, while free (unused) memory means that you could save money on RAM. Therefore, using unused memory (for example, by cleaning pages) is exactly what you do not want.
Amazingly, under Windows there are many memory optimization tools that cost real money and that do just that ...

About fixing memory, how it works is easy: the OS simply removes links to all pages of the working set. If the page is shared with another process, nothing exciting happens. If it refers to non-anonymous mapping and cannot be written (or written and not written), it goes to the buffer cache. Otherwise, it will be zap poof.
This removes any memory allocated using malloc , as well as the memory used by executable files and file associations, and (since all memory is page-based) everything else.

+2
source

Your OS probably uses this space for its own purposes.

For example, many modern operating systems will support loading programs into memory after they are completed, if you want to run them again. If their assumption is correct, it saves a lot of time due to some memory, which is not used in any case. Some operating systems even speculatively load some commonly used programs.

CPU usage works the same. Often your OS will speculatively do some work when the processor would otherwise be "inactive."

0
source

Source: https://habr.com/ru/post/1368985/


All Articles