Changeset 2031 for Whitix/trunk
- Timestamp:
- 04/02/09 21:32:43 (3 years ago)
- Files:
-
- 1 modified
-
Whitix/trunk/memory/slab.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/memory/slab.c
r1794 r2031 17 17 */ 18 18 19 #define DEBUG_ASSERTS 20 21 #include <assert.h> 19 22 #include <bitmap.h> 20 23 #include <module.h> … … 24 27 #include <slab.h> 25 28 #include <keobject.h> 29 #include <locks.h> 26 30 27 31 /* … … 52 56 }; 53 57 54 KE_OBJECT_TYPE(cacheType, NULL , cacheAttributes, OffsetOf(struct Cache, object));58 KE_OBJECT_TYPE(cacheType, NULL); 55 59 56 60 static int slabInfoSetup = 0; 57 61 58 62 /* General slab limits */ 59 #define SLAB_START 0xC 000000063 #define SLAB_START 0xC2000000 60 64 #define SLAB_END 0xD0000000 61 65 … … 78 82 DWORD size; 79 83 struct Cache* cache; 84 char* name; 80 85 }; 81 86 … … 83 88 84 89 static struct CacheSize cacheSizes[]={ 85 {16,NULL}, 86 {32,NULL}, 87 {64,NULL}, 88 {128,NULL}, 89 {256,NULL}, 90 {512,NULL}, 91 {1024,NULL}, 92 {2048,NULL}, 93 {4096,NULL}, 94 {8192,NULL}, 95 {16384,NULL}, 96 {32768,NULL}, 97 {65536,NULL}, 98 {131072,NULL}, /* 128k */ 99 }; 100 101 const char* mallocNames[]= 102 { 103 "Malloc16", 104 "Malloc32", 105 "Malloc64", 106 "Malloc128", 107 "Malloc256", 108 "Malloc512", 109 "Malloc1024", 110 "Malloc2048", 111 "Malloc4096", 112 "Malloc8192", 113 "Malloc16384", 114 "Malloc32768", 115 "Malloc65536", 116 "Malloc131072", 90 {16,NULL, "Malloc16"}, 91 {32,NULL, "Malloc32"}, 92 {64,NULL, "Malloc64"}, 93 {128,NULL, "Malloc128"}, 94 {256,NULL, "Malloc256"}, 95 {512,NULL, "Malloc512"}, 96 {1024,NULL, "Malloc1024"}, 97 {2048,NULL, "Malloc2048"}, 98 {4096,NULL, "Malloc4096"}, 99 {8192,NULL, "Malloc8192"}, 100 {16384,NULL, "Malloc16384"}, 101 {32768,NULL, "Malloc32768"}, 102 {65536,NULL, "Malloc65536"}, 103 {131072,NULL, "Malloc131072"}, /* 128k */ 117 104 }; 118 105 … … 169 156 170 157 /* And zero out the memory concerned */ 171 BmapSetBit(slab->bitmap, i, false); 158 BitClear(slab->bitmap, i); 159 172 160 slab->isFull=0; /* At least 1 piece is free now */ 173 161 … … 234 222 return NULL; 235 223 224 /* Allocate from a slab cache (which does keep its info on slab). */ 236 225 if (cache->options & SLAB_OFFSLAB) 237 226 { 238 /* Allocate from a slab cache, which does keep it's info on slab */239 227 slab=(struct Slab*)MemCacheAlloc(slabCache); 240 228 }else … … 242 230 243 231 /* Slab setup is performed here. ZeroMemory call also zeros the bitmap. */ 244 ZeroMemory(slab, sizeof(struct Slab));232 ZeroMemory(slab, sizeof(struct Slab)); 245 233 slab->page=virtAddr; 246 234 … … 340 328 if (!currSlab->isFull) 341 329 { 342 /* Search the bitmap */ 343 for (i=0; i<cache->numObjs; i++) 330 i = BitFindFirstZero(currSlab->bitmap, cache->numObjs); 331 332 if (i < cache->numObjs) 344 333 { 345 if (!BmapGetBit(currSlab->bitmap,i)) 346 { 347 BmapSetBit(currSlab->bitmap,i,true); 348 if (i == cache->numObjs-1) 349 currSlab->isFull=1; 350 351 if (!cache->ctor) 352 ZeroMemory(currSlab->page+cache->offset+(i*cache->size), cache->size); 353 354 IrqRestoreFlags(flags); 355 return (void*)(currSlab->page+cache->offset+(i*cache->size)); 356 } 334 BitSet(currSlab->bitmap, i); 335 336 if (i == cache->numObjs-1) 337 currSlab->isFull=1; 338 339 IrqRestoreFlags(flags); 340 return (void*)(currSlab->page+cache->offset+(i*cache->size)); 357 341 } 358 342 } … … 417 401 { 418 402 struct Cache* retVal; 403 DWORD flags; 419 404 420 405 if (!size) … … 437 422 retVal->numPages=1; 438 423 439 retVal->ctor =ctor;440 retVal->dtor =dtor;424 retVal->ctor = ctor; 425 retVal->dtor = dtor; 441 426 retVal->name = name; 442 427 … … 452 437 KeObjectCreate(&retVal->object, &cacheSet, name); 453 438 439 IrqSaveFlags(flags); 454 440 ListAddTail(&retVal->list, &cacheList); 441 IrqRestoreFlags(flags); 455 442 456 443 return retVal; … … 461 448 int SlabInfoInit() 462 449 { 463 KeSetCreate(&cacheSet, NULL, &cacheType, "Memory");464 465 450 /* Register all the caches created so far. */ 466 451 struct Cache* cache; 467 452 453 KeSetCreate(&cacheSet, NULL, &cacheType, "Memory"); 454 455 PreemptDisable(); 456 468 457 ListForEachEntry(cache, &cacheList, list) 469 {470 458 KeObjectCreate(&cache->object, &cacheSet, cache->name); 471 }472 459 473 460 slabInfoSetup = 1; 461 462 PreemptEnable(); 474 463 475 464 return 0; … … 490 479 for (i=0; i<count(cacheSizes); i++) 491 480 { 492 cacheSizes[i].cache=MemCacheCreate( mallocNames[i], cacheSizes[i].size, NULL, NULL, 0);481 cacheSizes[i].cache=MemCacheCreate(cacheSizes[i].name, cacheSizes[i].size, NULL, NULL, 0); 493 482 494 483 if (!cacheSizes[i].cache)
