免费注册 查看新帖 |

Chinaunix

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

关于current->bio_list的加锁疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 10:34 |只看该作者 |倒序浏览
3.0内核中generic_make_request()函数定义如下
  1. void generic_make_request(struct bio *bio)                                       
  2. {                                                                                
  3.         struct bio_list bio_list_on_stack;                                       
  4.                                                                                  
  5.         if (current->bio_list) {                                                
  6.                 /* make_request is active */                                    
  7.                 bio_list_add(current->bio_list, bio);                           
  8.                 return;                                                         
  9.         }                                                                        
  10.         /* following loop may be a bit non-obvious, and so deserves some         
  11.          * explanation.                                                         
  12.          * Before entering the loop, bio->bi_next is NULL (as all callers        
  13.          * ensure that) so we have a list with a single bio.                     
  14.          * We pretend that we have just taken it off a longer list, so           
  15.          * we assign bio_list to a pointer to the bio_list_on_stack,            
  16.          * thus initialising the bio_list of new bios to be                     
  17.          * added.  __generic_make_request may indeed add some more bios         
  18.          * through a recursive call to generic_make_request.  If it              
  19.          * did, we find a non-NULL value in bio_list and re-enter the loop           
  20.          * from the top.  In this case we really did just take the bio           
  21.          * of the top of the list (no pretending) and so remove it from         
  22.          * bio_list, and call into __generic_make_request again.                 
  23.          *                                                                       
  24.          * The loop was structured like this to make only one call to            
  25.          * __generic_make_request (which is important as it is large and         
  26.          * inlined) and to keep the structure simple.                           
  27.          */                                                                     
  28.         BUG_ON(bio->bi_next);                                                   
  29.         bio_list_init(&bio_list_on_stack);                                       
  30.         current->bio_list = &bio_list_on_stack;                                 
  31.         do {                                                                     
  32.                 __generic_make_request(bio);                                    
  33.                 bio = bio_list_pop(current->bio_list);                           
  34.         } while (bio);                                                           
  35.         current->bio_list = NULL; /* deactivate */                              
  36. }
复制代码
对bio_list为什么不需要锁的控制呢,有点不太明白

论坛徽章:
0
2 [报告]
发表于 2011-12-21 11:44 |只看该作者
明白了,bio_list是每个进程的结构,内核的几个竞争条件都不会触发
a) 中断: 该成员没有在中断中被访问
b) 抢占:因为是per task成员,不会产生竞争
c) SMP: 同b
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP