内存管理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; }
相关文章推荐
- 内存管理API之get_zeroed_page
- 内存管理API之page_address
- 内存管理API之kmem_cache_free
- Linux-0.11内核内存管理get_free_page()函数分析
- 内存管理API之kmem_cache_create
- 内存管理API之kmem_cache_destroy
- 内存管理API之__get_vm_area
- 内存管理API之kmem_cache_zalloc
- 使用API获取文件内部存储路径详解(getFilesDir()和getCacheDir())
- Linux内存管理之kmalloc 与 __get_free_page()
- Linux内存管理之kmalloc 与 __get_free_page()
- Linux内存管理之kmalloc 与 __get_free_page()
- Linux内存管理之kmalloc 与 __get_free_page()
- Linux内存管理之kmalloc 与 __get_free_page()
- Linux-0.11内核源码分析系列:内存管理get_empty_page()与put_page()函数分析
- [Happy Coding] malloc/kmalloc/vmalloc/slab cache/__get_free_page
- 内存管理API之get_vm_area_size
- Linux内存管理之kmalloc 与 __get_free_page()
- 内存管理API之get_unmapped_area
- Linux内存管理之kmalloc 与 __get_free_page()