Linux Slab分配器(五)--释放对象
| [日期:2012-06-18] |
来源:Linux社区
作者:t0nsha |
[字体:大 中 小]
|
- static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac)
- {
- int batchcount;
- struct kmem_list3 *l3;
- int node = numa_node_id();
-
- batchcount = ac->batchcount;
- #if DEBUG
- BUG_ON(!batchcount || batchcount > ac->avail);
- #endif
- check_irq_off();
- l3 = cachep->nodelists[node];
- spin_lock(&l3->list_lock);
- if (l3->shared) {
-
- struct array_cache *shared_array = l3->shared;
-
- int max = shared_array->limit - shared_array->avail;
- if (max) {
- if (batchcount > max)
- batchcount = max;
-
- memcpy(&(shared_array->entry[shared_array->avail]),
- ac->entry, sizeof(void *) * batchcount);
- shared_array->avail += batchcount;
- goto free_done;
- }
- }
-
-
- free_block(cachep, ac->entry, batchcount, node);
- free_done:
- #if STATS
- {
- int i = 0;
- struct list_head *p;
-
- p = l3->slabs_free.next;
- while (p != &(l3->slabs_free)) {
- struct slab *slabp;
-
- slabp = list_entry(p, struct slab, list);
- BUG_ON(slabp->inuse);
-
- i++;
- p = p->next;
- }
- STATS_SET_FREEABLE(cachep, i);
- }
- #endif
- spin_unlock(&l3->list_lock);
- ac->avail -= batchcount;
-
- memmove(ac->entry, &(ac->entry[batchcount]), sizeof(void *)*ac->avail);
- }
-
-
-
-
-
- static inline void __cache_free(struct kmem_cache *cachep, void *objp)
- {
- struct array_cache *ac = cpu_cache_get(cachep);
-
- check_irq_off();
- kmemleak_free_recursive(objp, cachep->flags);
- objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
-
- kmemcheck_slab_free(cachep, objp, obj_size(cachep));
-
-
-
-
-
-
-
-
- if (nr_online_nodes > 1 && cache_free_alien(cachep, objp))
- return;
-
-
- if (likely(ac->avail < ac->limit)) {
- STATS_INC_FREEHIT(cachep);
- ac->entry[ac->avail++] = objp;
- return;
- } else {
- STATS_INC_FREEMISS(cachep);
- cache_flusharray(cachep, ac);
- ac->entry[ac->avail++] = objp;
- }
- }

评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
|
|