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