CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Linux/Unix社区 >  内核及驱动程序研究区

读《情景分析》之swap_out时的不解,非常不解。

楼主mz_1984()2006-11-04 16:31:33 在 Linux/Unix社区 / 内核及驱动程序研究区 提问

面程序片断摘自2.4.0源代码(mm/vmscan.c),末尾的if与else中都有'break',即不论best为何值都要求break(执行goto   select也不行啊)而跳出循环,这样外层FOR还有作用么?mm->swap_cnt和RSS的作用和关系也写得不太清楚,望大虾指教!小弟先行谢过!!  
   
  附:swap_out  
  /*  
    *   Select   the   task   with   maximal   swap_cnt   and   try   to   swap   out   a   page.  
    *   N.B.   This   function   returns   only   0   or   1.     Return   values   !=   1   from  
    *   the   lower   level   routines   result   in   continued   processing.  
    */  
  #define   SWAP_SHIFT   5  
  #define   SWAP_MIN   8  
   
  static   int   swap_out(unsigned   int   priority,   int   gfp_mask)  
  {  
  int   counter;  
  int   __ret   =   0;  
   
  /*    
    *   We   make   one   or   two   passes   through   the   task   list,   indexed   by    
    *   assign   =   {0,   1}:  
    *       Pass   1:   select   the   swappable   task   with   maximal   RSS   that   has  
    *                   not   yet   been   swapped   out.    
    *       Pass   2:   re-assign   rss   swap_cnt   values,   then   select   as   above.  
    *  
    *   With   this   approach,   there's   no   need   to   remember   the   last   task  
    *   swapped   out.     If   the   swap-out   fails,   we   clear   swap_cnt   so   the    
    *   task   won't   be   selected   again   until   all   others   have   been   tried.  
    *  
    *   Think   of   swap_cnt   as   a   "shadow   rss"   -   it   tells   us   which   process  
    *   we   want   to   page   out   (always   try   largest   first).  
    */  
  counter   =   (nr_threads   <<   SWAP_SHIFT)   >>   priority;  
  if   (counter   <   1)  
  counter   =   1;  
   
  for   (;   counter   >=   0;   counter--)   {  
  struct   list_head   *p;  
  unsigned   long   max_cnt   =   0;  
  struct   mm_struct   *best   =   NULL;  
  int   assign   =   0;  
  int   found_task   =   0;  
  select:  
  spin_lock(&mmlist_lock);  
  p   =   init_mm.mmlist.next;  
  for   (;   p   !=   &init_mm.mmlist;   p   =   p->next)   {  
  struct   mm_struct   *mm   =   list_entry(p,   struct   mm_struct,   mmlist);  
    if   (mm->rss   <=   0)  
  continue;  
  found_task++;  
  /*   Refresh   swap_cnt?   */  
  if   (assign   ==   1)   {  
  mm->swap_cnt   =   (mm->rss   >>   SWAP_SHIFT);  
  if   (mm->swap_cnt   <   SWAP_MIN)  
  mm->swap_cnt   =   SWAP_MIN;  
  }  
  if   (mm->swap_cnt   >   max_cnt)   {  
  max_cnt   =   mm->swap_cnt;  
  best   =   mm;  
  }  
  }  
   
  /*   Make   sure   it   doesn't   disappear   */  
  if   (best)  
  atomic_inc(&best->mm_users);  
  spin_unlock(&mmlist_lock);  
   
  /*  
    *   We   have   dropped   the   tasklist_lock,   but   we  
    *   know   that   "mm"   still   exists:   we   are   running  
    *   with   the   big   kernel   lock,   and   exit_mm()  
    *   cannot   race   with   us.  
    */  
  if   (!best)   {  
  if   (!assign   &&   found_task   >   0)   {  
  assign   =   1;  
  goto   select;  
  }  
  break;  
  }   else   {  
  __ret   =   swap_out_mm(best,   gfp_mask);  
  mmput(best);  
  break;  
  }  
  }  
  return   __ret;  
  } 问题点数:100、回复次数:3Top

1 楼mz_1984()回复于 2006-11-06 13:34:08 得分 0

哎,好伤心哪。Top

2 楼xiangqian(天阁流云)回复于 2006-11-06 19:05:04 得分 0

不是还有continue么Top

3 楼mz_1984()回复于 2006-11-09 11:44:22 得分 0

进continue   是有条件的,条件不满足就不会continue,执行到最后就是那个IF{   。。break;}ELSE{...break;}了。Top

相关问题

关键词

得分解答快速导航

  • 帖主:mz_1984

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo