Changes in kernel/generic/src/mm/frame.c [8d308b9:7e752b2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r8d308b9 r7e752b2 45 45 #include <typedefs.h> 46 46 #include <mm/frame.h> 47 #include <mm/reserve.h>48 47 #include <mm/as.h> 49 48 #include <panic.h> … … 60 59 #include <macros.h> 61 60 #include <config.h> 62 #include <str.h>63 61 64 62 zones_t zones; … … 182 180 * 183 181 */ 184 NO_TRACE static size_t frame_total_free_get_internal(void) 182 #ifdef CONFIG_DEBUG 183 NO_TRACE static size_t total_frames_free(void) 185 184 { 186 185 size_t total = 0; 187 186 size_t i; 188 189 187 for (i = 0; i < zones.count; i++) 190 188 total += zones.info[i].free_count; … … 192 190 return total; 193 191 } 194 195 NO_TRACE size_t frame_total_free_get(void) 196 { 197 size_t total; 198 199 irq_spinlock_lock(&zones.lock, true); 200 total = frame_total_free_get_internal(); 201 irq_spinlock_unlock(&zones.lock, true); 202 203 return total; 204 } 205 192 #endif /* CONFIG_DEBUG */ 206 193 207 194 /** Find a zone with a given frames. … … 485 472 * @param frame_idx Frame index relative to zone. 486 473 * 487 * @return Number of freed frames. 488 * 489 */ 490 NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx) 474 */ 475 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx) 491 476 { 492 477 ASSERT(zone_flags_available(zone->flags)); 493 478 494 479 frame_t *frame = &zone->frames[frame_idx]; 495 size_t size = 0; 480 481 /* Remember frame order */ 482 uint8_t order = frame->buddy_order; 496 483 497 484 ASSERT(frame->refcount); 498 485 499 486 if (!--frame->refcount) { 500 size = 1 << frame->buddy_order;501 buddy_system_free(zone->buddy_system, &frame->buddy_link);487 buddy_system_free(zone->buddy_system, &frame->buddy_link); 488 502 489 /* Update zone information. */ 503 zone->free_count += size; 504 zone->busy_count -= size; 505 } 506 507 return size; 490 zone->free_count += (1 << order); 491 zone->busy_count -= (1 << order); 492 } 508 493 } 509 494 … … 531 516 ASSERT(link); 532 517 zone->free_count--; 533 reserve_force_alloc(1);534 518 } 535 519 … … 661 645 for (i = 0; i < cframes; i++) { 662 646 zones.info[znum].busy_count++; 663 (void)zone_frame_free(&zones.info[znum],647 zone_frame_free(&zones.info[znum], 664 648 pfn - zones.info[znum].base + i); 665 649 } … … 699 683 /* Free unneeded frames */ 700 684 for (i = count; i < (size_t) (1 << order); i++) 701 (void)zone_frame_free(&zones.info[znum], i + frame_idx);685 zone_frame_free(&zones.info[znum], i + frame_idx); 702 686 } 703 687 … … 711 695 * not to be 2^order size. Once the allocator is running it is no longer 712 696 * possible, merged configuration data occupies more space :-/ 697 * 698 * The function uses 713 699 * 714 700 */ … … 1013 999 size_t hint = pzone ? (*pzone) : 0; 1014 1000 1015 /*1016 * If not told otherwise, we must first reserve the memory.1017 */1018 if (!(flags & FRAME_NO_RESERVE))1019 reserve_force_alloc(size);1020 1021 1001 loop: 1022 1002 irq_spinlock_lock(&zones.lock, true); … … 1053 1033 if (flags & FRAME_ATOMIC) { 1054 1034 irq_spinlock_unlock(&zones.lock, true); 1055 if (!(flags & FRAME_NO_RESERVE))1056 reserve_free(size);1057 1035 return NULL; 1058 1036 } 1059 1037 1060 1038 #ifdef CONFIG_DEBUG 1061 size_t avail = frame_total_free_get_internal();1039 size_t avail = total_frames_free(); 1062 1040 #endif 1063 1041 … … 1110 1088 } 1111 1089 1112 void *frame_alloc(uint8_t order, frame_flags_t flags)1113 {1114 return frame_alloc_generic(order, flags, NULL);1115 }1116 1117 void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags)1118 {1119 return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL);1120 }1121 1122 1090 /** Free a frame. 1123 1091 * … … 1127 1095 * 1128 1096 * @param frame Physical Address of of the frame to be freed. 1129 * @param flags Flags to control memory reservation. 1130 * 1131 */ 1132 void frame_free_generic(uintptr_t frame, frame_flags_t flags) 1133 { 1134 size_t size; 1135 1097 * 1098 */ 1099 void frame_free(uintptr_t frame) 1100 { 1136 1101 irq_spinlock_lock(&zones.lock, true); 1137 1102 … … 1141 1106 pfn_t pfn = ADDR2PFN(frame); 1142 1107 size_t znum = find_zone(pfn, 1, 0); 1143 1144 1108 1145 1109 ASSERT(znum != (size_t) -1); 1146 1110 1147 size =zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);1111 zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base); 1148 1112 1149 1113 irq_spinlock_unlock(&zones.lock, true); … … 1154 1118 mutex_lock(&mem_avail_mtx); 1155 1119 if (mem_avail_req > 0) 1156 mem_avail_req -= min(mem_avail_req, size);1120 mem_avail_req--; 1157 1121 1158 1122 if (mem_avail_req == 0) { … … 1161 1125 } 1162 1126 mutex_unlock(&mem_avail_mtx); 1163 1164 if (!(flags & FRAME_NO_RESERVE))1165 reserve_free(size);1166 }1167 1168 void frame_free(uintptr_t frame)1169 {1170 frame_free_generic(frame, 0);1171 }1172 1173 void frame_free_noreserve(uintptr_t frame)1174 {1175 frame_free_generic(frame, FRAME_NO_RESERVE);1176 1127 } 1177 1128 … … 1404 1355 bool available = zone_flags_available(flags); 1405 1356 1406 uint64_t size;1407 const char *size_suffix;1408 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);1409 1410 1357 printf("Zone number: %zu\n", znum); 1411 1358 printf("Zone base address: %p\n", (void *) base); 1412 printf("Zone size: %zu frames (% " PRIu64 " %s)\n", count,1413 size, size_suffix);1359 printf("Zone size: %zu frames (%zu KiB)\n", count, 1360 SIZE2KB(FRAMES2SIZE(count))); 1414 1361 printf("Zone flags: %c%c%c\n", 1415 1362 available ? 'A' : ' ', … … 1418 1365 1419 1366 if (available) { 1420 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix, 1421 false); 1422 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n", 1423 busy_count, size, size_suffix); 1424 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix, 1425 false); 1426 printf("Available space: %zu frames (%" PRIu64 " %s)\n", 1427 free_count, size, size_suffix); 1367 printf("Allocated space: %zu frames (%zu KiB)\n", 1368 busy_count, SIZE2KB(FRAMES2SIZE(busy_count))); 1369 printf("Available space: %zu frames (%zu KiB)\n", 1370 free_count, SIZE2KB(FRAMES2SIZE(free_count))); 1428 1371 } 1429 1372 }
Note:
See TracChangeset
for help on using the changeset viewer.