Changeset 5f7a0ef in mainline


Ignore:
Timestamp:
2008-07-06T19:47:48Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
498b201
Parents:
2ec725f
Message:

Introduce FRAME_LOW_16_GiB slab/frame allocator flag. When specified, the
allocators will not allocate memory above 16 GiB. Each architecture needs to
make sure not to merge zones from below and above 16 GiB. Allocations that
require memory below 16 GiB need to be altered to use this flag.

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/mm/frame.h

    r2ec725f r5f7a0ef  
    5858#define ZONES_MAX               16
    5959
    60 /** If possible, merge with neighbouring zones. */
    61 #define ZONE_JOIN               0x1
    62 
    6360/** Convert the frame address to kernel va. */
    6461#define FRAME_KA                0x1
    6562/** Do not panic and do not sleep on failure. */
    66 #define FRAME_ATOMIC            0x2
     63#define FRAME_ATOMIC            0x2
    6764/** Do not start reclaiming when no free memory. */
    68 #define FRAME_NO_RECLAIM        0x4
     65#define FRAME_NO_RECLAIM        0x4
     66/** Do not allocate above 16GiB. */
     67#define FRAME_LOW_16_GiB        0x8
    6968
    7069static inline uintptr_t PFN2ADDR(pfn_t frame)
     
    9190
    9291#define IS_BUDDY_ORDER_OK(index, order)         \
    93         ((~(((unative_t) -1) << (order)) & (index)) == 0)
     92    ((~(((unative_t) -1) << (order)) & (index)) == 0)
    9493#define IS_BUDDY_LEFT_BLOCK(zone, frame)        \
    95         (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
     94    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
    9695#define IS_BUDDY_RIGHT_BLOCK(zone, frame)       \
    97         (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
     96    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
    9897#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame)    \
    99         (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
     98    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
    10099#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame)   \
    101         (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
     100    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
    102101
    103102#define frame_alloc(order, flags)               \
    104         frame_alloc_generic(order, flags, NULL)
     103    frame_alloc_generic(order, flags, NULL)
    105104
    106105extern void frame_init(void);
    107 extern void *frame_alloc_generic(uint8_t order, int flags, unsigned int *pzone);
    108 extern void frame_free(uintptr_t frame);
    109 extern void frame_reference_add(pfn_t pfn);
     106extern void *frame_alloc_generic(uint8_t, int, unsigned int *);
     107extern void frame_free(uintptr_t);
     108extern void frame_reference_add(pfn_t);
    110109
    111 extern int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags);
    112 extern void *frame_get_parent(pfn_t frame, unsigned int hint);
    113 extern void frame_set_parent(pfn_t frame, void *data, unsigned int hint);
    114 extern void frame_mark_unavailable(pfn_t start, count_t count);
    115 extern uintptr_t zone_conf_size(count_t count);
    116 extern void zone_merge(unsigned int z1, unsigned int z2);
     110extern int zone_create(pfn_t, count_t, pfn_t, int);
     111extern void *frame_get_parent(pfn_t, unsigned int);
     112extern void frame_set_parent(pfn_t, void *, unsigned int);
     113extern void frame_mark_unavailable(pfn_t, count_t);
     114extern uintptr_t zone_conf_size(count_t);
     115extern void zone_merge(unsigned int, unsigned int);
    117116extern void zone_merge_all(void);
    118117extern uint64_t zone_total_size(void);
     
    122121 */
    123122extern void zone_print_list(void);
    124 extern void zone_print_one(unsigned int znum);
     123extern void zone_print_one(unsigned int);
    125124
    126125#endif
  • kernel/generic/src/mm/frame.c

    r2ec725f r5f7a0ef  
    201201}
    202202
    203 /**
    204  * Try to find a zone where can we find the frame.
     203/** Try to find a zone where can we find the frame.
    205204 *
    206205 * Assume interrupts are disabled.
     
    238237                if (i >= zones.count)
    239238                        i = 0;
    240         } while(i != hint);
     239        } while (i != hint);
    241240
    242241        spinlock_unlock(&zones.lock);
     
    255254 *
    256255 * @param order         Size (2^order) of free space we are trying to find.
     256 * @param flags         Required flags of the target zone.
    257257 * @param pzone         Pointer to preferred zone or NULL, on return contains
    258258 *                      zone number.
    259259 */
    260 static zone_t *find_free_zone_and_lock(uint8_t order, unsigned int *pzone)
     260static zone_t *
     261find_free_zone_and_lock(uint8_t order, int flags, unsigned int *pzone)
    261262{
    262263        unsigned int i;
     
    264265        unsigned int hint = pzone ? *pzone : 0;
    265266       
     267        /* Mask off flags that are not applicable. */
     268        flags &= FRAME_LOW_16_GiB;
     269
    266270        spinlock_lock(&zones.lock);
    267271        if (hint >= zones.count)
     
    273277                spinlock_lock(&z->lock);
    274278
    275                 /* Check if the zone has 2^order frames area available  */
    276                 if (zone_can_alloc(z, order)) {
    277                         spinlock_unlock(&zones.lock);
    278                         if (pzone)
    279                                 *pzone = i;
    280                         return z;
     279                /*
     280                 * Check whether the zone meets the search criteria.
     281                 */
     282                if ((z->flags & flags) == flags) {
     283                        /*
     284                         * Check if the zone has 2^order frames area available.
     285                         */
     286                        if (zone_can_alloc(z, order)) {
     287                                spinlock_unlock(&zones.lock);
     288                                if (pzone)
     289                                        *pzone = i;
     290                                return z;
     291                        }
    281292                }
    282293                spinlock_unlock(&z->lock);
    283294                if (++i >= zones.count)
    284295                        i = 0;
    285         } while(i != hint);
     296        } while (i != hint);
    286297        spinlock_unlock(&zones.lock);
    287298        return NULL;
     
    811822        z->base = start;
    812823        z->count = count;
     824
     825        /* Mask off flags that are calculated automatically. */
     826        flags &= ~FRAME_LOW_16_GiB;
     827        /* Determine calculated flags. */
     828        if (z->base + count < (1ULL << (34 - FRAME_WIDTH)))     /* 16 GiB */
     829                flags |= FRAME_LOW_16_GiB;
     830
    813831        z->flags = flags;
     832
    814833        z->free_count = count;
    815834        z->busy_count = 0;
     
    9831002         * First, find suitable frame zone.
    9841003         */
    985         zone = find_free_zone_and_lock(order, pzone);
     1004        zone = find_free_zone_and_lock(order, flags, pzone);
    9861005       
    9871006        /* If no memory, reclaim some slab memory,
     
    9901009                freed = slab_reclaim(0);
    9911010                if (freed)
    992                         zone = find_free_zone_and_lock(order, pzone);
     1011                        zone = find_free_zone_and_lock(order, flags, pzone);
    9931012                if (!zone) {
    9941013                        freed = slab_reclaim(SLAB_RECLAIM_ALL);
    9951014                        if (freed)
    996                                 zone = find_free_zone_and_lock(order, pzone);
     1015                                zone = find_free_zone_and_lock(order, flags,
     1016                                    pzone);
    9971017                }
    9981018        }
Note: See TracChangeset for help on using the changeset viewer.