In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what is virtual memory and process address space". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what is virtual memory and process address space.
Virtual memory
Virtual memory, which is the middle layer between the physical memory of the operating system and the process, hides the concept of physical memory for the process, and provides a more concise and easy-to-use interface and more complex functions for the process.
Virtual memory makes the application think that it has continuous available memory (a contiguous and complete address space), when in fact, it is usually separated into multiple physical memory fragments, and some are temporarily stored on external disk storage for data exchange when needed.
Benefits of using virtual memory
Programs can use a series of adjacent virtual addresses to access large memory buffers that are not adjacent in physical memory.
Programs can use a series of virtual addresses to access memory buffers that are larger than the available physical memory.
Virtual addresses used by different processes are isolated from each other.
Partition of process address space
The modern operating system allocates a complete virtual memory address space to each process, the so-called process address space, that is, user space, user state.
The process address space is divided into several areas, namely code segment (code/text), data segment (data/gvar), BSS segment, stack area and stack area.
TEXT section: the code of the entire program, and all the constants; this part of the memory is fixed and read-only.
DATA section, also known as GVAR: a global variable initialized to a non-zero value
BSS section: global and static variables initialized to 0 or uninitialized
HEAP (heap space): dynamic memory area, memory requested using malloc or new
Unused memory
STACK (stack space): local variables, parameters, and return values all exist here. At the beginning of a function call, parameters are added to the stack, and local variables are added to the stack at the end of the call.
The size of the stack space and stack space is variable, the stack space grows from bottom to top, and the stack space grows from top to bottom.
Because constants are stored in the TEXT section, all assignments to constants generate segment fault exceptions.
You can assume that all bytes in the BSS segment are zeros. Because uninitialized global variables and static variables are in the BSS section, they will be initialized to 0, and the member variables of the class will also be initialized to 0, but the compiler does not guarantee the initialization of local variables.
It is said above that the STACK is allocated from top to bottom (high address to low address), and we know that the space of the function's local variables is allocated after entering the function body, in the stack space.
CPU addressing
CPU contains a hardware called memory management unit (Memory Management Unit, MMU), which translates virtual addresses into physical addresses.
Page replacement algorithm
The operating system manages memory on a page-by-page basis, and when a process finds that the data it needs to access is not in memory, the operating system may load the data into memory as pages.
Missing pages will occur when it is found that the page to be accessed is not in memory. If there is no free memory in memory, the operating system needs to select a page to move out of memory to make room for new pages.
The function of page replacement algorithm is to realize virtual storage management.
Common page replacement algorithm
OPT page replacement algorithm (the best page replacement algorithm)
FIFO page replacement algorithm (FIFO page replacement algorithm)
LRU page replacement algorithm (page replacement algorithm has not been used recently)
LFU page replacement algorithm (use page sorting algorithm at least)
Kernel space and user space
The following figure takes a 64-bit system as an example. The virtual memory space is divided as follows:
From 0x0000000000000000 to 0x00007FFFFFFFFFFF is the user space.
From 0xFFFF800000000000 to 0xFFFFFFFFFFFFFFFF is the kernel space.
At this point, I believe you have a deeper understanding of "what is virtual memory and process address space". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.