Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/frame.c

    r933cadf r7e752b2  
    4545#include <typedefs.h>
    4646#include <mm/frame.h>
    47 #include <mm/reserve.h>
    4847#include <mm/as.h>
    4948#include <panic.h>
     
    6059#include <macros.h>
    6160#include <config.h>
    62 #include <str.h>
    6361
    6462zones_t zones;
     
    474472 * @param frame_idx Frame index relative to zone.
    475473 *
    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 */
     475NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx)
    480476{
    481477        ASSERT(zone_flags_available(zone->flags));
    482478       
    483479        frame_t *frame = &zone->frames[frame_idx];
    484         size_t size = 0;
     480       
     481        /* Remember frame order */
     482        uint8_t order = frame->buddy_order;
    485483       
    486484        ASSERT(frame->refcount);
    487485       
    488486        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               
    491489                /* 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        }
    497493}
    498494
     
    520516        ASSERT(link);
    521517        zone->free_count--;
    522         reserve_force_alloc(1);
    523518}
    524519
     
    650645        for (i = 0; i < cframes; i++) {
    651646                zones.info[znum].busy_count++;
    652                 (void) zone_frame_free(&zones.info[znum],
     647                zone_frame_free(&zones.info[znum],
    653648                    pfn - zones.info[znum].base + i);
    654649        }
     
    688683        /* Free unneeded frames */
    689684        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);
    691686}
    692687
     
    700695 * not to be 2^order size. Once the allocator is running it is no longer
    701696 * possible, merged configuration data occupies more space :-/
     697 *
     698 * The function uses
    702699 *
    703700 */
     
    840837                        buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link);
    841838                }
    842 
    843                 /* "Unreserve" new frames. */
    844                 reserve_free(count);
    845839        } else
    846840                zone->frames = NULL;
     
    1005999        size_t hint = pzone ? (*pzone) : 0;
    10061000       
    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 
    10131001loop:
    10141002        irq_spinlock_lock(&zones.lock, true);
     
    10451033                if (flags & FRAME_ATOMIC) {
    10461034                        irq_spinlock_unlock(&zones.lock, true);
    1047                         if (!(flags & FRAME_NO_RESERVE))
    1048                                 reserve_free(size);
    10491035                        return NULL;
    10501036                }
     
    11021088}
    11031089
    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 
    11141090/** Free a frame.
    11151091 *
     
    11191095 *
    11201096 * @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 */
     1099void frame_free(uintptr_t frame)
     1100{
    11281101        irq_spinlock_lock(&zones.lock, true);
    11291102       
     
    11331106        pfn_t pfn = ADDR2PFN(frame);
    11341107        size_t znum = find_zone(pfn, 1, 0);
    1135 
    11361108       
    11371109        ASSERT(znum != (size_t) -1);
    11381110       
    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);
    11401112       
    11411113        irq_spinlock_unlock(&zones.lock, true);
     
    11461118        mutex_lock(&mem_avail_mtx);
    11471119        if (mem_avail_req > 0)
    1148                 mem_avail_req -= min(mem_avail_req, size);
     1120                mem_avail_req--;
    11491121       
    11501122        if (mem_avail_req == 0) {
     
    11531125        }
    11541126        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);
    11681127}
    11691128
     
    13961355        bool available = zone_flags_available(flags);
    13971356       
    1398         uint64_t size;
    1399         const char *size_suffix;
    1400         bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);
    1401        
    14021357        printf("Zone number:       %zu\n", znum);
    14031358        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)));
    14061361        printf("Zone flags:        %c%c%c\n",
    14071362            available ? 'A' : ' ',
     
    14101365       
    14111366        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)));
    14201371        }
    14211372}
Note: See TracChangeset for help on using the changeset viewer.