Changeset b0c2075 in mainline for kernel/generic/include/mm/frame.h


Ignore:
Timestamp:
2013-09-10T17:48:57Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
85147f3
Parents:
86733f3
Message:

new physical memory allocator supporting physical address constrains
the buddy allocator framework is retired and replaced by a two-level bitmap
the allocator can allocate an arbitrary number of frames, not only a power-of-two count

Caution: Change of semantics
The physical memory allocator no longer allocates naturally aligned blocks. If you require an aligned block, specify it as the constraint.

File:
1 edited

Legend:

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

    r86733f3 rb0c2075  
    3939#include <typedefs.h>
    4040#include <trace.h>
     41#include <adt/bitmap.h>
    4142#include <adt/list.h>
    42 #include <mm/buddy.h>
    4343#include <synch/spinlock.h>
    4444#include <arch/mm/page.h>
     
    9090
    9191typedef struct {
    92         size_t refcount;      /**< Tracking of shared frames */
    93         link_t buddy_link;    /**< Link to the next free block inside
    94                                    one order */
    95         void *parent;         /**< If allocated by slab, this points there */
    96         uint8_t buddy_order;  /**< Buddy system block order */
     92        size_t refcount;  /**< Tracking of shared frames */
     93        void *parent;     /**< If allocated by slab, this points there */
    9794} frame_t;
    9895
    9996typedef struct {
    100         pfn_t base;                    /**< Frame_no of the first frame
    101                                             in the frames array */
    102         size_t count;                  /**< Size of zone */
    103         size_t free_count;             /**< Number of free frame_t
    104                                             structures */
    105         size_t busy_count;             /**< Number of busy frame_t
    106                                             structures */
    107         zone_flags_t flags;            /**< Type of the zone */
     97        /** Frame_no of the first frame in the frames array */
     98        pfn_t base;
    10899       
    109         frame_t *frames;               /**< Array of frame_t structures
    110                                             in this zone */
    111         buddy_system_t *buddy_system;  /**< Buddy system for the zone */
     100        /** Size of zone */
     101        size_t count;
     102       
     103        /** Number of free frame_t structures */
     104        size_t free_count;
     105       
     106        /** Number of busy frame_t structures */
     107        size_t busy_count;
     108       
     109        /** Type of the zone */
     110        zone_flags_t flags;
     111       
     112        /** Frame bitmap */
     113        bitmap_t bitmap;
     114       
     115        /** Array of frame_t structures in this zone */
     116        frame_t *frames;
    112117} zone_t;
    113118
     
    124129extern zones_t zones;
    125130
    126 NO_TRACE static inline uintptr_t PFN2ADDR(pfn_t frame)
    127 {
    128         return (uintptr_t) (frame << FRAME_WIDTH);
    129 }
    130 
    131 NO_TRACE static inline pfn_t ADDR2PFN(uintptr_t addr)
    132 {
    133         return (pfn_t) (addr >> FRAME_WIDTH);
    134 }
    135 
    136 NO_TRACE static inline size_t SIZE2FRAMES(size_t size)
    137 {
    138         if (size == 0)
    139                 return 0;
    140        
    141         return (size_t) ((size - 1) >> FRAME_WIDTH) + 1;
    142 }
    143 
    144 NO_TRACE static inline size_t FRAMES2SIZE(size_t frames)
    145 {
    146         return (size_t) (frames << FRAME_WIDTH);
    147 }
    148 
    149 #define IS_BUDDY_ORDER_OK(index, order) \
    150     ((~(((sysarg_t) -1) << (order)) & (index)) == 0)
    151 #define IS_BUDDY_LEFT_BLOCK(zone, frame) \
    152     (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
    153 #define IS_BUDDY_RIGHT_BLOCK(zone, frame) \
    154     (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
    155 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \
    156     (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
    157 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \
    158     (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
    159 
    160131extern void frame_init(void);
    161132extern bool frame_adjust_zone_bounds(bool, uintptr_t *, size_t *);
    162 extern uintptr_t frame_alloc_generic(uint8_t, frame_flags_t, uintptr_t, size_t *);
    163 extern uintptr_t frame_alloc(uint8_t, frame_flags_t, uintptr_t);
    164 extern uintptr_t frame_alloc_noreserve(uint8_t, frame_flags_t, uintptr_t);
     133extern uintptr_t frame_alloc_generic(size_t, frame_flags_t, uintptr_t, size_t *);
     134extern uintptr_t frame_alloc(size_t, frame_flags_t, uintptr_t);
     135extern uintptr_t frame_alloc_noreserve(size_t, frame_flags_t, uintptr_t);
    165136extern void frame_free_generic(uintptr_t, frame_flags_t);
    166137extern void frame_free(uintptr_t);
Note: See TracChangeset for help on using the changeset viewer.