您的位置:首页 > 其它

内存管理API之page_cache_get_speculative

2018-02-03 08:13 791 查看
inline int page_cache_get_speculative(struct page *page)主要用于锁定page,如果page的引用计数是1的话,就返回0,如果引用计数已经是零,
就增加page的引用计数后,返回1
其源码分析如下:

static inline int page_cache_get_speculative(struct page *page)
{
#ifdef CONFIG_TINY_RCU
# ifdef CONFIG_PREEMPT_COUNT
VM_BUG_ON(!in_atomic() && !irqs_disabled());
# endif
/*
* Preempt must be disabled here - we rely on rcu_read_lock doing
* this for us.
*
* Pagecache won't be truncated from interrupt context, so if we have
* found a page in the radix tree here, we have pinned its refcount by
* disabling preempt, and hence no need for the "speculative get" that
* SMP requires.
*/
#在这种case下 下线断言page_count 不能为零,然后增加page的引用计数
VM_BUG_ON_PAGE(page_count(page) == 0, page);
page_ref_inc(page);

#else
#get_page_unless_zero线判断page的引用计数是否为零,如果为零就增加引用计数,否则啥也不做
if (unlikely(!get_page_unless_zero(page))) {
/*
* Either the page has been freed, or will be freed.
* In either case, retry here and the caller should
* do the right thing (see comments above).
*/
#这种case是page的引用计数是1,没有增加引用计数的case
return 0;
}
#endif
VM_BUG_ON_PAGE(PageTail(page), page);
#这种case就增加page的引用计数
return 1;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: