void slabs_free(slabs_t* pst, void *ptr, size_t size) { void *header; size += sizeof(slabheader_t); unsigned int id = slabs_clsid(pst, size); header = (void*)((char*)ptr - sizeof(slabheader_t)); do_slabs_free(pst, header, size, id); }
static void split_slab_page_into_freelist(char *ptr, const unsigned int id) { slabclass_t *p = &slabclass[id]; int x; for (x = 0; x < p->perslab; x++) { do_slabs_free(ptr, 0, id); ptr += p->size; } }
void Slab::split_slab_page_into_freelist(char* ptr, unsigned int id) { slabclass& p = mem_base[id]; int i; for (i = 0; i < p.perslab; i++) { do_slabs_free(ptr, 0, id); ptr += p.size; } }
static void do_smmgr_blck_free(struct default_engine *engine, sm_blck_t *blck) { do_smmgr_used_blck_unlink(blck); do_slabs_free(engine, blck, sm_anchor.blck_tsize, sm_anchor.blck_clsid); if (sm_anchor.free_limit_space > 0) { sm_anchor.free_chunk_space += sm_anchor.blck_tsize; } }
void slabs_free(struct default_engine *engine, void *ptr, size_t size, unsigned int id) { if (id < POWER_SMALLEST || id > engine->slabs.power_largest) return; pthread_mutex_lock(&engine->slabs.lock); do_slabs_free(engine, ptr, size, id); pthread_mutex_unlock(&engine->slabs.lock); }
/** * 将ptr所指向的slab初始化成item链表,链接到slabclass[id]的slot指针上。 * */ static void split_slab_page_into_freelist(char *ptr, const unsigned int id) { slabclass_t *p = &slabclass[id]; int x; //每个slabclass有多个slab,对每个slab按slabclass对应的size进行切分 for (x = 0; x < p->perslab; x++) { do_slabs_free(ptr, 0, id); //创建空闲item ptr += p->size; } }
//将ptr指向的内存页划分成一个个的item static void split_slab_page_into_freelist(char *ptr, const unsigned int id) { slabclass_t *p = &slabclass[id]; int x; for (x = 0; x < p->perslab; x++) { //将ptr指向的内存划分成一个个的item.一共划成perslab个 //并将这些item前后连起来。 //do_slabs_free函数本来是worker线程向内存池归还内存时调用的。但在这里 //新申请的内存也可以当作是向内存池归还内存。把内存注入内存池中 do_slabs_free(ptr, 0, id); ptr += p->size;//size是item的大小 } }
static void split_slab_page_into_freelist(char *ptr, const unsigned int id) { slabclass_t *p = &slabclass[id]; int x; // 初始化slab中的item的信息 // 把item全放在slots中。所以以后给用户分配内存的时候 // 直接从slots中找,不需要再遍历slab来找了。 // 估计这是优化后的结构,以前在slabclass中应该有存储当前 // 已用的slab的信息,而slots中存储free掉的item,这样当 // sltos中的item用完后,再从slab中取。 // 这把改为都从slots中取以后明显方便和快捷多了。 好改进!! for (x = 0; x < p->perslab; x++) { do_slabs_free(ptr, 0, id); ptr += p->size; } }
void slabs_free(void *ptr, size_t size, unsigned int id) { pthread_mutex_lock(&slabs_lock); do_slabs_free(ptr, size, id); pthread_mutex_unlock(&slabs_lock); }
void slabs_free(struct default_engine *engine, void *ptr, size_t size, unsigned int id) { cb_mutex_enter(&engine->slabs.lock); do_slabs_free(engine, ptr, size, id); cb_mutex_exit(&engine->slabs.lock); }
void Slab::slabs_free(void* ptr, size_t size, unsigned int id) { slabs_lock.lock(); do_slabs_free(ptr, size, id); slabs_lock.unlock(); }
void slabs_free(struct default_engine *engine, void *ptr, size_t size, unsigned int id) { pthread_mutex_lock(&engine->slabs.lock); do_slabs_free(engine, ptr, size, id); pthread_mutex_unlock(&engine->slabs.lock); }