Rev 1941 | Rev 1951 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1941 | Rev 1950 | ||
---|---|---|---|
Line 66... | Line 66... | ||
66 | typedef struct { |
66 | typedef struct { |
67 | link_t link; |
67 | link_t link; |
68 | count_t busy; /**< Count of full slots in magazine */ |
68 | count_t busy; /**< Count of full slots in magazine */ |
69 | count_t size; /**< Number of slots in magazine */ |
69 | count_t size; /**< Number of slots in magazine */ |
70 | void *objs[0]; /**< Slots in magazine */ |
70 | void *objs[0]; /**< Slots in magazine */ |
71 | }slab_magazine_t; |
71 | } slab_magazine_t; |
72 | 72 | ||
73 | typedef struct { |
73 | typedef struct { |
74 | slab_magazine_t *current; |
74 | slab_magazine_t *current; |
75 | slab_magazine_t *last; |
75 | slab_magazine_t *last; |
76 | SPINLOCK_DECLARE(lock); |
76 | SPINLOCK_DECLARE(lock); |
77 | }slab_mag_cache_t; |
77 | } slab_mag_cache_t; |
78 | 78 | ||
79 | 79 | ||
80 | typedef struct { |
80 | typedef struct { |
81 | char *name; |
81 | char *name; |
82 | 82 | ||
83 | link_t link; |
83 | link_t link; |
84 | /* Configuration */ |
84 | /* Configuration */ |
85 | size_t size; /**< Size of slab position - align_up(sizeof(obj)) */ |
85 | size_t size; /**< Size of slab position - align_up(sizeof(obj)) */ |
86 | int (*constructor)(void *obj, int kmflag); |
86 | int (*constructor)(void *obj, int kmflag); |
87 | int (*destructor)(void *obj); |
87 | int (*destructor)(void *obj); |
88 | int flags; /**< Flags changing behaviour of cache */ |
88 | int flags; /**< Flags changing behaviour of cache */ |
89 | 89 | ||
90 | /* Computed values */ |
90 | /* Computed values */ |
91 | uint8_t order; /**< Order of frames to be allocated */ |
91 | uint8_t order; /**< Order of frames to be allocated */ |
92 | int objects; /**< Number of objects that fit in */ |
92 | int objects; /**< Number of objects that fit in */ |
93 | 93 | ||
94 | /* Statistics */ |
94 | /* Statistics */ |
95 | atomic_t allocated_slabs; |
95 | atomic_t allocated_slabs; |
96 | atomic_t allocated_objs; |
96 | atomic_t allocated_objs; |
97 | atomic_t cached_objs; |
97 | atomic_t cached_objs; |
98 | atomic_t magazine_counter; /**< How many magazines in magazines list */ |
98 | atomic_t magazine_counter; /**< How many magazines in magazines list */ |
99 | 99 | ||
100 | /* Slabs */ |
100 | /* Slabs */ |
101 | link_t full_slabs; /**< List of full slabs */ |
101 | link_t full_slabs; /**< List of full slabs */ |
102 | link_t partial_slabs; /**< List of partial slabs */ |
102 | link_t partial_slabs; /**< List of partial slabs */ |
103 | SPINLOCK_DECLARE(slablock); |
103 | SPINLOCK_DECLARE(slablock); |
104 | /* Magazines */ |
104 | /* Magazines */ |
105 | link_t magazines; /**< List o full magazines */ |
105 | link_t magazines /**< List o full magazines */ |
106 | SPINLOCK_DECLARE(maglock); |
106 | SPINLOCK_DECLARE(maglock); |
107 | 107 | ||
108 | /** CPU cache */ |
108 | /** CPU cache */ |
109 | slab_mag_cache_t *mag_cache; |
109 | slab_mag_cache_t *mag_cache; |
110 | }slab_cache_t; |
110 | } slab_cache_t; |
111 | 111 | ||
112 | extern slab_cache_t * slab_cache_create(char *name, |
112 | extern slab_cache_t * slab_cache_create(char *name, |
113 | size_t size, |
113 | size_t size, |
114 | size_t align, |
114 | size_t align, |
115 | int (*constructor)(void *obj, int kmflag), |
115 | int (*constructor)(void *obj, int kmflag), |