vdisk 的缓存系统设计

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} span.EmailStyle15 {mso-style-type:personal; mso-style-noshow:yes; mso-ansi-font-size:9.0pt; mso-bidi-font-size:10.0pt; font-family:Arial; mso-ascii-font-family:Arial; mso-fareast-font-family:宋体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; color:windowtext;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:496922159; mso-list-type:hybrid; mso-list-template-ids:2038564230 1768743268 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-tab-stop:18.0pt; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

Linux 缓存系统设计:

 

1.       首先在系统启动的时候分配 256MB 的大小。并按照 16KB+header 建立 free list.

2.       为每个 Vdisk 维护一个二叉树,此二叉树是以 header->start_sect 排序。

3.       维护一个二叉堆用来管理应经使用的 buffer. 并切维护一个全局变量计数,最近使用的, header->id = gcnt, gcnt++.

 

这样,当访问 vdisk 的时候,首先从 vdisk->avl tree ,使用 start sect 去查找,如果找到,更新 header->id, 如果 gcnt 的值最高 4 位全为 1 时,则清空 usedbuffer 二叉堆得高 16 位。

更新 usedbuffer 二叉堆的排序。

 

如果不在 vdisk 的二叉树中, 判断 freelist, 如果 freelist 不为空,则从 freelist 中取下,取得数据,写入到缓冲区,更新 header->id

然后插入到 vdisk 的二叉树中,插入到 usedbuffer 的二叉堆中

 

如果 freelist 为空,则从 used 二叉堆中删除第一个最不常用的 , 从某个 vdisk 上删除 buffer ,考虑是否要回写。

更新 header->id, copy 数据,插入到 vdisk->avl tree ,更新 usedbuffer 二叉堆。

 

Header 应该有以下成员:

dirty

diskno:

start_sect:

last_time

LIST_ENTRY   usedlist;

LIST_ENTRY  freelist;

Freelist 需要加锁

usedbuffer 二叉堆需要锁

每个 vdisk->avl 需要锁

 

二叉树用 start sect 排序, usedbuf last_time 排序,这样就可以做到 LRU 的算法。访问时间用该是

 

更改用线性列表取代 usedbuffer 二叉堆,也是可以的。 Cnt 也是不需要的。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值