Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
cd93074e
Commit
cd93074e
authored
18 years ago
by
rtm
Browse files
Options
Downloads
Patches
Plain Diff
LRU disk cache replacement
parent
22bac2cb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Notes
+8
-0
8 additions, 0 deletions
Notes
bio.c
+28
-9
28 additions, 9 deletions
bio.c
buf.h
+2
-0
2 additions, 0 deletions
buf.h
fs.c
+1
-1
1 addition, 1 deletion
fs.c
usertests.c
+12
-2
12 additions, 2 deletions
usertests.c
with
51 additions
and
12 deletions
Notes
+
8
−
0
View file @
cd93074e
...
...
@@ -357,3 +357,11 @@ OH! recursive interrupts will use up any amount of cpu[].stack!
better buffer cache replacement
read/write of open file that's been unlinked
disk scheduling
mkdir
more than one directory content block
sh arguments
sh redirection
indirect blocks
two bugs in unlink
how come unlink xxx fails? iput problem?
This diff is collapsed.
Click to expand it.
bio.c
+
28
−
9
View file @
cd93074e
...
...
@@ -10,27 +10,41 @@
struct
buf
buf
[
NBUF
];
struct
spinlock
buf_table_lock
;
// linked list of all buffers, through prev/next.
// bufhead->next is most recently used.
// bufhead->tail is least recently used.
struct
buf
bufhead
;
void
binit
(
void
)
{
struct
buf
*
b
;
initlock
(
&
buf_table_lock
,
"buf_table"
);
bufhead
.
prev
=
&
bufhead
;
bufhead
.
next
=
&
bufhead
;
for
(
b
=
buf
;
b
<
buf
+
NBUF
;
b
++
){
b
->
next
=
bufhead
.
next
;
b
->
prev
=
&
bufhead
;
bufhead
.
next
->
prev
=
b
;
bufhead
.
next
=
b
;
}
}
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
++
)
for
(
b
=
buf
head
.
next
;
b
!=
&
bufhead
;
b
=
b
->
next
)
if
((
b
->
flags
&
(
B_BUSY
|
B_VALID
))
&&
b
->
dev
==
dev
&&
b
->
sector
==
sector
)
break
;
if
(
b
<
buf
+
NBUF
){
if
(
b
!=
&
bufhead
){
if
(
b
->
flags
&
B_BUSY
){
sleep
(
buf
,
&
buf_table_lock
);
}
else
{
...
...
@@ -39,10 +53,7 @@ getblk(uint dev, uint sector)
return
b
;
}
}
else
{
for
(
i
=
0
;
i
<
NBUF
;
i
++
){
b
=
scan
++
;
if
(
scan
>=
buf
+
NBUF
)
scan
=
buf
;
for
(
b
=
bufhead
.
prev
;
b
!=
&
bufhead
;
b
=
b
->
prev
){
if
((
b
->
flags
&
B_BUSY
)
==
0
){
b
->
flags
=
B_BUSY
;
b
->
dev
=
dev
;
...
...
@@ -64,8 +75,9 @@ bread(uint dev, uint sector)
extern
struct
spinlock
ide_lock
;
b
=
getblk
(
dev
,
sector
);
if
(
b
->
flags
&
B_VALID
)
if
(
b
->
flags
&
B_VALID
)
{
return
b
;
}
acquire
(
&
ide_lock
);
c
=
ide_start_rw
(
dev
&
0xff
,
sector
,
b
->
data
,
1
,
1
);
...
...
@@ -99,6 +111,13 @@ brelse(struct buf *b)
acquire
(
&
buf_table_lock
);
b
->
next
->
prev
=
b
->
prev
;
b
->
prev
->
next
=
b
->
next
;
b
->
next
=
bufhead
.
next
;
b
->
prev
=
&
bufhead
;
bufhead
.
next
->
prev
=
b
;
bufhead
.
next
=
b
;
b
->
flags
&=
~
B_BUSY
;
wakeup
(
buf
);
...
...
This diff is collapsed.
Click to expand it.
buf.h
+
2
−
0
View file @
cd93074e
...
...
@@ -2,6 +2,8 @@ struct buf {
int
flags
;
uint
dev
;
uint
sector
;
struct
buf
*
prev
;
struct
buf
*
next
;
uchar
data
[
512
];
};
#define B_BUSY 0x1
...
...
This diff is collapsed.
Click to expand it.
fs.c
+
1
−
1
View file @
cd93074e
...
...
@@ -505,7 +505,7 @@ unlink(char *cp)
if
((
ip
=
namei
(
cp
,
&
pinum
))
==
0
)
{
cprintf
(
"
file to be unlinked
doesn't exist
\n
"
);
cprintf
(
"
unlink(%s) it
doesn't exist
\n
"
,
cp
);
return
-
1
;
}
...
...
This diff is collapsed.
Click to expand it.
usertests.c
+
12
−
2
View file @
cd93074e
...
...
@@ -303,7 +303,7 @@ createdelete()
void
unlinkread
()
{
int
fd
;
int
fd
,
fd1
;
fd
=
open
(
"unlinkread"
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
){
...
...
@@ -322,15 +322,25 @@ unlinkread()
puts
(
"unlink unlinkread failed
\n
"
);
exit
();
}
fd1
=
open
(
"xxx"
,
O_CREATE
|
O_RDWR
);
write
(
fd1
,
"yyy"
,
3
);
close
(
fd1
);
if
(
read
(
fd
,
buf
,
sizeof
(
buf
))
!=
5
){
puts
(
"unlinkread read failed"
);
exit
();
}
if
(
buf
[
0
]
!=
'h'
){
puts
(
"unlinkread wrong data
\n
"
);
exit
();
}
if
(
write
(
fd
,
buf
,
10
)
!=
10
){
puts
(
"unlinkread write failed
\n
"
);
exit
();
}
close
(
fd
);
unlink
(
"xxx"
);
puts
(
"unlinkread ok
\n
"
);
}
...
...
@@ -339,7 +349,7 @@ main(int argc, char *argv[])
{
puts
(
"usertests starting
\n
"
);
//
unlinkread();
unlinkread
();
createdelete
();
twofiles
();
sharedfd
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment