linux page有两个非常重要的引用计数字段_refcount和_mapcount,都是atomic_t类型,其中,_refcount表示内核中应用该page的次数。当_refcount = 0时,表示该page为空闲或者将要被释放。当_refcount > 0,表示该page页面已经被分配且内核正在使用,暂时不会被释放。
_refcount
内核中常用的加减_refcount应用计数的API:get_page()和put_page()
static inline void get_page(struct page *page)
{
page = compound_head(page);
/*
* Getting a normal page or the head of a compound page
* requires to already have an elevated page->_refcount.
*/
VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);
page_ref_inc(page);
}
static inline void put_page(struct page *page)
{
page = compound_head(page);
/*
* For private device pages we need to catch refcount transition from
* 2 to 1, when refcount reach one it means the private device page is
* free and we need to inform the device driver through callback. See
* include/linux/memremap.h and HMM for details.
*/
if (IS_HMM_ENABLED && unlikely(is_device_private

文章详细介绍了Linux内核中_page结构的_refcount和_mapcount字段,它们用于跟踪页面的使用状态。_refcount表示页面的引用次数,当为0时可能被释放;_mapcount则表示页面被映射到进程的次数。在不同场景如alloc_pages、add_to_page_cache_lru、pagecache以及进程间共享时,这两个计数器会相应增加。read/write系统调用生成的pagecache_mapcount通常是-1,因为它们不直接映射到用户空间页表。
最低0.47元/天 解锁文章
1014

被折叠的 条评论
为什么被折叠?



