Linux-0.11 kernel source code analysis series: on Linear address, logical address, physical address of the relationship and difference, linux-0.11 source code

Source: Internet
Author: User

Linux-0.11 kernel source code analysis series: on Linear address, logical address, physical address of the relationship and difference, linux-0.11 source code

/** Author: David Lin * Date: 2014-11-22pm * Email: linpeng1577@163.com or linpeng1577@gmail.com * world: the city of SZ, in China * Ver: 000.000.001 * history: editor time do * 1) linPeng 2014-11-22 created this file! * 2) */all of the following describes the programming rules based on the Linux0.11 kernel and all the material and non-material infrastructure in the programming age: the X86 protection mode provides 4G physical address space, from 0 to 0 xFFFFFFFF. Of course, this is only the size of the space that can be addressable on the address bus. The specific size should be determined based on the memory size mounted on the address bus. Physical address: When writing Linux0.11, Linus only has 16 MB of memory on his computer. Therefore, the physical address described in Linux0.11 source code is from 0 to 16 Mb. Linear address: The linear address is also a flat address from 0 to 0xFFFFFFFF. If the paging mechanism is not enabled, the linear address is equal to the physical address. If the paging mechanism is enabled, linear addresses to physical addresses must undergo second-level address conversion, not sequential ing. Linear addresses can be large, but they eventually run on physical addresses. The page missing mechanism and demand loading are designed to make programs far greater than physical memory, running in such a small physical memory, if the physical memory is large enough, these situations may not happen. This is like giving A seat on A bus. Assume that the seat is memory, and the other standing space is A hard disk. You are very happy when you get on the bus. You and your girlfriend (process A, B) have seats, if a pregnant woman got on the bus at this time, the conductor elder sister (operating system) found that "pregnant women are given priority" and began to ask "who gave a seat to pregnant women" (process scheduling ), however, unfortunately, this system is non-preemptible, and pregnant women (process S) have to wait. As an ideal and ethical programmer, don't let it go and stand up on their own (process suspension ), the operating system saw a guy release the seat (memory), so the waiting pregnant women sat in your original position, and you switched to the bus floor (hard disk ). When a car arrives at a certain station and pregnant women get off the bus, you can sit in the seat again (memory occupied). During the whole operation of the public car, the seat (memory) is limited, people do not keep going up and down, so people first stand in the carriage, and then occupy or release the memory (seats) according to various written and unwritten rules ). Seats are limited, while people are relatively unlimited. Maybe the operating system should consider how to use limited resources to serve more processes. Why is linear address not a one-to-one ing with physical address? Here is an example, which is just a personal understanding, not very rigorous: for example, when playing a game such as hero Lian, the running file reaches 10 Gb or more, it far exceeds the 4G memory space supported by the 32-bit XP system. So what we need is not to load all the code and data into the memory as soon as the program is executed, instead, it needs to be loaded again. This is the so-called requirement loading. First, log on to the hero game and the game software will apply for one memory from the operating system. Assume that the memory size is 600 mb, assuming that the physical address space occupies the physical address 0.6G-1.2G, for this application, it will think that it occupies the entire 10 Gb of memory, inside the application, it considers itself as starting from 0 addresses (actually at a physical address of MB), and the game master program will load its code to its 0 address, assuming that the master program occupies 0-m of address space relative to the address, this part of the program stays in the memory and will be automatically released only when the game exits, while other level options, they are all stored in the hard disk. They are loaded into the memory only when needed (for example, in the space of-m relative addresses ). For example, when you only play the level "tiger-style elites", the memory only loads the code and map data in the Level "tiger-style elites, the code and data of the "Normandy login" level are stored in the hard disk. When a player wants to switch from the "tiger-style elite" level to the "Normandy login" level, the code and data of the "Normandy login" level cover the code and data of the "tiger-style elite" level. What if the map data at the "Normandy login level" is larger than MB? Still need to load, that is why in the "legend" game that year, game players will feel that the map is slowly spread on the computer screen, because the first thing is to read the map from the hard disk to the memory, the video card then displays the data in the memory, which is a process of constant updating. Logical Address: A Logical Address is also called a virtual address. It refers to the address provided by the segmentation mechanism. It consists of a segment and an offset. The segment mechanism is the basis for converting virtual addresses to linear addresses. Linear address = Segment Base Address + offset address. For example, a data segment is allocated with a linear address space of 9 m. For the data segment, it actually does not know where it is the starting address, therefore, it requires a reference system. During the compilation process of the program, it considers that the starting part of the data segment is the 0 address. Therefore, the base address of the segment is obtained through the segment descriptor, And the offset address is added, the linear address is obtained.

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.