提交 731ffe8e 创建 作者: Robert Morris's avatar Robert Morris

start of name cache

上级 e3f5ef60
......@@ -5,6 +5,7 @@ OBJS = \
exec.o\
file.o\
fs.o\
namecache.o\
ide.o\
ioapic.o\
kalloc.o\
......
......@@ -43,6 +43,7 @@ int filewrite(struct file*, char*, int n);
int dirlink(struct inode*, char*, uint);
struct inode* dirlookup(struct inode*, char*, uint*);
struct inode* ialloc(uint, short);
struct inode* iget(uint dev, uint inum);
struct inode* idup(struct inode*);
void iinit(void);
void ilock(struct inode*);
......@@ -197,6 +198,12 @@ int copyin(struct vmap *, uint, void*, uint);
int pagefault(struct vmap *, uint, uint);
void clearpages(pde_t *pgdir, void *begin, void *end);
// namecache.c
void nc_init();
struct inode * nc_lookup(struct inode *, char *);
void nc_insert(struct inode *, char *, struct inode *);
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
#define NULL 0
......@@ -146,8 +146,6 @@ iinit(void)
}
}
static struct inode* iget(uint dev, uint inum);
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct inode*
......@@ -195,7 +193,7 @@ iupdate(struct inode *ip)
// Find the inode with number inum on device dev
// and return the in-memory copy.
static struct inode*
struct inode*
iget(uint dev, uint inum)
{
struct inode *ip, *empty;
......@@ -587,21 +585,28 @@ namex(char *path, int nameiparent, char *name)
ip = idup(proc->cwd);
while((path = skipelem(path, name)) != 0){
ilock(ip);
if(ip->type != T_DIR){
iunlockput(ip);
return 0;
}
if(nameiparent && *path == '\0'){
// Stop one level early.
iunlock(ip);
return ip;
}
if((next = dirlookup(ip, name, 0)) == 0){
// XXX do we need to ilock(ip)?
// hopefully not, would be nice to have
// lock-free namecache hits.
next = nc_lookup(ip, name);
if(next == 0){
ilock(ip);
if(ip->type != T_DIR){
iunlockput(ip);
return 0;
}
if(nameiparent && *path == '\0'){
// Stop one level early.
iunlock(ip);
return ip;
}
if((next = dirlookup(ip, name, 0)) == 0){
iunlockput(ip);
return 0;
}
nc_insert(ip, name, next);
iunlockput(ip);
return 0;
}
iunlockput(ip);
ip = next;
}
if(nameiparent){
......
......@@ -105,8 +105,12 @@ kalloc(void)
}
if (r == 0) {
cprintf("kalloc: out of memory");
kmemprint();
return 0;
#if 0
panic("out of memory");
#endif
}
mtrace_label_register(mtrace_label_block,
......@@ -182,7 +186,7 @@ morecore(uint nu)
nu = 512; // we allocate nu * sizeof(Header)
}
p = kalloc();
if(p == (char*)-1)
if(p == 0)
return 0;
hp = (Header*)p;
hp->s.size = nu;
......
......@@ -69,7 +69,7 @@ allocproc(void)
// Allocate kernel stack if possible.
if((p->kstack = kalloc()) == 0){
p->state = UNUSED;
kmfree(p);
return 0;
}
sp = p->kstack + KSTACKSIZE;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论