Rev 759 | Rev 764 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 759 | Rev 762 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /* |
1 | /* |
| 2 | * Copyright (C) 2005 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
| 3 | * All rights reserved. |
3 | * All rights reserved. |
| 4 | * |
4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
7 | * are met: |
| Line 36... | Line 36... | ||
| 36 | #define SLAB_MAG_SIZE 4 |
36 | #define SLAB_MAG_SIZE 4 |
| 37 | 37 | ||
| 38 | /** If object size is less, store control structure inside SLAB */ |
38 | /** If object size is less, store control structure inside SLAB */ |
| 39 | #define SLAB_INSIDE_SIZE (PAGE_SIZE / 6) |
39 | #define SLAB_INSIDE_SIZE (PAGE_SIZE / 6) |
| 40 | 40 | ||
| 41 | /* slab_alloc constants */ |
41 | /** Maximum wasted space we allow for cache */ |
| 42 | #define SLAB_ATOMIC 0x1 /**< Do not sleep when no free memory, |
42 | #define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order) / 4) |
| 43 | may return NULL */ |
- | |
| 44 | #define SLAB_NO_RECLAIM 0x2 /**< Do not try to call slab_reclaim, if no |
- | |
| 45 | free memory is found - avoid deadlock */ |
- | |
| 46 | 43 | ||
| 47 | /* slab_reclaim constants */ |
44 | /* slab_reclaim constants */ |
| 48 | #define SLAB_RECLAIM_ALL 0x1 /**< Reclaim all possible memory, because |
45 | #define SLAB_RECLAIM_ALL 0x1 /**< Reclaim all possible memory, because |
| 49 | * we are in memory stress */ |
46 | * we are in memory stress */ |
| 50 | 47 | ||
| Line 52... | Line 49... | ||
| 52 | #define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */ |
49 | #define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */ |
| 53 | #define SLAB_CACHE_SLINSIDE 0x2 /**< Have control structure inside SLAB */ |
50 | #define SLAB_CACHE_SLINSIDE 0x2 /**< Have control structure inside SLAB */ |
| 54 | 51 | ||
| 55 | typedef struct { |
52 | typedef struct { |
| 56 | link_t link; |
53 | link_t link; |
| 57 | count_t busy; |
54 | count_t busy; /**< Count of full slots in magazine */ |
| 58 | count_t size; |
55 | count_t size; /**< Number of slots in magazine */ |
| 59 | void *objs[0]; |
56 | void *objs[0]; /**< Slots in magazine */ |
| 60 | }slab_magazine_t; |
57 | }slab_magazine_t; |
| 61 | 58 | ||
| 62 | typedef struct { |
59 | typedef struct { |
| 63 | char *name; |
60 | char *name; |
| 64 | 61 | ||
| 65 | SPINLOCK_DECLARE(lock); |
62 | SPINLOCK_DECLARE(lock); |
| 66 | link_t link; |
63 | link_t link; |
| 67 | /* Configuration */ |
64 | /* Configuration */ |
| 68 | size_t size; |
- | |
| 69 | size_t align; |
65 | size_t size; /**< Size of SLAB position - align_up(sizeof(obj)) */ |
| 70 | int (*constructor)(void *obj, int kmflag); |
66 | int (*constructor)(void *obj, int kmflag); |
| 71 | void (*destructor)(void *obj); |
67 | void (*destructor)(void *obj); |
| 72 | int flags; |
68 | int flags; /**< Flags changing behaviour of cache */ |
| 73 | 69 | ||
| 74 | /* Computed values */ |
70 | /* Computed values */ |
| 75 | int pages; |
71 | __u8 order; /**< Order of frames to be allocated */ |
| 76 | int objects; |
72 | int objects; /**< Number of objects that fit in */ |
| 77 | 73 | ||
| 78 | /* Statistics */ |
74 | /* Statistics */ |
| 79 | 75 | ||
| 80 | /* Slabs */ |
76 | /* Slabs */ |
| 81 | link_t full_slabs; |
77 | link_t full_slabs; /**< List of full slabs */ |
| 82 | link_t partial_slabs; |
78 | link_t partial_slabs; /**< List of partial slabs */ |
| 83 | /* Magazines */ |
79 | /* Magazines */ |
| 84 | link_t magazines; |
80 | link_t magazines; /**< List o full magazines */ |
| - | 81 | ||
| 85 | /* CPU cache */ |
82 | /** CPU cache */ |
| 86 | struct { |
83 | struct { |
| 87 | slab_magazine_t *current; |
84 | slab_magazine_t *current; |
| 88 | slab_magazine_t *last; |
85 | slab_magazine_t *last; |
| 89 | SPINLOCK_DECLARE(lock); |
86 | SPINLOCK_DECLARE(lock); |
| 90 | }mag_cache[0]; |
87 | }mag_cache[0]; |
| 91 | }slab_cache_t; |
88 | }slab_cache_t; |
| 92 | 89 | ||
| 93 | typedef struct { |
- | |
| 94 | slab_cache_t *cache; /**< Pointer to parent cache */ |
- | |
| 95 | void *start; /**< Start address of first available item */ |
- | |
| 96 | count_t available; /**< Count of available items in this slab */ |
- | |
| 97 | index_t nextavail; /**< The index of next available item */ |
- | |
| 98 | }slab_slab_t; |
- | |
| 99 | - | ||
| 100 | - | ||
| 101 | slab_cache_t * slab_cache_create(char *name, |
90 | extern slab_cache_t * slab_cache_create(char *name, |
| 102 | size_t size, |
91 | size_t size, |
| 103 | size_t align, |
92 | size_t align, |
| 104 | int (*constructor)(void *obj, int kmflag), |
93 | int (*constructor)(void *obj, int kmflag), |
| 105 | void (*destructor)(void *obj), |
94 | void (*destructor)(void *obj), |
| 106 | int flags); |
95 | int flags); |
| 107 | void slab_cache_destroy(slab_cache_t *cache); |
96 | extern void slab_cache_destroy(slab_cache_t *cache); |
| 108 | 97 | ||
| 109 | void * slab_alloc(slab_cache_t *cache, int flags); |
98 | extern void * slab_alloc(slab_cache_t *cache, int flags); |
| 110 | void slab_free(slab_cache_t *cache, void *obj); |
99 | extern void slab_free(slab_cache_t *cache, void *obj); |
| 111 | count_t slab_reclaim(int flags); |
100 | extern count_t slab_reclaim(int flags); |
| 112 | 101 | ||
| 113 | /** Initialize SLAB subsytem */ |
102 | /** Initialize SLAB subsytem */ |
| 114 | void slab_cache_init(void); |
103 | extern void slab_cache_init(void); |
| 115 | 104 | ||
| 116 | /* KConsole debug */ |
105 | /* KConsole debug */ |
| 117 | void slab_print_list(void); |
106 | extern void slab_print_list(void); |
| 118 | 107 | ||
| 119 | #endif |
108 | #endif |