Physical memory in X86 architecture-Overview through Linux

Source: Internet
Author: User

The full text of this article is reproduced at http://blog.csdn.net/dog250/article/details/6243276.

I have not studied other architectures in depth, but many of us know about x86. Its memory can support 4 GB (PAE is not considered), because the address bus is 32 bits, that is, 32 one-bit cables can select 4G addresses, therefore, we assume that after we buy two 2 GB memory inserts, our system will be able to have 4 GB memory available, and our system will be fully loaded, but is it true? The answer is no!
Because the so-called address bus 32-bit means that the bus from the CPU pin is 32-bit, which is for the CPU. Can these bus be connected to the motherboard's Ram? Will it connect to other devices? It depends on how the motherboard is designed. The beiqiao chip on the Main Board removes the address coupling between the CPU and the device. The typical design is that the 32-bit address bus from the CPU is all connected to the beiqiao chip, when the CPU sends a 32-bit address, such as 0xcb000000, it is up to beiqiao to decide where the address is sent, which may be sent to the Memory RAM, the display card, or other secondary bus, of course, it may also be sent to the nanqiao chip (a chip similar to the resolution address, the North Bridge decouples the CPU and the main board chip/bus, while the South Bridge decouples the main board chip/bus and external devices, devices such as ATA hard disks and USB can be connected to the nanqiao chip ). If beiqiao chooses to send this address to the PCI bus, it is clear that the Memory RAM cannot receive this address request, and since the design of the motherboard, theoretically this address will always be sent to PCI, of course, you can change it through methods such as jumpers (and many boards now have the BIOS "automatic detection/identification/setting" function, in this case, the address topology information does not need to be recorded in the bios, but is automatically generated when the BIOS starts to run. The generated method is similar to detecting-send level sequence signals to specific pins, then get a response, but the specific sending level information must also be determined by the motherboard and CPU), so although you have 4G so-called fully loaded Ram, however, its address 0xcb000000 cannot be used. The above is just an example. There are still many devices or bus on the motherboard that occupy some addresses on the address bus. In this way, there will be a lot of unavailable 4g RAM, which is typical, intel proposed PAE, which is a physical address extension that can support 4 GB or more RAM. In fact, its implementation is very simple. It adds several address bus bits to Ram and converts them into a 36-bit address bus, in this way, 64 gb ram can be inserted. At this time, the address bus space above 4 GB will not be occupied by other devices, while beiqiao will only send the address to ram.
Since the 4G address space cannot be fully used by the RAM memory, what addresses cannot be used by Ram? This information is very important, because this information will guide the operating system kernel to allocate physical memory. For example, the pages at the addresses used by other addresses cannot be allocated. Otherwise, the devices will be accessed, therefore, the pages at these addresses should be reserved and never used. In fact, they are wasted. The address information is stored in bios, and bios stores important information. This information can form a logical topology that truly reflects how the chips on the motherboard are arranged and placed, after the motherboard is powered on, the chip and bus on the motherboard form a real "map", which is detected under the guidance of the BIOS topology.
Since the BIOS stores the topology, how does the operating system kernel get it when it is started? after it is obtained, the operating system can establish its own physical address space ing. The method to obtain BIOS information is more than BIOS call, that is, 0x15 call. The parameter is specified by the register. If you want the address information, that is, the topology, then you need to set eax to 0x0000e820 and then read the returned information. The following is the address information obtained by Linux on machines with MB of memory, this information is called by BIOS during kernel startup:
BIOS-provided physical Ram map:
BIOS-e820: 0000000000000000-000000000009f800 (usable)
BIOS-e820: 000000000009f800-00000000000a0000 (Reserved)
BIOS-e820: 00000000000dc000-00000000000e0000 (Reserved)
BIOS-e820: 201710000000e4000-0000000000100000 (Reserved)
BIOS-e820: 0000000000100000-000000000fef0000 (usable)
BIOS-e820: 000000000fef0000-000000000feff000 (ACPI data)
BIOS-e820: 000000000feff000-000000000ff00000 (acpi nvs)
BIOS-e820: 000000000ff00000-0000000010000000 (usable)
BIOS-e820: 201710000fec00000-201710000fec10000 (Reserved)
BIOS-e820: 201710000fee00000-201710000fee01000 (Reserved)
BIOS-e820: 1270000fffe0000-0000000100000000 (Reserved)
Obviously, all RAM can be used. After all, it is too small. The address of a machine with 4 GB memory is as follows:
BIOS-provided physical Ram map:
BIOS-e820: 0000000000000000-000000000009f000 (usable)
BIOS-e820: 000000000009f000-00000000000a0000 (Reserved)
BIOS-e820: 00000000000f0000-0000000000100000 (Reserved)
BIOS-e820: 0000000000100000-00000000bdc90000 (usable)
BIOS-e820: commandid bdc90000-commandid bdce3000 (acpi nvs)
BIOS-e820: commandid bdce3000-commandid bdcf0000 (ACPI data)
BIOS-e820: 201710000bdcf0000-201710000bdd00000 (Reserved)
BIOS-e820: Too Many e0000000-too many f0000000 (Reserved)
BIOS-e820: 201710000fec00000-0000000100000000 (Reserved)
BIOS-e820: 0000000100000000-0000000140000000 (usable)
It can be seen that 0000000000100000-00000000bdc90000 a total of about 3 GB of RAM can be used by the OS, they can be addressable, and other nearly 1 GB RAM is set to reserved, they are wasted. In Linux/proc/meminfo, memtotal: The difference between 0x00000000bdc90000 and 0000000000100000 is displayed in a row. The specific devices used for these addresses can be seen in/proc/iomem, below is the iomem of the M memory machine:
Commandid -0000ffff: Reserved
0000000-0009f7ff: System Ram
0009f800-0009ffff: Reserved
000a0000-000bffff: Video RAM Area
000c0000-000c7fff: Video Rom
000c8000-000c8fff: adapter Rom
000c9000-000c9fff: adapter Rom
000ca000-000cafff: adapter Rom
000dc000-000dffff: Reserved
000e4000-000fffff: Reserved
000f0000-000fffff: system ROM
00100000-0feeffff: System Ram
0000000-01242d96: kernel code
01242d97-0133c847: kernel data
01394000-013cc243: Kernel BSS
0fef0000-0fefefff: ACPI tables
0feff000-0fefffff: ACPI non-volatile storage
0ff00000-0fffffff: System Ram
0000000-1000ffff: 0000:00:11. 0
10010000-1001ffff:. 0
10020000-1002ffff: 0000:00:13. 0
10030000-10037fff: 0000: 00: 0f. 0
10038000-1003bfff:. 0
E8000000-e87fffff: 0000: 00: 0f. 0
E8800000-e8800fff:. 0
F0000000-f7ffffff: 0000: 00: 0f. 0
Fec00000-fec0ffff: Reserved.
Fec00000-fec00fff: ioapic 0.
Fee00000-fee00fff: Local APIC
Fee00000-fee00fff: Reserved.
Fffe0000-ffffffff: Reserved // here is generally bios, all access from CPU to these addresses is routed to BIOS
Again, some addresses below 4G are reserved for the device instead of the ram below 4G. Many devices do not use the RAM chip for storage, they only occupy some addresses. For example, in the above iomem content, 000c8000-000c8fff: adapter Rom reserves the previous address to the ROM chip. When the CPU sends an access to one of the address segments, the chipset sends the address bus signal to the ROM instead of the Memory RAM.
In Linux, when the kernel is started, in a very early stage, the kernel calls detect_memory to detect the memory through the BIOS. It also calls detect_memory_e820 to detect the address information:
Static int detect_memory_e820 (void)
{
Int COUNT = 0;
Struct biosregs ireg, oreg;
Struct e820entry * DESC = boot_params.e820_map;
Static struct e820entry Buf;/* Static so it is zeroed */
Initregs (& ireg );
Ireg. Ax = 0xe820;
Ireg. Cx = sizeof Buf;
Ireg. edX = SMAP;
Ireg. DI = (size_t) & Buf;
Do {
Intcall (0x15, & ireg, & oreg); // call BIOS interrupt
Ireg. EBX = oreg. EBX;
If (oreg. eflags & x86_eflags_cf)
Break;
If (oreg. eax! = SMAP ){
Count = 0;
Break;
}
* DESC ++ = Buf;
Count ++;
} While (ireg. EBX & count <array_size (boot_params.e820_map ));
Return boot_params.e820_entries = count;
}
After this function is called, The boot_params.e820_map stores the "what is the address?" information. In the future, Linux will use this information when initializing the physical memory, for example, you can set the page to reversed at the address reserved for the device, so that when you allocate a physical page, the pages at these reserved addresses will be bypassed.
Appendix: Check for memory problems in Linux
In Linux, you can use top, free,/proc/meminfo and other methods to view the system memory. However, the total memory displayed by the kernel compiled by Different kernel compilation options is different, when highmem64g is compiled, that is, the compiled kernel is opened when PAE is enabled, the total memory size found will include the memory pages at the reserved address, and those pages are not calculated if PAE is not opened, obviously, the calculation method when you open PAE is unreasonable. After all, since there is so much memory, it should be usable. In fact, those pages cannot be used.
Appendix: Address ing diagram of the x86 System (Note: address, not Ram)

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.