Ignore:
File:
1 edited

Legend:

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

    r864b0dd r7e752b2  
    4545#include <typedefs.h>
    4646#include <mm/frame.h>
    47 #include <mm/reserve.h>
    4847#include <mm/as.h>
    4948#include <panic.h>
     
    473472 * @param frame_idx Frame index relative to zone.
    474473 *
    475  * @return          Number of freed frames.
    476  *
    477  */
    478 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)
    479476{
    480477        ASSERT(zone_flags_available(zone->flags));
    481478       
    482479        frame_t *frame = &zone->frames[frame_idx];
    483         size_t size = 0;
     480       
     481        /* Remember frame order */
     482        uint8_t order = frame->buddy_order;
    484483       
    485484        ASSERT(frame->refcount);
    486485       
    487486        if (!--frame->refcount) {
    488                 size = 1 << frame->buddy_order;
    489                 buddy_system_free(zone->buddy_system, &frame->buddy_link);             
     487                buddy_system_free(zone->buddy_system, &frame->buddy_link);
     488               
    490489                /* Update zone information. */
    491                 zone->free_count += size;
    492                 zone->busy_count -= size;
    493         }
    494        
    495         return size;
     490                zone->free_count += (1 << order);
     491                zone->busy_count -= (1 << order);
     492        }
    496493}
    497494
     
    519516        ASSERT(link);
    520517        zone->free_count--;
    521         reserve_force_alloc(1);
    522518}
    523519
     
    649645        for (i = 0; i < cframes; i++) {
    650646                zones.info[znum].busy_count++;
    651                 (void) zone_frame_free(&zones.info[znum],
     647                zone_frame_free(&zones.info[znum],
    652648                    pfn - zones.info[znum].base + i);
    653649        }
     
    687683        /* Free unneeded frames */
    688684        for (i = count; i < (size_t) (1 << order); i++)
    689                 (void) zone_frame_free(&zones.info[znum], i + frame_idx);
     685                zone_frame_free(&zones.info[znum], i + frame_idx);
    690686}
    691687
     
    699695 * not to be 2^order size. Once the allocator is running it is no longer
    700696 * possible, merged configuration data occupies more space :-/
     697 *
     698 * The function uses
    701699 *
    702700 */
     
    839837                        buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link);
    840838                }
    841 
    842                 /* "Unreserve" new frames. */
    843                 reserve_free(count);
    844839        } else
    845840                zone->frames = NULL;
     
    1004999        size_t hint = pzone ? (*pzone) : 0;
    10051000       
    1006         /*
    1007          * If not told otherwise, we must first reserve the memory.
    1008          */
    1009         if (!(flags & FRAME_NO_RESERVE))
    1010                 reserve_force_alloc(size);
    1011 
    10121001loop:
    10131002        irq_spinlock_lock(&zones.lock, true);
     
    10441033                if (flags & FRAME_ATOMIC) {
    10451034                        irq_spinlock_unlock(&zones.lock, true);
    1046                         if (!(flags & FRAME_NO_RESERVE))
    1047                                 reserve_free(size);
    10481035                        return NULL;
    10491036                }
     
    11011088}
    11021089
    1103 void *frame_alloc(uint8_t order, frame_flags_t flags)
    1104 {
    1105         return frame_alloc_generic(order, flags, NULL);
    1106 }
    1107 
    1108 void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags)
    1109 {
    1110         return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL);
    1111 }
    1112 
    11131090/** Free a frame.
    11141091 *
     
    11181095 *
    11191096 * @param frame Physical Address of of the frame to be freed.
    1120  * @param flags Flags to control memory reservation.
    1121  *
    1122  */
    1123 void frame_free_generic(uintptr_t frame, frame_flags_t flags)
    1124 {
    1125         size_t size;
    1126        
     1097 *
     1098 */
     1099void frame_free(uintptr_t frame)
     1100{
    11271101        irq_spinlock_lock(&zones.lock, true);
    11281102       
     
    11321106        pfn_t pfn = ADDR2PFN(frame);
    11331107        size_t znum = find_zone(pfn, 1, 0);
    1134 
    11351108       
    11361109        ASSERT(znum != (size_t) -1);
    11371110       
    1138         size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
     1111        zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
    11391112       
    11401113        irq_spinlock_unlock(&zones.lock, true);
     
    11451118        mutex_lock(&mem_avail_mtx);
    11461119        if (mem_avail_req > 0)
    1147                 mem_avail_req -= min(mem_avail_req, size);
     1120                mem_avail_req--;
    11481121       
    11491122        if (mem_avail_req == 0) {
     
    11521125        }
    11531126        mutex_unlock(&mem_avail_mtx);
    1154        
    1155         if (!(flags & FRAME_NO_RESERVE))
    1156                 reserve_free(size);
    1157 }
    1158 
    1159 void frame_free(uintptr_t frame)
    1160 {
    1161         frame_free_generic(frame, 0);
    1162 }
    1163 
    1164 void frame_free_noreserve(uintptr_t frame)
    1165 {
    1166         frame_free_generic(frame, FRAME_NO_RESERVE);
    11671127}
    11681128
Note: See TracChangeset for help on using the changeset viewer.