Subversion Repositories HelenOS

Rev

Rev 3149 | Rev 3211 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3149 Rev 3191
Line 56... Line 56...
56
#include <mm/as.h>
56
#include <mm/as.h>
57
#include <panic.h>
57
#include <panic.h>
58
#include <debug.h>
58
#include <debug.h>
59
#include <adt/list.h>
59
#include <adt/list.h>
60
#include <synch/spinlock.h>
60
#include <synch/spinlock.h>
-
 
61
#include <synch/mutex.h>
-
 
62
#include <synch/condvar.h>
61
#include <arch/asm.h>
63
#include <arch/asm.h>
62
#include <arch.h>
64
#include <arch.h>
63
#include <print.h>
65
#include <print.h>
64
#include <align.h>
66
#include <align.h>
65
#include <mm/slab.h>
67
#include <mm/slab.h>
Line 101... Line 103...
101
    zone_t *info[ZONES_MAX];
103
    zone_t *info[ZONES_MAX];
102
} zones_t;
104
} zones_t;
103
 
105
 
104
static zones_t zones;
106
static zones_t zones;
105
 
107
 
-
 
108
/*
-
 
109
 * Synchronization primitives used to sleep when there is no memory
-
 
110
 * available.
-
 
111
 */
-
 
112
mutex_t mem_avail_mtx;
-
 
113
condvar_t mem_avail_cv;
-
 
114
unsigned long mem_avail_frames = 0; /**< Number of available frames. */
-
 
115
unsigned long mem_avail_gen = 0;    /**< Generation counter. */
106
 
116
 
107
/********************/
117
/********************/
108
/* Helper functions */
118
/* Helper functions */
109
/********************/
119
/********************/
110
 
120
 
Line 127... Line 137...
127
static index_t make_frame_index(zone_t *zone, frame_t *frame)
137
static index_t make_frame_index(zone_t *zone, frame_t *frame)
128
{
138
{
129
    return (frame - zone->frames);
139
    return (frame - zone->frames);
130
}
140
}
131
 
141
 
132
/** Initialize frame structure
142
/** Initialize frame structure.
133
 *
-
 
134
 * Initialize frame structure.
-
 
135
 *
143
 *
136
 * @param frame Frame structure to be initialized.
144
 * @param frame     Frame structure to be initialized.
137
 */
145
 */
138
static void frame_initialize(frame_t *frame)
146
static void frame_initialize(frame_t *frame)
139
{
147
{
140
    frame->refcount = 1;
148
    frame->refcount = 1;
141
    frame->buddy_order = 0;
149
    frame->buddy_order = 0;
Line 143... Line 151...
143
 
151
 
144
/**********************/
152
/**********************/
145
/* Zoneinfo functions */
153
/* Zoneinfo functions */
146
/**********************/
154
/**********************/
147
 
155
 
148
/**
-
 
149
 * Insert-sort zone into zones list
156
/** Insert-sort zone into zones list.
150
 *
157
 *
151
 * @param newzone New zone to be inserted into zone list
158
 * @param newzone   New zone to be inserted into zone list.
152
 * @return zone number on success, -1 on error
159
 * @return      Zone number on success, -1 on error.
153
 */
160
 */
154
static int zones_add_zone(zone_t *newzone)
161
static int zones_add_zone(zone_t *newzone)
155
{
162
{
156
    unsigned int i, j;
163
    unsigned int i, j;
157
    ipl_t ipl;
164
    ipl_t ipl;
Line 169... Line 176...
169
    }
176
    }
170
   
177
   
171
    for (i = 0; i < zones.count; i++) {
178
    for (i = 0; i < zones.count; i++) {
172
        /* Check for overflow */
179
        /* Check for overflow */
173
        z = zones.info[i];
180
        z = zones.info[i];
174
        if (overlaps(newzone->base, newzone->count, z->base, z->count)) {
181
        if (overlaps(newzone->base, newzone->count, z->base,
-
 
182
            z->count)) {
175
            printf("Zones overlap!\n");
183
            printf("Zones overlap!\n");
176
            return -1;
184
            return -1;
177
        }
185
        }
178
        if (newzone->base < z->base)
186
        if (newzone->base < z->base)
179
            break;
187
            break;
Line 191... Line 199...
191
 
199
 
192
    return i;
200
    return i;
193
}
201
}
194
 
202
 
195
/**
203
/**
196
 * Try to find a zone where can we find the frame
204
 * Try to find a zone where can we find the frame.
197
 *
205
 *
198
 * Assume interrupts are disabled.
206
 * Assume interrupts are disabled.
199
 *
207
 *
200
 * @param frame Frame number contained in zone
208
 * @param frame     Frame number contained in zone.
201
 * @param pzone If not null, it is used as zone hint. Zone index
209
 * @param pzone     If not null, it is used as zone hint. Zone index is
202
 *              is filled into the variable on success.
210
 *          filled into the variable on success.
203
 * @return Pointer to locked zone containing frame
211
 * @return      Pointer to locked zone containing frame.
204
 */
212
 */
205
static zone_t * find_zone_and_lock(pfn_t frame, unsigned int *pzone)
213
static zone_t *find_zone_and_lock(pfn_t frame, unsigned int *pzone)
206
{
214
{
207
    unsigned int i;
215
    unsigned int i;
208
    unsigned int hint = pzone ? *pzone : 0;
216
    unsigned int hint = pzone ? *pzone : 0;
209
    zone_t *z;
217
    zone_t *z;
210
   
218
   
Line 243... Line 251...
243
 
251
 
244
/** Find and lock zone that can allocate order frames.
252
/** Find and lock zone that can allocate order frames.
245
 *
253
 *
246
 * Assume interrupts are disabled.
254
 * Assume interrupts are disabled.
247
 *
255
 *
248
 * @param order Size (2^order) of free space we are trying to find
256
 * @param order     Size (2^order) of free space we are trying to find.
249
 * @param pzone Pointer to preferred zone or NULL, on return contains zone
257
 * @param pzone     Pointer to preferred zone or NULL, on return contains
250
 *      number
258
 *          zone number.
251
 */
259
 */
252
static zone_t * find_free_zone_and_lock(uint8_t order, unsigned int *pzone)
260
static zone_t *find_free_zone_and_lock(uint8_t order, unsigned int *pzone)
253
{
261
{
254
    unsigned int i;
262
    unsigned int i;
255
    zone_t *z;
263
    zone_t *z;
256
    unsigned int hint = pzone ? *pzone : 0;
264
    unsigned int hint = pzone ? *pzone : 0;
257
   
265
   
Line 281... Line 289...
281
 
289
 
282
/**************************/
290
/**************************/
283
/* Buddy system functions */
291
/* Buddy system functions */
284
/**************************/
292
/**************************/
285
 
293
 
286
/** Buddy system find_block implementation
294
/** Buddy system find_block implementation.
287
 *
295
 *
288
 * Find block that is parent of current list.
296
 * Find block that is parent of current list.
289
 * That means go to lower addresses, until such block is found
297
 * That means go to lower addresses, until such block is found
290
 *
298
 *
291
 * @param order - Order of parent must be different then this parameter!!
299
 * @param order     Order of parent must be different then this
-
 
300
 *          parameter!!
292
 */
301
 */
293
static link_t *zone_buddy_find_block(buddy_system_t *b, link_t *child,
302
static link_t *zone_buddy_find_block(buddy_system_t *b, link_t *child,
294
    uint8_t order)
303
    uint8_t order)
295
{
304
{
296
    frame_t *frame;
305
    frame_t *frame;
Line 319... Line 328...
319
    zone = (zone_t *) b->data;
328
    zone = (zone_t *) b->data;
320
    index = frame_index(zone, frame);
329
    index = frame_index(zone, frame);
321
    printf("%" PRIi, index);
330
    printf("%" PRIi, index);
322
}                    
331
}                    
323
 
332
 
324
/** Buddy system find_buddy implementation
333
/** Buddy system find_buddy implementation.
325
 *
334
 *
326
 * @param b Buddy system.
335
 * @param b     Buddy system.
327
 * @param block Block for which buddy should be found
336
 * @param block     Block for which buddy should be found.
328
 *
337
 *
329
 * @return Buddy for given block if found
338
 * @return      Buddy for given block if found.
330
 */
339
 */
331
static link_t *zone_buddy_find_buddy(buddy_system_t *b, link_t *block)
340
static link_t *zone_buddy_find_buddy(buddy_system_t *b, link_t *block)
332
{
341
{
333
    frame_t *frame;
342
    frame_t *frame;
334
    zone_t *zone;
343
    zone_t *zone;
Line 343... Line 352...
343
    is_left = IS_BUDDY_LEFT_BLOCK_ABS(zone, frame);
352
    is_left = IS_BUDDY_LEFT_BLOCK_ABS(zone, frame);
344
    is_right = IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame);
353
    is_right = IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame);
345
 
354
 
346
    ASSERT(is_left ^ is_right);
355
    ASSERT(is_left ^ is_right);
347
    if (is_left) {
356
    if (is_left) {
348
        index = (frame_index(zone, frame)) + (1 << frame->buddy_order);
357
        index = (frame_index(zone, frame)) +
-
 
358
            (1 << frame->buddy_order);
349
    } else {    /* if (is_right) */
359
    } else {    /* if (is_right) */
350
        index = (frame_index(zone, frame)) - (1 << frame->buddy_order);
360
        index = (frame_index(zone, frame)) -
-
 
361
            (1 << frame->buddy_order);
351
    }
362
    }
352
   
363
   
353
    if (frame_index_valid(zone, index)) {
364
    if (frame_index_valid(zone, index)) {
354
        if (zone->frames[index].buddy_order == frame->buddy_order &&
365
        if (zone->frames[index].buddy_order == frame->buddy_order &&
355
            zone->frames[index].refcount == 0) {
366
            zone->frames[index].refcount == 0) {
Line 358... Line 369...
358
    }
369
    }
359
 
370
 
360
    return NULL;   
371
    return NULL;   
361
}
372
}
362
 
373
 
363
/** Buddy system bisect implementation
374
/** Buddy system bisect implementation.
364
 *
375
 *
365
 * @param b Buddy system.
376
 * @param b     Buddy system.
366
 * @param block Block to bisect
377
 * @param block     Block to bisect.
367
 *
378
 *
368
 * @return right block
379
 * @return      Right block.
369
 */
380
 */
370
static link_t * zone_buddy_bisect(buddy_system_t *b, link_t *block) {
381
static link_t *zone_buddy_bisect(buddy_system_t *b, link_t *block)
-
 
382
{
371
    frame_t *frame_l, *frame_r;
383
    frame_t *frame_l, *frame_r;
372
 
384
 
373
    frame_l = list_get_instance(block, frame_t, buddy_link);
385
    frame_l = list_get_instance(block, frame_t, buddy_link);
374
    frame_r = (frame_l + (1 << (frame_l->buddy_order - 1)));
386
    frame_r = (frame_l + (1 << (frame_l->buddy_order - 1)));
375
   
387
   
376
    return &frame_r->buddy_link;
388
    return &frame_r->buddy_link;
377
}
389
}
378
 
390
 
379
/** Buddy system coalesce implementation
391
/** Buddy system coalesce implementation.
380
 *
392
 *
381
 * @param b Buddy system.
393
 * @param b     Buddy system.
382
 * @param block_1 First block
394
 * @param block_1   First block.
383
 * @param block_2 First block's buddy
395
 * @param block_2   First block's buddy.
384
 *
396
 *
385
 * @return Coalesced block (actually block that represents lower address)
397
 * @return      Coalesced block (actually block that represents lower
-
 
398
 *          address).
386
 */
399
 */
387
static link_t *zone_buddy_coalesce(buddy_system_t *b, link_t *block_1,
400
static link_t *zone_buddy_coalesce(buddy_system_t *b, link_t *block_1,
388
    link_t *block_2)
401
    link_t *block_2)
389
{
402
{
390
    frame_t *frame1, *frame2;
403
    frame_t *frame1, *frame2;
Line 393... Line 406...
393
    frame2 = list_get_instance(block_2, frame_t, buddy_link);
406
    frame2 = list_get_instance(block_2, frame_t, buddy_link);
394
   
407
   
395
    return frame1 < frame2 ? block_1 : block_2;
408
    return frame1 < frame2 ? block_1 : block_2;
396
}
409
}
397
 
410
 
398
/** Buddy system set_order implementation
411
/** Buddy system set_order implementation.
399
 *
412
 *
400
 * @param b Buddy system.
413
 * @param b     Buddy system.
401
 * @param block Buddy system block
414
 * @param block     Buddy system block.
402
 * @param order Order to set
415
 * @param order     Order to set.
403
 */
416
 */
404
static void zone_buddy_set_order(buddy_system_t *b, link_t *block,
417
static void zone_buddy_set_order(buddy_system_t *b, link_t *block,
405
    uint8_t order) {
418
    uint8_t order)
-
 
419
{
406
    frame_t *frame;
420
    frame_t *frame;
407
    frame = list_get_instance(block, frame_t, buddy_link);
421
    frame = list_get_instance(block, frame_t, buddy_link);
408
    frame->buddy_order = order;
422
    frame->buddy_order = order;
409
}
423
}
410
 
424
 
411
/** Buddy system get_order implementation
425
/** Buddy system get_order implementation.
412
 *
426
 *
413
 * @param b Buddy system.
427
 * @param b     Buddy system.
414
 * @param block Buddy system block
428
 * @param block     Buddy system block.
415
 *
429
 *
416
 * @return Order of block
430
 * @return      Order of block.
417
 */
431
 */
418
static uint8_t zone_buddy_get_order(buddy_system_t *b, link_t *block) {
432
static uint8_t zone_buddy_get_order(buddy_system_t *b, link_t *block)
-
 
433
{
419
    frame_t *frame;
434
    frame_t *frame;
420
    frame = list_get_instance(block, frame_t, buddy_link);
435
    frame = list_get_instance(block, frame_t, buddy_link);
421
    return frame->buddy_order;
436
    return frame->buddy_order;
422
}
437
}
423
 
438
 
424
/** Buddy system mark_busy implementation
439
/** Buddy system mark_busy implementation.
425
 *
-
 
426
 * @param b Buddy system
-
 
427
 * @param block Buddy system block
-
 
428
 *
440
 *
-
 
441
 * @param b     Buddy system.
-
 
442
 * @param block     Buddy system block.
429
 */
443
 */
430
static void zone_buddy_mark_busy(buddy_system_t *b, link_t * block) {
444
static void zone_buddy_mark_busy(buddy_system_t *b, link_t * block)
-
 
445
{
431
    frame_t * frame;
446
    frame_t * frame;
432
 
447
 
433
    frame = list_get_instance(block, frame_t, buddy_link);
448
    frame = list_get_instance(block, frame_t, buddy_link);
434
    frame->refcount = 1;
449
    frame->refcount = 1;
435
}
450
}
436
 
451
 
437
/** Buddy system mark_available implementation
452
/** Buddy system mark_available implementation.
438
 *
-
 
439
 * @param b Buddy system
-
 
440
 * @param block Buddy system block
-
 
441
 *
453
 *
-
 
454
 * @param b     Buddy system.
-
 
455
 * @param block     Buddy system block.
442
 */
456
 */
443
static void zone_buddy_mark_available(buddy_system_t *b, link_t *block) {
457
static void zone_buddy_mark_available(buddy_system_t *b, link_t *block)
-
 
458
{
444
    frame_t *frame;
459
    frame_t *frame;
445
    frame = list_get_instance(block, frame_t, buddy_link);
460
    frame = list_get_instance(block, frame_t, buddy_link);
446
    frame->refcount = 0;
461
    frame->refcount = 0;
447
}
462
}
448
 
463
 
Line 460... Line 475...
460
 
475
 
461
/******************/
476
/******************/
462
/* Zone functions */
477
/* Zone functions */
463
/******************/
478
/******************/
464
 
479
 
465
/** Allocate frame in particular zone
480
/** Allocate frame in particular zone.
466
 *
481
 *
467
 * Assume zone is locked
482
 * Assume zone is locked.
468
 * Panics if allocation is impossible.
483
 * Panics if allocation is impossible.
469
 *
484
 *
470
 * @param zone  Zone to allocate from.
485
 * @param zone      Zone to allocate from.
471
 * @param order Allocate exactly 2^order frames.
486
 * @param order     Allocate exactly 2^order frames.
472
 *
487
 *
473
 * @return Frame index in zone
488
 * @return      Frame index in zone.
474
 *
489
 *
475
 */
490
 */
476
static pfn_t zone_frame_alloc(zone_t *zone, uint8_t order)
491
static pfn_t zone_frame_alloc(zone_t *zone, uint8_t order)
477
{
492
{
478
    pfn_t v;
493
    pfn_t v;
Line 494... Line 509...
494
    /* get frame address */
509
    /* get frame address */
495
    v = make_frame_index(zone, frame);
510
    v = make_frame_index(zone, frame);
496
    return v;
511
    return v;
497
}
512
}
498
 
513
 
499
/** Free frame from zone
514
/** Free frame from zone.
500
 *
515
 *
501
 * Assume zone is locked
516
 * Assume zone is locked.
502
 *
517
 *
503
 * @param zone Pointer to zone from which the frame is to be freed
518
 * @param zone      Pointer to zone from which the frame is to be freed.
504
 * @param frame_idx Frame index relative to zone
519
 * @param frame_idx Frame index relative to zone.
505
 */
520
 */
506
static void zone_frame_free(zone_t *zone, index_t frame_idx)
521
static void zone_frame_free(zone_t *zone, index_t frame_idx)
507
{
522
{
508
    frame_t *frame;
523
    frame_t *frame;
509
    uint8_t order;
524
    uint8_t order;
Line 522... Line 537...
522
        zone->free_count += (1 << order);
537
        zone->free_count += (1 << order);
523
        zone->busy_count -= (1 << order);
538
        zone->busy_count -= (1 << order);
524
    }
539
    }
525
}
540
}
526
 
541
 
527
/** Return frame from zone */
542
/** Return frame from zone. */
528
static frame_t * zone_get_frame(zone_t *zone, index_t frame_idx)
543
static frame_t *zone_get_frame(zone_t *zone, index_t frame_idx)
529
{
544
{
530
    ASSERT(frame_idx < zone->count);
545
    ASSERT(frame_idx < zone->count);
531
    return &zone->frames[frame_idx];
546
    return &zone->frames[frame_idx];
532
}
547
}
533
 
548
 
534
/** Mark frame in zone unavailable to allocation */
549
/** Mark frame in zone unavailable to allocation. */
535
static void zone_mark_unavailable(zone_t *zone, index_t frame_idx)
550
static void zone_mark_unavailable(zone_t *zone, index_t frame_idx)
536
{
551
{
537
    frame_t *frame;
552
    frame_t *frame;
538
    link_t *link;
553
    link_t *link;
539
 
554
 
Line 542... Line 557...
542
        return;
557
        return;
543
    link = buddy_system_alloc_block(zone->buddy_system,
558
    link = buddy_system_alloc_block(zone->buddy_system,
544
        &frame->buddy_link);
559
        &frame->buddy_link);
545
    ASSERT(link);
560
    ASSERT(link);
546
    zone->free_count--;
561
    zone->free_count--;
-
 
562
 
-
 
563
    mutex_lock(&mem_avail_mtx);
-
 
564
    mem_avail_frames--;
-
 
565
    mutex_unlock(&mem_avail_mtx);
547
}
566
}
548
 
567
 
549
/**
-
 
550
 * Join 2 zones
568
/** Join two zones.
551
 *
569
 *
552
 * Expect zone_t *z to point to space at least zone_conf_size large
570
 * Expect zone_t *z to point to space at least zone_conf_size large.
553
 *
571
 *
554
 * Assume z1 & z2 are locked
572
 * Assume z1 & z2 are locked.
555
 *
573
 *
556
 * @param z Target zone structure pointer
574
 * @param z     Target zone structure pointer.
557
 * @param z1 Zone to merge
575
 * @param z1        Zone to merge.
558
 * @param z2 Zone to merge
576
 * @param z2        Zone to merge.
559
 */
577
 */
560
static void _zone_merge(zone_t *z, zone_t *z1, zone_t *z2)
578
static void _zone_merge(zone_t *z, zone_t *z1, zone_t *z2)
561
{
579
{
562
    uint8_t max_order;
580
    uint8_t max_order;
563
    unsigned int i;
581
    unsigned int i;
Line 627... Line 645...
627
        frame->refcount = 0;
645
        frame->refcount = 0;
628
        buddy_system_free(z->buddy_system, &frame->buddy_link);
646
        buddy_system_free(z->buddy_system, &frame->buddy_link);
629
    }
647
    }
630
}
648
}
631
 
649
 
632
/** Return old configuration frames into the zone
650
/** Return old configuration frames into the zone.
633
 *
651
 *
634
 * We have several cases
652
 * We have several cases
635
 * - the conf. data is outside of zone -> exit, shall we call frame_free??
653
 * - the conf. data is outside of zone -> exit, shall we call frame_free??
636
 * - the conf. data was created by zone_create or
654
 * - the conf. data was created by zone_create or
637
 *   updated with reduce_region -> free every frame
655
 *   updated with reduce_region -> free every frame
638
 *
656
 *
639
 * @param newzone The actual zone where freeing should occur
657
 * @param newzone   The actual zone where freeing should occur.
640
 * @param oldzone Pointer to old zone configuration data that should
658
 * @param oldzone   Pointer to old zone configuration data that should
641
 *                be freed from new zone
659
 *          be freed from new zone.
642
 */
660
 */
643
static void return_config_frames(zone_t *newzone, zone_t *oldzone)
661
static void return_config_frames(zone_t *newzone, zone_t *oldzone)
644
{
662
{
645
    pfn_t pfn;
663
    pfn_t pfn;
646
    frame_t *frame;
664
    frame_t *frame;
Line 660... Line 678...
660
        newzone->busy_count++;
678
        newzone->busy_count++;
661
        zone_frame_free(newzone, pfn+i-newzone->base);
679
        zone_frame_free(newzone, pfn+i-newzone->base);
662
    }
680
    }
663
}
681
}
664
 
682
 
665
/** Reduce allocated block to count of order 0 frames
683
/** Reduce allocated block to count of order 0 frames.
666
 *
684
 *
667
 * The allocated block need 2^order frames of space. Reduce all frames
685
 * The allocated block need 2^order frames of space. Reduce all frames
668
 * in block to order 0 and free the unneeded frames. This means, that
686
 * in block to order 0 and free the unneeded frames. This means, that
669
 * when freeing the previously allocated block starting with frame_idx,
687
 * when freeing the previously allocated block starting with frame_idx,
670
 * you have to free every frame.
688
 * you have to free every frame.
671
 *
689
 *
672
 * @param zone
690
 * @param zone
673
 * @param frame_idx Index to block
691
 * @param frame_idx     Index to block.
674
 * @param count Allocated space in block
692
 * @param count         Allocated space in block.
675
 */
693
 */
676
static void zone_reduce_region(zone_t *zone, pfn_t frame_idx, count_t count)
694
static void zone_reduce_region(zone_t *zone, pfn_t frame_idx, count_t count)
677
{
695
{
678
    count_t i;
696
    count_t i;
679
    uint8_t order;
697
    uint8_t order;
Line 696... Line 714...
696
    for (i = count; i < (count_t) (1 << order); i++) {
714
    for (i = count; i < (count_t) (1 << order); i++) {
697
        zone_frame_free(zone, i + frame_idx);
715
        zone_frame_free(zone, i + frame_idx);
698
    }
716
    }
699
}
717
}
700
 
718
 
701
/** Merge zones z1 and z2
719
/** Merge zones z1 and z2.
702
 *
720
 *
703
 * - the zones must be 2 zones with no zone existing in between,
721
 * - the zones must be 2 zones with no zone existing in between,
704
 *   which means that z2 = z1+1
722
 *   which means that z2 = z1+1
705
 *
723
 *
706
 * - When you create a new zone, the frame allocator configuration does
724
 * - When you create a new zone, the frame allocator configuration does
Line 720... Line 738...
720
    spinlock_lock(&zones.lock);
738
    spinlock_lock(&zones.lock);
721
 
739
 
722
    if ((z1 >= zones.count) || (z2 >= zones.count))
740
    if ((z1 >= zones.count) || (z2 >= zones.count))
723
        goto errout;
741
        goto errout;
724
    /* We can join only 2 zones with none existing inbetween */
742
    /* We can join only 2 zones with none existing inbetween */
725
    if (z2-z1 != 1)
743
    if (z2 - z1 != 1)
726
        goto errout;
744
        goto errout;
727
 
745
 
728
    zone1 = zones.info[z1];
746
    zone1 = zones.info[z1];
729
    zone2 = zones.info[z2];
747
    zone2 = zones.info[z2];
730
    spinlock_lock(&zone1->lock);
748
    spinlock_lock(&zone1->lock);
Line 771... Line 789...
771
errout:
789
errout:
772
    spinlock_unlock(&zones.lock);
790
    spinlock_unlock(&zones.lock);
773
    interrupts_restore(ipl);
791
    interrupts_restore(ipl);
774
}
792
}
775
 
793
 
776
/**
-
 
777
 * Merge all zones into one big zone
794
/** Merge all zones into one big zone.
778
 *
795
 *
779
 * It is reasonable to do this on systems whose bios reports parts in chunks,
796
 * It is reasonable to do this on systems whose bios reports parts in chunks,
780
 * so that we could have 1 zone (it's faster).
797
 * so that we could have 1 zone (it's faster).
781
 */
798
 */
782
void zone_merge_all(void)
799
void zone_merge_all(void)
783
{
800
{
784
    int count = zones.count;
801
    int count = zones.count;
785
 
802
 
786
    while (zones.count > 1 && --count) {
803
    while (zones.count > 1 && --count) {
787
        zone_merge(0,1);
804
        zone_merge(0, 1);
788
        break;
805
        break;
789
    }
806
    }
790
}
807
}
791
 
808
 
792
/** Create frame zone
-
 
793
 *
-
 
794
 * Create new frame zone.
809
/** Create new frame zone.
795
 *
810
 *
796
 * @param start Physical address of the first frame within the zone.
811
 * @param start     Physical address of the first frame within the zone.
797
 * @param count Count of frames in zone
812
 * @param count     Count of frames in zone.
798
 * @param z Address of configuration information of zone
813
 * @param z     Address of configuration information of zone.
799
 * @param flags Zone flags.
814
 * @param flags     Zone flags.
800
 *
815
 *
801
 * @return Initialized zone.
816
 * @return      Initialized zone.
802
 */
817
 */
803
static void zone_construct(pfn_t start, count_t count, zone_t *z, int flags)
818
static void zone_construct(pfn_t start, count_t count, zone_t *z, int flags)
804
{
819
{
805
    unsigned int i;
820
    unsigned int i;
806
    uint8_t max_order;
821
    uint8_t max_order;
Line 817... Line 832...
817
     */
832
     */
818
    max_order = fnzb(count);
833
    max_order = fnzb(count);
819
    z->buddy_system = (buddy_system_t *)&z[1];
834
    z->buddy_system = (buddy_system_t *)&z[1];
820
   
835
   
821
    buddy_system_create(z->buddy_system, max_order,
836
    buddy_system_create(z->buddy_system, max_order,
822
                &zone_buddy_system_operations,
837
        &zone_buddy_system_operations, (void *) z);
823
                (void *) z);
-
 
824
   
838
   
825
    /* Allocate frames _after_ the conframe */
839
    /* Allocate frames _after_ the conframe */
826
    /* Check sizes */
840
    /* Check sizes */
827
    z->frames = (frame_t *)((uint8_t *) z->buddy_system +
841
    z->frames = (frame_t *)((uint8_t *) z->buddy_system +
828
        buddy_conf_size(max_order));
842
        buddy_conf_size(max_order));
Line 835... Line 849...
835
        z->frames[i].refcount = 0;
849
        z->frames[i].refcount = 0;
836
        buddy_system_free(z->buddy_system, &z->frames[i].buddy_link);
850
        buddy_system_free(z->buddy_system, &z->frames[i].buddy_link);
837
    }
851
    }
838
}
852
}
839
 
853
 
840
/** Compute configuration data size for zone
854
/** Compute configuration data size for zone.
841
 *
855
 *
842
 * @param count Size of zone in frames
856
 * @param count     Size of zone in frames.
843
 * @return Size of zone configuration info (in bytes)
857
 * @return      Size of zone configuration info (in bytes).
844
 */
858
 */
845
uintptr_t zone_conf_size(count_t count)
859
uintptr_t zone_conf_size(count_t count)
846
{
860
{
847
    int size = sizeof(zone_t) + count * sizeof(frame_t);
861
    int size = sizeof(zone_t) + count * sizeof(frame_t);
848
    int max_order;
862
    int max_order;
Line 850... Line 864...
850
    max_order = fnzb(count);
864
    max_order = fnzb(count);
851
    size += buddy_conf_size(max_order);
865
    size += buddy_conf_size(max_order);
852
    return size;
866
    return size;
853
}
867
}
854
 
868
 
855
/** Create and add zone to system
869
/** Create and add zone to system.
856
 *
870
 *
857
 * @param start First frame number (absolute)
871
 * @param start     First frame number (absolute).
858
 * @param count Size of zone in frames
872
 * @param count     Size of zone in frames.
859
 * @param confframe Where configuration frames are supposed to be.
873
 * @param confframe Where configuration frames are supposed to be.
860
 *                  Automatically checks, that we will not disturb the
874
 *          Automatically checks, that we will not disturb the
861
 *                  kernel and possibly init.
875
 *          kernel and possibly init.  If confframe is given
862
 *                  If confframe is given _outside_ this zone, it is expected,
876
 *          _outside_ this zone, it is expected, that the area is
863
 *                  that the area is already marked BUSY and big enough
877
 *          already marked BUSY and big enough to contain
864
 *                  to contain zone_conf_size() amount of data.
878
 *          zone_conf_size() amount of data.  If the confframe is
865
 *                  If the confframe is inside the area, the zone free frame
879
 *          inside the area, the zone free frame information is
866
 *                  information is modified not to include it.
880
 *          modified not to include it.
867
 *
881
 *
868
 * @return Zone number or -1 on error
882
 * @return      Zone number or -1 on error.
869
 */
883
 */
870
int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags)
884
int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags)
871
{
885
{
872
    zone_t *z;
886
    zone_t *z;
873
    uintptr_t addr;
887
    uintptr_t addr;
Line 882... Line 896...
882
    ASSERT(confframe);
896
    ASSERT(confframe);
883
    /* If conframe is supposed to be inside our zone, then make sure
897
    /* If conframe is supposed to be inside our zone, then make sure
884
     * it does not span kernel & init
898
     * it does not span kernel & init
885
     */
899
     */
886
    confcount = SIZE2FRAMES(zone_conf_size(count));
900
    confcount = SIZE2FRAMES(zone_conf_size(count));
887
    if (confframe >= start && confframe < start+count) {
901
    if (confframe >= start && confframe < start + count) {
888
        for (;confframe < start + count; confframe++) {
902
        for (; confframe < start + count; confframe++) {
889
            addr = PFN2ADDR(confframe);
903
            addr = PFN2ADDR(confframe);
890
            if (overlaps(addr, PFN2ADDR(confcount),
904
            if (overlaps(addr, PFN2ADDR(confcount),
891
                KA2PA(config.base), config.kernel_size))
905
                KA2PA(config.base), config.kernel_size))
892
                continue;
906
                continue;
893
           
907
           
Line 917... Line 931...
917
    zone_construct(start, count, z, flags);
931
    zone_construct(start, count, z, flags);
918
    znum = zones_add_zone(z);
932
    znum = zones_add_zone(z);
919
    if (znum == -1)
933
    if (znum == -1)
920
        return -1;
934
        return -1;
921
 
935
 
-
 
936
    mutex_lock(&mem_avail_mtx);
-
 
937
    mem_avail_frames += count;
-
 
938
    mutex_unlock(&mem_avail_mtx);
-
 
939
 
922
    /* If confdata in zone, mark as unavailable */
940
    /* If confdata in zone, mark as unavailable */
923
    if (confframe >= start && confframe < start + count)
941
    if (confframe >= start && confframe < start + count)
924
        for (i = confframe; i < confframe + confcount; i++) {
942
        for (i = confframe; i < confframe + confcount; i++) {
925
            zone_mark_unavailable(z, i - z->base);
943
            zone_mark_unavailable(z, i - z->base);
926
        }
944
        }
-
 
945
   
927
    return znum;
946
    return znum;
928
}
947
}
929
 
948
 
930
/***************************************/
949
/***************************************/
931
/* Frame functions */
950
/* Frame functions */
932
 
951
 
933
/** Set parent of frame */
952
/** Set parent of frame. */
934
void frame_set_parent(pfn_t pfn, void *data, unsigned int hint)
953
void frame_set_parent(pfn_t pfn, void *data, unsigned int hint)
935
{
954
{
936
    zone_t *zone = find_zone_and_lock(pfn, &hint);
955
    zone_t *zone = find_zone_and_lock(pfn, &hint);
937
 
956
 
938
    ASSERT(zone);
957
    ASSERT(zone);
939
 
958
 
940
    zone_get_frame(zone, pfn-zone->base)->parent = data;
959
    zone_get_frame(zone, pfn - zone->base)->parent = data;
941
    spinlock_unlock(&zone->lock);
960
    spinlock_unlock(&zone->lock);
942
}
961
}
943
 
962
 
944
void *frame_get_parent(pfn_t pfn, unsigned int hint)
963
void *frame_get_parent(pfn_t pfn, unsigned int hint)
945
{
964
{
Line 953... Line 972...
953
    return res;
972
    return res;
954
}
973
}
955
 
974
 
956
/** Allocate power-of-two frames of physical memory.
975
/** Allocate power-of-two frames of physical memory.
957
 *
976
 *
958
 * @param order  Allocate exactly 2^order frames.
977
 * @param order     Allocate exactly 2^order frames.
959
 * @param flags  Flags for host zone selection and address processing.
978
 * @param flags     Flags for host zone selection and address processing.
960
 * @param pzone  Preferred zone
979
 * @param pzone     Preferred zone.
961
 *
980
 *
962
 * @return Physical address of the allocated frame.
981
 * @return      Physical address of the allocated frame.
963
 *
982
 *
964
 */
983
 */
965
void * frame_alloc_generic(uint8_t order, int flags, unsigned int *pzone)
984
void *frame_alloc_generic(uint8_t order, int flags, unsigned int *pzone)
966
{
985
{
967
    ipl_t ipl;
986
    ipl_t ipl;
968
    int freed;
987
    int freed;
969
    pfn_t v;
988
    pfn_t v;
970
    zone_t *zone;
989
    zone_t *zone;
-
 
990
    unsigned long gen = 0;
971
   
991
   
972
loop:
992
loop:
973
    ipl = interrupts_disable();
993
    ipl = interrupts_disable();
974
   
994
   
975
    /*
995
    /*
Line 989... Line 1009...
989
                zone = find_free_zone_and_lock(order, pzone);
1009
                zone = find_free_zone_and_lock(order, pzone);
990
        }
1010
        }
991
    }
1011
    }
992
    if (!zone) {
1012
    if (!zone) {
993
        /*
1013
        /*
994
         * TODO: Sleep until frames are available again.
1014
         * Sleep until some frames are available again.
995
         */
1015
         */
-
 
1016
        if (flags & FRAME_ATOMIC) {
996
        interrupts_restore(ipl);
1017
            interrupts_restore(ipl);
997
 
-
 
998
        if (flags & FRAME_ATOMIC)
-
 
999
            return 0;
1018
            return 0;
-
 
1019
        }
1000
       
1020
       
-
 
1021
#ifdef CONFIG_DEBUG
-
 
1022
        unsigned long avail;
-
 
1023
 
-
 
1024
        mutex_lock(&mem_avail_mtx);
-
 
1025
        avail = mem_avail_frames;
1001
        panic("Sleep not implemented.\n");
1026
        mutex_unlock(&mem_avail_mtx);
-
 
1027
 
-
 
1028
        printf("Thread %" PRIu64 " waiting for %u frames, "
-
 
1029
            "%u available.\n", THREAD->tid, 1ULL << order, avail);
-
 
1030
#endif
-
 
1031
 
-
 
1032
        mutex_lock(&mem_avail_mtx);
-
 
1033
        while ((mem_avail_frames < (1ULL << order)) ||
-
 
1034
            gen == mem_avail_gen)
-
 
1035
            condvar_wait(&mem_avail_cv, &mem_avail_mtx);
-
 
1036
        gen = mem_avail_gen;
-
 
1037
        mutex_unlock(&mem_avail_mtx);
-
 
1038
 
-
 
1039
#ifdef CONFIG_DEBUG
-
 
1040
        mutex_lock(&mem_avail_mtx);
-
 
1041
        avail = mem_avail_frames;
-
 
1042
        mutex_unlock(&mem_avail_mtx);
-
 
1043
 
-
 
1044
        printf("Thread %" PRIu64 " woken up, %u frames available.\n",
-
 
1045
            THREAD->tid, avail);
-
 
1046
#endif
-
 
1047
 
-
 
1048
        interrupts_restore(ipl);
1002
        goto loop;
1049
        goto loop;
1003
    }
1050
    }
1004
   
1051
   
1005
    v = zone_frame_alloc(zone, order);
1052
    v = zone_frame_alloc(zone, order);
1006
    v += zone->base;
1053
    v += zone->base;
1007
 
1054
 
1008
    spinlock_unlock(&zone->lock);
1055
    spinlock_unlock(&zone->lock);
-
 
1056
   
-
 
1057
    mutex_lock(&mem_avail_mtx);
-
 
1058
    mem_avail_frames -= (1ULL << order);
-
 
1059
    mutex_unlock(&mem_avail_mtx);
-
 
1060
 
1009
    interrupts_restore(ipl);
1061
    interrupts_restore(ipl);
1010
 
1062
 
1011
    if (flags & FRAME_KA)
1063
    if (flags & FRAME_KA)
1012
        return (void *)PA2KA(PFN2ADDR(v));
1064
        return (void *)PA2KA(PFN2ADDR(v));
1013
    return (void *)PFN2ADDR(v);
1065
    return (void *)PFN2ADDR(v);
Line 1017... Line 1069...
1017
 *
1069
 *
1018
 * Find respective frame structure for supplied physical frame address.
1070
 * Find respective frame structure for supplied physical frame address.
1019
 * Decrement frame reference count.
1071
 * Decrement frame reference count.
1020
 * If it drops to zero, move the frame structure to free list.
1072
 * If it drops to zero, move the frame structure to free list.
1021
 *
1073
 *
1022
 * @param Frame Physical Address of of the frame to be freed.
1074
 * @param frame     Physical Address of of the frame to be freed.
1023
 */
1075
 */
1024
void frame_free(uintptr_t frame)
1076
void frame_free(uintptr_t frame)
1025
{
1077
{
1026
    ipl_t ipl;
1078
    ipl_t ipl;
1027
    zone_t *zone;
1079
    zone_t *zone;
1028
    pfn_t pfn = ADDR2PFN(frame);
1080
    pfn_t pfn = ADDR2PFN(frame);
1029
 
1081
 
1030
    ipl = interrupts_disable();
1082
    ipl = interrupts_disable();
1031
   
1083
 
1032
    /*
1084
    /*
1033
     * First, find host frame zone for addr.
1085
     * First, find host frame zone for addr.
1034
     */
1086
     */
1035
    zone = find_zone_and_lock(pfn,NULL);
1087
    zone = find_zone_and_lock(pfn, NULL);
1036
    ASSERT(zone);
1088
    ASSERT(zone);
1037
   
1089
   
1038
    zone_frame_free(zone, pfn-zone->base);
1090
    zone_frame_free(zone, pfn - zone->base);
1039
   
1091
   
1040
    spinlock_unlock(&zone->lock);
1092
    spinlock_unlock(&zone->lock);
-
 
1093
   
-
 
1094
    /*
-
 
1095
     * Signal that some memory has been freed.
-
 
1096
     */
-
 
1097
    mutex_lock(&mem_avail_mtx);
-
 
1098
    mem_avail_frames++;
-
 
1099
    mem_avail_gen++;
-
 
1100
    condvar_broadcast(&mem_avail_cv);
-
 
1101
    mutex_unlock(&mem_avail_mtx);
-
 
1102
 
1041
    interrupts_restore(ipl);
1103
    interrupts_restore(ipl);
1042
}
1104
}
1043
 
1105
 
1044
/** Add reference to frame.
1106
/** Add reference to frame.
1045
 *
1107
 *
1046
 * Find respective frame structure for supplied PFN and
1108
 * Find respective frame structure for supplied PFN and
1047
 * increment frame reference count.
1109
 * increment frame reference count.
1048
 *
1110
 *
1049
 * @param pfn Frame number of the frame to be freed.
1111
 * @param pfn       Frame number of the frame to be freed.
1050
 */
1112
 */
1051
void frame_reference_add(pfn_t pfn)
1113
void frame_reference_add(pfn_t pfn)
1052
{
1114
{
1053
    ipl_t ipl;
1115
    ipl_t ipl;
1054
    zone_t *zone;
1116
    zone_t *zone;
Line 1057... Line 1119...
1057
    ipl = interrupts_disable();
1119
    ipl = interrupts_disable();
1058
   
1120
   
1059
    /*
1121
    /*
1060
     * First, find host frame zone for addr.
1122
     * First, find host frame zone for addr.
1061
     */
1123
     */
1062
    zone = find_zone_and_lock(pfn,NULL);
1124
    zone = find_zone_and_lock(pfn, NULL);
1063
    ASSERT(zone);
1125
    ASSERT(zone);
1064
   
1126
   
1065
    frame = &zone->frames[pfn-zone->base];
1127
    frame = &zone->frames[pfn - zone->base];
1066
    frame->refcount++;
1128
    frame->refcount++;
1067
   
1129
   
1068
    spinlock_unlock(&zone->lock);
1130
    spinlock_unlock(&zone->lock);
1069
    interrupts_restore(ipl);
1131
    interrupts_restore(ipl);
1070
}
1132
}
1071
 
1133
 
1072
/** Mark given range unavailable in frame zones */
1134
/** Mark given range unavailable in frame zones. */
1073
void frame_mark_unavailable(pfn_t start, count_t count)
1135
void frame_mark_unavailable(pfn_t start, count_t count)
1074
{
1136
{
1075
    unsigned int i;
1137
    unsigned int i;
1076
    zone_t *zone;
1138
    zone_t *zone;
1077
    unsigned int prefzone = 0;
1139
    unsigned int prefzone = 0;
Line 1084... Line 1146...
1084
 
1146
 
1085
        spinlock_unlock(&zone->lock);
1147
        spinlock_unlock(&zone->lock);
1086
    }
1148
    }
1087
}
1149
}
1088
 
1150
 
1089
/** Initialize physical memory management
1151
/** Initialize physical memory management. */
1090
 *
-
 
1091
 * Initialize physical memory managemnt.
-
 
1092
 */
-
 
1093
void frame_init(void)
1152
void frame_init(void)
1094
{
1153
{
1095
    if (config.cpu_active == 1) {
1154
    if (config.cpu_active == 1) {
1096
        zones.count = 0;
1155
        zones.count = 0;
1097
        spinlock_initialize(&zones.lock, "zones.lock");
1156
        spinlock_initialize(&zones.lock, "zones.lock");
-
 
1157
        mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE);
-
 
1158
        condvar_initialize(&mem_avail_cv);
1098
    }
1159
    }
1099
    /* Tell the architecture to create some memory */
1160
    /* Tell the architecture to create some memory */
1100
    frame_arch_init();
1161
    frame_arch_init();
1101
    if (config.cpu_active == 1) {
1162
    if (config.cpu_active == 1) {
1102
        frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)),
1163
        frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)),
Line 1120... Line 1181...
1120
        frame_mark_unavailable(0, 1);
1181
        frame_mark_unavailable(0, 1);
1121
    }
1182
    }
1122
}
1183
}
1123
 
1184
 
1124
 
1185
 
1125
/** Return total size of all zones
1186
/** Return total size of all zones. */
1126
 *
-
 
1127
 */
-
 
1128
uint64_t zone_total_size(void) {
1187
uint64_t zone_total_size(void)
-
 
1188
{
1129
    zone_t *zone = NULL;
1189
    zone_t *zone = NULL;
1130
    unsigned int i;
1190
    unsigned int i;
1131
    ipl_t ipl;
1191
    ipl_t ipl;
1132
    uint64_t total = 0;
1192
    uint64_t total = 0;
1133
 
1193
 
Line 1145... Line 1205...
1145
    interrupts_restore(ipl);
1205
    interrupts_restore(ipl);
1146
   
1206
   
1147
    return total;
1207
    return total;
1148
}
1208
}
1149
 
1209
 
1150
 
-
 
1151
 
-
 
1152
/** Prints list of zones
1210
/** Prints list of zones. */
1153
 *
-
 
1154
 */
-
 
1155
void zone_print_list(void) {
1211
void zone_print_list(void)
-
 
1212
{
1156
    zone_t *zone = NULL;
1213
    zone_t *zone = NULL;
1157
    unsigned int i;
1214
    unsigned int i;
1158
    ipl_t ipl;
1215
    ipl_t ipl;
1159
 
1216
 
1160
    ipl = interrupts_disable();
1217
    ipl = interrupts_disable();
Line 1173... Line 1230...
1173
    for (i = 0; i < zones.count; i++) {
1230
    for (i = 0; i < zones.count; i++) {
1174
        zone = zones.info[i];
1231
        zone = zones.info[i];
1175
        spinlock_lock(&zone->lock);
1232
        spinlock_lock(&zone->lock);
1176
 
1233
 
1177
#ifdef __32_BITS__
1234
#ifdef __32_BITS__
1178
        printf("%-2u   %10p %12" PRIc " %12" PRIc "\n", i, PFN2ADDR(zone->base),
1235
        printf("%-2u   %10p %12" PRIc " %12" PRIc "\n",
-
 
1236
            i, PFN2ADDR(zone->base), zone->free_count,
1179
            zone->free_count, zone->busy_count);
1237
            zone->busy_count);
1180
#endif
1238
#endif
1181
 
1239
 
1182
#ifdef __64_BITS__
1240
#ifdef __64_BITS__
1183
        printf("%-2u   %18p %12" PRIc " %12" PRIc "\n", i, PFN2ADDR(zone->base),
1241
        printf("%-2u   %18p %12" PRIc " %12" PRIc "\n", i,
1184
            zone->free_count, zone->busy_count);
1242
            PFN2ADDR(zone->base), zone->free_count, zone->busy_count);
1185
#endif
1243
#endif
1186
       
1244
       
1187
        spinlock_unlock(&zone->lock);
1245
        spinlock_unlock(&zone->lock);
1188
    }
1246
    }
1189
   
1247
   
Line 1191... Line 1249...
1191
    interrupts_restore(ipl);
1249
    interrupts_restore(ipl);
1192
}
1250
}
1193
 
1251
 
1194
/** Prints zone details.
1252
/** Prints zone details.
1195
 *
1253
 *
1196
 * @param num Zone base address or zone number.
1254
 * @param num       Zone base address or zone number.
1197
 */
1255
 */
1198
void zone_print_one(unsigned int num) {
1256
void zone_print_one(unsigned int num)
-
 
1257
{
1199
    zone_t *zone = NULL;
1258
    zone_t *zone = NULL;
1200
    ipl_t ipl;
1259
    ipl_t ipl;
1201
    unsigned int i;
1260
    unsigned int i;
1202
 
1261
 
1203
    ipl = interrupts_disable();
1262
    ipl = interrupts_disable();
Line 1216... Line 1275...
1216
   
1275
   
1217
    spinlock_lock(&zone->lock);
1276
    spinlock_lock(&zone->lock);
1218
    printf("Memory zone information\n");
1277
    printf("Memory zone information\n");
1219
    printf("Zone base address: %p\n", PFN2ADDR(zone->base));
1278
    printf("Zone base address: %p\n", PFN2ADDR(zone->base));
1220
    printf("Zone size: %" PRIc " frames (%" PRIs " KB)\n", zone->count,
1279
    printf("Zone size: %" PRIc " frames (%" PRIs " KB)\n", zone->count,
1221
        SIZE2KB(FRAMES2SIZE(zone->count)));
1280
        SIZE2KB(FRAMES2SIZE(zone->count)));
1222
    printf("Allocated space: %" PRIc " frames (%" PRIs " KB)\n", zone->busy_count,
1281
    printf("Allocated space: %" PRIc " frames (%" PRIs " KB)\n",
1223
        SIZE2KB(FRAMES2SIZE(zone->busy_count)));
1282
        zone->busy_count, SIZE2KB(FRAMES2SIZE(zone->busy_count)));
1224
    printf("Available space: %" PRIc " frames (%" PRIs " KB)\n", zone->free_count,
1283
    printf("Available space: %" PRIc " frames (%" PRIs " KB)\n",
1225
        SIZE2KB(FRAMES2SIZE(zone->free_count)));
1284
        zone->free_count, SIZE2KB(FRAMES2SIZE(zone->free_count)));
1226
    buddy_system_structure_print(zone->buddy_system, FRAME_SIZE);
1285
    buddy_system_structure_print(zone->buddy_system, FRAME_SIZE);
1227
    spinlock_unlock(&zone->lock);
1286
    spinlock_unlock(&zone->lock);
1228
   
1287
   
1229
out:
1288
out:
1230
    spinlock_unlock(&zones.lock);
1289
    spinlock_unlock(&zones.lock);