Subversion Repositories HelenOS-historic

Rev

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

Rev 791 Rev 814
Line 94... Line 94...
94
#include <synch/spinlock.h>
94
#include <synch/spinlock.h>
95
#include <mm/slab.h>
95
#include <mm/slab.h>
96
#include <adt/list.h>
96
#include <adt/list.h>
97
#include <memstr.h>
97
#include <memstr.h>
98
#include <align.h>
98
#include <align.h>
99
#include <mm/heap.h>
-
 
100
#include <mm/frame.h>
99
#include <mm/frame.h>
101
#include <config.h>
100
#include <config.h>
102
#include <print.h>
101
#include <print.h>
103
#include <arch.h>
102
#include <arch.h>
104
#include <panic.h>
103
#include <panic.h>
Line 152... Line 151...
152
{
151
{
153
    void *data;
152
    void *data;
154
    slab_t *slab;
153
    slab_t *slab;
155
    size_t fsize;
154
    size_t fsize;
156
    int i;
155
    int i;
157
    zone_t *zone = NULL;
-
 
158
    int status;
156
    int status;
159
    frame_t *frame;
157
    pfn_t pfn;
-
 
158
    int zone=0;
160
 
159
   
161
    data = (void *)frame_alloc_rc_zone(cache->order, FRAME_KA | flags, &status, &zone);
160
    pfn = frame_alloc_rc_zone(cache->order, FRAME_KA | flags, &status, &zone);
-
 
161
    data = (void *) PA2KA(PFN2ADDR(pfn));
162
    if (status != FRAME_OK) {
162
    if (status != FRAME_OK) {
163
        return NULL;
163
        return NULL;
164
    }
164
    }
165
    if (! (cache->flags & SLAB_CACHE_SLINSIDE)) {
165
    if (! (cache->flags & SLAB_CACHE_SLINSIDE)) {
166
        slab = slab_alloc(slab_extern_cache, flags);
166
        slab = slab_alloc(slab_extern_cache, flags);
167
        if (!slab) {
167
        if (!slab) {
168
            frame_free((__address)data);
168
            frame_free(ADDR2PFN(KA2PA(data)));
169
            return NULL;
169
            return NULL;
170
        }
170
        }
171
    } else {
171
    } else {
172
        fsize = (PAGE_SIZE << cache->order);
172
        fsize = (PAGE_SIZE << cache->order);
173
        slab = data + fsize - sizeof(*slab);
173
        slab = data + fsize - sizeof(*slab);
174
    }
174
    }
175
       
175
       
176
    /* Fill in slab structures */
176
    /* Fill in slab structures */
177
    /* TODO: some better way of accessing the frame */
-
 
178
    for (i=0; i < (1 << cache->order); i++) {
177
    for (i=0; i < (1 << cache->order); i++)
179
        frame = ADDR2FRAME(zone, KA2PA((__address)(data+i*PAGE_SIZE)));
-
 
180
        frame->parent = slab;
178
        frame_set_parent(pfn+i, slab, zone);
181
    }
-
 
182
 
179
 
183
    slab->start = data;
180
    slab->start = data;
184
    slab->available = cache->objects;
181
    slab->available = cache->objects;
185
    slab->nextavail = 0;
182
    slab->nextavail = 0;
186
    slab->cache = cache;
183
    slab->cache = cache;
Line 197... Line 194...
197
 *
194
 *
198
 * @return number of freed frames
195
 * @return number of freed frames
199
 */
196
 */
200
static count_t slab_space_free(slab_cache_t *cache, slab_t *slab)
197
static count_t slab_space_free(slab_cache_t *cache, slab_t *slab)
201
{
198
{
202
    frame_free((__address)slab->start);
199
    frame_free(ADDR2PFN(KA2PA(slab->start)));
203
    if (! (cache->flags & SLAB_CACHE_SLINSIDE))
200
    if (! (cache->flags & SLAB_CACHE_SLINSIDE))
204
        slab_free(slab_extern_cache, slab);
201
        slab_free(slab_extern_cache, slab);
205
 
202
 
206
    atomic_dec(&cache->allocated_slabs);
203
    atomic_dec(&cache->allocated_slabs);
207
   
204
   
Line 209... Line 206...
209
}
206
}
210
 
207
 
211
/** Map object to slab structure */
208
/** Map object to slab structure */
212
static slab_t * obj2slab(void *obj)
209
static slab_t * obj2slab(void *obj)
213
{
210
{
214
    frame_t *frame;
-
 
215
 
-
 
216
    frame = frame_addr2frame((__address)obj);
-
 
217
    return (slab_t *)frame->parent;
211
    return (slab_t *)frame_get_parent(ADDR2PFN(KA2PA(obj)), 0);
218
}
212
}
219
 
213
 
220
/**************************************/
214
/**************************************/
221
/* SLAB functions */
215
/* SLAB functions */
222
 
216
 
Line 723... Line 717...
723
    void *result = NULL;
717
    void *result = NULL;
724
   
718
   
725
    /* Disable interrupts to avoid deadlocks with interrupt handlers */
719
    /* Disable interrupts to avoid deadlocks with interrupt handlers */
726
    ipl = interrupts_disable();
720
    ipl = interrupts_disable();
727
 
721
 
728
    if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
722
    if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) {
729
        result = magazine_obj_get(cache);
723
        result = magazine_obj_get(cache);
-
 
724
    }
730
    if (!result)
725
    if (!result)
731
        result = slab_obj_create(cache, flags);
726
        result = slab_obj_create(cache, flags);
732
 
727
 
733
    interrupts_restore(ipl);
728
    interrupts_restore(ipl);
734
 
729