免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1580 | 回复: 1
打印 上一主题 下一主题

[网络子系统] rt_check_expire调用rt_may_expire产生的问题【已解决】 [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-11-20 22:59 |只看该作者 |倒序浏览
本帖最后由 jiufei19 于 2016-11-21 10:49 编辑

内核版本V2.6.23-V2.6.38代码都相同或类似

   575 static void rt_check_expire(unsigned long dummy)
  {
    ...      ...
   588     for (; goal > 0; goal--) {   
   ...       ...
   596         spin_lock(rt_hash_lock_addr(i));
   597         while ((rth = *rthp) != NULL) {
  598             if (rth->u.dst.expires) {
   599                 /* Entry is expired even if it is in use */
   600                 if (time_before_eq(now, rth->u.dst.expires)) {
   601                     tmo >>= 1;
   602                     rthp = &rth->u.dst.rt_next;
   603                     continue;
   604                 }
   605             } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) {
   606                 tmo >>= 1;
   607                 rthp = &rth->u.dst.rt_next;
   608                 continue;
   609             }
   ...       ...
   ----------------------------------------------------
   520 static int rt_may_expire(struct rtable *rth, unsigned long tmo1, unsigned long tmo2)
   521 {
   522     unsigned long age;
   523     int ret = 0;
   524
   525     if (atomic_read(&rth->u.dst.__refcnt))
   526         goto out;
   527
   528     ret = 1;
   529     if (rth->u.dst.expires &&
   530         time_after_eq(jiffies, rth->u.dst.expires))
   531         goto out;

   ...       ...


我的问题是: 既然在rt_check_expire函数第596行蓝色代码处,已经对此哈希bucket进行了加锁,并且假定第598行if条件不成立,于是rth->u.dst.expires一定为0,那么为啥在紧接调用rt_may_expire函数的第529行还需对rth->u.dst.expires又进行了非0判断呢?难道在这个调用过程中rth->u.dst.expires还有机会从0变为非0?

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
2 [报告]
发表于 2016-11-21 10:48 |只看该作者
用cscope查了下,原来rt_may_expire函数有两个地方会调用,即在rt_garbage_collect函数中也会调用它来检查,因此这里必须有此判断
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP