Skip to content

Commit

Permalink
buffer cache, fifo replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm committed Aug 12, 2006
1 parent 7ce01cf commit 14938f9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Notes
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,6 @@ HMM maybe the variables at the end of struct cpu are being overwritten

OH! recursive interrupts will use up any amount of cpu[].stack!
underflow and wrecks *previous* cpu's struct

better buffer cache replacement
read/write of open file that's been unlinked
23 changes: 19 additions & 4 deletions bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,31 @@ struct buf *
getblk(uint dev, uint sector)
{
struct buf *b;
static struct buf *scan = buf;
int i;

acquire(&buf_table_lock);

while(1){
for(b = buf; b < buf+NBUF; b++)
if((b->flags & B_BUSY) && b->dev == dev && b->sector)
if((b->flags & (B_BUSY|B_VALID)) && b->dev == dev && b->sector == sector)
break;

if(b < buf+NBUF){
sleep(buf, &buf_table_lock);
if(b->flags & B_BUSY){
sleep(buf, &buf_table_lock);
} else {
b->flags |= B_BUSY;
release(&buf_table_lock);
return b;
}
} else {
for(b = buf; b < buf+NBUF; b++){
for(i = 0; i < NBUF; i++){
b = scan++;
if(scan >= buf+NBUF)
scan = buf;
if((b->flags & B_BUSY) == 0){
b->flags |= B_BUSY;
b->flags = B_BUSY;
b->dev = dev;
b->sector = sector;
release(&buf_table_lock);
Expand All @@ -53,11 +64,14 @@ bread(uint dev, uint sector)
extern struct spinlock ide_lock;

b = getblk(dev, sector);
if(b->flags & B_VALID)
return b;

acquire(&ide_lock);
c = ide_start_rw(dev & 0xff, sector, b->data, 1, 1);
sleep (c, &ide_lock);
ide_finish(c);
b->flags |= B_VALID;
release(&ide_lock);

return b;
Expand All @@ -73,6 +87,7 @@ bwrite(uint dev, struct buf *b, uint sector)
c = ide_start_rw(dev & 0xff, sector, b->data, 1, 0);
sleep (c, &ide_lock);
ide_finish(c);
b->flags |= B_VALID;
release(&ide_lock);
}

Expand Down
1 change: 1 addition & 0 deletions buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ struct buf {
uchar data[512];
};
#define B_BUSY 0x1
#define B_VALID 0x2
2 changes: 1 addition & 1 deletion usertests.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ main(int argc, char *argv[])
{
puts("usertests starting\n");

unlinkread();
//unlinkread();
createdelete();
twofiles();
sharedfd();
Expand Down

0 comments on commit 14938f9

Please sign in to comment.