Changes in kernel/generic/src/mm/frame.c [7e752b2:d060900] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r7e752b2 rd060900 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> … … 472 473 * @param frame_idx Frame index relative to zone. 473 474 * 474 */ 475 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx) 475 * @return Number of freed frames. 476 * 477 */ 478 NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx) 476 479 { 477 480 ASSERT(zone_flags_available(zone->flags)); 478 481 479 482 frame_t *frame = &zone->frames[frame_idx]; 480 481 /* Remember frame order */ 482 uint8_t order = frame->buddy_order; 483 size_t size = 1 << frame->buddy_order; 483 484 484 485 ASSERT(frame->refcount); … … 488 489 489 490 /* Update zone information. */ 490 zone->free_count += (1 << order); 491 zone->busy_count -= (1 << order); 492 } 491 zone->free_count += size; 492 zone->busy_count -= size; 493 } 494 495 return size; 493 496 } 494 497 … … 516 519 ASSERT(link); 517 520 zone->free_count--; 521 reserve_force_alloc(1); 518 522 } 519 523 … … 645 649 for (i = 0; i < cframes; i++) { 646 650 zones.info[znum].busy_count++; 647 zone_frame_free(&zones.info[znum],651 (void) zone_frame_free(&zones.info[znum], 648 652 pfn - zones.info[znum].base + i); 649 653 } … … 683 687 /* Free unneeded frames */ 684 688 for (i = count; i < (size_t) (1 << order); i++) 685 zone_frame_free(&zones.info[znum], i + frame_idx);689 (void) zone_frame_free(&zones.info[znum], i + frame_idx); 686 690 } 687 691 … … 695 699 * not to be 2^order size. Once the allocator is running it is no longer 696 700 * possible, merged configuration data occupies more space :-/ 697 *698 * The function uses699 701 * 700 702 */ … … 837 839 buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link); 838 840 } 841 842 /* "Unreserve" new frames. */ 843 reserve_free(count); 839 844 } else 840 845 zone->frames = NULL; … … 999 1004 size_t hint = pzone ? (*pzone) : 0; 1000 1005 1006 /* 1007 * If not told otherwise, we must first reserve the memory. 1008 */ 1009 if (!(flags & FRAME_NO_RESERVE)) { 1010 if (flags & FRAME_ATOMIC) { 1011 if (!reserve_try_alloc(size)) 1012 return NULL; 1013 } else { 1014 reserve_force_alloc(size); 1015 } 1016 } 1017 1001 1018 loop: 1002 1019 irq_spinlock_lock(&zones.lock, true); … … 1033 1050 if (flags & FRAME_ATOMIC) { 1034 1051 irq_spinlock_unlock(&zones.lock, true); 1052 if (!(flags & FRAME_NO_RESERVE)) 1053 reserve_free(size); 1035 1054 return NULL; 1036 1055 } … … 1088 1107 } 1089 1108 1109 void *frame_alloc(uint8_t order, frame_flags_t flags) 1110 { 1111 return frame_alloc_generic(order, flags, NULL); 1112 } 1113 1114 void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags) 1115 { 1116 return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL); 1117 } 1118 1090 1119 /** Free a frame. 1091 1120 * … … 1095 1124 * 1096 1125 * @param frame Physical Address of of the frame to be freed. 1097 * 1098 */ 1099 void frame_free(uintptr_t frame) 1100 { 1126 * @param flags Flags to control memory reservation. 1127 * 1128 */ 1129 void frame_free_generic(uintptr_t frame, frame_flags_t flags) 1130 { 1131 size_t size; 1132 1101 1133 irq_spinlock_lock(&zones.lock, true); 1102 1134 … … 1106 1138 pfn_t pfn = ADDR2PFN(frame); 1107 1139 size_t znum = find_zone(pfn, 1, 0); 1140 1108 1141 1109 1142 ASSERT(znum != (size_t) -1); 1110 1143 1111 zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);1144 size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base); 1112 1145 1113 1146 irq_spinlock_unlock(&zones.lock, true); … … 1118 1151 mutex_lock(&mem_avail_mtx); 1119 1152 if (mem_avail_req > 0) 1120 mem_avail_req --;1153 mem_avail_req -= min(mem_avail_req, size); 1121 1154 1122 1155 if (mem_avail_req == 0) { … … 1125 1158 } 1126 1159 mutex_unlock(&mem_avail_mtx); 1160 1161 if (!(flags & FRAME_NO_RESERVE)) 1162 reserve_free(size); 1163 } 1164 1165 void frame_free(uintptr_t frame) 1166 { 1167 frame_free_generic(frame, 0); 1168 } 1169 1170 void frame_free_noreserve(uintptr_t frame) 1171 { 1172 frame_free_generic(frame, FRAME_NO_RESERVE); 1127 1173 } 1128 1174
Note:
See TracChangeset
for help on using the changeset viewer.