📄 memory.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0064)http://www.geocities.com/marco_corvi/games/lkpe/memory/index.htm -->
<HTML><HEAD><TITLE>Memory</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"><LINK
href="Memory_file/style.css" rel=stylesheet>
<META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD>
<BODY>
<H2>Memory</H2>
<P>Memory management is not an easy task. It begins with memory detection at
setup, when the kernel has not been uncompressed yet. The setup.S code tries to
detect the amount of memory present on the system in three different ways: with
the instruction e820, with the instruction e801, and with the instruction 88.
<P>Linux uses a flat memory model with four descriptors (besides a few others),
two for the kernel (code+data) and two for user processes (code+data), each
spanning the full 4 GB. The memory is paged: at the beginning of the kernel code
a few pages are defined: the GDT (swapper_pg_dir), the page zero and the page
one, the empty_zero_page, the empty_bad_page and the empty_bad_pte_page. The
first and second user entries (index 0, 1) and kernel entries (index 768, 769)
of the swapper_pg_dir point to pg0 and pg1 respectively. The kernel loaded at
physical address 0x00100000, and these pages begin at 0x00101000.
<P>Paging is activated by the function <TT>paging_init()</TT> ( in
arch/i386/mm/init.c ) which calls <TT>pagetable_init()</TT>, sets the
<TT>swapper_pg_dir</TT> into cr3, and flushes the TLB (translation lookaside
buffer). It also sets the zones sizes and calls <TT>free_area_init()</TT>.
<P><TT>pagetable_init()</TT> sets up the pagetables. The first 8 MB are mapped
into pages in head.S. The base page directory is the page
<TT>swapper_pg_dir</TT>. For each entry in the PGD from PAGE_OFFSET to the
virtual address of the last physical page frame (therefore for each entry in the
kernel virtual address space) prepare the pages. If the CPU has PSE (page size
extension) use 4MB pages: set the entry value to the physical address
(<TT>__pa</TT>) of the entry virtual address, plus some flags. In other words
entry 0x300, which corresponds to the virtual address 0xc0000000, is assigned
value 0x0. Entry 0x301 (virtual 0xc0400000) is assigned 0x00400000. Otherwise a
PTE page is allocated with <TT>alloc_bootmem_low_pages</TT> and each entry in
the PTE is assigned the physical address of the virtual address <TT>pgd *
PGDIR_SIZE + pte * PAGE_SIZE</TT>; finally the PGD entry is assigned the
physical address of the PTE page. For example the entries of the first PTE are
assigned addresses 0x00400000, 0x00401000, etc.
<P><TT>mem_map</TT> is defind in memory.c and initialized in numa.c to
(mem_map_t *)PAGE_OFFSET. In other words the global mem_map is virtual address
0xc0000000, ie, physical address 0x0. The kernel is at address 0x00100000 (1MB),
ie, at page 0x100 (256). The struct page is rather short, 64 bytes (2**6). Each
4KB (2**12) page contains 2**6 struct page's, which map 256KB (2**18). 256 pages
therefore map 64MB (2**26). Need more room if we have more memory: in order to
map 1GB (2**30) we need 2**12 pages of mem_map, that is a mem_map of size 2**24
(4MB), and the kernel must be at 0x00400000. [TO FIX]
<P>With 4MB per page, need 256 pages (4KB*2563 = 1MB of space) to make the pages
for 1 GB of memory. Beside, the MM uses 64B for each page_t struct, thus 1GB
(=256K pages) takes 4MB of space for the mem_map.
<P>
<DIV><IMG src="Memory_file/memory.gif"> </DIV>
<DIV></DIV><B>Exercise</B><BR>
<DIV>[to do] </DIV>
<P><BR clear=all><FONT size=-1>Marco Corvi - 2003</FONT> <!-- text below generated by server. PLEASE REMOVE --></OBJECT></LAYER>
<DIV></DIV></SPAN></STYLE></NOSCRIPT></TABLE></SCRIPT></APPLET>
<SCRIPT
language=JavaScript>var PUpage="76001084"; var PUprop="geocities"; </SCRIPT>
<SCRIPT language=JavaScript src="Memory_file/pu5geo.js"></SCRIPT>
<SCRIPT language=JavaScript src="Memory_file/ygIELib9.js"></SCRIPT>
<SCRIPT language=JavaScript>var yviContents='http://us.toto.geo.yahoo.com/toto?s=76001084&l=NE&b=1&t=1057747167';yviR='us';yfiEA(0);</SCRIPT>
<SCRIPT language=JavaScript src="Memory_file/mc.js"></SCRIPT>
<SCRIPT language=JavaScript src="Memory_file/geov2.js"></SCRIPT>
<SCRIPT language=javascript>geovisit();</SCRIPT>
<NOSCRIPT><IMG height=1 alt=setstats src="Memory_file/visit.gif" width=1
border=0></NOSCRIPT> <IMG height=1 alt=1 src="Memory_file/serv.gif" width=1> <!-- w9.geo.scd.yahoo.com compressed/chunked Wed Jul 9 03:39:27 PDT 2003 --></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -