Rev 2071 | Rev 2124 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2106 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | 54 | ||
55 | /** Maximum wasted space we allow for cache */ |
55 | /** Maximum wasted space we allow for cache */ |
56 | #define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order) >> 2) |
56 | #define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order) >> 2) |
57 | 57 | ||
58 | /* slab_reclaim constants */ |
58 | /* slab_reclaim constants */ |
- | 59 | ||
59 | #define SLAB_RECLAIM_ALL 0x1 /**< Reclaim all possible memory, because we are in memory stress */ |
60 | /** Reclaim all possible memory, because we are in memory stress */ |
- | 61 | #define SLAB_RECLAIM_ALL 0x1 |
|
60 | 62 | ||
61 | /* cache_create flags */ |
63 | /* cache_create flags */ |
- | 64 | ||
- | 65 | /** Do not use per-cpu cache */ |
|
62 | #define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */ |
66 | #define SLAB_CACHE_NOMAGAZINE 0x1 |
63 | #define SLAB_CACHE_SLINSIDE 0x2 /**< Have control structure inside SLAB */ |
67 | /** Have control structure inside SLAB */ |
- | 68 | #define SLAB_CACHE_SLINSIDE 0x2 |
|
- | 69 | /** We add magazine cache later, if we have this flag */ |
|
64 | #define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE) /**< We add magazine cache later, if we have this flag */ |
70 | #define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE) |
65 | 71 | ||
66 | typedef struct { |
72 | typedef struct { |
67 | link_t link; |
73 | link_t link; |
68 | count_t busy; /**< Count of full slots in magazine */ |
74 | count_t busy; /**< Count of full slots in magazine */ |
69 | count_t size; /**< Number of slots in magazine */ |
75 | count_t size; /**< Number of slots in magazine */ |
Line 79... | Line 85... | ||
79 | 85 | ||
80 | typedef struct { |
86 | typedef struct { |
81 | char *name; |
87 | char *name; |
82 | 88 | ||
83 | link_t link; |
89 | link_t link; |
- | 90 | ||
84 | /* Configuration */ |
91 | /* Configuration */ |
85 | size_t size; /**< Size of slab position - align_up(sizeof(obj)) */ |
92 | /** Size of slab position - align_up(sizeof(obj)) */ |
- | 93 | size_t size; |
|
- | 94 | ||
86 | int (*constructor)(void *obj, int kmflag); |
95 | int (*constructor)(void *obj, int kmflag); |
87 | int (*destructor)(void *obj); |
96 | int (*destructor)(void *obj); |
- | 97 | ||
88 | int flags; /**< Flags changing behaviour of cache */ |
98 | /** Flags changing behaviour of cache */ |
- | 99 | int flags; |
|
89 | 100 | ||
90 | /* Computed values */ |
101 | /* Computed values */ |
91 | uint8_t order; /**< Order of frames to be allocated */ |
102 | uint8_t order; /**< Order of frames to be allocated */ |
92 | int objects; /**< Number of objects that fit in */ |
103 | int objects; /**< Number of objects that fit in */ |
93 | 104 | ||
94 | /* Statistics */ |
105 | /* Statistics */ |
95 | atomic_t allocated_slabs; |
106 | atomic_t allocated_slabs; |
96 | atomic_t allocated_objs; |
107 | atomic_t allocated_objs; |
97 | atomic_t cached_objs; |
108 | atomic_t cached_objs; |
98 | atomic_t magazine_counter; /**< How many magazines in magazines list */ |
109 | /** How many magazines in magazines list */ |
- | 110 | atomic_t magazine_counter; |
|
99 | 111 | ||
100 | /* Slabs */ |
112 | /* Slabs */ |
101 | link_t full_slabs; /**< List of full slabs */ |
113 | link_t full_slabs; /**< List of full slabs */ |
102 | link_t partial_slabs; /**< List of partial slabs */ |
114 | link_t partial_slabs; /**< List of partial slabs */ |
103 | SPINLOCK_DECLARE(slablock); |
115 | SPINLOCK_DECLARE(slablock); |
Line 107... | Line 119... | ||
107 | 119 | ||
108 | /** CPU cache */ |
120 | /** CPU cache */ |
109 | slab_mag_cache_t *mag_cache; |
121 | slab_mag_cache_t *mag_cache; |
110 | } slab_cache_t; |
122 | } slab_cache_t; |
111 | 123 | ||
112 | extern slab_cache_t * slab_cache_create(char *name, |
124 | extern slab_cache_t * slab_cache_create(char *name, size_t size, size_t align, |
113 | size_t size, |
- | |
114 | size_t align, |
- | |
115 | int (*constructor)(void *obj, int kmflag), |
125 | int (*constructor)(void *obj, int kmflag), int (*destructor)(void *obj), |
116 | int (*destructor)(void *obj), |
- | |
117 | int flags); |
126 | int flags); |
118 | extern void slab_cache_destroy(slab_cache_t *cache); |
127 | extern void slab_cache_destroy(slab_cache_t *cache); |
119 | 128 | ||
120 | extern void * slab_alloc(slab_cache_t *cache, int flags); |
129 | extern void * slab_alloc(slab_cache_t *cache, int flags); |
121 | extern void slab_free(slab_cache_t *cache, void *obj); |
130 | extern void slab_free(slab_cache_t *cache, void *obj); |
122 | extern count_t slab_reclaim(int flags); |
131 | extern count_t slab_reclaim(int flags); |
123 | 132 | ||
124 | /** Initialize slab subsytem */ |
133 | /* slab subsytem initialization */ |
125 | extern void slab_cache_init(void); |
134 | extern void slab_cache_init(void); |
126 | extern void slab_enable_cpucache(void); |
135 | extern void slab_enable_cpucache(void); |
127 | 136 | ||
128 | /* kconsole debug */ |
137 | /* kconsole debug */ |
129 | extern void slab_print_list(void); |
138 | extern void slab_print_list(void); |