Changeset 5f7a0ef in mainline
- Timestamp:
- 2008-07-06T19:47:48Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 498b201
- Parents:
- 2ec725f
- Location:
- kernel/generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/frame.h
r2ec725f r5f7a0ef 58 58 #define ZONES_MAX 16 59 59 60 /** If possible, merge with neighbouring zones. */61 #define ZONE_JOIN 0x162 63 60 /** Convert the frame address to kernel va. */ 64 61 #define FRAME_KA 0x1 65 62 /** Do not panic and do not sleep on failure. */ 66 #define FRAME_ATOMIC 63 #define FRAME_ATOMIC 0x2 67 64 /** Do not start reclaiming when no free memory. */ 68 #define FRAME_NO_RECLAIM 0x4 65 #define FRAME_NO_RECLAIM 0x4 66 /** Do not allocate above 16GiB. */ 67 #define FRAME_LOW_16_GiB 0x8 69 68 70 69 static inline uintptr_t PFN2ADDR(pfn_t frame) … … 91 90 92 91 #define IS_BUDDY_ORDER_OK(index, order) \ 93 92 ((~(((unative_t) -1) << (order)) & (index)) == 0) 94 93 #define IS_BUDDY_LEFT_BLOCK(zone, frame) \ 95 94 (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 96 95 #define IS_BUDDY_RIGHT_BLOCK(zone, frame) \ 97 96 (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 98 97 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \ 99 98 (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 100 99 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \ 101 100 (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 102 101 103 102 #define frame_alloc(order, flags) \ 104 103 frame_alloc_generic(order, flags, NULL) 105 104 106 105 extern void frame_init(void); 107 extern void *frame_alloc_generic(uint8_t order, int flags, unsigned int *pzone);108 extern void frame_free(uintptr_t frame);109 extern void frame_reference_add(pfn_t pfn);106 extern void *frame_alloc_generic(uint8_t, int, unsigned int *); 107 extern void frame_free(uintptr_t); 108 extern void frame_reference_add(pfn_t); 110 109 111 extern int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags);112 extern void *frame_get_parent(pfn_t frame, unsigned int hint);113 extern void frame_set_parent(pfn_t frame, void *data, unsigned int hint);114 extern void frame_mark_unavailable(pfn_t start, count_t count);115 extern uintptr_t zone_conf_size(count_t count);116 extern void zone_merge(unsigned int z1, unsigned int z2);110 extern int zone_create(pfn_t, count_t, pfn_t, int); 111 extern void *frame_get_parent(pfn_t, unsigned int); 112 extern void frame_set_parent(pfn_t, void *, unsigned int); 113 extern void frame_mark_unavailable(pfn_t, count_t); 114 extern uintptr_t zone_conf_size(count_t); 115 extern void zone_merge(unsigned int, unsigned int); 117 116 extern void zone_merge_all(void); 118 117 extern uint64_t zone_total_size(void); … … 122 121 */ 123 122 extern void zone_print_list(void); 124 extern void zone_print_one(unsigned int znum);123 extern void zone_print_one(unsigned int); 125 124 126 125 #endif -
kernel/generic/src/mm/frame.c
r2ec725f r5f7a0ef 201 201 } 202 202 203 /** 204 * Try to find a zone where can we find the frame. 203 /** Try to find a zone where can we find the frame. 205 204 * 206 205 * Assume interrupts are disabled. … … 238 237 if (i >= zones.count) 239 238 i = 0; 240 } while (i != hint);239 } while (i != hint); 241 240 242 241 spinlock_unlock(&zones.lock); … … 255 254 * 256 255 * @param order Size (2^order) of free space we are trying to find. 256 * @param flags Required flags of the target zone. 257 257 * @param pzone Pointer to preferred zone or NULL, on return contains 258 258 * zone number. 259 259 */ 260 static zone_t *find_free_zone_and_lock(uint8_t order, unsigned int *pzone) 260 static zone_t * 261 find_free_zone_and_lock(uint8_t order, int flags, unsigned int *pzone) 261 262 { 262 263 unsigned int i; … … 264 265 unsigned int hint = pzone ? *pzone : 0; 265 266 267 /* Mask off flags that are not applicable. */ 268 flags &= FRAME_LOW_16_GiB; 269 266 270 spinlock_lock(&zones.lock); 267 271 if (hint >= zones.count) … … 273 277 spinlock_lock(&z->lock); 274 278 275 /* Check if the zone has 2^order frames area available */ 276 if (zone_can_alloc(z, order)) { 277 spinlock_unlock(&zones.lock); 278 if (pzone) 279 *pzone = i; 280 return z; 279 /* 280 * Check whether the zone meets the search criteria. 281 */ 282 if ((z->flags & flags) == flags) { 283 /* 284 * Check if the zone has 2^order frames area available. 285 */ 286 if (zone_can_alloc(z, order)) { 287 spinlock_unlock(&zones.lock); 288 if (pzone) 289 *pzone = i; 290 return z; 291 } 281 292 } 282 293 spinlock_unlock(&z->lock); 283 294 if (++i >= zones.count) 284 295 i = 0; 285 } while (i != hint);296 } while (i != hint); 286 297 spinlock_unlock(&zones.lock); 287 298 return NULL; … … 811 822 z->base = start; 812 823 z->count = count; 824 825 /* Mask off flags that are calculated automatically. */ 826 flags &= ~FRAME_LOW_16_GiB; 827 /* Determine calculated flags. */ 828 if (z->base + count < (1ULL << (34 - FRAME_WIDTH))) /* 16 GiB */ 829 flags |= FRAME_LOW_16_GiB; 830 813 831 z->flags = flags; 832 814 833 z->free_count = count; 815 834 z->busy_count = 0; … … 983 1002 * First, find suitable frame zone. 984 1003 */ 985 zone = find_free_zone_and_lock(order, pzone);1004 zone = find_free_zone_and_lock(order, flags, pzone); 986 1005 987 1006 /* If no memory, reclaim some slab memory, … … 990 1009 freed = slab_reclaim(0); 991 1010 if (freed) 992 zone = find_free_zone_and_lock(order, pzone);1011 zone = find_free_zone_and_lock(order, flags, pzone); 993 1012 if (!zone) { 994 1013 freed = slab_reclaim(SLAB_RECLAIM_ALL); 995 1014 if (freed) 996 zone = find_free_zone_and_lock(order, pzone); 1015 zone = find_free_zone_and_lock(order, flags, 1016 pzone); 997 1017 } 998 1018 }
Note:
See TracChangeset
for help on using the changeset viewer.