// Xen/ARCH/x86/mm. c
Void _ init init_frametable (void)
{
Unsigned long nr_pages, page_step, I, MFN;
Frame_table = (struct page_info *) frametable_pai_start;
Nr_pages = pfn_up (max_page * sizeof (* frame_table ));
Printk ("#################### test begin/N ");
Printk ("frametable_assist_start: % LX/N", frametable_assist_start );
Printk ("sizeof frame_table: % d/N", sizeof (* frame_table ));
Printk ("nr_pages: % LD/N", nr_pages );
Printk ("max_page: % LD/N", max_page );
Page_step = (1 <l2_pagetable_shift)> page_shift;
Printk ("page_step: % LD/N", page_step );
Printk ("l2_pagetable_shift: % d/N", l2_pagetable_shift );
Printk ("page_shift: % d/N", page_shift );
For (I = 0; I <nr_pages; I + = page_step)
{
MFN = alloc_boot_pages (min (nr_pages-I, page_step), page_step );
If (MFN = 0)
Panic ("not enough memory for frame table/N ");
Printk ("MFN ----");
Printk ("% lD", MFN );
Printk ("---- % LD/N", I );
Map_pages_to_xen (
Frametable_virt_start + (I <page_shift ),
MFN, page_step, page_hypervisor );
}
Printk ("#################### test end/N ");
Memset (frame_table, 0, nr_pages <page_shift );}
}
Then make & make install
Mkinitrd-v-f -- with = aacraid -- with = sd_mod -- with = scsi_mod/boot/initrd-2.6.18.8-xen.img 2.6.18.8-xen
Because the grub. conf file has been compiled before, you do not need to modify it here. roboot restarts the system.
[Root @ localhost ~] # XM DM
The output information is displayed. The custom output is as follows:
(Xen) ##################### test begin
(Xen) frametable_0000_start: f6800000 // (0xf6800000-0xfc800000)
(Xen) sizeof frame_table: 24
(Xen) nr_pages: 3072
(Xen) max_page: 524288 //
(Xen) page_step: 512
(Xen) l2_pagetable_shift: 21
(Xen) page_shift: 12
(Xen) MFN ---- 523264----0 // 524288-523264 = 1024, I/O remapping Area
(Xen) MFN ---- 522752----512
(Xen) MFN ---- 522240----1024
(Xen) MFN ---- 521728----1536
(Xen) MFN ---- 521216----2048
(Xen) MFN ---- 520704----2560
(Xen) ##################### test end
Analyze the above information:
1. Maximum page number max_page: 524288, physical memory capacity = max_page * 4kb = 2 GB
2. every element of the frame_table array is 24B. to track all physical pages, the array length should be max_page. Therefore, the number of pages occupied by the frame_table array is max_page * 24/4 kb = 3072, exactly equal to nr_pages.
3. page_step = 512 indicates that 512 pages are allocated each time the frame_table array is allocated space. The returned MFN values are:
(Xen) MFN ---- 523264 // 524288-523264 = 1024, I/O remapping Area
(Xen) MFN ---- 522752
(Xen) MFN ---- 522240
(Xen) MFN ---- 521728
(Xen) MFN ---- 521216
(Xen) MFN ---- 520704
This indicates that physical memory is allocated sequentially. In addition, the first MFN is 523264. Max_page-523264 = 1024, Which is exactly 4 MB, corresponds to the I/O remapping area in the xen 64 MB space, that is, I/O re ing. At the same time, it also indicates that the allocation of xen 64 MB address space starts from high to low, that is, it occupies the high-end 64 MB physical memory of the machine's physical memory. [The problem has occurred and is being further verified]
The above is purely personal speculation! I am very grateful for your comments and corrections!
Appendix:
Void _ init init_frametable (void)
{
Unsigned long nr_pages, page_step, I, MFN;
Frame_table = (struct page_info *) frametable_pai_start; // frame_table is the first address of the array.
// Sizeof (* frame_table) = 24.
Nr_pages = pfn_up (max_page * sizeof (* frame_table ));
// Nr_pages = 3072 (max_page * 24B/4kb = nr_pages)
Page_step = (1 <l2_pagetable_shift)> page_shift; // page_step = 512
For (I = 0; I <nr_pages; I + = page_step) // for (I = 0; I <3072; I = I + 512)
{
MFN = alloc_boot_pages (min (nr_pages-I, page_step), page_step );
If (MFN = 0)
Panic ("not enough memory for frame table/N ");
Map_pages_to_xen (
Frametable_virt_start + (I <page_shift ),
MFN, page_step, page_hypervisor );
}
Memset (frame_table, 0, nr_pages <page_shift); // nr_pages <page_shift = 12582912
// 12582912/max_page = 24
}
2. When the physical memory is 1 GB
(Xen) system RAM: 1023 MB (1048124kb)
(Xen) ##################### test begin
(Xen) frametable_1__start: f6800000
(Xen) sizeof frame_table: 24
(Xen) nr_pages: 1536
(Xen) max_page: 262144
(Xen) page_step: 512
(Xen) l2_pagetable_shift: 21
(Xen) page_shift: 12
(Xen) MFN ---- 258560----0
(Xen) MFN ---- 258048------512
(Xen) MFN ---- 257536----1024
(Xen) ##################### test end