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