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

keep track of inode cache size

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