Linux虚拟文件系统(内核初始化<二>)
| [日期:2012-02-09] |
来源:Linux社区
作者:bullbat |
[字体:大 中 小]
|
-
-
-
-
-
-
-
-
- static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
- {
- LIST_HEAD(referenced);
- LIST_HEAD(tmp);
- struct dentry *dentry;
- int cnt = 0;
-
- BUG_ON(!sb);
- BUG_ON((flags & DCACHE_REFERENCED) && count == NULL);
- spin_lock(&dcache_lock);
- if (count != NULL)
-
- cnt = *count;
- restart:
- if (count == NULL)
- list_splice_init(&sb->s_dentry_lru, &tmp);
- else {
- while (!list_empty(&sb->s_dentry_lru)) {
- dentry = list_entry(sb->s_dentry_lru.prev,
- struct dentry, d_lru);
- BUG_ON(dentry->d_sb != sb);
-
- spin_lock(&dentry->d_lock);
-
-
-
-
-
-
- if ((flags & DCACHE_REFERENCED)
- && (dentry->d_flags & DCACHE_REFERENCED)) {
- dentry->d_flags &= ~DCACHE_REFERENCED;
- list_move(&dentry->d_lru, &referenced);
- spin_unlock(&dentry->d_lock);
- } else {
-
- list_move_tail(&dentry->d_lru, &tmp);
- spin_unlock(&dentry->d_lock);
- cnt--;
- if (!cnt)
- break;
- }
- cond_resched_lock(&dcache_lock);
- }
- }
-
- while (!list_empty(&tmp)) {
- dentry = list_entry(tmp.prev, struct dentry, d_lru);
-
- dentry_lru_del_init(dentry);
- spin_lock(&dentry->d_lock);
-
-
-
-
-
- if (atomic_read(&dentry->d_count)) {
- spin_unlock(&dentry->d_lock);
- continue;
- }
- prune_one_dentry(dentry);
-
- cond_resched_lock(&dcache_lock);
- }
- if (count == NULL && !list_empty(&sb->s_dentry_lru))
- goto restart;
- if (count != NULL)
- *count = cnt;
- if (!list_empty(&referenced))
- list_splice(&referenced, &sb->s_dentry_lru);
- spin_unlock(&dcache_lock);
- }
- static void dentry_lru_del_init(struct dentry *dentry)
- {
- if (likely(!list_empty(&dentry->d_lru))) {
- list_del_init(&dentry->d_lru);
- dentry->d_sb->s_nr_dentry_unused--;
- dentry_stat.nr_unused--;
- }
- }
- /*
- * Throw away a dentry - free the inode, dput the parent. This requires that
- * the LRU list has already been removed.
- *
- * Try to prune ancestors as well. This is necessary to prevent
- * quadratic behavior of shrink_dcache_parent(), but is also expected
- * to be beneficial in reducing dentry cache fragmentation.
- */
- static void prune_one_dentry(struct dentry * dentry)
- __releases(dentry->d_lock)
- __releases(dcache_lock)
- __acquires(dcache_lock)
- {
- __d_drop(dentry);
- dentry = d_kill(dentry);/*释放dentry*/
-
- /*
- * Prune ancestors. Locking is simpler than in dput(),
- * because dcache_lock needs to be taken anyway.
- */
- spin_lock(&dcache_lock);
- while (dentry) {
- if (!atomic_dec_and_lock(&dentry->d_count, &dentry->d_lock))
- return;
-
- if (dentry->d_op && dentry->d_op->d_delete)
- dentry->d_op->d_delete(dentry);
- dentry_lru_del_init(dentry);
- __d_drop(dentry);
- dentry = d_kill(dentry);
- spin_lock(&dcache_lock);
- }
- }

评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
|
|