Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1066 serge 1
 
2
3
 
4
      (index_t)( (frame) - z_core.frames)
5
6
 
7
    (frame)->refcount = 1;          \
8
    (frame)->buddy_order = 0
9
10
 
11
    ((frame_t*)(block))->buddy_order
12
13
 
14
     ((frame_t*)(block))->buddy_order = (order)
15
16
 
17
    ((frame_t*)(block))->refcount = 1
18
19
 
20
  (((frame_index((frame)) >> (frame)->buddy_order) & 0x1) == 0)
21
22
 
23
    (((frame_index((frame)) >> (frame)->buddy_order) & 0x1) == 1)
24
25
 
26
    ((frame_t*)(block))->refcount = 0
27
28
 
29
 
30
{
31
    frame_t *frame_l, *frame_r;
32
33
 
34
    frame_r = (frame_l + (1 << (frame_l->buddy_order - 1)));
35
36
 
37
}
38
39
 
40
{
41
    frame_t *frame1, *frame2;
42
43
 
44
    frame2 = (frame_t*)block_2;
45
46
 
47
}
48
49
 
50
{
51
    frame_t  *frame;
52
    index_t   index;
53
    u32_t     is_left, is_right;
54
55
 
56
 //   ASSERT(IS_BUDDY_ORDER_OK(frame_index_abs(zone, frame),frame->buddy_order));
57
58
 
59
    is_right = IS_BUDDY_RIGHT_BLOCK( frame);
60
61
 
62
    if (is_left) {
63
        index = (frame_index(frame)) + (1 << frame->buddy_order);
64
    } else {  /* if (is_right) */
65
        index = (frame_index(frame)) - (1 << frame->buddy_order);
66
    }
67
68
 
69
    {
70
        if (z_core.frames[index].buddy_order == frame->buddy_order &&
71
            z_core.frames[index].refcount == 0) {
72
            return &z_core.frames[index].buddy_link;
73
      }
74
    }
75
76
 
77
}
78
79
 
80
 
81
{
82
    frame_t *frame;
83
    index_t index;
84
85
 
86
87
 
88
    do {
89
        if (z_core.frames[index].buddy_order != order)
90
            return &z_core.frames[index].buddy_link;
91
92
 
93
    return NULL;
94
}
95
96
 
97
{
98
    link_t *buddy, *hlp;
99
    u32_t i;
100
101
 
102
	 * Determine block's order.
103
	 */
104
    i = buddy_get_order(block);
105
106
 
107
108
 
109
    {
110
		/*
111
		 * See if there is any buddy in the list of order i.
112
		 */
113
        buddy = find_buddy( block );
114
        if (buddy)
115
		{
116
117
 
118
			/*
119
			 * Remove buddy from the list of order i.
120
			 */
121
			list_remove(buddy);
122
123
 
124
			 * Invalidate order of both block and buddy.
125
			 */
126
            buddy_set_order(block, BUDDY_SYSTEM_INNER_BLOCK);
127
            buddy_set_order(buddy, BUDDY_SYSTEM_INNER_BLOCK);
128
129
 
130
			 * Coalesce block and buddy into one block.
131
			 */
132
            hlp = buddy_coalesce( block, buddy );
133
134
 
135
			 * Set order of the coalesced block to i + 1.
136
			 */
137
            buddy_set_order(hlp, i + 1);
138
139
 
140
			 * Recursively add the coalesced block to the list of order i + 1.
141
			 */
142
            buddy_system_free( hlp );
143
			return;
144
		}
145
	}
146
	/*
147
	 * Insert block into the list of order i.
148
	 */
149
    list_append(block, &z_core.order[i]);
150
}
151
152
 
153
 
154
{
155
	link_t *res, *hlp;
156
157
 
158
159
 
160
	 * If the list of order i is not empty,
161
	 * the request can be immediatelly satisfied.
162
	 */
163
    if (!list_empty(&z_core.order[i])) {
164
        res = z_core.order[i].next;
165
		list_remove(res);
166
		buddy_mark_busy(res);
167
		return res;
168
	}
169
	/*
170
	 * If order i is already the maximal order,
171
	 * the request cannot be satisfied.
172
	 */
173
    if (i == z_core.max_order)
174
		return NULL;
175
176
 
177
	 * Try to recursively satisfy the request from higher order lists.
178
	 */
179
    hlp = buddy_alloc( i + 1 );
180
181
 
182
	 * The request could not be satisfied
183
	 * from higher order lists.
184
	 */
185
	if (!hlp)
186
		return NULL;
187
188
 
189
190
 
191
	 * Bisect the block and set order of both of its parts to i.
192
	 */
193
	hlp = buddy_bisect( res );
194
195
 
196
	buddy_set_order(hlp, i);
197
198
 
199
	 * Return the other half to buddy system. Mark the first part
200
	 * full, so that it won't coalesce again.
201
	 */
202
	buddy_mark_busy(res);
203
	buddy_system_free( hlp );
204
205
 
206
}
207
208
 
209
{
210
	link_t *left,*right, *tmp;
211
    u32_t order;
212
213
 
214
    ASSERT(left);
215
	list_remove(left);
216
    while (1)
217
   {
218
        if ( !buddy_get_order(left))
219
        {
220
            buddy_mark_busy(left);
221
			return left;
222
		}
223
224
 
225
226
 
227
        buddy_set_order(left, order-1);
228
        buddy_set_order(right, order-1);
229
230
 
231
232
 
233
            right = left;
234
            left = tmp;
235
        }
236
        ASSERT(tmp == left);
237
        buddy_mark_busy(left);
238
        buddy_system_free(right);
239
        buddy_mark_available(left);
240
	}
241
}
242
243
 
244
{
245
    unsigned int i;
246
247
 
248
249
 
250
    z->count = count;
251
    z->free_count = count;
252
    z->busy_count = 0;
253
254
 
255
256
 
257
258
 
259
        list_initialize(&z->order[i]);
260
261
 
262
263
 
264
		frame_initialize(&z->frames[i]);
265
266
 
267
    for (i = 0; i < count; i++) {
268
        z_core.frames[i].buddy_order=0;
269
        z_core.frames[i].parent = NULL;
270
        z_core.frames[i].refcount=1;
271
	}
272
273
 
274
    {
275
        z_core.frames[i].refcount = 0;
276
        buddy_system_free(&z_core.frames[i].buddy_link);
277
    }
278
*/
279
280
 
281
         start, count, z->max_order);
282
283
 
284
285
 
286
{
287
	frame_t *frame;
288
	link_t *link;
289
290
 
291
292
 
293
294
 
295
		return;
296
    link = buddy_alloc_block( &frame->buddy_link);
297
    ASSERT(link);
298
	zone->free_count--;
299
}
300
301
 
302
{
303
    int i;
304
    pfn_t top = base + count;
305
306
 
307
        return;
308
309
 
310
        base = z->base;
311
312
 
313
        top = z->base+z->count;
314
315
 
316
317
 
318
        zone_mark_unavailable(z, i - z->base);
319
320
 
321
322
 
323
{
324
    int i;
325
    pfn_t top = base+count;
326
327
 
328
        return;
329
330
 
331
        base = z->base;
332
333
 
334
        top = z->base+z->count;
335
336
 
337
338
 
339
        z->frames[i-z->base].refcount = 0;
340
        buddy_system_free(&z->frames[i-z->base].buddy_link);
341
    }
342
};
343
344
 
345
{
346
    ASSERT(frame_idx < zone->count);
347
	return &zone->frames[frame_idx];
348
}
349
350
 
351
{
352
  spinlock_lock(&z_core.lock);
353
  zone_get_frame(&z_core, pfn-z_core.base)->parent = data;
354
  spinlock_unlock(&z_core.lock);
355
}
356
357
 
358
{
359
	void *res;
360
361
 
362
    res = zone_get_frame(&z_core, pfn)->parent;
363
    spinlock_unlock(&z_core.lock);
364
365
 
366
}
367