- 论坛徽章:
- 0
|
本帖最后由 blake326 于 2012-04-28 14:36 编辑
回复 3# GFree_Wind
void fput(struct file *file)
{
if (atomic_long_dec_and_test(&file->f_count))
__fput(file);
}
static void __fput(struct file *file)
{
file_free(file);
}
static inline void file_free_rcu(struct rcu_head *head)
{
struct file *f = container_of(head, struct file, f_u.fu_rcuhead);
put_cred(f->f_cred);
kmem_cache_free(filp_cachep, f);
}
static inline void file_free(struct file *f)
{
percpu_counter_dec(&nr_files);
file_check_state(f);
call_rcu(&f->f_u.fu_rcuhead, file_free_rcu);
}
一般一个内核路径打开一个file初始化f_count=1,close的时候f_count=0,然后释放,这个时候管它什么共享的子进程,父进程的时候,f_count=0,了,大家都不用它了,谁还会访问它.这个时候直接释放到slab cache有何不可呢?
并且,我也没有看出file变量是rcu变量,因为本身修改file的某个属性时,并没有先去拷贝它然后再修改什么的。
|
|