Changes in kernel/generic/src/mm/frame.c [933cadf:af96dd57] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r933cadf raf96dd57 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; … … 147 145 (!iswithin(zones.info[i].base, zones.info[i].count, 148 146 base, count))) { 149 printf("Zone (%p, %p) overlaps " 150 "with previous zone (%p %p)!\n", 151 (void *) PFN2ADDR(base), (void *) PFN2ADDR(count), 152 (void *) PFN2ADDR(zones.info[i].base), 153 (void *) PFN2ADDR(zones.info[i].count)); 147 printf("Zone (%p, %p) overlaps with previous zone (%p, %p)!\n", 148 PFN2ADDR(base), PFN2ADDR(count), 149 PFN2ADDR(zones.info[i].base), 150 PFN2ADDR(zones.info[i].count)); 154 151 } 155 152 … … 474 471 * @param frame_idx Frame index relative to zone. 475 472 * 476 * @return Number of freed frames. 477 * 478 */ 479 NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx) 473 */ 474 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx) 480 475 { 481 476 ASSERT(zone_flags_available(zone->flags)); 482 477 483 478 frame_t *frame = &zone->frames[frame_idx]; 484 size_t size = 0; 479 480 /* Remember frame order */ 481 uint8_t order = frame->buddy_order; 485 482 486 483 ASSERT(frame->refcount); 487 484 488 485 if (!--frame->refcount) { 489 size = 1 << frame->buddy_order;490 buddy_system_free(zone->buddy_system, &frame->buddy_link);486 buddy_system_free(zone->buddy_system, &frame->buddy_link); 487 491 488 /* Update zone information. */ 492 zone->free_count += size; 493 zone->busy_count -= size; 494 } 495 496 return size; 489 zone->free_count += (1 << order); 490 zone->busy_count -= (1 << order); 491 } 497 492 } 498 493 … … 520 515 ASSERT(link); 521 516 zone->free_count--; 522 reserve_force_alloc(1);523 517 } 524 518 … … 650 644 for (i = 0; i < cframes; i++) { 651 645 zones.info[znum].busy_count++; 652 (void)zone_frame_free(&zones.info[znum],646 zone_frame_free(&zones.info[znum], 653 647 pfn - zones.info[znum].base + i); 654 648 } … … 688 682 /* Free unneeded frames */ 689 683 for (i = count; i < (size_t) (1 << order); i++) 690 (void)zone_frame_free(&zones.info[znum], i + frame_idx);684 zone_frame_free(&zones.info[znum], i + frame_idx); 691 685 } 692 686 … … 700 694 * not to be 2^order size. Once the allocator is running it is no longer 701 695 * possible, merged configuration data occupies more space :-/ 696 * 697 * The function uses 702 698 * 703 699 */ … … 840 836 buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link); 841 837 } 842 843 /* "Unreserve" new frames. */844 reserve_free(count);845 838 } else 846 839 zone->frames = NULL; … … 885 878 * the assert 886 879 */ 887 ASSERT(confframe != ADDR2PFN((uintptr_t ) NULL));880 ASSERT(confframe != NULL); 888 881 889 882 /* If confframe is supposed to be inside our zone, then make sure … … 1005 998 size_t hint = pzone ? (*pzone) : 0; 1006 999 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 1013 1000 loop: 1014 1001 irq_spinlock_lock(&zones.lock, true); … … 1045 1032 if (flags & FRAME_ATOMIC) { 1046 1033 irq_spinlock_unlock(&zones.lock, true); 1047 if (!(flags & FRAME_NO_RESERVE))1048 reserve_free(size);1049 1034 return NULL; 1050 1035 } … … 1064 1049 1065 1050 #ifdef CONFIG_DEBUG 1066 printf("Thread %" PRIu64 " waiting for % zuframes, "1067 "% zuavailable.\n", THREAD->tid, size, avail);1051 printf("Thread %" PRIu64 " waiting for %" PRIs " frames, " 1052 "%" PRIs " available.\n", THREAD->tid, size, avail); 1068 1053 #endif 1069 1054 … … 1102 1087 } 1103 1088 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 1114 1089 /** Free a frame. 1115 1090 * … … 1119 1094 * 1120 1095 * @param frame Physical Address of of the frame to be freed. 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 1096 * 1097 */ 1098 void frame_free(uintptr_t frame) 1099 { 1128 1100 irq_spinlock_lock(&zones.lock, true); 1129 1101 … … 1132 1104 */ 1133 1105 pfn_t pfn = ADDR2PFN(frame); 1134 size_t znum = find_zone(pfn, 1, 0); 1135 1106 size_t znum = find_zone(pfn, 1, NULL); 1136 1107 1137 1108 ASSERT(znum != (size_t) -1); 1138 1109 1139 size =zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);1110 zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base); 1140 1111 1141 1112 irq_spinlock_unlock(&zones.lock, true); … … 1146 1117 mutex_lock(&mem_avail_mtx); 1147 1118 if (mem_avail_req > 0) 1148 mem_avail_req -= min(mem_avail_req, size);1119 mem_avail_req--; 1149 1120 1150 1121 if (mem_avail_req == 0) { … … 1153 1124 } 1154 1125 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);1168 1126 } 1169 1127 … … 1183 1141 * First, find host frame zone for addr. 1184 1142 */ 1185 size_t znum = find_zone(pfn, 1, 0);1143 size_t znum = find_zone(pfn, 1, NULL); 1186 1144 1187 1145 ASSERT(znum != (size_t) -1); … … 1339 1297 bool available = zone_flags_available(flags); 1340 1298 1341 printf("%-4 zu", i);1299 printf("%-4" PRIs, i); 1342 1300 1343 1301 #ifdef __32_BITS__ 1344 printf(" % p", (void *)base);1302 printf(" %10p", base); 1345 1303 #endif 1346 1304 1347 1305 #ifdef __64_BITS__ 1348 printf(" % p", (void *)base);1306 printf(" %18p", base); 1349 1307 #endif 1350 1308 1351 printf(" %12 zu%c%c%c ", count,1309 printf(" %12" PRIs " %c%c%c ", count, 1352 1310 available ? 'A' : ' ', 1353 1311 (flags & ZONE_RESERVED) ? 'R' : ' ', … … 1355 1313 1356 1314 if (available) 1357 printf("%14 zu %14zu",1315 printf("%14" PRIs " %14" PRIs, 1358 1316 free_count, busy_count); 1359 1317 … … 1396 1354 bool available = zone_flags_available(flags); 1397 1355 1398 uint64_t size; 1399 const char *size_suffix; 1400 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false); 1401 1402 printf("Zone number: %zu\n", znum); 1403 printf("Zone base address: %p\n", (void *) base); 1404 printf("Zone size: %zu frames (%" PRIu64 " %s)\n", count, 1405 size, size_suffix); 1356 printf("Zone number: %" PRIs "\n", znum); 1357 printf("Zone base address: %p\n", base); 1358 printf("Zone size: %" PRIs " frames (%" PRIs " KiB)\n", count, 1359 SIZE2KB(FRAMES2SIZE(count))); 1406 1360 printf("Zone flags: %c%c%c\n", 1407 1361 available ? 'A' : ' ', … … 1410 1364 1411 1365 if (available) { 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); 1366 printf("Allocated space: %" PRIs " frames (%" PRIs " KiB)\n", 1367 busy_count, SIZE2KB(FRAMES2SIZE(busy_count))); 1368 printf("Available space: %" PRIs " frames (%" PRIs " KiB)\n", 1369 free_count, SIZE2KB(FRAMES2SIZE(free_count))); 1420 1370 } 1421 1371 }
Note:
See TracChangeset
for help on using the changeset viewer.