Changes in kernel/generic/src/mm/frame.c [7e752b2:933cadf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r7e752b2 r933cadf 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; … … 472 474 * @param frame_idx Frame index relative to zone. 473 475 * 474 */ 475 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx) 476 * @return Number of freed frames. 477 * 478 */ 479 NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx) 476 480 { 477 481 ASSERT(zone_flags_available(zone->flags)); 478 482 479 483 frame_t *frame = &zone->frames[frame_idx]; 480 481 /* Remember frame order */ 482 uint8_t order = frame->buddy_order; 484 size_t size = 0; 483 485 484 486 ASSERT(frame->refcount); 485 487 486 488 if (!--frame->refcount) { 487 buddy_system_free(zone->buddy_system, &frame->buddy_link);488 489 size = 1 << frame->buddy_order; 490 buddy_system_free(zone->buddy_system, &frame->buddy_link); 489 491 /* Update zone information. */ 490 zone->free_count += (1 << order); 491 zone->busy_count -= (1 << order); 492 } 492 zone->free_count += size; 493 zone->busy_count -= size; 494 } 495 496 return size; 493 497 } 494 498 … … 516 520 ASSERT(link); 517 521 zone->free_count--; 522 reserve_force_alloc(1); 518 523 } 519 524 … … 645 650 for (i = 0; i < cframes; i++) { 646 651 zones.info[znum].busy_count++; 647 zone_frame_free(&zones.info[znum],652 (void) zone_frame_free(&zones.info[znum], 648 653 pfn - zones.info[znum].base + i); 649 654 } … … 683 688 /* Free unneeded frames */ 684 689 for (i = count; i < (size_t) (1 << order); i++) 685 zone_frame_free(&zones.info[znum], i + frame_idx);690 (void) zone_frame_free(&zones.info[znum], i + frame_idx); 686 691 } 687 692 … … 695 700 * not to be 2^order size. Once the allocator is running it is no longer 696 701 * possible, merged configuration data occupies more space :-/ 697 *698 * The function uses699 702 * 700 703 */ … … 837 840 buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link); 838 841 } 842 843 /* "Unreserve" new frames. */ 844 reserve_free(count); 839 845 } else 840 846 zone->frames = NULL; … … 999 1005 size_t hint = pzone ? (*pzone) : 0; 1000 1006 1007 /* 1008 * If not told otherwise, we must first reserve the memory. 1009 */ 1010 if (!(flags & FRAME_NO_RESERVE)) 1011 reserve_force_alloc(size); 1012 1001 1013 loop: 1002 1014 irq_spinlock_lock(&zones.lock, true); … … 1033 1045 if (flags & FRAME_ATOMIC) { 1034 1046 irq_spinlock_unlock(&zones.lock, true); 1047 if (!(flags & FRAME_NO_RESERVE)) 1048 reserve_free(size); 1035 1049 return NULL; 1036 1050 } … … 1088 1102 } 1089 1103 1104 void *frame_alloc(uint8_t order, frame_flags_t flags) 1105 { 1106 return frame_alloc_generic(order, flags, NULL); 1107 } 1108 1109 void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags) 1110 { 1111 return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL); 1112 } 1113 1090 1114 /** Free a frame. 1091 1115 * … … 1095 1119 * 1096 1120 * @param frame Physical Address of of the frame to be freed. 1097 * 1098 */ 1099 void frame_free(uintptr_t frame) 1100 { 1121 * @param flags Flags to control memory reservation. 1122 * 1123 */ 1124 void frame_free_generic(uintptr_t frame, frame_flags_t flags) 1125 { 1126 size_t size; 1127 1101 1128 irq_spinlock_lock(&zones.lock, true); 1102 1129 … … 1106 1133 pfn_t pfn = ADDR2PFN(frame); 1107 1134 size_t znum = find_zone(pfn, 1, 0); 1135 1108 1136 1109 1137 ASSERT(znum != (size_t) -1); 1110 1138 1111 zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);1139 size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base); 1112 1140 1113 1141 irq_spinlock_unlock(&zones.lock, true); … … 1118 1146 mutex_lock(&mem_avail_mtx); 1119 1147 if (mem_avail_req > 0) 1120 mem_avail_req --;1148 mem_avail_req -= min(mem_avail_req, size); 1121 1149 1122 1150 if (mem_avail_req == 0) { … … 1125 1153 } 1126 1154 mutex_unlock(&mem_avail_mtx); 1155 1156 if (!(flags & FRAME_NO_RESERVE)) 1157 reserve_free(size); 1158 } 1159 1160 void frame_free(uintptr_t frame) 1161 { 1162 frame_free_generic(frame, 0); 1163 } 1164 1165 void frame_free_noreserve(uintptr_t frame) 1166 { 1167 frame_free_generic(frame, FRAME_NO_RESERVE); 1127 1168 } 1128 1169 … … 1355 1396 bool available = zone_flags_available(flags); 1356 1397 1398 uint64_t size; 1399 const char *size_suffix; 1400 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false); 1401 1357 1402 printf("Zone number: %zu\n", znum); 1358 1403 printf("Zone base address: %p\n", (void *) base); 1359 printf("Zone size: %zu frames (% zu KiB)\n", count,1360 SIZE2KB(FRAMES2SIZE(count)));1404 printf("Zone size: %zu frames (%" PRIu64 " %s)\n", count, 1405 size, size_suffix); 1361 1406 printf("Zone flags: %c%c%c\n", 1362 1407 available ? 'A' : ' ', … … 1365 1410 1366 1411 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))); 1412 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix, 1413 false); 1414 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n", 1415 busy_count, size, size_suffix); 1416 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix, 1417 false); 1418 printf("Available space: %zu frames (%" PRIu64 " %s)\n", 1419 free_count, size, size_suffix); 1371 1420 } 1372 1421 }
Note:
See TracChangeset
for help on using the changeset viewer.