提交 12abb1a5 创建 作者: Robert Morris's avatar Robert Morris

don't let dirty blocks be evicted from cache!

上级 38eee5bc
...@@ -79,9 +79,9 @@ bget(uint dev, uint sector) ...@@ -79,9 +79,9 @@ bget(uint dev, uint sector)
} }
} }
// Not cached; recycle some existing buffer. // Not cached; recycle some non-busy and clean buffer.
for(b = bcache.head.prev; b != &bcache.head; b = b->prev){ for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
if((b->flags & B_BUSY) == 0){ if((b->flags & B_BUSY) == 0 && (b->flags & B_DIRTY) == 0){
b->dev = dev; b->dev = dev;
b->sector = sector; b->sector = sector;
b->flags = B_BUSY; b->flags = B_BUSY;
......
//
// File descriptors
//
#include "types.h" #include "types.h"
#include "defs.h" #include "defs.h"
#include "param.h" #include "param.h"
...@@ -87,7 +91,7 @@ filestat(struct file *f, struct stat *st) ...@@ -87,7 +91,7 @@ filestat(struct file *f, struct stat *st)
return -1; return -1;
} }
// Read from file f. Addr is kernel address. // Read from file f.
int int
fileread(struct file *f, char *addr, int n) fileread(struct file *f, char *addr, int n)
{ {
...@@ -108,7 +112,7 @@ fileread(struct file *f, char *addr, int n) ...@@ -108,7 +112,7 @@ fileread(struct file *f, char *addr, int n)
} }
//PAGEBREAK! //PAGEBREAK!
// Write to file f. Addr is kernel address. // Write to file f.
int int
filewrite(struct file *f, char *addr, int n) filewrite(struct file *f, char *addr, int n)
{ {
......
...@@ -177,6 +177,7 @@ log_write(struct buf *b) ...@@ -177,6 +177,7 @@ log_write(struct buf *b)
brelse(lbuf); brelse(lbuf);
if (i == log.lh.n) if (i == log.lh.n)
log.lh.n++; log.lh.n++;
b->flags |= B_DIRTY; // XXX prevent eviction
} }
//PAGEBREAK! //PAGEBREAK!
......
//
// File-system system calls.
// Mostly argument checking, since we don't trust
// user code, and calls into file.c and fs.c.
//
#include "types.h" #include "types.h"
#include "defs.h" #include "defs.h"
#include "param.h" #include "param.h"
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论