Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44674
  • 博文数量: 14
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 35
  • 用 户 组: 普通用户
  • 注册时间: 2018-11-19 18:25
文章分类

全部博文(14)

文章存档

2018年(14)

我的朋友

分类: LINUX

2018-11-19 19:45:49

上一篇回收slab对象时,先考虑放入local cache,当local cache已超过上限时,尝试放入shared cache。
否则从local cache中批量释放batch_count对象放入slab三链。
当slab三链的空闲对象超过上限,并且待释放的slab对象对应的slab中已经没有正在使用的对象时,将slab直接释放掉

释放slab对应的函数是slab_destroy,下面分析一下。

点击(此处)折叠或打开

  1. /**
  2.  * slab_destroy - destroy and release all objects in a slab
  3.  * @cachep: cache pointer being destroyed
  4.  * @slabp: slab pointer being destroyed
  5.  *
  6.  * Destroy all the objs in a slab, and release the mem back to the system.
  7.  * Before calling the slab must have been unlinked from the cache. The
  8.  * cache-lock is not held/needed.
  9.  */
  10. static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp)
  11. {
  12.     /* slabp->s_mem记录的是slab对象的起始地址,由于着色偏移,所以需要减去colouroff指向slab首页面的地址 */
  13.     void *addr = slabp->s_mem - slabp->colouroff;

  14.     slab_destroy_debugcheck(cachep, slabp);
  15.     /* 判断一下使用那种销毁方式,rcu是多核中的一种同步机制 */
  16.     if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) {
  17.         struct slab_rcu *slab_rcu;

  18.         slab_rcu = (struct slab_rcu *)slabp;
  19.         slab_rcu->cachep = cachep;
  20.         slab_rcu->addr = addr;
  21.         call_rcu(&slab_rcu->head, kmem_rcu_free);
  22.     } else {
  23.         /* 释放slab占用的页面,如果slab管理对象内置的话,随着页面一起释放了 */
  24.         kmem_freepages(cachep, addr);
  25.         /* 如果slab管理对象是外置的花,需要单独释放一下 */
  26.         if (OFF_SLAB(cachep))
  27.             kmem_cache_free(cachep->slabp_cache, slabp);
  28.     }
  29. }
函数比较简单,kmem_freepages在后续分析伙伴关系系统时,再来分析。

阅读(1828) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~