Subversion Repositories HelenOS

Rev

Rev 3425 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3425 Rev 4377
Line 39... Line 39...
39
#include <synch/spinlock.h>
39
#include <synch/spinlock.h>
40
#include <atomic.h>
40
#include <atomic.h>
41
#include <mm/frame.h>
41
#include <mm/frame.h>
42
 
42
 
43
/** Minimum size to be allocated by malloc */
43
/** Minimum size to be allocated by malloc */
44
#define SLAB_MIN_MALLOC_W 4
44
#define SLAB_MIN_MALLOC_W  4
45
 
45
 
46
/** Maximum size to be allocated by malloc */
46
/** Maximum size to be allocated by malloc */
47
#define SLAB_MAX_MALLOC_W 18
47
#define SLAB_MAX_MALLOC_W  22
48
 
48
 
49
/** Initial Magazine size (TODO: dynamically growing magazines) */
49
/** Initial Magazine size (TODO: dynamically growing magazines) */
50
#define SLAB_MAG_SIZE  4
50
#define SLAB_MAG_SIZE  4
51
 
51
 
52
/** If object size is less, store control structure inside SLAB */
52
/** If object size is less, store control structure inside SLAB */
53
#define SLAB_INSIDE_SIZE   (PAGE_SIZE >> 3)
53
#define SLAB_INSIDE_SIZE  (PAGE_SIZE >> 3)
54
 
54
 
55
/** Maximum wasted space we allow for cache */
55
/** Maximum wasted space we allow for cache */
56
#define SLAB_MAX_BADNESS(cache) \
56
#define SLAB_MAX_BADNESS(cache) \
57
    (((unsigned int) PAGE_SIZE << (cache)->order) >> 2)
57
    (((unsigned int) PAGE_SIZE << (cache)->order) >> 2)
58
 
58
 
59
/* slab_reclaim constants */
59
/* slab_reclaim constants */
60
 
60
 
61
/** Reclaim all possible memory, because we are in memory stress */
61
/** Reclaim all possible memory, because we are in memory stress */
62
#define SLAB_RECLAIM_ALL  0x1 
62
#define SLAB_RECLAIM_ALL  0x01
63
 
63
 
64
/* cache_create flags */
64
/* cache_create flags */
65
 
65
 
66
/** Do not use per-cpu cache */
66
/** Do not use per-cpu cache */
67
#define SLAB_CACHE_NOMAGAZINE 0x1
67
#define SLAB_CACHE_NOMAGAZINE   0x01
68
/** Have control structure inside SLAB */
68
/** Have control structure inside SLAB */
69
#define SLAB_CACHE_SLINSIDE   0x2
69
#define SLAB_CACHE_SLINSIDE     0x02
70
/** We add magazine cache later, if we have this flag */
70
/** We add magazine cache later, if we have this flag */
71
#define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE)
71
#define SLAB_CACHE_MAGDEFERRED  (0x04 | SLAB_CACHE_NOMAGAZINE)
72
 
72
 
73
typedef struct {
73
typedef struct {
74
    link_t link;
74
    link_t link;
75
    count_t busy;   /**< Count of full slots in magazine */
75
    count_t busy;  /**< Count of full slots in magazine */
76
    count_t size;   /**< Number of slots in magazine */
76
    count_t size;  /**< Number of slots in magazine */
77
    void *objs[];   /**< Slots in magazine */
77
    void *objs[];  /**< Slots in magazine */
78
} slab_magazine_t;
78
} slab_magazine_t;
79
 
79
 
80
typedef struct {
80
typedef struct {
81
    slab_magazine_t *current;
81
    slab_magazine_t *current;
82
    slab_magazine_t *last;
82
    slab_magazine_t *last;
Line 84... Line 84...
84
} slab_mag_cache_t;
84
} slab_mag_cache_t;
85
 
85
 
86
 
86
 
87
typedef struct {
87
typedef struct {
88
    char *name;
88
    char *name;
89
 
89
   
90
    link_t link;
90
    link_t link;
91
 
91
   
92
    /* Configuration */
92
    /* Configuration */
93
    /** Size of slab position - align_up(sizeof(obj)) */
93
    /** Size of slab position - align_up(sizeof(obj)) */
94
    size_t size;
94
    size_t size;
95
 
95
   
96
    int (*constructor)(void *obj, int kmflag);
96
    int (*constructor)(void *obj, int kmflag);
97
    int (*destructor)(void *obj);
97
    int (*destructor)(void *obj);
98
 
98
   
99
    /** Flags changing behaviour of cache */
99
    /** Flags changing behaviour of cache */
100
    int flags;
100
    int flags;
101
 
101
   
102
    /* Computed values */
102
    /* Computed values */
103
    uint8_t order;          /**< Order of frames to be allocated */
103
    uint8_t order;         /**< Order of frames to be allocated */
104
    unsigned int objects;       /**< Number of objects that fit in */
104
    unsigned int objects;  /**< Number of objects that fit in */
105
 
105
   
106
    /* Statistics */
106
    /* Statistics */
107
    atomic_t allocated_slabs;
107
    atomic_t allocated_slabs;
108
    atomic_t allocated_objs;
108
    atomic_t allocated_objs;
109
    atomic_t cached_objs;
109
    atomic_t cached_objs;
110
    /** How many magazines in magazines list */
110
    /** How many magazines in magazines list */
111
    atomic_t magazine_counter;
111
    atomic_t magazine_counter;
112
 
112
   
113
    /* Slabs */
113
    /* Slabs */
114
    link_t full_slabs;  /**< List of full slabs */
114
    link_t full_slabs;     /**< List of full slabs */
115
    link_t partial_slabs;   /**< List of partial slabs */
115
    link_t partial_slabs;  /**< List of partial slabs */
116
    SPINLOCK_DECLARE(slablock);
116
    SPINLOCK_DECLARE(slablock);
117
    /* Magazines  */
117
    /* Magazines */
118
    link_t magazines;   /**< List o full magazines */
118
    link_t magazines;  /**< List o full magazines */
119
    SPINLOCK_DECLARE(maglock);
119
    SPINLOCK_DECLARE(maglock);
120
 
120
   
121
    /** CPU cache */
121
    /** CPU cache */
122
    slab_mag_cache_t *mag_cache;
122
    slab_mag_cache_t *mag_cache;
123
} slab_cache_t;
123
} slab_cache_t;
124
 
124
 
125
extern slab_cache_t *slab_cache_create(char *, size_t, size_t,
125
extern slab_cache_t *slab_cache_create(char *, size_t, size_t,
Line 139... Line 139...
139
 
139
 
140
/* malloc support */
140
/* malloc support */
141
extern void *malloc(unsigned int, int);
141
extern void *malloc(unsigned int, int);
142
extern void *realloc(void *, unsigned int, int);
142
extern void *realloc(void *, unsigned int, int);
143
extern void free(void *);
143
extern void free(void *);
-
 
144
 
144
#endif
145
#endif
145
 
146
 
146
/** @}
147
/** @}
147
 */
148
 */