Changeset 89bcb520 in mainline


Ignore:
Timestamp:
2011-04-16T16:53:49Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
28295955
Parents:
fe754c8
Message:

Reserve / unreserve memory upon frame allocation / deallocation.

File:
1 edited

Legend:

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

    rfe754c8 r89bcb520  
    4545#include <typedefs.h>
    4646#include <mm/frame.h>
     47#include <mm/reserve.h>
    4748#include <mm/as.h>
    4849#include <panic.h>
     
    472473 * @param frame_idx Frame index relative to zone.
    473474 *
    474  */
    475 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx)
     475 * @return          Number of freed frames.
     476 *
     477 */
     478NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx)
    476479{
    477480        ASSERT(zone_flags_available(zone->flags));
    478481       
    479482        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;
    483484       
    484485        ASSERT(frame->refcount);
     
    488489               
    489490                /* 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;
    493496}
    494497
     
    645648        for (i = 0; i < cframes; i++) {
    646649                zones.info[znum].busy_count++;
    647                 zone_frame_free(&zones.info[znum],
     650                (void) zone_frame_free(&zones.info[znum],
    648651                    pfn - zones.info[znum].base + i);
    649652        }
     
    683686        /* Free unneeded frames */
    684687        for (i = count; i < (size_t) (1 << order); i++)
    685                 zone_frame_free(&zones.info[znum], i + frame_idx);
     688                (void) zone_frame_free(&zones.info[znum], i + frame_idx);
    686689}
    687690
     
    9971000        size_t hint = pzone ? (*pzone) : 0;
    9981001       
     1002        /*
     1003         * If not told otherwise, we must first reserve the memory.
     1004         */
     1005        if (!(flags & FRAME_NO_RESERVE)) {
     1006                if (flags & FRAME_ATOMIC) {
     1007                        if (!reserve_try_alloc(size))
     1008                                return NULL;
     1009                } else {
     1010                        reserve_force_alloc(size);
     1011                }
     1012        }
     1013       
    9991014loop:
    10001015        irq_spinlock_lock(&zones.lock, true);
     
    10311046                if (flags & FRAME_ATOMIC) {
    10321047                        irq_spinlock_unlock(&zones.lock, true);
     1048                        if (!(flags & FRAME_NO_RESERVE))
     1049                                reserve_free(size);
    10331050                        return NULL;
    10341051                }
     
    11081125void frame_free_generic(uintptr_t frame, frame_flags_t flags)
    11091126{
     1127        size_t size;
     1128       
    11101129        irq_spinlock_lock(&zones.lock, true);
    11111130       
     
    11151134        pfn_t pfn = ADDR2PFN(frame);
    11161135        size_t znum = find_zone(pfn, 1, 0);
     1136
    11171137       
    11181138        ASSERT(znum != (size_t) -1);
    11191139       
    1120         zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
     1140        size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
    11211141       
    11221142        irq_spinlock_unlock(&zones.lock, true);
     
    11341154        }
    11351155        mutex_unlock(&mem_avail_mtx);
     1156       
     1157        if (!(flags & FRAME_NO_RESERVE))
     1158                reserve_free(size);
    11361159}
    11371160
Note: See TracChangeset for help on using the changeset viewer.