Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
48aa9174
提交
48aa9174
8月 28, 2014
创建
作者:
Robert Morris
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
i think this is a working concurrent logging scheme
上级
71453f72
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
69 行增加
和
51 行删除
+69
-51
bio.c
bio.c
+2
-0
log.c
log.c
+19
-2
mkfs.c
mkfs.c
+1
-1
param.h
param.h
+3
-2
usertests.c
usertests.c
+44
-46
没有找到文件。
bio.c
浏览文件 @
48aa9174
...
...
@@ -80,6 +80,8 @@ bget(uint dev, uint sector)
}
// Not cached; recycle some non-busy and clean buffer.
// "clean" because B_DIRTY and !B_BUSY means log.c
// hasn't yet committed the changes to the buffer.
for
(
b
=
bcache
.
head
.
prev
;
b
!=
&
bcache
.
head
;
b
=
b
->
prev
){
if
((
b
->
flags
&
B_BUSY
)
==
0
&&
(
b
->
flags
&
B_DIRTY
)
==
0
){
b
->
dev
=
dev
;
...
...
log.c
浏览文件 @
48aa9174
...
...
@@ -52,6 +52,10 @@ struct log log;
static
void
recover_from_log
(
void
);
static
void
commit
();
// statistics, delete eventually XXX.
static
int
maxsize
;
static
int
maxoutstanding
;
void
initlog
(
void
)
{
...
...
@@ -131,10 +135,15 @@ begin_op(void)
while
(
1
){
if
(
log
.
committing
){
sleep
(
&
log
,
&
log
.
lock
);
}
else
if
(
log
.
lh
.
n
+
(
log
.
outstanding
+
1
)
*
MAXOPBLOCKS
>
LOGSIZE
){
// this op might exhaust log space; wait for commit.
sleep
(
&
log
,
&
log
.
lock
);
}
else
{
// XXX wait (for a commit) if log is longish.
// need to reserve to avoid over-commit of log space.
log
.
outstanding
+=
1
;
if
(
log
.
outstanding
>
maxoutstanding
){
maxoutstanding
=
log
.
outstanding
;
cprintf
(
"%d outstanding
\n
"
,
log
.
outstanding
);
}
release
(
&
log
.
lock
);
break
;
}
...
...
@@ -155,6 +164,9 @@ end_op(void)
if
(
log
.
outstanding
==
0
){
do_commit
=
1
;
log
.
committing
=
1
;
}
else
{
// begin_op() may be waiting for log space.
wakeup
(
&
log
);
}
release
(
&
log
.
lock
);
...
...
@@ -208,6 +220,11 @@ log_write(struct buf *b)
if
(
i
==
log
.
lh
.
n
)
log
.
lh
.
n
++
;
b
->
flags
|=
B_DIRTY
;
// XXX prevent eviction
if
(
log
.
lh
.
n
>
maxsize
){
maxsize
=
log
.
lh
.
n
;
cprintf
(
"log size %d/%d
\n
"
,
log
.
lh
.
n
,
LOGSIZE
);
}
}
//PAGEBREAK!
...
...
mkfs.c
浏览文件 @
48aa9174
...
...
@@ -13,7 +13,7 @@
#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
int
nblocks
=
985
;
int
nblocks
=
(
995
-
LOGSIZE
)
;
int
nlog
=
LOGSIZE
;
int
ninodes
=
200
;
int
size
=
1024
;
...
...
param.h
浏览文件 @
48aa9174
...
...
@@ -3,10 +3,11 @@
#define NCPU 8 // maximum number of CPUs
#define NOFILE 16 // open files per process
#define NFILE 100 // open files per system
#define NBUF 10 // size of disk block cache
#define NINODE 50 // maximum number of active i-nodes
#define NDEV 10 // maximum major device number
#define ROOTDEV 1 // device number of file system root disk
#define MAXARG 32 // max exec arguments
#define LOGSIZE 10 // max data sectors in on-disk log
#define MAXOPBLOCKS 10 // max # of blocks any FS op writes
#define LOGSIZE (MAXOPBLOCKS*3) // max data sectors in on-disk log
#define NBUF (MAXOPBLOCKS*3) // size of disk block cache (>= LOGSIZE)
usertests.c
浏览文件 @
48aa9174
...
...
@@ -512,18 +512,20 @@ sharedfd(void)
}
}
//
two processes write two
different files at the same
//
four processes write
different files at the same
// time, to test block allocation.
void
two
files
(
void
)
four
files
(
void
)
{
int
fd
,
pid
,
i
,
j
,
n
,
total
;
int
fd
,
pid
,
i
,
j
,
n
,
total
,
pi
;
char
*
names
[]
=
{
"f0"
,
"f1"
,
"f2"
,
"f3"
};
char
*
fname
;
printf
(
1
,
"
two
files test
\n
"
);
printf
(
1
,
"
four
files test
\n
"
);
unlink
(
"f1"
);
unlink
(
"f2"
);
for
(
pi
=
0
;
pi
<
4
;
pi
++
){
fname
=
names
[
pi
];
unlink
(
fname
);
pid
=
fork
();
if
(
pid
<
0
){
...
...
@@ -531,32 +533,35 @@ twofiles(void)
exit
();
}
fname
=
pid
?
"f1"
:
"f2"
;
if
(
pid
==
0
){
fd
=
open
(
fname
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
){
printf
(
1
,
"create failed
\n
"
);
exit
();
}
memset
(
buf
,
pid
?
'p'
:
'c'
,
512
);
memset
(
buf
,
'0'
+
pi
,
512
);
for
(
i
=
0
;
i
<
12
;
i
++
){
if
((
n
=
write
(
fd
,
buf
,
500
))
!=
500
){
printf
(
1
,
"write failed %d
\n
"
,
n
);
exit
();
}
}
close
(
fd
);
if
(
pid
)
wait
();
else
exit
();
}
}
for
(
pi
=
0
;
pi
<
4
;
pi
++
){
wait
();
}
for
(
i
=
0
;
i
<
2
;
i
++
){
fd
=
open
(
i
?
"f1"
:
"f2"
,
0
);
fname
=
names
[
i
];
fd
=
open
(
fname
,
0
);
total
=
0
;
while
((
n
=
read
(
fd
,
buf
,
sizeof
(
buf
)))
>
0
){
for
(
j
=
0
;
j
<
n
;
j
++
){
if
(
buf
[
j
]
!=
(
i
?
'p'
:
'c'
)
){
if
(
buf
[
j
]
!=
'0'
+
i
){
printf
(
1
,
"wrong char
\n
"
);
exit
();
}
...
...
@@ -568,30 +573,31 @@ twofiles(void)
printf
(
1
,
"wrong length %d
\n
"
,
total
);
exit
();
}
unlink
(
fname
);
}
unlink
(
"f1"
);
unlink
(
"f2"
);
printf
(
1
,
"twofiles ok
\n
"
);
printf
(
1
,
"fourfiles ok
\n
"
);
}
//
two
processes create and delete different files in same directory
//
four
processes create and delete different files in same directory
void
createdelete
(
void
)
{
enum
{
N
=
20
};
int
pid
,
i
,
fd
;
int
pid
,
i
,
fd
,
pi
;
char
name
[
32
];
printf
(
1
,
"createdelete test
\n
"
);
for
(
pi
=
0
;
pi
<
4
;
pi
++
){
pid
=
fork
();
if
(
pid
<
0
){
printf
(
1
,
"fork failed
\n
"
);
exit
();
}
name
[
0
]
=
pid
?
'p'
:
'c'
;
if
(
pid
==
0
){
name
[
0
]
=
'p'
+
pi
;
name
[
2
]
=
'\0'
;
for
(
i
=
0
;
i
<
N
;
i
++
){
name
[
1
]
=
'0'
+
i
;
...
...
@@ -609,14 +615,18 @@ createdelete(void)
}
}
}
if
(
pid
==
0
)
exit
();
else
}
}
for
(
pi
=
0
;
pi
<
4
;
pi
++
){
wait
();
}
name
[
0
]
=
name
[
1
]
=
name
[
2
]
=
0
;
for
(
i
=
0
;
i
<
N
;
i
++
){
name
[
0
]
=
'p'
;
for
(
pi
=
0
;
pi
<
4
;
pi
++
){
name
[
0
]
=
'p'
+
pi
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
0
);
if
((
i
==
0
||
i
>=
N
/
2
)
&&
fd
<
0
){
...
...
@@ -628,27 +638,15 @@ createdelete(void)
}
if
(
fd
>=
0
)
close
(
fd
);
name
[
0
]
=
'c'
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
0
);
if
((
i
==
0
||
i
>=
N
/
2
)
&&
fd
<
0
){
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
exit
();
}
else
if
((
i
>=
1
&&
i
<
N
/
2
)
&&
fd
>=
0
){
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
exit
();
}
if
(
fd
>=
0
)
close
(
fd
);
}
for
(
i
=
0
;
i
<
N
;
i
++
){
name
[
0
]
=
'p'
;
for
(
pi
=
0
;
pi
<
4
;
pi
++
){
name
[
0
]
=
'p'
+
i
;
name
[
1
]
=
'0'
+
i
;
unlink
(
name
);
name
[
0
]
=
'c'
;
unlink
(
name
);
}
}
printf
(
1
,
"createdelete ok
\n
"
);
...
...
@@ -1716,6 +1714,12 @@ main(int argc, char *argv[])
}
close
(
open
(
"usertests.ran"
,
O_CREATE
));
createdelete
();
linkunlink
();
concreate
();
fourfiles
();
sharedfd
();
bigargtest
();
bigwrite
();
bigargtest
();
...
...
@@ -1741,18 +1745,12 @@ main(int argc, char *argv[])
fourteen
();
bigfile
();
subdir
();
concreate
();
linkunlink
();
linktest
();
unlinkread
();
createdelete
();
twofiles
();
sharedfd
();
dirfile
();
iref
();
forktest
();
bigdir
();
// slow
exectest
();
exit
();
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论