How the program works in memory and how memory is processed by the operating system

I do not understand memory management when a process is executing at runtime

Here is a chart enter image description here

I do not understand that in the picture:

  • 1) What is the stack this image refers to?
  • 2) What is a memory mapping segment related to file associations?
  • 3) What the heap does in the process. Is the heap handled only in the process or is the heap something supported by the kernel of the operating system, and then the malloc memory space is allocated (using the heap) when the user application is calling this?

The article mentions http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/

virtual address space, which in 32-bit mode is always a block of 4 GB of memory address. These virtual addresses are mapped to physical memory tables by page,

  • 4) Does this mean that at one time in memory is only one program, occupying only 4 GB of RAM?

The same article also mentions

Linux randomizes the stack, memory mapping segment, and heap by adding offsets to their start addresses. Unfortunately, the 32-bit address space is pretty tough, leaving little room for randomization and hindering its effectiveness.

  • 5) Does this relate to the randomization of the stack in the process, or does it relate to what remains after calculating the space of all processes?
+7
source share
3 answers

1) What is the stack this image refers to?

stack is designed to highlight local variables and function frames (which include functions such as functional parameters, where to return after the function, etc.).

2) What is a memory mapping segment that relates to file associations?

the memory mapping segment contains linked libraries. Also, mmap calls are highlighted here. In general, a memory mapped file is simply a memory area supported by the file.

3) What the heap does in the process. Is the heap handled only in the process or is the heap something supported by the kernel of the operating system, and then the malloc memory space is allocated (using the heap) when the user application is calling this?

heap depends on the process and is controlled by the process itself, however, it must first request memory from the OS (and if necessary). You are right, this is usually when malloc calls are allocated. However, in most malloc implementations, mmap used to request blocks of memory, so there is really less difference between the heap and the memory mapping segment. Indeed, the heap can be considered part of a memory mapped segment.

4) Does this mean that at one time in memory is only one program, occupying only 4 GB of RAM?

No, this means that the amount of address memory available for the program is limited to 4 GB of RAM, what is actually contained in the memory at any given time depends on how the OS allocates physical memory and goes beyond the scope of this question.

5) Does this relate to the randomization of the stack in the process, or does it relate to what remains after calculating the space of all processes?

I have never seen anything that suggests that 4 GB of space β€œimpedes” the effectiveness of the memory allocation strategies used by the OS. In addition, as @Jason notes, the locations of the stack, memory mapping segment, and heaps are randomized "to prevent predictable security exploits, or at least make them much harder than if every process controlled by the OS had every part of the executable file same place in virtual memory. " To be specific, the OS randomizes virtual addresses for the stack, memory mapped heap, and heap. In this note, all that the process sees is a virtual address , which is then mapped to a physical address in memory, depending on where the particular page is located. More information on mapping between virtual and physical addresses can be found here .

This paging article is a good starting point to learn how the OS manages memory between processes, and is a good reading resource for answering questions 4 and 5. In short, memory is allocated on process pages, and these pages either exist in main memory, or "unloaded" to disk. When a memory address is requested by a process, it moves the page from disk to main memory, replacing another page if necessary. There are various page replacement strategies that are used, and I refer you to the article to learn more about the advantages and disadvantages of each of them.

+7
source

Part 1. Stack ...

A function may call a function that may call another function. Any allocated variables are pushed onto the stack through each iteration. And de-distributed as each function exits, hence the "stack". You can review Wikipedia for this material ... http://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29

+1
source

Linux randomizes the stack, memory mapping segment, and heap by adding offsets to their start addresses. Unfortunately, the 32-bit address space is quite tough, which leaves little room for randomization and makes its efficiency more difficult.

I believe that this is rather a generalization made in the article when comparing the possibility of randomization in 32 and 64 bits. 3 GB of address memory in 32 bits is still quite a lot of space for "moving" ... it's not as much space as can be done in a 64-bit OS, and there are certain applications, such as images, editors, etc. ., which occupy memory very intensively and can easily use all 3 GB of address memory available to them. Keep in mind that I say β€œaddressable” memory ... it depends on the platform, not on the amount of physical memory available on the system.

+1
source

All Articles