Buffer Cache

Overview

The buffer cache is a linked list of buf structures holding cached copies of disk block contents.

Caching disk blocks in memory reduces the number of disk reads and also provides a synchronization point for disk blocks used by multiple processes.

Role

1. Sync access to disk blocks to ensure only one copy of a block in memory and only one kernel thread can use this copy.

2. Cache popular blocks See bio.c

Source code

struct buf {
  int valid;   // has data been read from disk?
  int disk;    // does disk “own” buf?
  uint dev;
  uint blockno;
  struct sleeplock lock;
  uint refcnt;
  struct buf *prev; // LRU cache list
  struct buf *next;
  uchar data[BSIZE];
};

Last updated

Was this helpful?