{"id":1590,"date":"2012-03-31T01:10:12","date_gmt":"2012-03-30T16:10:12","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=1590"},"modified":"2012-03-31T01:51:16","modified_gmt":"2012-03-30T16:51:16","slug":"xv6-56-chapter-5-file-system-code-buffer-cache","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/1590","title":{"rendered":"[xv6 #56] Chapter 5 &#8211; File system &#8211; Code: Buffer cache"},"content":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u306e65\u301c66\u30da\u30fc\u30b8<\/p>\n<h3>\u672c\u6587<\/h3>\n<p>\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u306e2\u91cd\u30ea\u30f3\u30af\u30ea\u30b9\u30c8\uff08\u6b21\u306e\u8981\u7d20\u3060\u3051\u3067\u306a\u304f\u524d\u306e\u8981\u7d20\u3078\u306e\u30ea\u30f3\u30af\u3082\u6301\u3064\u30ea\u30b9\u30c8\uff09\u3067\u3042\u308b\u3002<br \/>\nbinit\u95a2\u6570\u306f\u3001main\u95a2\u6570\u304b\u3089\u547c\u3070\u308c\u3001buf\u69cb\u9020\u4f53\u3092\u5229\u7528\u3057\u305fNBUF\u500b\u306e\u30d0\u30c3\u30d5\u30a1\uff08\u56fa\u5b9a\u9577\u914d\u5217\uff09\u3092\u521d\u671f\u5316\u3059\u308b\u3002<br \/>\n\u3053\u306e\u4ed6\u306e\u3059\u3079\u3066\u306e\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u3078\u30a2\u30af\u30bb\u30b9\u306f\u3001buf\u306e\u914d\u5217\u3078\u76f4\u63a5\u3067\u306f\u306a\u304f\u3001bcache.head\u7d4c\u7531\u3067\u884c\u308f\u308c\u308b\u3002<\/p>\n<p>bio.c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ Buffer cache.\r\n\/\/\r\n\/\/ The buffer cache is a linked list of buf structures holding\r\n\/\/ cached copies of disk block contents.  Caching disk blocks\r\n\/\/ in memory reduces the number of disk reads and also provides\r\n\/\/ a synchronization point for disk blocks used by multiple processes.\r\n\/\/ \r\n\/\/ Interface:\r\n\/\/ * To get a buffer for a particular disk block, call bread.\r\n\/\/ * After changing buffer data, call bwrite to flush it to disk.\r\n\/\/ * When done with the buffer, call brelse.\r\n\/\/ * Do not use the buffer after calling brelse.\r\n\/\/ * Only one process at a time can use a buffer,\r\n\/\/     so do not keep them longer than necessary.\r\n\/\/ \r\n\/\/ The implementation uses three state flags internally:\r\n\/\/ * B_BUSY: the block has been returned from bread\r\n\/\/     and has not been passed back to brelse.  \r\n\/\/ * B_VALID: the buffer data has been initialized\r\n\/\/     with the associated disk block contents.\r\n\/\/ * B_DIRTY: the buffer data has been modified\r\n\/\/     and needs to be written to disk.\r\n\r\n#include &quot;types.h&quot;\r\n#include &quot;defs.h&quot;\r\n#include &quot;param.h&quot;\r\n#include &quot;spinlock.h&quot;\r\n#include &quot;buf.h&quot;\r\n\r\nstruct {\r\n  struct spinlock lock;\r\n  struct buf buf&#x5B;NBUF];\r\n\r\n  \/\/ Linked list of all buffers, through prev\/next.\r\n  \/\/ head.next is most recently used.\r\n  struct buf head;\r\n} bcache;\r\n\r\nvoid\r\nbinit(void)\r\n{\r\n  struct buf *b;\r\n\r\n  initlock(&amp;bcache.lock, &quot;bcache&quot;);\r\n\r\n\/\/PAGEBREAK!\r\n  \/\/ Create linked list of buffers\r\n  bcache.head.prev = &amp;bcache.head;\r\n  bcache.head.next = &amp;bcache.head;\r\n  for(b = bcache.buf; b &lt; bcache.buf+NBUF; b++){\r\n    b-&gt;next = bcache.head.next;\r\n    b-&gt;prev = &amp;bcache.head;\r\n    b-&gt;dev = -1;\r\n    bcache.head.next-&gt;prev = b;\r\n    bcache.head.next = b;\r\n  }\r\n}\r\n\r\n\/\/ Look through buffer cache for sector on device dev.\r\n\/\/ If not found, allocate fresh block.\r\n\/\/ In either case, return locked buffer.\r\nstatic struct buf*\r\nbget(uint dev, uint sector)\r\n{\r\n  struct buf *b;\r\n\r\n  acquire(&amp;bcache.lock);\r\n\r\n loop:\r\n  \/\/ Try for cached block.\r\n  for(b = bcache.head.next; b != &amp;bcache.head; b = b-&gt;next){\r\n    if(b-&gt;dev == dev &amp;&amp; b-&gt;sector == sector){\r\n      if(!(b-&gt;flags &amp; B_BUSY)){\r\n        b-&gt;flags |= B_BUSY;\r\n        release(&amp;bcache.lock);\r\n        return b;\r\n      }\r\n      sleep(b, &amp;bcache.lock);\r\n      goto loop;\r\n    }\r\n  }\r\n\r\n  \/\/ Allocate fresh block.\r\n  for(b = bcache.head.prev; b != &amp;bcache.head; b = b-&gt;prev){\r\n    if((b-&gt;flags &amp; B_BUSY) == 0){\r\n      b-&gt;dev = dev;\r\n      b-&gt;sector = sector;\r\n      b-&gt;flags = B_BUSY;\r\n      release(&amp;bcache.lock);\r\n      return b;\r\n    }\r\n  }\r\n  panic(&quot;bget: no buffers&quot;);\r\n}\r\n\r\n\/\/ Return a B_BUSY buf with the contents of the indicated disk sector.\r\nstruct buf*\r\nbread(uint dev, uint sector)\r\n{\r\n  struct buf *b;\r\n\r\n  b = bget(dev, sector);\r\n  if(!(b-&gt;flags &amp; B_VALID))\r\n    iderw(b);\r\n  return b;\r\n}\r\n\r\n\/\/ Write b's contents to disk.  Must be locked.\r\nvoid\r\nbwrite(struct buf *b)\r\n{\r\n  if((b-&gt;flags &amp; B_BUSY) == 0)\r\n    panic(&quot;bwrite&quot;);\r\n  b-&gt;flags |= B_DIRTY;\r\n  iderw(b);\r\n}\r\n\r\n\/\/ Release the buffer b.\r\nvoid\r\nbrelse(struct buf *b)\r\n{\r\n  if((b-&gt;flags &amp; B_BUSY) == 0)\r\n    panic(&quot;brelse&quot;);\r\n\r\n  acquire(&amp;bcache.lock);\r\n\r\n  b-&gt;next-&gt;prev = b-&gt;prev;\r\n  b-&gt;prev-&gt;next = b-&gt;next;\r\n  b-&gt;next = bcache.head.next;\r\n  b-&gt;prev = &amp;bcache.head;\r\n  bcache.head.next-&gt;prev = b;\r\n  bcache.head.next = b;\r\n\r\n  b-&gt;flags &amp;= ~B_BUSY;\r\n  wakeup(b);\r\n\r\n  release(&amp;bcache.lock);\r\n}<\/pre>\n<p>\u30d0\u30c3\u30d5\u30a1\u306f3\u3064\u306e\u72b6\u614b\u30d5\u30e9\u30b0\u3092\u6301\u3064\u3002<br \/>\nB_VALID\u306f\u3001\u305d\u306e\u30d6\u30ed\u30c3\u30af\u306e\u6b63\u3057\u3044\u30b3\u30d4\u30fc\u3092\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u542b\u3080\u3053\u3068\u3092\u793a\u3059\u3002<br \/>\nB_DIRTY\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u306e\u5185\u5bb9\u304c\u5909\u66f4\u3055\u308c\u3001\u30c7\u30a3\u30b9\u30af\u3078\u66f8\u304d\u51fa\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u3092\u793a\u3059\u3002<br \/>\nB_BUSY\u306f\u3001\u3069\u3053\u304b\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u304c\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u53c2\u7167\u3057\u3066\u3044\u3066\u3001\u307e\u3060\u89e3\u653e\u3057\u3066\u306a\u3044\u3053\u3068\u3092\u793a\u3059\u3002<\/p>\n<p>bread\u95a2\u6570\u306f\u3001\u4e0e\u3048\u3089\u308c\u305f\u30bb\u30af\u30bf\u306e\u305f\u3081\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u5f97\u308b\u305f\u3081\u306bbget\u95a2\u6570\u3092\u547c\u3076\u3002<br \/>\n\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306e\u5185\u5bb9\u3092\u30c7\u30a3\u30b9\u30af\u304b\u3089\u8aad\u307f\u8fbc\u3080\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3001bread\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u8fd4\u3059\u524d\u306b\u3001iderw\u95a2\u6570\u3092\u547c\u3076\u3002<\/p>\n<p>bget\u95a2\u6570\u306f\u3001\u4e0e\u3048\u3089\u308c\u305f\u30c7\u30d0\u30a4\u30b9\u3068\u30bb\u30af\u30bf\u306b\u5bfe\u5fdc\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u3092\u635c\u3059\u305f\u3081\u306b\u30d0\u30c3\u30d5\u30a1\u306e\u30ea\u30b9\u30c8\u3092\u8d70\u67fb\u3059\u308b\u3002<br \/>\n\u5408\u81f4\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u3042\u308a\u3001\u304b\u3064\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304cB_BUSY\u3067\u306f\u306a\u3044\u5834\u5408\u3001bget\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306bB_BUSY\u30d5\u30e9\u30b0\u3092\u30bb\u30c3\u30c8\u3057\u8fd4\u3059\u3002<br \/>\n\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u5229\u7528\u4e2d\u306e\u5834\u5408\u3001bget\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u89e3\u653e\u3055\u308c\u308b\u306e\u3092\u5f85\u3064\u305f\u3081\u306b\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u30c1\u30e3\u30f3\u30cd\u30eb\u3068\u3057\u3066sleep\u3059\u308b\u3002<br \/>\nsleep\u304c\u8fd4\u3063\u3066\u304d\u305f\u3068\u304d\u3067\u3082\u3001bget\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u5229\u7528\u53ef\u80fd\u3067\u3042\u308b\u3068\u4eee\u5b9a\u3059\u308b\u3053\u3068\u306f\u51fa\u6765\u306a\u3044\u3002<br \/>\nsleep\u306f\u3001bcache.lock\u3092\u89e3\u653e\u3057\u518d\u7372\u5f97\u3059\u308b\u306e\u3067\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1b\u304c\u307e\u3060\u5229\u7528\u53ef\u80fd\u3067\u3042\u308b\u3068\u3044\u3046\u4fdd\u8a3c\u306f\u306a\u3044\u3002<br \/>\n\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u3001\u5225\u306e\u30bb\u30af\u30bf\u306e\u305f\u3081\u306b\u518d\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\nbget\u306f\u3001\u4eca\u56de\u3068\u306f\u9055\u3063\u305f\u7d50\u672b\u306b\u306a\u308b\u3067\u3042\u308d\u3046\u4e8b\u3092\u5e0c\u671b\u3057\u3066\u3001\u3084\u308a\u76f4\u3059\u3057\u304b\u306a\u3044\u3002\uff08goto loop;\u306e\u3068\u3053\u308d\uff09<\/p>\n<p>\uff08\u3053\u306e\u6bb5\u843d\u306e\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u76f4\u8a33\u98a8\u5473\u306b\u306a\u3063\u3066\u307e\u3059\u3002\u8a73\u7d30\u306f\u611f\u60f3\u306b\u66f8\u304d\u307e\u3059\u3002\uff09<br \/>\nbget\u306b\u3001\u3082\u3057goto\u6587\u304c\u306a\u304b\u3063\u305f\u3068\u3057\u305f\u3089\u3001\u56f35-3\u306e\u3088\u3046\u306a\u7af6\u5408\u72b6\u614b\u304c\u8d77\u304d\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\n\u6700\u521d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u3001\u3042\u308b\u30d0\u30c3\u30d5\u30a1\u3092\u6301\u3061\u3001\u305d\u3057\u3066\u305d\u306e\u4e2d\u306b\u30bb\u30af\u30bf3\u3092\u8aad\u307f\u8fbc\u307f\u3053\u3093\u3060\u3002<br \/>\n\u4eca2\u3064\u306e\u4ed6\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u3064\u3044\u3066\u304f\u308b\u3002<br \/>\n\u6700\u521d\u306e\u305d\u308c\u306f\u3001\u30d0\u30c3\u30d5\u30a13\u306e\u305f\u3081\u306b\u53d6\u5f97\u3092\u884c\u3044\u3001\u305d\u3057\u3066\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305f\u30d6\u30ed\u30c3\u30af\u306e\u305f\u3081\u306e\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u30b9\u30ea\u30fc\u30d7\u3059\u308b\u3002<br \/>\n2\u756a\u76ee\u306e\u305d\u308c\u306f\u3001\u30d0\u30c3\u30d5\u30a14\u306e\u305f\u3081\u306b\u53d6\u5f97\u3092\u884c\u3044\u3001\u65b0\u305f\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u305f\u30d6\u30ed\u30c3\u30af\u306e\u305f\u3081\u306e\u30eb\u30fc\u30d7\u306e\u4e2d\u4ee5\u5916\u306e\u540c\u3058\u30d0\u30c3\u30d5\u30a1\u4e0a\u3067\u30b9\u30ea\u30fc\u30d7\u51fa\u6765\u305f\u3002<br \/>\n\u306a\u305c\u306a\u3089\u3001\u7a7a\u304d\u30d0\u30c3\u30d5\u30a1\u304c\u306a\u304f\u3001\u305d\u3057\u30663\u3092\u4fdd\u6301\u3057\u3066\u3044\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u3001\u30ea\u30b9\u30c8\u306e\u6700\u524d\u9762\u3067\u3042\u308a\u3001\u518d\u5229\u7528\u306e\u305f\u3081\u306b\u9078\u629e\u3055\u308c\u305f\u304b\u3089\u3002<br \/>\n\u6700\u521d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u958b\u653e\u3057\u3001wakeup\u306f\u30d7\u30ed\u30bb\u30b93\u3092\u307e\u305a\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3059\u308b\u4e8b\u614b\u3092\u5f15\u304d\u8d77\u3053\u3057\u3001\u305d\u308c\u306f\u30d0\u30c3\u30d5\u30a1\u3092\u3064\u304b\u307f\u3001\u305d\u308c\u306b\u30bb\u30af\u30bf4\u3092\u8aad\u307f\u8fbc\u3080\u3060\u308d\u3046\u3002<br \/>\n\u305d\u308c\u304c\u5b8c\u4e86\u3059\u308b\u3068\u304d\u3001\u305d\u308c\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\uff08\u30bb\u30af\u30bf4\u3092\u542b\u3080\uff09\u3092\u89e3\u653e\u3057\u3001\u30d7\u30ed\u30bb\u30b92\u3092\u8d77\u3053\u3059\u3060\u308d\u3046\u3002<br \/>\ngoto\u6587\u306a\u3057\u306e\u30d7\u30ed\u30bb\u30b92\u306f\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092BUSY\u3068\u30de\u30fc\u30af\u3057\u3001\u305d\u3057\u3066bget\u304b\u3089\u623b\u308b\u3002<br \/>\n\u3057\u304b\u3057\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u30bb\u30af\u30bf3\u3067\u306f\u306a\u304f\u3001\u30bb\u30af\u30bf4\u3092\u542b\u3080\u3002<br \/>\n\u30bb\u30af\u30bf3\u3068\u30bb\u30af\u30bf4\u306f\u9055\u3046\u5185\u5bb9\u3092\u6301\u3064\u306e\u3067\u3001\u3053\u306e\u30a8\u30e9\u30fc\u306f\u69d8\u3005\u306a\u5927\u7834\u58ca\u3092\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\nxv6\u306f\u305d\u308c\u3089\u3092inode\u306e\u4fdd\u7ba1\u306b\u4f7f\u3063\u3066\u3044\u308b\u3002<\/p>\n<p><a href=\"https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05-300x194.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2012-03-31 1.04.05\" width=\"300\" height=\"194\" class=\"aligncenter size-medium wp-image-1591\" srcset=\"https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05-300x194.png 300w, https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05.png 706w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n\u56f35-3 process 2\u306f\u30d6\u30ed\u30c3\u30af3\u306b\u3064\u3044\u3066\u554f\u3044\u5408\u308f\u305b\u305f\u306e\u306b\u3001\u7d50\u679c\u7684\u306b\u30d6\u30ed\u30c3\u30af4\u3092\u542b\u3080\u30d0\u30c3\u30d5\u30a1\u3092\u53d7\u3051\u53d6\u3063\u3066\u3057\u307e\u3046\u7af6\u5408\u306e\u4f8b<br \/>\n\uff08\u539f\u6587\u3067\u306f\u3001process 3\u306f\u301c\u3068\u306a\u3063\u3066\u308b\u3051\u3069\u591a\u5206\u9593\u9055\u3044\uff09<\/p>\n<p>\u4e0e\u3048\u3089\u308c\u305f\u30bb\u30af\u30bf\u306b\u5bfe\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u306a\u3044\u5834\u5408\u3001bget\u306f\u305d\u308c\u3092\u4f5c\u3089\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001\u5225\u306e\u30bb\u30af\u30bf\u3092\u4fdd\u6301\u3057\u3066\u305f\u30d0\u30c3\u30d5\u30a1\u3092\u51fa\u6765\u308b\u9650\u308a\u518d\u5229\u7528\u3059\u308b\u3002<br \/>\nbget\u306f\u3001\u3082\u3046\u4e00\u5ea6\u30d0\u30c3\u30d5\u30a1\u306e\u30ea\u30b9\u30c8\u3092\u8d70\u67fb\u3057\u3001B_BUSY\u3067\u306f\u306a\u3044\u30d6\u30ed\u30c3\u30af\uff08\u4f7f\u3048\u308b\u30d6\u30ed\u30c3\u30af\uff09\u3092\u635c\u3059\u3002<br \/>\nbget\u306f\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u8fd4\u3059\u524d\u306b\u3001\u65b0\u3057\u3044\u30c7\u30d0\u30a4\u30b9\u756a\u53f7\u3068\u30bb\u30af\u30bf\u756a\u53f7\u3092\u8a18\u9332\u3057\u3001\u5229\u7528\u4e2d\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3092\u30de\u30fc\u30af\u3059\u308b\u305f\u3081\u306b\u30d6\u30ed\u30c3\u30af\u306e\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u7de8\u96c6\u3059\u308b\u3002<br \/>\n\u3053\u306e\u30d5\u30e9\u30b0\u3078\u306e\u4ee3\u5165\u306f\u3001B_BUSY\u30d5\u30e9\u30b0\u3092\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3067\u306f\u306a\u304f\u3001B_VALID\u3084B_DIRTY\u30d5\u30e9\u30b0\u3082\u30af\u30ea\u30a2\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001bread\u304c\u4ee5\u524d\u306e\u30d6\u30ed\u30c3\u30af\u306e\u5185\u5bb9\u3092\u4f7f\u3046\u4e8b\u7121\u304f\u3001\u30c7\u30a3\u30b9\u30af\u304b\u3089\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306e\u30c7\u30fc\u30bf\u3092\u30ea\u30d5\u30ec\u30c3\u30b7\u30e5\u3059\u308b\u3053\u3068\u3092\u4fdd\u8a3c\u3059\u308b\u3002<\/p>\n<p>\u540c\u671f\u5316\u306e\u305f\u3081\u306b\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u4f7f\u308f\u308c\u308b\u306e\u3067\u3001\u30c7\u30a3\u30b9\u30af\u306e\u5404\u30bb\u30af\u30bf\u306b\u3064\u3044\u3066\u3001\u591a\u304f\u3066\u3082\u305f\u3063\u305f\u4e00\u3064\u306e\u30d0\u30c3\u30d5\u30a1\u3057\u304b\u5b58\u5728\u3057\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u91cd\u8981\u3067\u3042\u308b\u3002<br \/>\nbget\u306e\u6700\u521d\u306e\u30eb\u30fc\u30d7\u306f\u3001\u305d\u306e\u30bb\u30af\u30bf\u306b\u5bfe\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u65e2\u306b\u5b58\u5728\u3057\u3066\u3044\u306a\u3044\u3068\u6c7a\u5fc3\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u4ee3\u5165\uff08b-&gt;dev = dev; b-&gt;sector = sector; b-&gt;flags = B_BUSY;\uff09\u306f\u3001\u552f\u4e00\u306e\u5b89\u5168\u7b56\u3067\u3042\u308a\u3001\u305d\u3057\u3066bget\u306f\u305d\u308c\u4ee5\u6765bcache.lock\u3092\u624b\u653e\u3057\u3066\u3044\u306a\u3044\u3002\uff08\u8b0e\uff09<\/p>\n<p>\u3082\u3057\u3059\u3079\u3066\u306e\u30d0\u30c3\u30d5\u30a1\u304cB_BUSY\u306a\u5834\u5408\u3001\u4f55\u304b\u304a\u304b\u3057\u306a\u4e8b\u614b\u306b\u306a\u3063\u3066\u304a\u308a\u3001bget\u306fpanic\u3092\u547c\u3076\u3002<br \/>\n\u3082\u3063\u3068\u89aa\u5207\u306a\u53cd\u5fdc\u3068\u3057\u3066\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u306b\u7a7a\u304d\u304c\u51fa\u6765\u308b\u307e\u3067\u30b9\u30ea\u30fc\u30d7\u3059\u3079\u304d\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u3082\u3063\u3068\u3082\u3001\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u306e\u53ef\u80fd\u6027\u306f\u3042\u308b\u304c\u3002<\/p>\n<p>\u4e00\u5ea6bread\u304c\u3001\u547c\u3073\u51fa\u3057\u5074\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u8fd4\u3057\u305f\u3089\u3001\u547c\u3073\u51fa\u3057\u5074\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306e\u72ec\u5360\u6a29\u3092\u6301\u3061\u3001\u30d0\u30a4\u30c8\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u66f8\u304d\u3067\u304d\u308b\u3002<br \/>\n\u547c\u3073\u51fa\u3057\u5074\u304c\u3001\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3093\u3060\u5834\u5408\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u89e3\u653e\u3059\u308b\u524d\u306b\u3001bwrite\u3092\u547c\u3093\u3067\u3001\u5909\u66f4\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u30c7\u30a3\u30b9\u30af\u306b\u66f8\u304d\u8fbc\u307e\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\nbwrite\u306f\u3001B_DIRTY\u30d5\u30e9\u30b0\u3092\u30bb\u30c3\u30c8\u3057\u3001\u305d\u3057\u3066\u30c7\u30a3\u30b9\u30af\u3078\u30d0\u30c3\u30d5\u30a1\u306e\u5185\u5bb9\u3092\u66f8\u304d\u8fbc\u3080\u305f\u3081\u306biderw\u3092\u547c\u3076\u3002<\/p>\n<p>\u547c\u3073\u51fa\u3057\u5074\u304c\u30d0\u30c3\u30d5\u30a1\u3092\u4f7f\u3044\u7d42\u308f\u3063\u305f\u3089\u3001\u30d0\u30c3\u30d5\u30a1\u3092\u89e3\u653e\u3059\u308b\u305f\u3081\u306bbrelse\u3092\u547c\u3076\u3079\u304d\u3067\u3042\u308b\u3002<br \/>\n\uff08brelse\u3068\u3044\u3046\u540d\u524d\u306f\u3001b-release\u306e\u77ed\u7e2e\u3067\u3001\u96a0\u8a9e\u3067\u306f\u3042\u308b\u304c\u899a\u3048\u3066\u304a\u304f\u4fa1\u5024\u304c\u3042\u308b\u3002Unix\u3092\u8d77\u6e90\u3068\u3057\u3001BSD\u3084Linux\u3084Solaris\u306a\u3069\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u3002\uff09<br \/>\nbrelse\u306f\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u30ea\u30f3\u30af\u30ea\u30b9\u30c8\u306e\u5143\u306e\u4f4d\u7f6e\u304b\u3089\u30ea\u30b9\u30c8\u306e\u6700\u524d\u306b\u79fb\u52d5\u3057\u3001B_BUSY\u30d5\u30e9\u30b0\u3092\u30af\u30ea\u30a2\u3057\u3001\u305d\u3057\u3066\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u5f85\u3063\u3066\u30b9\u30ea\u30fc\u30d7\u3057\u3066\u308b\u3069\u3053\u304b\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8d77\u3053\u3059\u3002<br \/>\n\u30d0\u30c3\u30d5\u30a1\u306e\u79fb\u52d5\u306f\u3001\u6700\u8fd1\u4f7f\u308f\u308c\u305f\uff08\u89e3\u653e\u3055\u308c\u305f\u3068\u3044\u3046\u610f\u5473\u3067\uff09\u9806\u756a\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u4e26\u3073\u66ff\u3048\u308b\u52b9\u679c\u304c\u3042\u308b\u3002<br \/>\n\u30ea\u30b9\u30c8\u306e\u6700\u521d\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u3001\u4e00\u756a\u6700\u8fd1\u4f7f\u308f\u308c\u305f\u3082\u306e\u3067\u3042\u308a\u3001\u30ea\u30b9\u30c8\u306e\u6700\u5f8c\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u3001\u4f7f\u308f\u308c\u3066\u304b\u3089\u4e00\u756a\u6642\u9593\u304c\u7d4c\u3063\u3066\u3044\u308b\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\nbget\u306e2\u3064\u306e\u30eb\u30fc\u30d7\u306f\u3001\u3053\u306e\u512a\u4f4d\u6027\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3002<br \/>\n\u5b58\u5728\u3057\u3066\u3044\u308b\u30d0\u30c3\u30d5\u30a1\u306e\u8d70\u67fb\u306f\u3001\u6700\u60aa\u306e\u5834\u5408\u30ea\u30b9\u30c8\u306e\u3059\u3079\u3066\u3092\u51e6\u7406\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u304c\u3001\u6700\u8fd1\u4f7f\u308f\u308c\u305f\u30d0\u30c3\u30d5\u30a1\u3092\u5148\u306b\u8abf\u3079\u308b\u4e8b\uff08bcache.head\u304b\u3089\u306f\u3058\u3081\u3066next\u30dd\u30a4\u30f3\u30bf\u3092\u305f\u3069\u308b\u4e8b\uff09\u306f\u3001\u826f\u3044\u53c2\u7167\u306e\u5c40\u6240\u6027\u304c\u3042\u308b\u5834\u5408\u306b\u3001\u8d70\u67fb\u306b\u639b\u304b\u308b\u6642\u9593\u3092\u7bc0\u7d04\u3059\u308b\u3060\u308d\u3046\u3002<br \/>\n\u518d\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u9078\u3076\u305f\u3081\u306e\u8d70\u67fb\u306f\u3001\u9006\u9806\u306b\u8d70\u67fb\uff08prev\u30dd\u30a4\u30f3\u30bf\u3092\u305f\u3069\u308b\uff09\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u4f7f\u308f\u308c\u3066\u304b\u3089\u4e00\u756a\u6642\u9593\u304c\u7d4c\u3063\u3066\u3044\u308b\u3082\u306e\u304b\u3089\u8abf\u3079\u308b\u3002<\/p>\n<h3>\u611f\u60f3<\/h3>\n<p>\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b9f\u88c5\u306e\u8aac\u660e\u3067\u3059\u3002<\/p>\n<p>\u9014\u4e2d\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u3044\u3068\u66f8\u3044\u305f\u6bb5\u843d\u306b\u3064\u3044\u3066\u3002<br \/>\ngoto loop;\u304c\u306a\u3044\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u7af6\u5408\u72b6\u614b\u306e\u6a5f\u5e8f\u306b\u3064\u3044\u3066\u306e\u8aac\u660e\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3069\u3046\u8003\u3048\u3066\u3082\u66f8\u304b\u308c\u3066\u308b\u3088\u3046\u306a\u4e8b\u306f\u8d77\u304d\u306a\u3044\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ed6\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u3088\u3063\u3066bcache.head\u306e\u4f4d\u7f6e\u304c\u5909\u308f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067\u3001\u53d6\u308a\u3053\u307c\u3055\u306a\u3044\u3088\u3046\u521d\u3081\u304b\u3089\u518d\u30eb\u30fc\u30d7\u3059\u308b\u305f\u3081\u306bgoto loop;\u304c\u5fc5\u8981\u306a\u4e8b\u306f\u5206\u304b\u308a\u307e\u3059\u304c\u3001b-&gt;dev == dev &amp;&amp; b-&gt;sector == sector \u306e\u30c1\u30a7\u30c3\u30af\u306f\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u884c\u3063\u3066\u308b\u306e\u3067\u3001\u554f\u984c\u306a\u3044\u3068\u3044\u3046\u304b\u3001\u305d\u3082\u305d\u3082\u30bb\u30af\u30bf\u304c\u30c1\u30a7\u30c3\u30af\u3055\u308c\u3066\u308b\u306e\u3067\u3001\u5225\u306e\u30bb\u30af\u30bf\u3092\u5fc5\u8981\u3068\u3059\u308b\uff08\u56f3\u3067\u3044\u3046\u3068\u3053\u308d\u306e\uff09\u30d7\u30ed\u30bb\u30b92\u3068\u30d7\u30ed\u30bb\u30b93\u304c\u540c\u3058\u30d0\u30c3\u30d5\u30a1\u3092\u5f85\u3063\u3066\u30b9\u30ea\u30fc\u30d7\u3059\u308b\u3053\u3068\u306f\u306a\u3044\u306f\u305a\u3067\u3059\u3002<\/p>\n<p>\u3082\u3057\u30d7\u30ed\u30bb\u30b92\u304c\u30d7\u30ed\u30bb\u30b93\u3067\u5229\u7528\u4e2d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u5f85\u3063\u3066\u30b9\u30ea\u30fc\u30d7\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3042\u308a\u5f97\u305f\u3068\u3057\u3066\u3082\u3001\u30d7\u30ed\u30bb\u30b93\u3067wakeup\u3055\u308c\u3066\u30d7\u30ed\u30bb\u30b92\u306esleep\u304c\u8fd4\u3063\u3066\u304d\u305f\u6bb5\u968e\u3067\u3001\u307e\u305fb-&gt;dev == dev &amp;&amp; b-&gt;sector == sector \u306e\u30c1\u30a7\u30c3\u30af\u304c\u884c\u308f\u308c\u3001\u305d\u308c\u306b\u5408\u81f4\u3057\u306a\u3044\u306e\u3067\uff08\u30bb\u30af\u30bf\u304c\u9055\u3046\u306e\u3067\uff09\u5358\u7d14\u306b\u305d\u306e\u30eb\u30fc\u30d7\u306f\u98db\u3070\u3055\u308c\u308b\u3060\u3051\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f55\u304b\u91cd\u5927\u306a\u52d8\u9055\u3044\u3092\u3057\u3066\u308b\u3093\u3060\u308d\u3046\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u306e65\u301c66\u30da\u30fc\u30b8<\/p>\n<h3>\u672c\u6587<\/h3>\n<p>\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u306e2\u91cd\u30ea\u30f3\u30af\u30ea\u30b9\u30c8\uff08\u6b21\u306e\u8981\u7d20\u3060\u3051\u3067\u306a\u304f\u524d\u306e\u8981\u7d20\u3078\u306e\u30ea\u30f3\u30af\u3082\u6301\u3064\u30ea\u30b9\u30c8\uff09\u3067\u3042\u308b\u3002<br \/>\nbinit\u95a2\u6570\u306f\u3001main\u95a2\u6570\u304b\u3089\u547c\u3070\u308c\u3001buf\u69cb\u9020\u4f53\u3092\u5229\u7528\u3057\u305fNBUF\u500b\u306e\u30d0\u30c3\u30d5\u30a1\uff08\u56fa\u5b9a\u9577\u914d\u5217\uff09\u3092\u521d\u671f\u5316\u3059\u308b\u3002<br \/>\n\u3053\u306e\u4ed6\u306e\u3059\u3079\u3066\u306e\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u3078\u30a2\u30af\u30bb\u30b9\u306f\u3001buf\u306e\u914d\u5217\u3078\u76f4\u63a5\u3067\u306f\u306a\u304f\u3001bcache.head\u7d4c\u7531\u3067\u884c\u308f\u308c\u308b\u3002<\/p>\n<p>bio.c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ Buffer cache.\r\n\/\/\r\n\/\/ The buffer cache is a linked list of buf structures holding\r\n\/\/ cached copies of disk block contents.  Caching disk blocks\r\n\/\/ in memory reduces the number of disk reads and also provides\r\n\/\/ a synchronization point for disk blocks used by multiple processes.\r\n\/\/ \r\n\/\/ Interface:\r\n\/\/ * To get a buffer for a particular disk block, call bread.\r\n\/\/ * After changing buffer data, call bwrite to flush it to disk.\r\n\/\/ * When done with the buffer, call brelse.\r\n\/\/ * Do not use the buffer after calling brelse.\r\n\/\/ * Only one process at a time can use a buffer,\r\n\/\/     so do not keep them longer than necessary.\r\n\/\/ \r\n\/\/ The implementation uses three state flags internally:\r\n\/\/ * B_BUSY: the block has been returned from bread\r\n\/\/     and has not been passed back to brelse.  \r\n\/\/ * B_VALID: the buffer data has been initialized\r\n\/\/     with the associated disk block contents.\r\n\/\/ * B_DIRTY: the buffer data has been modified\r\n\/\/     and needs to be written to disk.\r\n\r\n#include &quot;types.h&quot;\r\n#include &quot;defs.h&quot;\r\n#include &quot;param.h&quot;\r\n#include &quot;spinlock.h&quot;\r\n#include &quot;buf.h&quot;\r\n\r\nstruct {\r\n  struct spinlock lock;\r\n  struct buf buf&#x5B;NBUF];\r\n\r\n  \/\/ Linked list of all buffers, through prev\/next.\r\n  \/\/ head.next is most recently used.\r\n  struct buf head;\r\n} bcache;\r\n\r\nvoid\r\nbinit(void)\r\n{\r\n  struct buf *b;\r\n\r\n  initlock(&amp;bcache.lock, &quot;bcache&quot;);\r\n\r\n\/\/PAGEBREAK!\r\n  \/\/ Create linked list of buffers\r\n  bcache.head.prev = &amp;bcache.head;\r\n  bcache.head.next = &amp;bcache.head;\r\n  for(b = bcache.buf; b &lt; bcache.buf+NBUF; b++){\r\n    b-&gt;next = bcache.head.next;\r\n    b-&gt;prev = &amp;bcache.head;\r\n    b-&gt;dev = -1;\r\n    bcache.head.next-&gt;prev = b;\r\n    bcache.head.next = b;\r\n  }\r\n}\r\n\r\n\/\/ Look through buffer cache for sector on device dev.\r\n\/\/ If not found, allocate fresh block.\r\n\/\/ In either case, return locked buffer.\r\nstatic struct buf*\r\nbget(uint dev, uint sector)\r\n{\r\n  struct buf *b;\r\n\r\n  acquire(&amp;bcache.lock);\r\n\r\n loop:\r\n  \/\/ Try for cached block.\r\n  for(b = bcache.head.next; b != &amp;bcache.head; b = b-&gt;next){\r\n    if(b-&gt;dev == dev &amp;&amp; b-&gt;sector == sector){\r\n      if(!(b-&gt;flags &amp; B_BUSY)){\r\n        b-&gt;flags |= B_BUSY;\r\n        release(&amp;bcache.lock);\r\n        return b;\r\n      }\r\n      sleep(b, &amp;bcache.lock);\r\n      goto loop;\r\n    }\r\n  }\r\n\r\n  \/\/ Allocate fresh block.\r\n  for(b = bcache.head.prev; b != &amp;bcache.head; b = b-&gt;prev){\r\n    if((b-&gt;flags &amp; B_BUSY) == 0){\r\n      b-&gt;dev = dev;\r\n      b-&gt;sector = sector;\r\n      b-&gt;flags = B_BUSY;\r\n      release(&amp;bcache.lock);\r\n      return b;\r\n    }\r\n  }\r\n  panic(&quot;bget: no buffers&quot;);\r\n}\r\n\r\n\/\/ Return a B_BUSY buf with the contents of the indicated disk sector.\r\nstruct buf*\r\nbread(uint dev, uint sector)\r\n{\r\n  struct buf *b;\r\n\r\n  b = bget(dev, sector);\r\n  if(!(b-&gt;flags &amp; B_VALID))\r\n    iderw(b);\r\n  return b;\r\n}\r\n\r\n\/\/ Write b's contents to disk.  Must be locked.\r\nvoid\r\nbwrite(struct buf *b)\r\n{\r\n  if((b-&gt;flags &amp; B_BUSY) == 0)\r\n    panic(&quot;bwrite&quot;);\r\n  b-&gt;flags |= B_DIRTY;\r\n  iderw(b);\r\n}\r\n\r\n\/\/ Release the buffer b.\r\nvoid\r\nbrelse(struct buf *b)\r\n{\r\n  if((b-&gt;flags &amp; B_BUSY) == 0)\r\n    panic(&quot;brelse&quot;);\r\n\r\n  acquire(&amp;bcache.lock);\r\n\r\n  b-&gt;next-&gt;prev = b-&gt;prev;\r\n  b-&gt;prev-&gt;next = b-&gt;next;\r\n  b-&gt;next = bcache.head.next;\r\n  b-&gt;prev = &amp;bcache.head;\r\n  bcache.head.next-&gt;prev = b;\r\n  bcache.head.next = b;\r\n\r\n  b-&gt;flags &amp;= ~B_BUSY;\r\n  wakeup(b);\r\n\r\n  release(&amp;bcache.lock);\r\n}<\/pre>\n<p>\u30d0\u30c3\u30d5\u30a1\u306f3\u3064\u306e\u72b6\u614b\u30d5\u30e9\u30b0\u3092\u6301\u3064\u3002<br \/>\nB_VALID\u306f\u3001\u305d\u306e\u30d6\u30ed\u30c3\u30af\u306e\u6b63\u3057\u3044\u30b3\u30d4\u30fc\u3092\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u542b\u3080\u3053\u3068\u3092\u793a\u3059\u3002<br \/>\nB_DIRTY\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u306e\u5185\u5bb9\u304c\u5909\u66f4\u3055\u308c\u3001\u30c7\u30a3\u30b9\u30af\u3078\u66f8\u304d\u51fa\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u3092\u793a\u3059\u3002<br \/>\nB_BUSY\u306f\u3001\u3069\u3053\u304b\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u304c\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u53c2\u7167\u3057\u3066\u3044\u3066\u3001\u307e\u3060\u89e3\u653e\u3057\u3066\u306a\u3044\u3053\u3068\u3092\u793a\u3059\u3002<\/p>\n<p>bread\u95a2\u6570\u306f\u3001\u4e0e\u3048\u3089\u308c\u305f\u30bb\u30af\u30bf\u306e\u305f\u3081\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u5f97\u308b\u305f\u3081\u306bbget\u95a2\u6570\u3092\u547c\u3076\u3002<br \/>\n\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306e\u5185\u5bb9\u3092\u30c7\u30a3\u30b9\u30af\u304b\u3089\u8aad\u307f\u8fbc\u3080\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3001bread\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u8fd4\u3059\u524d\u306b\u3001iderw\u95a2\u6570\u3092\u547c\u3076\u3002<\/p>\n<p>bget\u95a2\u6570\u306f\u3001\u4e0e\u3048\u3089\u308c\u305f\u30c7\u30d0\u30a4\u30b9\u3068\u30bb\u30af\u30bf\u306b\u5bfe\u5fdc\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u3092\u635c\u3059\u305f\u3081\u306b\u30d0\u30c3\u30d5\u30a1\u306e\u30ea\u30b9\u30c8\u3092\u8d70\u67fb\u3059\u308b\u3002<br \/>\n\u5408\u81f4\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u3042\u308a\u3001\u304b\u3064\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304cB_BUSY\u3067\u306f\u306a\u3044\u5834\u5408\u3001bget\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306bB_BUSY\u30d5\u30e9\u30b0\u3092\u30bb\u30c3\u30c8\u3057\u8fd4\u3059\u3002<br \/>\n\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u5229\u7528\u4e2d\u306e\u5834\u5408\u3001bget\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u89e3\u653e\u3055\u308c\u308b\u306e\u3092\u5f85\u3064\u305f\u3081\u306b\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u30c1\u30e3\u30f3\u30cd\u30eb\u3068\u3057\u3066sleep\u3059\u308b\u3002<br \/>\nsleep\u304c\u8fd4\u3063\u3066\u304d\u305f\u3068\u304d\u3067\u3082\u3001bget\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u304c\u5229\u7528\u53ef\u80fd\u3067\u3042\u308b\u3068\u4eee\u5b9a\u3059\u308b\u3053\u3068\u306f\u51fa\u6765\u306a\u3044\u3002<br \/>\nsleep\u306f\u3001bcache.lock\u3092\u89e3\u653e\u3057\u518d\u7372\u5f97\u3059\u308b\u306e\u3067\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1b\u304c\u307e\u3060\u5229\u7528\u53ef\u80fd\u3067\u3042\u308b\u3068\u3044\u3046\u4fdd\u8a3c\u306f\u306a\u3044\u3002<br \/>\n\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u3001\u5225\u306e\u30bb\u30af\u30bf\u306e\u305f\u3081\u306b\u518d\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\nbget\u306f\u3001\u4eca\u56de\u3068\u306f\u9055\u3063\u305f\u7d50\u672b\u306b\u306a\u308b\u3067\u3042\u308d\u3046\u4e8b\u3092\u5e0c\u671b\u3057\u3066\u3001\u3084\u308a\u76f4\u3059\u3057\u304b\u306a\u3044\u3002\uff08goto loop;\u306e\u3068\u3053\u308d\uff09<\/p>\n<p>\uff08\u3053\u306e\u6bb5\u843d\u306e\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u76f4\u8a33\u98a8\u5473\u306b\u306a\u3063\u3066\u307e\u3059\u3002\u8a73\u7d30\u306f\u611f\u60f3\u306b\u66f8\u304d\u307e\u3059\u3002\uff09<br \/>\nbget\u306b\u3001\u3082\u3057goto\u6587\u304c\u306a\u304b\u3063\u305f\u3068\u3057\u305f\u3089\u3001\u56f35-3\u306e\u3088\u3046\u306a\u7af6\u5408\u72b6\u614b\u304c\u8d77\u304d\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\n\u6700\u521d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u3001\u3042\u308b\u30d0\u30c3\u30d5\u30a1\u3092\u6301\u3061\u3001\u305d\u3057\u3066\u305d\u306e\u4e2d\u306b\u30bb\u30af\u30bf3\u3092\u8aad\u307f\u8fbc\u307f\u3053\u3093\u3060\u3002<br \/>\n\u4eca2\u3064\u306e\u4ed6\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u3064\u3044\u3066\u304f\u308b\u3002<br \/>\n\u6700\u521d\u306e\u305d\u308c\u306f\u3001\u30d0\u30c3\u30d5\u30a13\u306e\u305f\u3081\u306b\u53d6\u5f97\u3092\u884c\u3044\u3001\u305d\u3057\u3066\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305f\u30d6\u30ed\u30c3\u30af\u306e\u305f\u3081\u306e\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u30b9\u30ea\u30fc\u30d7\u3059\u308b\u3002<br \/>\n2\u756a\u76ee\u306e\u305d\u308c\u306f\u3001\u30d0\u30c3\u30d5\u30a14\u306e\u305f\u3081\u306b\u53d6\u5f97\u3092\u884c\u3044\u3001\u65b0\u305f\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u305f\u30d6\u30ed\u30c3\u30af\u306e\u305f\u3081\u306e\u30eb\u30fc\u30d7\u306e\u4e2d\u4ee5\u5916\u306e\u540c\u3058\u30d0\u30c3\u30d5\u30a1\u4e0a\u3067\u30b9\u30ea\u30fc\u30d7\u51fa\u6765\u305f\u3002<br \/>\n\u306a\u305c\u306a\u3089\u3001\u7a7a\u304d\u30d0\u30c3\u30d5\u30a1\u304c\u306a\u304f\u3001\u305d\u3057\u30663\u3092\u4fdd\u6301\u3057\u3066\u3044\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u3001\u30ea\u30b9\u30c8\u306e\u6700\u524d\u9762\u3067\u3042\u308a\u3001\u518d\u5229\u7528\u306e\u305f\u3081\u306b\u9078\u629e\u3055\u308c\u305f\u304b\u3089\u3002<br \/>\n\u6700\u521d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u958b\u653e\u3057\u3001wakeup\u306f\u30d7\u30ed\u30bb\u30b93\u3092\u307e\u305a\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3059\u308b\u4e8b\u614b\u3092\u5f15\u304d\u8d77\u3053\u3057\u3001\u305d\u308c\u306f\u30d0\u30c3\u30d5\u30a1\u3092\u3064\u304b\u307f\u3001\u305d\u308c\u306b\u30bb\u30af\u30bf4\u3092\u8aad\u307f\u8fbc\u3080\u3060\u308d\u3046\u3002<br \/>\n\u305d\u308c\u304c\u5b8c\u4e86\u3059\u308b\u3068\u304d\u3001\u305d\u308c\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\uff08\u30bb\u30af\u30bf4\u3092\u542b\u3080\uff09\u3092\u89e3\u653e\u3057\u3001\u30d7\u30ed\u30bb\u30b92\u3092\u8d77\u3053\u3059\u3060\u308d\u3046\u3002<br \/>\ngoto\u6587\u306a\u3057\u306e\u30d7\u30ed\u30bb\u30b92\u306f\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092BUSY\u3068\u30de\u30fc\u30af\u3057\u3001\u305d\u3057\u3066bget\u304b\u3089\u623b\u308b\u3002<br \/>\n\u3057\u304b\u3057\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u30bb\u30af\u30bf3\u3067\u306f\u306a\u304f\u3001\u30bb\u30af\u30bf4\u3092\u542b\u3080\u3002<br \/>\n\u30bb\u30af\u30bf3\u3068\u30bb\u30af\u30bf4\u306f\u9055\u3046\u5185\u5bb9\u3092\u6301\u3064\u306e\u3067\u3001\u3053\u306e\u30a8\u30e9\u30fc\u306f\u69d8\u3005\u306a\u5927\u7834\u58ca\u3092\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\nxv6\u306f\u305d\u308c\u3089\u3092inode\u306e\u4fdd\u7ba1\u306b\u4f7f\u3063\u3066\u3044\u308b\u3002<\/p>\n<p><a href=\"https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05-300x194.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2012-03-31 1.04.05\" width=\"300\" height=\"194\" class=\"aligncenter size-medium wp-image-1591\" srcset=\"https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05-300x194.png 300w, https:\/\/peta.okechan.net\/blog\/wp-content\/uploads\/2012\/03\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2012-03-31-1.04.05.png 706w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n\u56f35-3 process 2\u306f\u30d6\u30ed\u30c3\u30af3\u306b\u3064\u3044\u3066\u554f\u3044\u5408\u308f\u305b\u305f\u306e\u306b\u3001\u7d50\u679c\u7684\u306b\u30d6\u30ed\u30c3\u30af4\u3092\u542b\u3080\u30d0\u30c3\u30d5\u30a1\u3092\u53d7\u3051\u53d6\u3063\u3066\u3057\u307e\u3046\u7af6\u5408\u306e\u4f8b<br \/>\n\uff08\u539f\u6587\u3067\u306f\u3001process 3\u306f\u301c\u3068\u306a\u3063\u3066\u308b\u3051\u3069\u591a\u5206\u9593\u9055\u3044\uff09<\/p>\n<p>\u4e0e\u3048\u3089\u308c\u305f\u30bb\u30af\u30bf\u306b\u5bfe\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u306a\u3044\u5834\u5408\u3001bget\u306f\u305d\u308c\u3092\u4f5c\u3089\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001\u5225\u306e\u30bb\u30af\u30bf\u3092\u4fdd\u6301\u3057\u3066\u305f\u30d0\u30c3\u30d5\u30a1\u3092\u51fa\u6765\u308b\u9650\u308a\u518d\u5229\u7528\u3059\u308b\u3002<br \/>\nbget\u306f\u3001\u3082\u3046\u4e00\u5ea6\u30d0\u30c3\u30d5\u30a1\u306e\u30ea\u30b9\u30c8\u3092\u8d70\u67fb\u3057\u3001B_BUSY\u3067\u306f\u306a\u3044\u30d6\u30ed\u30c3\u30af\uff08\u4f7f\u3048\u308b\u30d6\u30ed\u30c3\u30af\uff09\u3092\u635c\u3059\u3002<br \/>\nbget\u306f\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u8fd4\u3059\u524d\u306b\u3001\u65b0\u3057\u3044\u30c7\u30d0\u30a4\u30b9\u756a\u53f7\u3068\u30bb\u30af\u30bf\u756a\u53f7\u3092\u8a18\u9332\u3057\u3001\u5229\u7528\u4e2d\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3092\u30de\u30fc\u30af\u3059\u308b\u305f\u3081\u306b\u30d6\u30ed\u30c3\u30af\u306e\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u7de8\u96c6\u3059\u308b\u3002<br \/>\n\u3053\u306e\u30d5\u30e9\u30b0\u3078\u306e\u4ee3\u5165\u306f\u3001B_BUSY\u30d5\u30e9\u30b0\u3092\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3067\u306f\u306a\u304f\u3001B_VALID\u3084B_DIRTY\u30d5\u30e9\u30b0\u3082\u30af\u30ea\u30a2\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001bread\u304c\u4ee5\u524d\u306e\u30d6\u30ed\u30c3\u30af\u306e\u5185\u5bb9\u3092\u4f7f\u3046\u4e8b\u7121\u304f\u3001\u30c7\u30a3\u30b9\u30af\u304b\u3089\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306e\u30c7\u30fc\u30bf\u3092\u30ea\u30d5\u30ec\u30c3\u30b7\u30e5\u3059\u308b\u3053\u3068\u3092\u4fdd\u8a3c\u3059\u308b\u3002<\/p>\n<p>\u540c\u671f\u5316\u306e\u305f\u3081\u306b\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u4f7f\u308f\u308c\u308b\u306e\u3067\u3001\u30c7\u30a3\u30b9\u30af\u306e\u5404\u30bb\u30af\u30bf\u306b\u3064\u3044\u3066\u3001\u591a\u304f\u3066\u3082\u305f\u3063\u305f\u4e00\u3064\u306e\u30d0\u30c3\u30d5\u30a1\u3057\u304b\u5b58\u5728\u3057\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u91cd\u8981\u3067\u3042\u308b\u3002<br \/>\nbget\u306e\u6700\u521d\u306e\u30eb\u30fc\u30d7\u306f\u3001\u305d\u306e\u30bb\u30af\u30bf\u306b\u5bfe\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u304c\u65e2\u306b\u5b58\u5728\u3057\u3066\u3044\u306a\u3044\u3068\u6c7a\u5fc3\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u4ee3\u5165\uff08b-&gt;dev = dev; b-&gt;sector = sector; b-&gt;flags = B_BUSY;\uff09\u306f\u3001\u552f\u4e00\u306e\u5b89\u5168\u7b56\u3067\u3042\u308a\u3001\u305d\u3057\u3066bget\u306f\u305d\u308c\u4ee5\u6765bcache.lock\u3092\u624b\u653e\u3057\u3066\u3044\u306a\u3044\u3002\uff08\u8b0e\uff09<\/p>\n<p>\u3082\u3057\u3059\u3079\u3066\u306e\u30d0\u30c3\u30d5\u30a1\u304cB_BUSY\u306a\u5834\u5408\u3001\u4f55\u304b\u304a\u304b\u3057\u306a\u4e8b\u614b\u306b\u306a\u3063\u3066\u304a\u308a\u3001bget\u306fpanic\u3092\u547c\u3076\u3002<br \/>\n\u3082\u3063\u3068\u89aa\u5207\u306a\u53cd\u5fdc\u3068\u3057\u3066\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u306b\u7a7a\u304d\u304c\u51fa\u6765\u308b\u307e\u3067\u30b9\u30ea\u30fc\u30d7\u3059\u3079\u304d\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u3082\u3063\u3068\u3082\u3001\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u306e\u53ef\u80fd\u6027\u306f\u3042\u308b\u304c\u3002<\/p>\n<p>\u4e00\u5ea6bread\u304c\u3001\u547c\u3073\u51fa\u3057\u5074\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u8fd4\u3057\u305f\u3089\u3001\u547c\u3073\u51fa\u3057\u5074\u306f\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u306e\u72ec\u5360\u6a29\u3092\u6301\u3061\u3001\u30d0\u30a4\u30c8\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u66f8\u304d\u3067\u304d\u308b\u3002<br \/>\n\u547c\u3073\u51fa\u3057\u5074\u304c\u3001\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3093\u3060\u5834\u5408\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u89e3\u653e\u3059\u308b\u524d\u306b\u3001bwrite\u3092\u547c\u3093\u3067\u3001\u5909\u66f4\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u30c7\u30a3\u30b9\u30af\u306b\u66f8\u304d\u8fbc\u307e\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\nbwrite\u306f\u3001B_DIRTY\u30d5\u30e9\u30b0\u3092\u30bb\u30c3\u30c8\u3057\u3001\u305d\u3057\u3066\u30c7\u30a3\u30b9\u30af\u3078\u30d0\u30c3\u30d5\u30a1\u306e\u5185\u5bb9\u3092\u66f8\u304d\u8fbc\u3080\u305f\u3081\u306biderw\u3092\u547c\u3076\u3002<\/p>\n<p>\u547c\u3073\u51fa\u3057\u5074\u304c\u30d0\u30c3\u30d5\u30a1\u3092\u4f7f\u3044\u7d42\u308f\u3063\u305f\u3089\u3001\u30d0\u30c3\u30d5\u30a1\u3092\u89e3\u653e\u3059\u308b\u305f\u3081\u306bbrelse\u3092\u547c\u3076\u3079\u304d\u3067\u3042\u308b\u3002<br \/>\n\uff08brelse\u3068\u3044\u3046\u540d\u524d\u306f\u3001b-release\u306e\u77ed\u7e2e\u3067\u3001\u96a0\u8a9e\u3067\u306f\u3042\u308b\u304c\u899a\u3048\u3066\u304a\u304f\u4fa1\u5024\u304c\u3042\u308b\u3002Unix\u3092\u8d77\u6e90\u3068\u3057\u3001BSD\u3084Linux\u3084Solaris\u306a\u3069\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u3002\uff09<br \/>\nbrelse\u306f\u3001\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u30ea\u30f3\u30af\u30ea\u30b9\u30c8\u306e\u5143\u306e\u4f4d\u7f6e\u304b\u3089\u30ea\u30b9\u30c8\u306e\u6700\u524d\u306b\u79fb\u52d5\u3057\u3001B_BUSY\u30d5\u30e9\u30b0\u3092\u30af\u30ea\u30a2\u3057\u3001\u305d\u3057\u3066\u305d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u5f85\u3063\u3066\u30b9\u30ea\u30fc\u30d7\u3057\u3066\u308b\u3069\u3053\u304b\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8d77\u3053\u3059\u3002<br \/>\n\u30d0\u30c3\u30d5\u30a1\u306e\u79fb\u52d5\u306f\u3001\u6700\u8fd1\u4f7f\u308f\u308c\u305f\uff08\u89e3\u653e\u3055\u308c\u305f\u3068\u3044\u3046\u610f\u5473\u3067\uff09\u9806\u756a\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u4e26\u3073\u66ff\u3048\u308b\u52b9\u679c\u304c\u3042\u308b\u3002<br \/>\n\u30ea\u30b9\u30c8\u306e\u6700\u521d\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u3001\u4e00\u756a\u6700\u8fd1\u4f7f\u308f\u308c\u305f\u3082\u306e\u3067\u3042\u308a\u3001\u30ea\u30b9\u30c8\u306e\u6700\u5f8c\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u3001\u4f7f\u308f\u308c\u3066\u304b\u3089\u4e00\u756a\u6642\u9593\u304c\u7d4c\u3063\u3066\u3044\u308b\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\nbget\u306e2\u3064\u306e\u30eb\u30fc\u30d7\u306f\u3001\u3053\u306e\u512a\u4f4d\u6027\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3002<br \/>\n\u5b58\u5728\u3057\u3066\u3044\u308b\u30d0\u30c3\u30d5\u30a1\u306e\u8d70\u67fb\u306f\u3001\u6700\u60aa\u306e\u5834\u5408\u30ea\u30b9\u30c8\u306e\u3059\u3079\u3066\u3092\u51e6\u7406\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u304c\u3001\u6700\u8fd1\u4f7f\u308f\u308c\u305f\u30d0\u30c3\u30d5\u30a1\u3092\u5148\u306b\u8abf\u3079\u308b\u4e8b\uff08bcache.head\u304b\u3089\u306f\u3058\u3081\u3066next\u30dd\u30a4\u30f3\u30bf\u3092\u305f\u3069\u308b\u4e8b\uff09\u306f\u3001\u826f\u3044\u53c2\u7167\u306e\u5c40\u6240\u6027\u304c\u3042\u308b\u5834\u5408\u306b\u3001\u8d70\u67fb\u306b\u639b\u304b\u308b\u6642\u9593\u3092\u7bc0\u7d04\u3059\u308b\u3060\u308d\u3046\u3002<br \/>\n\u518d\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u9078\u3076\u305f\u3081\u306e\u8d70\u67fb\u306f\u3001\u9006\u9806\u306b\u8d70\u67fb\uff08prev\u30dd\u30a4\u30f3\u30bf\u3092\u305f\u3069\u308b\uff09\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u4f7f\u308f\u308c\u3066\u304b\u3089\u4e00\u756a\u6642\u9593\u304c\u7d4c\u3063\u3066\u3044\u308b\u3082\u306e\u304b\u3089\u8abf\u3079\u308b\u3002<\/p>\n<h3>\u611f\u60f3<\/h3>\n<p>\u30d0\u30c3\u30d5\u30a1\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b9f\u88c5\u306e\u8aac\u660e\u3067\u3059\u3002<\/p>\n<p>\u9014\u4e2d\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u3044\u3068\u66f8\u3044\u305f\u6bb5\u843d\u306b\u3064\u3044\u3066\u3002<br \/>\ngoto loop;\u304c\u306a\u3044\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u7af6\u5408\u72b6\u614b\u306e\u6a5f\u5e8f\u306b\u3064\u3044\u3066\u306e\u8aac\u660e\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3069\u3046\u8003\u3048\u3066\u3082\u66f8\u304b\u308c\u3066\u308b\u3088\u3046\u306a\u4e8b\u306f\u8d77\u304d\u306a\u3044\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ed6\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u3088\u3063\u3066bcache.head\u306e\u4f4d\u7f6e\u304c\u5909\u308f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067\u3001\u53d6\u308a\u3053\u307c\u3055\u306a\u3044\u3088\u3046\u521d\u3081\u304b\u3089\u518d\u30eb\u30fc\u30d7\u3059\u308b\u305f\u3081\u306bgoto loop;\u304c\u5fc5\u8981\u306a\u4e8b\u306f\u5206\u304b\u308a\u307e\u3059\u304c\u3001b-&gt;dev == dev &amp;&amp; b-&gt;sector == sector \u306e\u30c1\u30a7\u30c3\u30af\u306f\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u884c\u3063\u3066\u308b\u306e\u3067\u3001\u554f\u984c\u306a\u3044\u3068\u3044\u3046\u304b\u3001\u305d\u3082\u305d\u3082\u30bb\u30af\u30bf\u304c\u30c1\u30a7\u30c3\u30af\u3055\u308c\u3066\u308b\u306e\u3067\u3001\u5225\u306e\u30bb\u30af\u30bf\u3092\u5fc5\u8981\u3068\u3059\u308b\uff08\u56f3\u3067\u3044\u3046\u3068\u3053\u308d\u306e\uff09\u30d7\u30ed\u30bb\u30b92\u3068\u30d7\u30ed\u30bb\u30b93\u304c\u540c\u3058\u30d0\u30c3\u30d5\u30a1\u3092\u5f85\u3063\u3066\u30b9\u30ea\u30fc\u30d7\u3059\u308b\u3053\u3068\u306f\u306a\u3044\u306f\u305a\u3067\u3059\u3002<\/p>\n<p>\u3082\u3057\u30d7\u30ed\u30bb\u30b92\u304c\u30d7\u30ed\u30bb\u30b93\u3067\u5229\u7528\u4e2d\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u5f85\u3063\u3066\u30b9\u30ea\u30fc\u30d7\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3042\u308a\u5f97\u305f\u3068\u3057\u3066\u3082\u3001\u30d7\u30ed\u30bb\u30b93\u3067wakeup\u3055\u308c\u3066\u30d7\u30ed\u30bb\u30b92\u306esleep\u304c\u8fd4\u3063\u3066\u304d\u305f\u6bb5\u968e\u3067\u3001\u307e\u305fb-&gt;dev == dev &amp;&amp; b-&gt;sector == sector \u306e\u30c1\u30a7\u30c3\u30af\u304c\u884c\u308f\u308c\u3001\u305d\u308c\u306b\u5408\u81f4\u3057\u306a\u3044\u306e\u3067\uff08\u30bb\u30af\u30bf\u304c\u9055\u3046\u306e\u3067\uff09\u5358\u7d14\u306b\u305d\u306e\u30eb\u30fc\u30d7\u306f\u98db\u3070\u3055\u308c\u308b\u3060\u3051\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f55\u304b\u91cd\u5927\u306a\u52d8\u9055\u3044\u3092\u3057\u3066\u308b\u3093\u3060\u308d\u3046\u304b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[405],"class_list":["post-1590","post","type-post","status-publish","format-standard","hentry","category-tech","tag-xv6"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=1590"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1590\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=1590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=1590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=1590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}