Rev 1894 | Rev 2035 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1894 | Rev 1981 | ||
---|---|---|---|
Line 228... | Line 228... | ||
228 | * Assume interrupts are disabled!! |
228 | * Assume interrupts are disabled!! |
229 | * |
229 | * |
230 | * @param order Size (2^order) of free space we are trying to find |
230 | * @param order Size (2^order) of free space we are trying to find |
231 | * @param pzone Pointer to preferred zone or NULL, on return contains zone number |
231 | * @param pzone Pointer to preferred zone or NULL, on return contains zone number |
232 | */ |
232 | */ |
233 | static zone_t * find_free_zone_lock(uint8_t order, int *pzone) |
233 | static zone_t * find_free_zone_and_lock(uint8_t order, int *pzone) |
234 | { |
234 | { |
235 | int i; |
235 | int i; |
236 | zone_t *z; |
236 | zone_t *z; |
237 | int hint = pzone ? *pzone : 0; |
237 | int hint = pzone ? *pzone : 0; |
238 | 238 | ||
Line 323... | Line 323... | ||
323 | is_right = IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame); |
323 | is_right = IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame); |
324 | 324 | ||
325 | ASSERT(is_left ^ is_right); |
325 | ASSERT(is_left ^ is_right); |
326 | if (is_left) { |
326 | if (is_left) { |
327 | index = (frame_index(zone, frame)) + (1 << frame->buddy_order); |
327 | index = (frame_index(zone, frame)) + (1 << frame->buddy_order); |
328 | } else { // if (is_right) |
328 | } else { /* if (is_right) */ |
329 | index = (frame_index(zone, frame)) - (1 << frame->buddy_order); |
329 | index = (frame_index(zone, frame)) - (1 << frame->buddy_order); |
330 | } |
330 | } |
331 | 331 | ||
332 | if (frame_index_valid(zone, index)) { |
332 | if (frame_index_valid(zone, index)) { |
333 | if (zone->frames[index].buddy_order == frame->buddy_order && |
333 | if (zone->frames[index].buddy_order == frame->buddy_order && |
Line 944... | Line 944... | ||
944 | ipl = interrupts_disable(); |
944 | ipl = interrupts_disable(); |
945 | 945 | ||
946 | /* |
946 | /* |
947 | * First, find suitable frame zone. |
947 | * First, find suitable frame zone. |
948 | */ |
948 | */ |
949 | zone = find_free_zone_lock(order, pzone); |
949 | zone = find_free_zone_and_lock(order, pzone); |
950 | 950 | ||
951 | /* If no memory, reclaim some slab memory, |
951 | /* If no memory, reclaim some slab memory, |
952 | if it does not help, reclaim all */ |
952 | if it does not help, reclaim all */ |
953 | if (!zone && !(flags & FRAME_NO_RECLAIM)) { |
953 | if (!zone && !(flags & FRAME_NO_RECLAIM)) { |
954 | freed = slab_reclaim(0); |
954 | freed = slab_reclaim(0); |
955 | if (freed) |
955 | if (freed) |
956 | zone = find_free_zone_lock(order, pzone); |
956 | zone = find_free_zone_and_lock(order, pzone); |
957 | if (!zone) { |
957 | if (!zone) { |
958 | freed = slab_reclaim(SLAB_RECLAIM_ALL); |
958 | freed = slab_reclaim(SLAB_RECLAIM_ALL); |
959 | if (freed) |
959 | if (freed) |
960 | zone = find_free_zone_lock(order, pzone); |
960 | zone = find_free_zone_and_lock(order, pzone); |
961 | } |
961 | } |
962 | } |
962 | } |
963 | if (!zone) { |
963 | if (!zone) { |
964 | /* |
964 | /* |
965 | * TODO: Sleep until frames are available again. |
965 | * TODO: Sleep until frames are available again. |
Line 1046... | Line 1046... | ||
1046 | int i; |
1046 | int i; |
1047 | zone_t *zone; |
1047 | zone_t *zone; |
1048 | int prefzone = 0; |
1048 | int prefzone = 0; |
1049 | 1049 | ||
1050 | for (i=0; i < count; i++) { |
1050 | for (i=0; i < count; i++) { |
1051 | zone = find_zone_and_lock(start+i,&prefzone); |
1051 | zone = find_zone_and_lock(start + i, &prefzone); |
1052 | if (!zone) /* PFN not found */ |
1052 | if (!zone) /* PFN not found */ |
1053 | continue; |
1053 | continue; |
1054 | zone_mark_unavailable(zone, start+i-zone->base); |
1054 | zone_mark_unavailable(zone, start + i - zone->base); |
1055 | 1055 | ||
1056 | spinlock_unlock(&zone->lock); |
1056 | spinlock_unlock(&zone->lock); |
1057 | } |
1057 | } |
1058 | } |
1058 | } |
1059 | 1059 | ||
Line 1063... | Line 1063... | ||
1063 | */ |
1063 | */ |
1064 | void frame_init(void) |
1064 | void frame_init(void) |
1065 | { |
1065 | { |
1066 | if (config.cpu_active == 1) { |
1066 | if (config.cpu_active == 1) { |
1067 | zones.count = 0; |
1067 | zones.count = 0; |
1068 | spinlock_initialize(&zones.lock,"zones_glob_lock"); |
1068 | spinlock_initialize(&zones.lock, "zones.lock"); |
1069 | } |
1069 | } |
1070 | /* Tell the architecture to create some memory */ |
1070 | /* Tell the architecture to create some memory */ |
1071 | frame_arch_init(); |
1071 | frame_arch_init(); |
1072 | if (config.cpu_active == 1) { |
1072 | if (config.cpu_active == 1) { |
1073 | frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), SIZE2FRAMES(config.kernel_size)); |
1073 | frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), SIZE2FRAMES(config.kernel_size)); |