Rev 26 | Rev 34 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 26 | Rev 27 | ||
---|---|---|---|
1 | <?xml version="1.0" encoding="UTF-8"?> |
1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <chapter id="mm"> |
2 | <chapter id="mm"> |
3 | <?dbhtml filename="mm.html"?> |
3 | <?dbhtml filename="mm.html"?> |
4 | 4 | ||
5 | <title>Memory management</title> |
5 | <title>Memory management</title> |
6 | 6 | ||
7 | <section> |
7 | <section> |
8 | <!-- VM --> |
8 | <!-- VM --> |
9 | 9 | ||
10 | <title>Virtual memory management</title> |
10 | <title>Virtual memory management</title> |
11 | 11 | ||
12 | <section> |
12 | <section> |
13 | <title>Address spaces</title> |
13 | <title>Address spaces</title> |
14 | 14 | ||
15 | <para></para> |
15 | <para></para> |
16 | </section> |
16 | </section> |
17 | 17 | ||
18 | <section> |
18 | <section> |
19 | <title>Virtual address translation</title> |
19 | <title>Virtual address translation</title> |
20 | 20 | ||
21 | <para></para> |
21 | <para></para> |
22 | </section> |
22 | </section> |
23 | </section> |
23 | </section> |
24 | 24 | ||
25 | <!-- End of VM --> |
25 | <!-- End of VM --> |
26 | 26 | ||
27 | <section> |
27 | <section> |
28 | <!-- Phys mem --> |
28 | <!-- Phys mem --> |
29 | 29 | ||
30 | <title>Physical memory management</title> |
30 | <title>Physical memory management</title> |
31 | 31 | ||
32 | <section id="zones_and_frames"> |
32 | <section id="zones_and_frames"> |
33 | <title>Zones and frames</title> |
33 | <title>Zones and frames</title> |
34 | 34 | ||
35 | <para> |
35 | <para> |
36 | <!--graphic fileref="images/mm2.png" /--> |
36 | <!--graphic fileref="images/mm2.png" /--> |
37 | 37 | ||
38 | <!--graphic fileref="images/buddy_alloc.svg" format="SVG" /--> |
38 | <!--graphic fileref="images/buddy_alloc.svg" format="SVG" /--> |
39 | <mediaobject |
- | |
40 | 39 | ||
41 | 40 | ||
42 | </para> |
41 | </para> |
43 | 42 | ||
44 | <para>On some architectures not whole physical memory is available for |
43 | <para>On some architectures not whole physical memory is available for |
45 | conventional usage. This limitations require from kernel to maintain a |
44 | conventional usage. This limitations require from kernel to maintain a |
46 | table of available and unavailable ranges of physical memory addresses. |
45 | table of available and unavailable ranges of physical memory addresses. |
47 | Main idea of zones is in creating memory zone entity, that is a |
46 | Main idea of zones is in creating memory zone entity, that is a |
48 | continuous chunk of memory available for allocation. If some chunk is |
47 | continuous chunk of memory available for allocation. If some chunk is |
49 | not available, we simply do not put it in any zone.</para> |
48 | not available, we simply do not put it in any zone.</para> |
50 | 49 | ||
51 | <para>Zone is also serves for informational purposes, containing |
50 | <para>Zone is also serves for informational purposes, containing |
52 | information about number of free and busy frames. Physical memory |
51 | information about number of free and busy frames. Physical memory |
53 | allocation is also done inside the certain zone. Allocation of zone |
52 | allocation is also done inside the certain zone. Allocation of zone |
54 | frame must be organized by the <link linkend="frame_allocator">frame |
53 | frame must be organized by the <link linkend="frame_allocator">frame |
55 | allocator</link> associated with the zone.</para> |
54 | allocator</link> associated with the zone.</para> |
56 | 55 | ||
57 | <para>Some of the architectures (mips32, ppc32) have only one zone, that |
56 | <para>Some of the architectures (mips32, ppc32) have only one zone, that |
58 | covers whole physical memory, and the others (like ia32) may have |
57 | covers whole physical memory, and the others (like ia32) may have |
59 | multiple zones. Information about zones on current machine is stored in |
58 | multiple zones. Information about zones on current machine is stored in |
60 | BIOS hardware tables or can be hardcoded into kernel during compile |
59 | BIOS hardware tables or can be hardcoded into kernel during compile |
61 | time.</para> |
60 | time.</para> |
62 | </section> |
61 | </section> |
63 | 62 | ||
64 | <section id="frame_allocator"> |
63 | <section id="frame_allocator"> |
65 | <title>Frame allocator</title> |
64 | <title>Frame allocator</title> |
66 | 65 | ||
67 | <formalpara> |
66 | <formalpara> |
68 | <title>Overview</title> |
67 | <title>Overview</title> |
69 | 68 | ||
70 | <para>Frame allocator provides physical memory allocation for the |
69 | <para>Frame allocator provides physical memory allocation for the |
71 | kernel. Because of zonal organization of physical memory, frame |
70 | kernel. Because of zonal organization of physical memory, frame |
72 | allocator is always working in context of some zone, thus making |
71 | allocator is always working in context of some zone, thus making |
73 | impossible to allocate a piece of memory, which lays in different |
72 | impossible to allocate a piece of memory, which lays in different |
74 | zone, which cannot happen, because two adjacent zones can be merged |
73 | zone, which cannot happen, because two adjacent zones can be merged |
75 | into one. Frame allocator is also being responsible to update |
74 | into one. Frame allocator is also being responsible to update |
76 | information on the number of free/busy frames in zone. Physical memory |
75 | information on the number of free/busy frames in zone. Physical memory |
77 | allocation inside one <link linkend="zones_and_frames">memory |
76 | allocation inside one <link linkend="zones_and_frames">memory |
78 | zone</link> is being handled by an instance of <link |
77 | zone</link> is being handled by an instance of <link |
79 | linkend="buddy_allocator">buddy allocator</link> tailored to allocate |
78 | linkend="buddy_allocator">buddy allocator</link> tailored to allocate |
80 | blocks of physical memory frames.</para> |
79 | blocks of physical memory frames.</para> |
81 | </formalpara> |
80 | </formalpara> |
82 | 81 | ||
83 | <formalpara> |
82 | <formalpara> |
84 | <title>Allocation / deallocation</title> |
83 | <title>Allocation / deallocation</title> |
85 | 84 | ||
86 | <para>Upon allocation request, frame allocator tries to find first |
85 | <para>Upon allocation request, frame allocator tries to find first |
87 | zone, that can satisfy the incoming request (has required amount of |
86 | zone, that can satisfy the incoming request (has required amount of |
88 | free frames to allocate). During deallocation, frame allocator needs |
87 | free frames to allocate). During deallocation, frame allocator needs |
89 | to find zone, that contain deallocated frame. This approach could |
88 | to find zone, that contain deallocated frame. This approach could |
90 | bring up two potential problems: <itemizedlist> |
89 | bring up two potential problems: <itemizedlist> |
91 | <listitem> |
90 | <listitem> |
92 | Linear search of zones does not any good to performance, but number of zones is not expected to be high. And if yes, list of zones can be replaced with more time-efficient B-tree. |
91 | Linear search of zones does not any good to performance, but number of zones is not expected to be high. And if yes, list of zones can be replaced with more time-efficient B-tree. |
93 | </listitem> |
92 | </listitem> |
94 | 93 | ||
95 | <listitem> |
94 | <listitem> |
96 | Quickly find out if zone contains required number of frames to allocate and if this chunk of memory is properly aligned. This issue is perfectly solved bu the buddy allocator. |
95 | Quickly find out if zone contains required number of frames to allocate and if this chunk of memory is properly aligned. This issue is perfectly solved bu the buddy allocator. |
97 | </listitem> |
96 | </listitem> |
98 | </itemizedlist></para> |
97 | </itemizedlist></para> |
99 | </formalpara> |
98 | </formalpara> |
100 | </section> |
99 | </section> |
101 | </section> |
100 | </section> |
102 | 101 | ||
103 | <section id="buddy_allocator"> |
102 | <section id="buddy_allocator"> |
104 | <title>Buddy allocator</title> |
103 | <title>Buddy allocator</title> |
105 | 104 | ||
106 | <section> |
105 | <section> |
107 | <title>Overview</title> |
106 | <title>Overview</title> |
108 | 107 | ||
109 | <para>In buddy allocator, memory is broken down into power-of-two sized |
108 | <para>In buddy allocator, memory is broken down into power-of-two sized |
110 | naturally aligned blocks. These blocks are organized in an array of |
109 | naturally aligned blocks. These blocks are organized in an array of |
111 | lists in which list with index i contains all unallocated blocks of the |
110 | lists in which list with index i contains all unallocated blocks of the |
112 | size <mathphrase>2<superscript>i</superscript></mathphrase>. The index i |
111 | size <mathphrase>2<superscript>i</superscript></mathphrase>. The index i |
113 | is called the order of block. Should there be two adjacent equally sized |
112 | is called the order of block. Should there be two adjacent equally sized |
114 | blocks in list <mathphrase>i</mathphrase> (i.e. buddies), the buddy |
113 | blocks in list <mathphrase>i</mathphrase> (i.e. buddies), the buddy |
115 | allocator would coalesce them and put the resulting block in list |
114 | allocator would coalesce them and put the resulting block in list |
116 | <mathphrase>i + 1</mathphrase>, provided that the resulting block would |
115 | <mathphrase>i + 1</mathphrase>, provided that the resulting block would |
117 | be naturally aligned. Similarily, when the allocator is asked to |
116 | be naturally aligned. Similarily, when the allocator is asked to |
118 | allocate a block of size |
117 | allocate a block of size |
119 | <mathphrase>2<superscript>i</superscript></mathphrase>, it first tries |
118 | <mathphrase>2<superscript>i</superscript></mathphrase>, it first tries |
120 | to satisfy the request from list with index i. If the request cannot be |
119 | to satisfy the request from list with index i. If the request cannot be |
121 | satisfied (i.e. the list i is empty), the buddy allocator will try to |
120 | satisfied (i.e. the list i is empty), the buddy allocator will try to |
122 | allocate and split larger block from list with index i + 1. Both of |
121 | allocate and split larger block from list with index i + 1. Both of |
123 | these algorithms are recursive. The recursion ends either when there are |
122 | these algorithms are recursive. The recursion ends either when there are |
124 | no blocks to coalesce in the former case or when there are no blocks |
123 | no blocks to coalesce in the former case or when there are no blocks |
125 | that can be split in the latter case.</para> |
124 | that can be split in the latter case.</para> |
126 | 125 | ||
127 | <graphic fileref="images/mm1.png" format="EPS" /> |
126 | <!--graphic fileref="images/mm1.png" format="EPS" /--> |
128 | 127 | ||
129 | <para>This approach greatly reduces external fragmentation of memory and |
128 | <para>This approach greatly reduces external fragmentation of memory and |
130 | helps in allocating bigger continuous blocks of memory aligned to their |
129 | helps in allocating bigger continuous blocks of memory aligned to their |
131 | size. On the other hand, the buddy allocator suffers increased internal |
130 | size. On the other hand, the buddy allocator suffers increased internal |
132 | fragmentation of memory and is not suitable for general kernel |
131 | fragmentation of memory and is not suitable for general kernel |
133 | allocations. This purpose is better addressed by the <link |
132 | allocations. This purpose is better addressed by the <link |
134 | linkend="slab">slab allocator</link>.</para> |
133 | linkend="slab">slab allocator</link>.</para> |
135 | </section> |
134 | </section> |
136 | 135 | ||
137 | <section> |
136 | <section> |
138 | <title>Implementation</title> |
137 | <title>Implementation</title> |
139 | 138 | ||
140 | <para>The buddy allocator is, in fact, an abstract framework wich can be |
139 | <para>The buddy allocator is, in fact, an abstract framework wich can be |
141 | easily specialized to serve one particular task. It knows nothing about |
140 | easily specialized to serve one particular task. It knows nothing about |
142 | the nature of memory it helps to allocate. In order to beat the lack of |
141 | the nature of memory it helps to allocate. In order to beat the lack of |
143 | this knowledge, the buddy allocator exports an interface that each of |
142 | this knowledge, the buddy allocator exports an interface that each of |
144 | its clients is required to implement. When supplied an implementation of |
143 | its clients is required to implement. When supplied an implementation of |
145 | this interface, the buddy allocator can use specialized external |
144 | this interface, the buddy allocator can use specialized external |
146 | functions to find buddy for a block, split and coalesce blocks, |
145 | functions to find buddy for a block, split and coalesce blocks, |
147 | manipulate block order and mark blocks busy or available. For precize |
146 | manipulate block order and mark blocks busy or available. For precize |
148 | documentation of this interface, refer to <link linkend="???">HelenOS |
147 | documentation of this interface, refer to <link linkend="???">HelenOS |
149 | Generic Kernel Reference Manual</link>.</para> |
148 | Generic Kernel Reference Manual</link>.</para> |
150 | 149 | ||
151 | <formalpara> |
150 | <formalpara> |
152 | <title>Data organization</title> |
151 | <title>Data organization</title> |
153 | 152 | ||
154 | <para>Each entity allocable by the buddy allocator is required to |
153 | <para>Each entity allocable by the buddy allocator is required to |
155 | contain space for storing block order number and a link variable used |
154 | contain space for storing block order number and a link variable used |
156 | to interconnect blocks within the same order.</para> |
155 | to interconnect blocks within the same order.</para> |
157 | 156 | ||
158 | <para>Whatever entities are allocated by the buddy allocator, the |
157 | <para>Whatever entities are allocated by the buddy allocator, the |
159 | first entity within a block is used to represent the entire block. The |
158 | first entity within a block is used to represent the entire block. The |
160 | first entity keeps the order of the whole block. Other entities within |
159 | first entity keeps the order of the whole block. Other entities within |
161 | the block are assigned the magic value |
160 | the block are assigned the magic value |
162 | <constant>BUDDY_INNER_BLOCK</constant>. This is especially important |
161 | <constant>BUDDY_INNER_BLOCK</constant>. This is especially important |
163 | for effective identification of buddies in one-dimensional array |
162 | for effective identification of buddies in one-dimensional array |
164 | because the entity that represents a potential buddy cannot be |
163 | because the entity that represents a potential buddy cannot be |
165 | associated with <constant>BUDDY_INNER_BLOCK</constant> (i.e. if it is |
164 | associated with <constant>BUDDY_INNER_BLOCK</constant> (i.e. if it is |
166 | associated with <constant>BUDDY_INNER_BLOCK</constant> then it is not |
165 | associated with <constant>BUDDY_INNER_BLOCK</constant> then it is not |
167 | a buddy).</para> |
166 | a buddy).</para> |
168 | </formalpara> |
167 | </formalpara> |
169 | 168 | ||
170 | <formalpara> |
169 | <formalpara> |
171 | <title>Data organization</title> |
170 | <title>Data organization</title> |
172 | 171 | ||
173 | <para>Buddy allocator always uses first frame to represent frame |
172 | <para>Buddy allocator always uses first frame to represent frame |
174 | block. This frame contains <varname>buddy_order</varname> variable to |
173 | block. This frame contains <varname>buddy_order</varname> variable to |
175 | provide information about the block size it actually represents ( |
174 | provide information about the block size it actually represents ( |
176 | <mathphrase>2<superscript>buddy_order</superscript></mathphrase> |
175 | <mathphrase>2<superscript>buddy_order</superscript></mathphrase> |
177 | frames block). Other frames in block have this value set to magic |
176 | frames block). Other frames in block have this value set to magic |
178 | <constant>BUDDY_INNER_BLOCK</constant> that is much greater than buddy |
177 | <constant>BUDDY_INNER_BLOCK</constant> that is much greater than buddy |
179 | <varname>max_order</varname> value.</para> |
178 | <varname>max_order</varname> value.</para> |
180 | 179 | ||
181 | <para>Each <varname>frame_t</varname> also contains pointer member to |
180 | <para>Each <varname>frame_t</varname> also contains pointer member to |
182 | hold frame structure in the linked list inside one order.</para> |
181 | hold frame structure in the linked list inside one order.</para> |
183 | </formalpara> |
182 | </formalpara> |
184 | 183 | ||
185 | <formalpara> |
184 | <formalpara> |
186 | <title>Allocation algorithm</title> |
185 | <title>Allocation algorithm</title> |
187 | 186 | ||
188 | <para>Upon <mathphrase>2<superscript>i</superscript></mathphrase> |
187 | <para>Upon <mathphrase>2<superscript>i</superscript></mathphrase> |
189 | frames block allocation request, allocator checks if there are any |
188 | frames block allocation request, allocator checks if there are any |
190 | blocks available at the order list <varname>i</varname>. If yes, |
189 | blocks available at the order list <varname>i</varname>. If yes, |
191 | removes block from order list and returns its address. If no, |
190 | removes block from order list and returns its address. If no, |
192 | recursively allocates |
191 | recursively allocates |
193 | <mathphrase>2<superscript>i+1</superscript></mathphrase> frame block, |
192 | <mathphrase>2<superscript>i+1</superscript></mathphrase> frame block, |
194 | splits it into two |
193 | splits it into two |
195 | <mathphrase>2<superscript>i</superscript></mathphrase> frame blocks. |
194 | <mathphrase>2<superscript>i</superscript></mathphrase> frame blocks. |
196 | Then adds one of the blocks to the <varname>i</varname> order list and |
195 | Then adds one of the blocks to the <varname>i</varname> order list and |
197 | returns address of another.</para> |
196 | returns address of another.</para> |
198 | </formalpara> |
197 | </formalpara> |
199 | 198 | ||
200 | <formalpara> |
199 | <formalpara> |
201 | <title>Deallocation algorithm</title> |
200 | <title>Deallocation algorithm</title> |
202 | 201 | ||
203 | <para>Check if block has so called buddy (another free |
202 | <para>Check if block has so called buddy (another free |
204 | <mathphrase>2<superscript>i</superscript></mathphrase> frame block |
203 | <mathphrase>2<superscript>i</superscript></mathphrase> frame block |
205 | that can be linked with freed block into the |
204 | that can be linked with freed block into the |
206 | <mathphrase>2<superscript>i+1</superscript></mathphrase> block). |
205 | <mathphrase>2<superscript>i+1</superscript></mathphrase> block). |
207 | Technically, buddy is a odd/even block for even/odd block |
206 | Technically, buddy is a odd/even block for even/odd block |
208 | respectively. Plus we can put an extra requirement, that resulting |
207 | respectively. Plus we can put an extra requirement, that resulting |
209 | block must be aligned to its size. This requirement guarantees natural |
208 | block must be aligned to its size. This requirement guarantees natural |
210 | block alignment for the blocks coming out the allocation |
209 | block alignment for the blocks coming out the allocation |
211 | system.</para> |
210 | system.</para> |
212 | 211 | ||
213 | <para>Using direct pointer arithmetics, |
212 | <para>Using direct pointer arithmetics, |
214 | <varname>frame_t::ref_count</varname> and |
213 | <varname>frame_t::ref_count</varname> and |
215 | <varname>frame_t::buddy_order</varname> variables, finding buddy is |
214 | <varname>frame_t::buddy_order</varname> variables, finding buddy is |
216 | done at constant time.</para> |
215 | done at constant time.</para> |
217 | </formalpara> |
216 | </formalpara> |
218 | </section> |
217 | </section> |
219 | 218 | ||
220 | <section id="slab"> |
219 | <section id="slab"> |
221 | <title>Slab allocator</title> |
220 | <title>Slab allocator</title> |
222 | 221 | ||
223 | <section> |
222 | <section> |
224 | <title>Introduction</title> |
223 | <title>Introduction</title> |
225 | 224 | ||
226 | <para>The majority of memory allocation requests in the kernel are for |
225 | <para>The majority of memory allocation requests in the kernel are for |
227 | small, frequently used data structures. For this purpose the slab |
226 | small, frequently used data structures. For this purpose the slab |
228 | allocator is a perfect solution. The basic idea behind a slab |
227 | allocator is a perfect solution. The basic idea behind a slab |
229 | allocator is to have lists of commonly used objects available packed |
228 | allocator is to have lists of commonly used objects available packed |
230 | into pages. This avoids the overhead of allocating and destroying |
229 | into pages. This avoids the overhead of allocating and destroying |
231 | commonly used types of objects such as inodes, threads, virtual memory |
230 | commonly used types of objects such as inodes, threads, virtual memory |
232 | structures etc.</para> |
231 | structures etc.</para> |
233 | 232 | ||
234 | <para>Original slab allocator locking mechanism has become a |
233 | <para>Original slab allocator locking mechanism has become a |
235 | significant preformance bottleneck on SMP architectures. <termdef>Slab |
234 | significant preformance bottleneck on SMP architectures. <termdef>Slab |
236 | SMP perfromance bottleneck was resolved by introducing a per-CPU |
235 | SMP perfromance bottleneck was resolved by introducing a per-CPU |
237 | caching scheme called as <glossterm>magazine |
236 | caching scheme called as <glossterm>magazine |
238 | layer</glossterm></termdef>.</para> |
237 | layer</glossterm></termdef>.</para> |
239 | </section> |
238 | </section> |
240 | 239 | ||
241 | <section> |
240 | <section> |
242 | <title>Implementation details (needs revision)</title> |
241 | <title>Implementation details (needs revision)</title> |
243 | 242 | ||
244 | <para>The SLAB allocator is closely modelled after <ulink |
243 | <para>The SLAB allocator is closely modelled after <ulink |
245 | url="http://www.usenix.org/events/usenix01/full_papers/bonwick/bonwick_html/"> |
244 | url="http://www.usenix.org/events/usenix01/full_papers/bonwick/bonwick_html/"> |
246 | OpenSolaris SLAB allocator by Jeff Bonwick and Jonathan Adams </ulink> |
245 | OpenSolaris SLAB allocator by Jeff Bonwick and Jonathan Adams </ulink> |
247 | with the following exceptions: <itemizedlist> |
246 | with the following exceptions: <itemizedlist> |
248 | <listitem> |
247 | <listitem> |
249 | empty SLABS are deallocated immediately (in Linux they are kept in linked list, in Solaris ???) |
248 | empty SLABS are deallocated immediately (in Linux they are kept in linked list, in Solaris ???) |
250 | </listitem> |
249 | </listitem> |
251 | 250 | ||
252 | <listitem> |
251 | <listitem> |
253 | empty magazines are deallocated when not needed (in Solaris they are held in linked list in slab cache) |
252 | empty magazines are deallocated when not needed (in Solaris they are held in linked list in slab cache) |
254 | </listitem> |
253 | </listitem> |
255 | </itemizedlist> Following features are not currently supported but |
254 | </itemizedlist> Following features are not currently supported but |
256 | would be easy to do: <itemizedlist> |
255 | would be easy to do: <itemizedlist> |
257 | <listitem> |
256 | <listitem> |
258 | - cache coloring |
257 | - cache coloring |
259 | </listitem> |
258 | </listitem> |
260 | 259 | ||
261 | <listitem> |
260 | <listitem> |
262 | - dynamic magazine growing (different magazine sizes are already supported, but we would need to adjust allocation strategy) |
261 | - dynamic magazine growing (different magazine sizes are already supported, but we would need to adjust allocation strategy) |
263 | </listitem> |
262 | </listitem> |
264 | </itemizedlist></para> |
263 | </itemizedlist></para> |
265 | 264 | ||
266 | <para>The SLAB allocator supports per-CPU caches ('magazines') to |
265 | <para>The SLAB allocator supports per-CPU caches ('magazines') to |
267 | facilitate good SMP scaling.</para> |
266 | facilitate good SMP scaling.</para> |
268 | 267 | ||
269 | <para>When a new object is being allocated, it is first checked, if it |
268 | <para>When a new object is being allocated, it is first checked, if it |
270 | is available in CPU-bound magazine. If it is not found there, it is |
269 | is available in CPU-bound magazine. If it is not found there, it is |
271 | allocated from CPU-shared SLAB - if partial full is found, it is used, |
270 | allocated from CPU-shared SLAB - if partial full is found, it is used, |
272 | otherwise a new one is allocated.</para> |
271 | otherwise a new one is allocated.</para> |
273 | 272 | ||
274 | <para>When an object is being deallocated, it is put to CPU-bound |
273 | <para>When an object is being deallocated, it is put to CPU-bound |
275 | magazine. If there is no such magazine, new one is allocated (if it |
274 | magazine. If there is no such magazine, new one is allocated (if it |
276 | fails, the object is deallocated into SLAB). If the magazine is full, |
275 | fails, the object is deallocated into SLAB). If the magazine is full, |
277 | it is put into cpu-shared list of magazines and new one is |
276 | it is put into cpu-shared list of magazines and new one is |
278 | allocated.</para> |
277 | allocated.</para> |
279 | 278 | ||
280 | <para>The CPU-bound magazine is actually a pair of magazines to avoid |
279 | <para>The CPU-bound magazine is actually a pair of magazines to avoid |
281 | thrashing when somebody is allocating/deallocating 1 item at the |
280 | thrashing when somebody is allocating/deallocating 1 item at the |
282 | magazine size boundary. LIFO order is enforced, which should avoid |
281 | magazine size boundary. LIFO order is enforced, which should avoid |
283 | fragmentation as much as possible.</para> |
282 | fragmentation as much as possible.</para> |
284 | 283 | ||
285 | <para>Every cache contains list of full slabs and list of partialy |
284 | <para>Every cache contains list of full slabs and list of partialy |
286 | full slabs. Empty SLABS are immediately freed (thrashing will be |
285 | full slabs. Empty SLABS are immediately freed (thrashing will be |
287 | avoided because of magazines).</para> |
286 | avoided because of magazines).</para> |
288 | 287 | ||
289 | <para>The SLAB information structure is kept inside the data area, if |
288 | <para>The SLAB information structure is kept inside the data area, if |
290 | possible. The cache can be marked that it should not use magazines. |
289 | possible. The cache can be marked that it should not use magazines. |
291 | This is used only for SLAB related caches to avoid deadlocks and |
290 | This is used only for SLAB related caches to avoid deadlocks and |
292 | infinite recursion (the SLAB allocator uses itself for allocating all |
291 | infinite recursion (the SLAB allocator uses itself for allocating all |
293 | it's control structures).</para> |
292 | it's control structures).</para> |
294 | 293 | ||
295 | <para>The SLAB allocator allocates lots of space and does not free it. |
294 | <para>The SLAB allocator allocates lots of space and does not free it. |
296 | When frame allocator fails to allocate the frame, it calls |
295 | When frame allocator fails to allocate the frame, it calls |
297 | slab_reclaim(). It tries 'light reclaim' first, then brutal reclaim. |
296 | slab_reclaim(). It tries 'light reclaim' first, then brutal reclaim. |
298 | The light reclaim releases slabs from cpu-shared magazine-list, until |
297 | The light reclaim releases slabs from cpu-shared magazine-list, until |
299 | at least 1 slab is deallocated in each cache (this algorithm should |
298 | at least 1 slab is deallocated in each cache (this algorithm should |
300 | probably change). The brutal reclaim removes all cached objects, even |
299 | probably change). The brutal reclaim removes all cached objects, even |
301 | from CPU-bound magazines.</para> |
300 | from CPU-bound magazines.</para> |
302 | 301 | ||
303 | <para>TODO: <itemizedlist> |
302 | <para>TODO: <itemizedlist> |
304 | <listitem> |
303 | <listitem> |
305 | For better CPU-scaling the magazine allocation strategy should be extended. Currently, if the cache does not have magazine, it asks for non-cpu cached magazine cache to provide one. It might be feasible to add cpu-cached magazine cache (which would allocate it's magazines from non-cpu-cached mag. cache). This would provide a nice per-cpu buffer. The other possibility is to use the per-cache 'empty-magazine-list', which decreases competing for 1 per-system magazine cache. |
304 | For better CPU-scaling the magazine allocation strategy should be extended. Currently, if the cache does not have magazine, it asks for non-cpu cached magazine cache to provide one. It might be feasible to add cpu-cached magazine cache (which would allocate it's magazines from non-cpu-cached mag. cache). This would provide a nice per-cpu buffer. The other possibility is to use the per-cache 'empty-magazine-list', which decreases competing for 1 per-system magazine cache. |
306 | </listitem> |
305 | </listitem> |
307 | 306 | ||
308 | <listitem> |
307 | <listitem> |
309 | - it might be good to add granularity of locks even to slab level, we could then try_spinlock over all partial slabs and thus improve scalability even on slab level |
308 | - it might be good to add granularity of locks even to slab level, we could then try_spinlock over all partial slabs and thus improve scalability even on slab level |
310 | </listitem> |
309 | </listitem> |
311 | </itemizedlist></para> |
310 | </itemizedlist></para> |
312 | </section> |
311 | </section> |
313 | </section> |
312 | </section> |
314 | 313 | ||
315 | <!-- End of Physmem --> |
314 | <!-- End of Physmem --> |
316 | </section> |
315 | </section> |
317 | 316 | ||
318 | <section> |
317 | <section> |
319 | <title>Memory sharing</title> |
318 | <title>Memory sharing</title> |
320 | 319 | ||
321 | <para>Not implemented yet(?)</para> |
320 | <para>Not implemented yet(?)</para> |
322 | </section> |
321 | </section> |
323 | </chapter> |
322 | </chapter> |