Process Memory Distribution

Source: Internet
Author: User
Process Memory Distribution

has been in the analysis stack, the role of the stack this thing is also introduced almost, but where the stack has not been clear, as well as the heap, code, global variables where they are, this involves the process of memory distribution. process memory distribution for Linux 0.01

Memory distribution with the replacement of the operating system, more and more scientific and reasonable, and more complex, so we first understand the early operating system of the typical Linux 0.01 process memory distribution:

A process in Linux 0.01 is fixed with 64MB of linear memory space (the maximum memory footprint of a single program in the ACM Competition is limited to 64MB, there's got to be something fishy. O (∩_∩) o~, each process is placed in a single page catalog table, a page catalog table can manage 4G of linear space, so The linux0.01 has a maximum of 64 processes. The memory distribution for each process is as follows:

. Text contains the machine code sequence. Rodata is a source string, such as read-only content. The data store is the initialized global variable. BSS is an introduction, the existence of uninitialized global variable heap, stack is not to introduce it.

. text. Rodata. BSS is resident memory, which means that the process runs from start to process zombie They are squatting there, so accessing them is a constant address , and the stack is a constant Gar (function call), minus frame (function return), Local variables within a frame can only be accessed relative to the current ESP (pointing to the top of the stack) or EBP (pointing to the current frame).

The stack is placed at a high address for a reason: the call function (Gar) is minus ESP, function return (frame) is added ESP, call in the front, so the stack is to the low address extension, put in a high address is more appropriate . process Memory distribution of modern operating systems

After understanding the memory distribution of Linux 0.01, see what happens to the memory distribution of modern operating systems:

  first of all, the Linux 0.01 process 64MB memory limit is too outdated, now the program has the potential to use 2GB, 3GB memory space (each process a page table of contents), of course, the machine has a bad words can not, my computer is only 2GB memory, want to use 3GB Memory is out of the expectation. But it is not 4GB memory can be used 4GB (32-bit), because the operating system also has to occupy a pit. Modern Linux 0xc0000000 above 1GB space is operating system-specific, and Linux 0.01, the 1th 64MB is the operating system pit, so the other processes completely occupy their 64MB, do not have to be polite with the operating system.

  second , Linux 0.01 has no threads, but modern Linux has multiple threads (Linux threads are actually a lightweight process), sharing global variables, heaps, open files among multiple threads of a process ... But stacks are not shared : each layer of function frames in the stack represents an execution clue, and a thread is an execution clue, so each thread is exclusive to one stack, which must be in the memory space of the owning process.

Based on the above two points, the memory distribution of the process becomes the following:

Moreover, if the dynamically loaded dynamic link library is also taken into account, the above map will be more "broken".

  If our program does not use multithreading, it is generally simple to think that its memory distribution model is the type of Linux 0.01 .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.