Rev 34 | Rev 37 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 34 | Rev 35 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | 6 | ||
7 | <section> |
7 | <section> |
8 | <title>Virtual memory management</title> |
8 | <title>Virtual memory management</title> |
9 | 9 | ||
10 | <section> |
10 | <section> |
11 | <title>Address spaces</title> |
11 | <title>Introduction</title> |
12 | 12 | ||
- | 13 | <para>Virtual memory is a special memory management technique, used by |
|
- | 14 | kernel to achieve a bunch of mission critical goals. <itemizedlist> |
|
13 | <para /> |
15 | <listitem> |
- | 16 | Isolate each task from other tasks that are running on the system at the same time. |
|
- | 17 | </listitem> |
|
- | 18 | ||
- | 19 | <listitem> |
|
- | 20 | Allow to allocate more memory, than is actual physical memory size of the machine. |
|
- | 21 | </listitem> |
|
- | 22 | ||
- | 23 | <listitem> |
|
- | 24 | Allowing, in general, to load and execute two programs that are linked on the same address without complicated relocations. |
|
- | 25 | </listitem> |
|
- | 26 | </itemizedlist></para> |
|
14 | </section> |
27 | </section> |
15 | 28 | ||
16 | <section> |
29 | <section> |
- | 30 | ||
- | 31 | ||
17 | <title>Virtual address translation</title> |
32 | <title>Paging</title> |
- | 33 | ||
- | 34 | ||
- | 35 | ||
- | 36 | <para>Virtual memory is usually using paged memory model, where virtual |
|
- | 37 | memory address space is divided into the <emphasis>pages</emphasis> |
|
- | 38 | (usually having size 4096 bytes) and physical memory is divided into the |
|
- | 39 | frames (same sized as a page, of cause). Each page may be mapped to some |
|
- | 40 | frame and then, upon memory access to the virtual address, CPU performs |
|
- | 41 | <emphasis>address translation</emphasis> during the instruction |
|
- | 42 | execution. Non-existing mapping generates page fault exception, calling |
|
- | 43 | kernel exception handler, thus allowing kernel to manipulate rules of |
|
- | 44 | memory access. Information for pages mapping is stored by kernel in the |
|
- | 45 | <link linkend="page_tables">page tables</link></para> |
|
- | 46 | ||
- | 47 | ||
- | 48 | ||
- | 49 | <para>The majority of the architectures use multi-level page tables, |
|
- | 50 | which means need to access physical memory several times before getting |
|
- | 51 | physical address. This fact would make serios performance overhead in |
|
- | 52 | virtual memory management. To avoid this <link linkend="tlb">Traslation |
|
- | 53 | Lookaside Buffer (TLB)</link> is used.</para> |
|
- | 54 | ||
- | 55 | ||
- | 56 | ||
- | 57 | <para>At the moment HelenOS does not support swapping.</para> |
|
18 | 58 | ||
19 | <para /> |
- | |
- | 59 | - pouzivame vypadky stranky k alokaci ramcu on-demand v ramci as_area - na architekturach, ktere to podporuji, podporujeme non-exec stranky |
|
20 | </section> |
60 | </section> |
21 | 61 | ||
22 | <para>Page tables. 4 level hierarchical and hash directly supported. B+ |
62 | <section> |
23 | Tree can be implemented.</para> |
63 | <title>Address spaces</title> |
24 | 64 | ||
- | 65 | <section> |
|
25 | <para>For paging there is an abstract layer</para> |
66 | <title>Address spaces and areas</title> |
26 | 67 | ||
27 | <para>TLB shootdown implementation (update TLB upon mapping |
68 | <para>- adresovy prostor se sklada z tzv. address space areas |
- | 69 | usporadanych v B+stromu; tyto areas popisuji vyuzivane casti |
|
28 | update/remove). TLB shootdown ASID/ASID:PAGE/ALL. TLB shootdown requests |
70 | adresoveho prostoru patrici do user address space. Kazda cast je dana |
- | 71 | svoji bazovou adresou, velikosti a flagy (rwx/dd).</para> |
|
- | 72 | ||
- | 73 | <para>- uzivatelske thready maji moznost manipulovat se svym adresovym |
|
- | 74 | prostorem (vytvaret/resizovat/sdilet) as_areas pomoci syscallu</para> |
|
- | 75 | </section> |
|
- | 76 | ||
- | 77 | <section> |
|
- | 78 | <title>Address Space ID (ASID)</title> |
|
- | 79 | ||
- | 80 | <para>- nektery hardware umoznuje rozlisit ruzne adresove prostory od |
|
- | 81 | sebe (cilem je maximalizovat vyuziti TLB); dela to tak, ze s kazdou |
|
- | 82 | polozkou TLB/strankovacich tabulek sdruzi identifikator adresoveho |
|
- | 83 | prostoru (ASID, RID, ppc32 ???). Tyto id mivaji ruznou sirku: 8-bitu |
|
- | 84 | az 24-bitu (kolik ma ppc32?)</para> |
|
- | 85 | ||
- | 86 | <para>- kernel tomu rozumi a sam pouziva abstrakci ASIDu (na ia64 to |
|
- | 87 | je napr. cislo odvozene od RIDu, na mips32 to je ASID samotny); |
|
- | 88 | existence ASIDu je nutnou podminkou pouziti _global_ page hash table |
|
- | 89 | mechanismu.</para> |
|
- | 90 | ||
- | 91 | <para>- na vsech arch. plati, ze asidu je mnohem mene, nez teoreticky |
|
29 | can come in asynchroniously so there is a cache of TLB shootdown requests. |
92 | pocet soucasne bezicich tasku ~ adresovych prostoru, takze je |
- | 93 | implementovan mechanismus, ktery umoznuje jednomu adresovemu prostoru |
|
30 | Upon cache overflow TLB shootdown ALL is executed</para> |
94 | ASID odebrat a pridelit ho jinemu</para> |
31 | 95 | ||
32 | <para>Address spaces. Address space area (B+ tree). Only for uspace. Set |
96 | <para>- vztah task ~ adresovy prostor: teoreticky existuje moznost, ze |
- | 97 | je adresovy prostor sdilen vice tasky, avsak tuto moznost nepouzivame |
|
- | 98 | a neni ani nijak osetrena. Tim padem plati, ze kazdy task ma vlastni |
|
- | 99 | adresovy prostor</para> |
|
- | 100 | </section> |
|
- | 101 | </section> |
|
- | 102 | ||
- | 103 | <section> |
|
- | 104 | <title>Virtual address translation</title> |
|
- | 105 | ||
- | 106 | <section id="page_tables"> |
|
- | 107 | <title>Page tables</title> |
|
- | 108 | ||
- | 109 | <para>HelenOS kernel has two different approaches to the paging |
|
- | 110 | implementation: <emphasis>4 level page tables</emphasis> and |
|
33 | of syscalls (shrink/extend etc). Special address space area type - device |
111 | <emphasis>global hash tables</emphasis>, which are accessible via |
- | 112 | generic paging abstraction layer. This division was caused by the |
|
- | 113 | major architectural differences between different platforms.</para> |
|
- | 114 | ||
- | 115 | <formalpara> |
|
- | 116 | <title>4-level page tables</title> |
|
- | 117 | ||
- | 118 | <para>4-level page tables are the generalization of the hardware |
|
- | 119 | capabilities of the certain platforms. <itemizedlist> |
|
- | 120 | <listitem> |
|
34 | - prohibits shrink/extend syscalls to call on it. Address space has link |
121 | ia32 uses 2-level page tables, with full hardware support. |
- | 122 | </listitem> |
|
- | 123 | ||
- | 124 | <listitem> |
|
- | 125 | amd64 uses 4-level page tables, also coming with full hardware support. |
|
- | 126 | </listitem> |
|
- | 127 | ||
- | 128 | <listitem> |
|
- | 129 | mips and ppc32 have 2-level tables, software simulated support. |
|
- | 130 | </listitem> |
|
- | 131 | </itemizedlist></para> |
|
- | 132 | </formalpara> |
|
- | 133 | ||
- | 134 | <formalpara> |
|
- | 135 | <title>Global hash tables</title> |
|
- | 136 | ||
- | 137 | <para>- global page hash table: existuje jen jedna v celem systemu |
|
- | 138 | (vyuziva ji ia64), pozn. ia64 ma zatim vypnuty VHPT. Pouziva se |
|
- | 139 | genericke hash table s oddelenymi collision chains</para> |
|
- | 140 | </formalpara> |
|
- | 141 | ||
35 | to mapping tables (hierarchical - per Address space, hash - global |
142 | <para>Thanks to the abstract paging interface, there is possibility |
- | 143 | left have more paging implementations, for example B-Tree page |
|
36 | tables).</para> |
144 | tables.</para> |
- | 145 | </section> |
|
- | 146 | ||
- | 147 | <section id="tlb"> |
|
- | 148 | <title>Translation Lookaside buffer</title> |
|
- | 149 | ||
- | 150 | <para>- TLB cachuji informace ve strankovacich tabulkach; alternativne |
|
- | 151 | se lze na strankovaci tabulky (ci ruzne hw rozsireni [e.g. VHPT, ppc32 |
|
- | 152 | hw hash table]) divat jako na velke TLB</para> |
|
- | 153 | ||
- | 154 | <para>- pri modifikaci mapovani nebo odstraneni mapovani ze |
|
- | 155 | strankovacich tabulek je potreba zajistit konsistenci TLB a techto |
|
- | 156 | tabulek; nutne delat na vsech CPU; na to mame zjednodusenou verzi TLB |
|
- | 157 | shootdown mechanismu; je to variace na algoritmus popsany zde: D. |
|
- | 158 | Black et al., "Translation Lookaside Buffer Consistency: A Software |
|
- | 159 | Approach," Proc. Third Int'l Conf. Architectural Support for |
|
- | 160 | Programming Languages and Operating Systems, 1989, pp. 113-122.</para> |
|
- | 161 | ||
- | 162 | <para>- nutno poznamenat, ze existuji odlehcenejsi verze TLB shootdown |
|
- | 163 | algoritmu</para> |
|
- | 164 | </section> |
|
- | 165 | </section> |
|
37 | </section> |
166 | </section> |
38 | 167 | ||
39 | <!-- End of VM --> |
168 | <!-- End of VM --> |
40 | 169 | ||
41 | <section> |
170 | <section> |