Changeset 5df1963 in mainline for kernel/generic/src/mm/frame.c


Ignore:
Timestamp:
2013-09-10T21:47:25Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0511549
Parents:
a501e22c
Message:

bitmap frame allocator does not keep track of the size of the allocated frame blocks
to avoid memory leaks the number of allocated frames needs to be passed explicitly during deallocation

File:
1 edited

Legend:

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

    ra501e22c r5df1963  
    348348       
    349349        frame_t *frame = zone_get_frame(zone, index);
    350         size_t size = 0;
    351350       
    352351        ASSERT(frame->refcount > 0);
     
    359358                zone->busy_count--;
    360359               
    361                 size = FRAME_SIZE;
    362         }
    363        
    364         return size;
     360                return 1;
     361        }
     362       
     363        return 0;
    365364}
    366365
     
    891890}
    892891
    893 /** Free a frame.
    894  *
    895  * Find respective frame structure for supplied physical frame address.
    896  * Decrement frame reference count. If it drops to zero, move the frame
    897  * structure to free list.
    898  *
    899  * @param frame Physical Address of of the frame to be freed.
     892/** Free frames of physical memory.
     893 *
     894 * Find respective frame structures for supplied physical frames.
     895 * Decrement each frame reference count. If it drops to zero, mark
     896 * the frames as available.
     897 *
     898 * @param start Physical Address of the first frame to be freed.
     899 * @param count Number of frames to free.
    900900 * @param flags Flags to control memory reservation.
    901901 *
    902902 */
    903 void frame_free_generic(uintptr_t frame, frame_flags_t flags)
    904 {
     903void frame_free_generic(uintptr_t start, size_t count, frame_flags_t flags)
     904{
     905        size_t freed = 0;
     906       
    905907        irq_spinlock_lock(&zones.lock, true);
    906908       
    907         /*
    908          * First, find host frame zone for addr.
    909          */
    910         pfn_t pfn = ADDR2PFN(frame);
    911         size_t znum = find_zone(pfn, 1, 0);
    912        
    913         ASSERT(znum != (size_t) -1);
    914        
    915         size_t size =
    916             zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
     909        for (size_t i = 0; i < count; i++) {
     910                /*
     911                 * First, find host frame zone for addr.
     912                 */
     913                pfn_t pfn = ADDR2PFN(start) + i;
     914                size_t znum = find_zone(pfn, 1, 0);
     915               
     916                ASSERT(znum != (size_t) -1);
     917               
     918                freed += zone_frame_free(&zones.info[znum],
     919                    pfn - zones.info[znum].base);
     920        }
    917921       
    918922        irq_spinlock_unlock(&zones.lock, true);
     
    920924        /*
    921925         * Signal that some memory has been freed.
    922          */
    923        
    924        
    925         /*
    926          * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
    927          * to prevent deadlock with TLB shootdown.
     926         * Since the mem_avail_mtx is an active mutex,
     927         * we need to disable interruptsto prevent deadlock
     928         * with TLB shootdown.
    928929         */
    929930       
     
    932933       
    933934        if (mem_avail_req > 0)
    934                 mem_avail_req -= min(mem_avail_req, size);
     935                mem_avail_req -= min(mem_avail_req, freed);
    935936       
    936937        if (mem_avail_req == 0) {
     
    943944       
    944945        if (!(flags & FRAME_NO_RESERVE))
    945                 reserve_free(size);
    946 }
    947 
    948 void frame_free(uintptr_t frame)
    949 {
    950         frame_free_generic(frame, 0);
    951 }
    952 
    953 void frame_free_noreserve(uintptr_t frame)
    954 {
    955         frame_free_generic(frame, FRAME_NO_RESERVE);
     946                reserve_free(freed);
     947}
     948
     949void frame_free(uintptr_t frame, size_t count)
     950{
     951        frame_free_generic(frame, count, 0);
     952}
     953
     954void frame_free_noreserve(uintptr_t frame, size_t count)
     955{
     956        frame_free_generic(frame, count, FRAME_NO_RESERVE);
    956957}
    957958
Note: See TracChangeset for help on using the changeset viewer.