Permalink
Browse files

don't let dirty blocks be evicted from cache!

  • Loading branch information...
Robert Morris
Robert Morris committed Oct 14, 2011
1 parent 38eee5b commit 12abb1a56164a0d71fb7a76a465c912409f2f60b
Showing with 15 additions and 4 deletions.
  1. +2 −2 bio.c
  2. +6 −2 file.c
  3. +1 −0 log.c
  4. +6 −0 sysfile.c
View
4 bio.c
@@ -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){
- if((b->flags & B_BUSY) == 0){
+ if((b->flags & B_BUSY) == 0 && (b->flags & B_DIRTY) == 0){
b->dev = dev;
b->sector = sector;
b->flags = B_BUSY;
View
8 file.c
@@ -1,3 +1,7 @@
+//
+// File descriptors
+//
+
#include "types.h"
#include "defs.h"
#include "param.h"
@@ -87,7 +91,7 @@ filestat(struct file *f, struct stat *st)
return -1;
}
-// Read from file f. Addr is kernel address.
+// Read from file f.
int
fileread(struct file *f, char *addr, int n)
{
@@ -108,7 +112,7 @@ fileread(struct file *f, char *addr, int n)
}
//PAGEBREAK!
-// Write to file f. Addr is kernel address.
+// Write to file f.
int
filewrite(struct file *f, char *addr, int n)
{
View
1 log.c
@@ -177,6 +177,7 @@ log_write(struct buf *b)
brelse(lbuf);
if (i == log.lh.n)
log.lh.n++;
+ b->flags |= B_DIRTY; // XXX prevent eviction
}
//PAGEBREAK!
View
@@ -1,3 +1,9 @@
+//
+// 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 "defs.h"
#include "param.h"

0 comments on commit 12abb1a

Please sign in to comment.