⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 021_mm_swap_c.html

📁 重读linux 2.4.2o所写的笔记
💻 HTML
字号:
  <html lang="zh-CN" xmlns:gdoc="">  <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <style type="text/css">/* default css */table {  font-size: 1em;  line-height: inherit;}div, address, ol, ul, li, option, select {   margin-top: 0px;  margin-bottom: 0px;}p {  margin: 0px;}body {        margin: 0px;          padding: 0px;    font-family: Verdana, sans-serif;  font-size: 10pt;  background-color: #ffffff;}h6 { font-size: 10pt }h5 { font-size: 11pt }h4 { font-size: 12pt }h3 { font-size: 13pt }h2 { font-size: 14pt }h1 { font-size: 16pt }blockquote {padding: 10px; border: 1px #DDD dashed }a img {border: 0}div.google_header, div.google_footer {  position: relative;  margin-top: 1em;  margin-bottom: 1em;}/* end default css */  /* default print css */    @media print {    body {       padding: 0;       margin: 0;     }    div.google_header, div.google_footer {      display: block;      min-height: 0;      border: none;    }    div.google_header {      flow: static(header);    }    /* used to insert page numbers */    div.google_header::before, div.google_footer::before {      position: absolute;      top: 0;    }    div.google_footer {      flow: static(footer);    }    /* always consider this element at the start of the doc */    div#google_footer {      flow: static(footer, start);    }    span.google_pagenumber {      content: counter(page);    }    span.google_pagecount {      content: counter(pages);    }  }  @page {    @top {      content: flow(header);    }    @bottom {      content: flow(footer);    }  }  /* end default print css */ /* custom css *//* end custom css */  /* ui edited css */    body {    font-family: Verdana;        font-size: 10.0pt;    line-height: normal;    background-color: #ffffff;  }    .documentBG {    background-color: #ffffff;  }  /* end ui edited css */</style>   </head>  <body  revision="dcbsxfpf_62fqv2gzc7:4">      <table align=center cellpadding=0 cellspacing=0 height=5716 width=768>
  <tbody>
  <tr>
    <td height=5716 valign=top width=100%>
      <pre>2006-8-5<br>mm/swap.c<br><br>    这个文件内容比较凌乱,大部分的内容在分析memory.c, filemap.c的时候都有<br>涉及.这里就给个大概的描述吧.以说明我们也搞过这个文件了.<br><br>    仔细阅读一下注释,freepages的含义就一目了然了:<br> freepages.min :当系统的空闲页面(buddy中)少于此数量时,只有kernel有权利使<br>       用这些页面.<br> freepages.low :当系统空闲页面低于此值时,内核开始大规模启动swap .<br><br> freepages.high :我们努力保持系统的空闲页面不低于此值. 如果低于此值内核<br>        即刻开始逐渐swap out,以使内核'永不'进行较大规模的swap.<br>		   <br>/*<br> * We identify three levels of free memory.  We never let free mem<br> * fall below the freepages.min except for atomic allocations.  We<br> * start background swapping if we fall below freepages.high free<br> * pages, and we begin intensive swapping below freepages.low.<br> *<br> * Actual initialization is done in mm/page_alloc.c or <br> * arch/sparc(64)/mm/init.c.<br> */<br>freepages_t freepages = {<br>	0,	/* freepages.min */ /*When the number of free pages in the system<br>		reaches this number, only the kernel can allocate more memory. */<br><br>	0,	/* freepages.low *//*If the number of free pages gets below this<br>		point, the kernel starts swapping aggressively.*/<br><br>	0	/* freepages.high *//*The kernel tries to keep up to this amount of<br>		memory free; if memory comes below this point,<br>		the kernel gently starts swapping in the hopes<br>		that it never has to do real aggressive swapping.*/<br>};<br><br>  关于alloc page的详细情况,见filemap.c的分析.<br><br>  下面是page_cluster和memory_pressure:  <br>/* How many pages do we try to swap or page in/out together? */<br>int page_cluster; /*每个cluster拥有的页面个数,2^page_cluster*/<br>/*<br>    page_cluster: 用于filemap, swap in   的预读簇<br>    SWAPFILE_CLUSTER: swap 设备分配swap entry(swap page)使用的簇<br>*/<br><br>  <br>/*<br> * This variable contains the amount of page steals the system<br> * is doing, averaged over a minute. We use this to determine how<br> * many inactive pages we should have.<br> *<br> * In reclaim_page and __alloc_pages: memory_pressure++<br> * In __free_pages_ok: memory_pressure--<br> * In recalculate_vm_stats the value is decayed (once a second)<br> */<br>int memory_pressure;<br><br>   也请看filemap.c的相关分析.<br> <br>   <br>   <br>   然后是 nr_async_pages: <br>/* We track the number of pages currently being asynchronously swapped<br> *   out, so that we don't try to swap TOO many pages out at once <br> */<br> /* rw_swap_page_base: inc nr_async_pages    end_buffer_io_async:dec this one*/<br> /*异步io 状态就是提交读/写后不等待页面get unlocked*/<br> atomic_t nr_async_pages = ATOMIC_INIT(0); /*所有在异步io状态的页面总数*/<br><br><br><br>   buffer_mem, page_cache 几乎被放弃了,2.6的实现较为利落.不再分析.<br>   <br>   <br>   <br>  在pager_daemon中只有pager_daemon.swap_cluster 还有意义,其他值都没有地方<br>使用.	<br>    pager_daemon.swap_cluster; /*最多预读的cluster个数*/<br>    面分析的page_cluster,是每个cluster的页面数量,这里的swap_cluster是一次<br>最多容许swap的cluster数量.<br><br>  <br>   剩下的函数实现操作page-&gt;age,以及在lru cache内移动page.filemap.c的分析中<br>解释了lru cache的组成.请见相关分析.<br>   这里申明一下PG_referenced的具体含义:<br>   <br> /* -- user page 在try_to_swap_out 通过遍历进程页<br>  *  目录,操作page-&gt;age. 而对于内核使用的页<br>  *  面,比如buffer,inode等,try_to_swap_out无法确定<br>  *  是否应该老化此页面. 解决的办法就是<br>  *  通过PG_referenced bit,内核访问的时候置此位<br>  *  相当于hit.<br>  *  mm.h 的注释如下<br>  * For choosing which pages to swap out, inode pages carry a<br>  * PG_referenced bit, which is set any time the system accesses<br>  * that page through the (inode,offset) hash table.<br>  */<br>   <br>   剩余的函数逻辑都是清楚的,理解lru,page cache,swap cache后不难. 不再列出.<br>   <br> <br></pre>
    </td>
  </tr>
  </tbody>
</table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -