提交 d5fd5fdd 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

keep track of inode cache size

上级 022104b1
...@@ -133,18 +133,14 @@ bfree(int dev, uint b) ...@@ -133,18 +133,14 @@ bfree(int dev, uint b)
static struct ns *ins; static struct ns *ins;
static struct { uint x __attribute__((aligned (CACHELINE))); } icache_free[NCPU];
void void
iinit(void) iinit(void)
{ {
ins = nsalloc(0); ins = nsalloc(0);
for (int i = 0; i < NINODE; i++) { for (int i = 0; i < NCPU; i++)
struct inode *ip = kmalloc(sizeof(*ip)); icache_free[i].x = NINODE;
memset(ip, 0, sizeof(*ip));
ip->inum = -i-1;
initlock(&ip->lock, "icache-lock");
initcondvar(&ip->cv, "icache-cv");
ns_insert(ins, KII(ip->dev, ip->inum), ip);
}
} }
//PAGEBREAK! //PAGEBREAK!
...@@ -271,6 +267,8 @@ iget(uint dev, uint inum) ...@@ -271,6 +267,8 @@ iget(uint dev, uint inum)
// Allocate fresh inode cache slot. // Allocate fresh inode cache slot.
retry_evict: retry_evict:
(void) 0; (void) 0;
uint cur_free = icache_free[cpu->id].x;
if (cur_free == 0) {
struct inode *victim = ns_enumerate(ins, evict, 0); struct inode *victim = ns_enumerate(ins, evict, 0);
if (!victim) if (!victim)
panic("iget out of space"); panic("iget out of space");
...@@ -284,6 +282,10 @@ iget(uint dev, uint inum) ...@@ -284,6 +282,10 @@ iget(uint dev, uint inum)
release(&victim->lock); release(&victim->lock);
ns_remove(ins, KII(victim->dev, victim->inum), victim); ns_remove(ins, KII(victim->dev, victim->inum), victim);
rcu_delayed(victim, ifree); rcu_delayed(victim, ifree);
} else {
if (!__sync_bool_compare_and_swap(&icache_free[cpu->id].x, cur_free, cur_free-1))
goto retry_evict;
}
ip = kmalloc(sizeof(*ip)); ip = kmalloc(sizeof(*ip));
ip->dev = dev; ip->dev = dev;
...@@ -380,6 +382,8 @@ iput(struct inode *ip) ...@@ -380,6 +382,8 @@ iput(struct inode *ip)
release(&ip->lock); release(&ip->lock);
return; return;
} }
release(&ip->lock);
ns_remove(ins, KII(ip->dev, ip->inum), ip);
itrunc(ip); itrunc(ip);
ip->type = 0; ip->type = 0;
...@@ -388,9 +392,8 @@ iput(struct inode *ip) ...@@ -388,9 +392,8 @@ iput(struct inode *ip)
ip->gen += 1; ip->gen += 1;
iupdate(ip); iupdate(ip);
release(&ip->lock);
ns_remove(ins, KII(ip->dev, ip->inum), ip);
rcu_delayed(ip, ifree); rcu_delayed(ip, ifree);
__sync_fetch_and_add(&icache_free[cpu->id].x, 1);
return; return;
} }
release(&ip->lock); release(&ip->lock);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论