Subversion Repositories HelenOS-historic

Rev

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

Rev 1248 Rev 1269
Line 432... Line 432...
432
/* Zone functions */
432
/* Zone functions */
433
 
433
 
434
/** Allocate frame in particular zone
434
/** Allocate frame in particular zone
435
 *
435
 *
436
 * Assume zone is locked
436
 * Assume zone is locked
437
 * Panics, if allocation is impossible.
437
 * Panics if allocation is impossible.
-
 
438
 *
-
 
439
 * @param zone  Zone to allocate from.
-
 
440
 * @param order Allocate exactly 2^order frames.
438
 *
441
 *
439
 * @return Frame index in zone
442
 * @return Frame index in zone
-
 
443
 *
440
 */
444
 */
441
static pfn_t zone_frame_alloc(zone_t *zone,__u8 order)
445
static pfn_t zone_frame_alloc(zone_t *zone, __u8 order)
442
{
446
{
443
    pfn_t v;
447
    pfn_t v;
444
    link_t *tmp;
448
    link_t *tmp;
445
    frame_t *frame;
449
    frame_t *frame;
446
 
450
 
Line 889... Line 893...
889
    return res;
893
    return res;
890
}
894
}
891
 
895
 
892
/** Allocate power-of-two frames of physical memory.
896
/** Allocate power-of-two frames of physical memory.
893
 *
897
 *
-
 
898
 * @param order  Allocate exactly 2^order frames.
894
 * @param flags Flags for host zone selection and address processing.
899
 * @param flags  Flags for host zone selection and address processing.
895
 * @param order Allocate exactly 2^order frames.
900
 * @param status Allocation status (FRAME_OK on success), unused if NULL.
896
 * @param pzone Preferred zone
901
 * @param pzone  Preferred zone
897
 *
902
 *
898
 * @return Allocated frame.
903
 * @return Allocated frame.
-
 
904
 *
899
 */
905
 */
900
pfn_t frame_alloc_generic(__u8 order, int flags, int * status, int *pzone)
906
pfn_t frame_alloc_generic(__u8 order, int flags, int *status, int *pzone)
901
{
907
{
902
    ipl_t ipl;
908
    ipl_t ipl;
903
    int freed;
909
    int freed;
904
    pfn_t v;
910
    pfn_t v;
905
    zone_t *zone;
911
    zone_t *zone;
906
   
912
   
907
loop:
913
loop:
908
    ipl = interrupts_disable();
914
    ipl = interrupts_disable();
-
 
915
   
909
    /*
916
    /*
910
     * First, find suitable frame zone.
917
     * First, find suitable frame zone.
911
     */
918
     */
912
    zone = find_free_zone_lock(order,pzone);
919
    zone = find_free_zone_lock(order, pzone);
-
 
920
   
913
    /* If no memory, reclaim some slab memory,
921
    /* If no memory, reclaim some slab memory,
914
       if it does not help, reclaim all */
922
       if it does not help, reclaim all */
915
    if (!zone && !(flags & FRAME_NO_RECLAIM)) {
923
    if (!zone && !(flags & FRAME_NO_RECLAIM)) {
916
        freed = slab_reclaim(0);
924
        freed = slab_reclaim(0);
917
        if (freed)
925
        if (freed)
918
            zone = find_free_zone_lock(order,pzone);
926
            zone = find_free_zone_lock(order, pzone);
919
        if (!zone) {
927
        if (!zone) {
920
            freed = slab_reclaim(SLAB_RECLAIM_ALL);
928
            freed = slab_reclaim(SLAB_RECLAIM_ALL);
921
            if (freed)
929
            if (freed)
922
                zone = find_free_zone_lock(order,pzone);
930
                zone = find_free_zone_lock(order, pzone);
923
        }
931
        }
924
    }
932
    }
925
    if (!zone) {
933
    if (!zone) {
926
        if (flags & FRAME_PANIC)
934
        if (flags & FRAME_PANIC)
927
            panic("Can't allocate frame.\n");
935
            panic("Can't allocate frame.\n");
Line 939... Line 947...
939
        }
947
        }
940
       
948
       
941
        panic("Sleep not implemented.\n");
949
        panic("Sleep not implemented.\n");
942
        goto loop;
950
        goto loop;
943
    }
951
    }
-
 
952
   
944
    v = zone_frame_alloc(zone,order);
953
    v = zone_frame_alloc(zone, order);
945
    v += zone->base;
954
    v += zone->base;
946
 
955
 
947
    spinlock_unlock(&zone->lock);
956
    spinlock_unlock(&zone->lock);
948
    interrupts_restore(ipl);
957
    interrupts_restore(ipl);
949
 
958