How much memory does the temporary page table map during Linux Startup?

Source: Internet
Author: User
Starting from the linux-2.4 kernel, when creating a temporary page table, the general textbooks all say that the physical memory is mapped 8 m, but why is the ing 8 m? At that time there was information on the Internet said 8 m enough, but why is enough, has not been thoroughly clarified, and today again to analyze this part of the code (linux-2.6.24 ). First, let's look at the following memory layout diagram: The size of memory mapped to a temporary page table depends on the following aspects: (1) kernel size in Protected Mode: kernel code must be mapped (2) size of the space occupied by the temporary page table: assume that the temporary page table maps to the linear address space of the entire 4G, the number of pages = 4g/4 k = 1 M. Each page corresponds to a page table item, 4 bytes, so a total of 4 MB space (3) bootmem allocator is used for memory management before the real page table is created. He uses a single-digit chart to manage the entire memory, each bit represents a page box. If there is 4 GB physical memory, 1 MB of page Space = 1 m/8 = 128 K. (4) because of the space occupied by alignment (which can be ignored, feel the order of magnitude of K), the physical memory to be mapped is approximately equal: protection Mode kernel size + space occupied by temporary page tables + bootmem Allocator bit chart size = Current kernel approximately 4 m Max4 m 128 K = 8 m + 128 K in the Linux Kernel head_32.s, run the following code: movl $ (pg0-_ page_offset), % EDI
Movl $ (swapper_pg_dir-_ page_offset), % edX
Movl $0x007, % eax/* 0x007 = present + RW + User */
10:
Leal 0x007 (% EDI), % ECx/* Create PVDF entry */
Movl % ECx, (% EDX)/* store identity PVDF entry */
Movl % ECx, page_pde_offset (% EDX)/* store kernel PVDF entry */
Addl $4, % edX
Movl $1024, % ECx
11:
Stosl
Addl $0x1000, % eax
Loop 11b
/* End condition: we must map up to and including init_map_beyond_end */
/* Bytes beyond the end of our own page tables; The + 0x007 is the attribute bits */
Leal (init_map_beyond_end + 0x007) (% EDI), % EBP
CMPL % EBP, % eax
JB 10b
Movl % EDI, (init_pg_tables_end-_ page_offset) the red part is related to the mapped memory: bytes = bootbitmap_size + (page_table_size + allocator_slop) * page_size_asm = 128 K + (4 K + 4) * 4 k = 128 K + 4 m + 4 K, so 8 m physical memory is mapped, that is, 10: the subsequent code is executed twice, this fully satisfies the size of the physical memory to be mapped. You can obtain the verification from the comments in the kernel code :/*
* Paging_init () sets up the page tables-note that the first 8 Mb are
* Already mapped by head. S.
*
* This routines also unmaps the page at virtual kernel address 0, so
* That we can trap those pesky null-reference errors in the kernel.
*/We also mentioned that the ing of the first page starting with the virtual address = 0 is removed, mainly to track the error of NULL pointer reference. The above are some of my experiences in the code, which may be incorrect. I hope you can give me some advice and communicate with each other.

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.