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

start of name cache

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