In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is Linux memory addressing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In the early days, programs were run directly on the physical address, that is, if the space required by this program does not exceed the physical memory of the machine, there will be no problem, but in the actual scenario, it is multi-tasking and multi-process, and this kind of physical address reserved to each process is unreliable.
Take Chestnut as an example: if there are three programs: aQuery, b, and c need 10m, b needs 100m, c needs 20m, and the total memory is 120m. According to the previous allocation, the first 10m is given to 10m by 10m, and the system still has 10m left, but c needs 20m. Obviously, the remaining memory is not enough for c. What shall I do?
Why memory management: 1. Efficiency problem
You may think that when the c program runs, the data of the b program is written to disk, and then the data is written back from the disk when b is run, not to mention that it can not meet the needs of the parallel running of the c program, and even the time-consuming problems caused by frequent io operations cannot be accepted.
two。 Process address isolation problem
In addition to efficiency issues, the space given to a process by reserved will crash if it needs to be accessed by another process. For example, the space accessed by a process is the first 10m, but if there is a piece of code in a program that accesses 10-110m, it may lead to the collapse of program b, so the address space of the process needs to be isolated from each other.
3. Relocation problem
In real scenarios, it is impossible for a single task to run in separate memory. When multiple tasks are running in parallel, it is possible to apply for addresses in other processes when dynamically applying for memory release. In this case, you need to relocate to a new address.
Memory management is nothing more than to find a way to solve the above three problems, how to improve the efficiency of memory use? How to isolate the address space of a process? How to solve the relocation problem when the program is running?
How memory management maps from virtual addresses to physical addresses:
The process of mapping memory management from a virtual address to a physical address is the process of solving the above three problems. Memory management uses segmentation mechanism and paging mechanism to solve the above three problems respectively, as shown in the following figure:
Segmentation mechanism:
As long as the program divides the segment and translates the whole segment to any location, the address in the segment remains the same relative to the base address of the segment. No matter what the base address of the segment is, as long as the offset address within the segment is given, cpu can access the correct instructions. So when loading the user program, as long as the contents of the whole segment are copied to a new location, and then the address in the segment base address register is changed to that address, the program can run accurately, because the program uses an intra-segment offset address, which is relative to the new segment base address. the content of the offset address is the same.
It can be seen that the segmentation mechanism solves the problem of inter-process isolation and relocation. This action is done in hardware, but some hardware does not have a segmentation mechanism. As a cross-platform linux, it uses a more general paging mechanism to solve the translation from linear address to virtual address to physical address.
Paging mechanism:
In order to be compatible with 32-bit and 64-bit, linux usually uses four-level page table, page global catalog, page parent catalog, page middle catalog, page table:
This does not explain in detail how linux converts linear addresses (virtual addresses) to physical addresses through a four-level page table.
When a process switches, it finds the pgd field in mm_struct according to task_struct, obtains the page global catalog of the new process, and then fills it into the CR3 register to complete the page switch.
Take a look at the process of mmu paging addressing:
The above code:
You can see that the physical address corresponding to the virtual address ffff99b488d48000 is 80000000c8d48000. This process is also the process of mmu.
This is the end of "what is Linux memory addressing"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.