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

📄 036_fs_dcache_c.html

📁 重读linux 2.4.2o所写的笔记
💻 HTML
📖 第 1 页 / 共 3 页
字号:
  <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_18c72n4z:276">      <TABLE align=center cellPadding=0 cellSpacing=0 height=5716 width=802>
  <TBODY>
  <TR>
    <TD height=5716 vAlign=top width=802>
      <PRE><B><FONT color=#ff00ff><FONT size=4>dcache.c</FONT>       <BR></FONT>            </B>2007-<SPAN style=FONT-FAMILY:Verdana>11-26<BR><BR></SPAN></PRE>
      感觉文件系统里尽是cache, buffer cache, dcahce, inode, super 呵呵. 真是叫人目不暇给(这成语啥意思??).
      好在dcache 并不想buffer cache那样千丝万缕不易理出个头绪.<BR>
      <BR>
      <FONT size=4><B>分配dentry和dentry tree</B></FONT><BR>
      <BR>
      <BR>
      文件系统的比较核心的一棵树, 也就是dentry和mnt组成的一整棵大树,
      这里给出一个dentry树的以部分结构,我们先集中精力到这棵树的机构上来,这是一个数据结构的问题:<BR>
      struct dentry {<BR>
      &nbsp;&nbsp;&nbsp; .....<BR>
      &nbsp;&nbsp;&nbsp; struct inode&nbsp; * d_inode;&nbsp;&nbsp;&nbsp; /*
      Where the name belongs to - NULL is negative */<BR>
      &nbsp;&nbsp;&nbsp; struct dentry * <B>d_parent</B>;&nbsp;&nbsp;&nbsp; /*
      parent directory */<BR>
      &nbsp;&nbsp;&nbsp; struct list_head d_vfsmnt;<BR>
      &nbsp;&nbsp;&nbsp; struct list_head d_hash;&nbsp;&nbsp;&nbsp; /* lookup
      hash list */<BR>
      &nbsp;&nbsp;&nbsp; struct list_head d_lru;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp; /* d_count = 0 LRU list */<BR>
      &nbsp;&nbsp;&nbsp; struct list_head <B>d_child</B>;&nbsp;&nbsp;&nbsp; /*
      child of parent list */<BR>
      &nbsp;&nbsp;&nbsp; struct list_head<B> d_subdirs</B>;&nbsp;&nbsp;&nbsp; /*
      our children */<BR>
      &nbsp;&nbsp;&nbsp; struct list_head d_alias;&nbsp;&nbsp;&nbsp; /* inode
      alias list */<BR>
      &nbsp; &nbsp; ..... &nbsp;<BR>
      &nbsp;&nbsp;&nbsp; struct super_block * d_sb;&nbsp;&nbsp;&nbsp; /* The
      root of the dentry tree */<BR>
      &nbsp;&nbsp;&nbsp; ......<BR>
      };<BR>
      <BR>
      dentry本身是一个树形结构,下面两个函数 build这颗树:<BR>
      static kmem_cache_t *<FONT color=#3333ff><B>dentry_cache</B></FONT>;&nbsp;
      /*dentry 的free list,一个mem cache*/<BR>
      struct dentry * <FONT color=#006600><B>d_alloc</B></FONT>(struct dentry *
      parent, const struct qstr *name)<BR>
      struct dentry *<FONT color=#006600> <B>d_alloc_root</B></FONT>(struct
      inode * root_inode)<BR>
      <DIV id=mq9f style="PADDING-RIGHT:0pt; PADDING-LEFT:0pt; PADDING-BOTTOM:1em; PADDING-TOP:1em; TEXT-ALIGN:left">
        <IMG src=036_fs_dcache_c_images/dcbsxfpf_19f6zntnfd.gif>
      </DIV>
      <BR>
      <FONT size=4><B>dentry的回收</B></FONT><BR>
      <BR>
      <BR>
      static struct list_head
      *<FONT color=#990000><B>dentry_hashtable</B></FONT>;
      hash,通过dentry-&gt;d_hash接入.<BR>
      <FONT size=3>一个dentry可以存在于hash中,可以有一个inode与之对应或者没有(negative,已删除).还有一个unused队列:</FONT><BR>
      static LIST_HEAD(<FONT color=#990000><B>dentry_unused</B></FONT>); &nbsp;
      这是一个已经删除了但是还没有unhash的,等待回收的denty list, 通过dentry-&gt;d_lru接入;<BR>
      <BR>
      <FONT size=2>dentry cache 的复杂就在释放和回收上了. 简单的ref count是不够的.
      先看看</FONT><FONT size=2><B>纯粹的内存释</B>放函数:</FONT><BR>
      static inline void <FONT color=#006600><B>d_free</B></FONT>(struct dentry
      *dentry)<BR>
      {<BR>
      &nbsp;&nbsp;&nbsp; if (dentry-&gt;d_op &amp;&amp;
      dentry-&gt;d_op-&gt;d_release)<BR>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
      dentry-&gt;d_op-&gt;d_release(dentry);<BR>
      &nbsp;&nbsp;&nbsp; if (dname_external(dentry))<BR>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; kfree(dentry-&gt;d_name.name);<BR>
      &nbsp;&nbsp;&nbsp; kmem_cache_free(dentry_cache, dentry);<BR>
      &nbsp;&nbsp;&nbsp; dentry_stat.nr_dentry--;<BR>
      }<BR>
      然后是<B>hash摘除函数</B>:<BR>
      <FONT color=#3333ff>/**</FONT><BR>
      <FONT color=#3333ff>&nbsp;* d_drop - drop a dentry</FONT><BR>
      <FONT color=#3333ff>&nbsp;* @dentry: dentry to drop</FONT><BR>
      <FONT color=#3333ff>&nbsp;*</FONT><BR>
      <FONT color=#3333ff>&nbsp;* d_drop() <B>unhashes</B> <B>the entry</B> from
      the parent</FONT><BR>
      <FONT color=#3333ff>&nbsp;* dentry hashes, so that it won't be found
      through</FONT><BR>
      <FONT color=#3333ff>&nbsp;* a VFS lookup any more. Note that this is
      different</FONT><BR>
      <FONT color=#3333ff>&nbsp;* from deleting the dentry - <B>d_delete</B>
      will try to</FONT><BR>
      <FONT color=#3333ff>&nbsp;* mark the dentry negative if possible, giving
      a</FONT><BR>
      <FONT color=#3333ff>&nbsp;* successful _negative_ lookup, while d_drop
      will</FONT><BR>
      <FONT color=#3333ff>&nbsp;* just make the cache lookup fail.</FONT><BR>
      <FONT color=#3333ff>&nbsp;*</FONT><BR>
      <FONT color=#3333ff>&nbsp;* d_drop() is used mainly for stuff that
      wants</FONT><BR>
      <FONT color=#3333ff>&nbsp;* to invalidate a dentry for some reason

⌨️ 快捷键说明

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