page cache 在linux vfs 中是比较重要的一层,其功能就不详细介绍了。主要介绍了几个关键性函数,容易帮助了解page cache里的整体逻辑和流程先看一下page 的结构体
- /*
- * Each physical page in the system has a struct page associated with
- * it to keep track of whatever it is we are using the page for at the
- * moment. Note that we have no way to track which tasks are using
- * a page.
- */
- struct page {
- unsigned long flags; /* Atomic flags, some possibly
- * updated asynchronously */
- atomic_t _count; /* Usage count, see below. */
- atomic_t _mapcount; /* Count of ptes mapped in mms,
- * to show when page is mapped
- * & limit reverse map searches.
- */
- union {
- struct {
- unsigned long private; /* Mapping-private opaque data:
- * usually used for buffer_heads
- * if PagePrivate set; used for
- * swp_entry_t if PageSwapCache;
- * indicates order in the buddy
- * system if PG_buddy is set.
- */
- struct address_space *mapping; /* If low bit clear, points to
- * inode address_space, or NULL.
- * If page mapped as anonymous
- * memory, low bit is set, and
- * it points to anon_vma object:
- * see PAGE_MAPPING_ANON below.
- */
- };
- #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
- spinlock_t ptl;
- #endif
- };
- pgoff_t index; /* Our offset within mapping. */
- struct list_head lru; /* Pageout list, eg. active_list
- * protected by zone->lru_lock !
- */
- /*
- * On machines where all RAM is mapped into kernel address space,
- * we can simply calculate the virtual address. On machines with
- * highmem some memory is mapped into kernel virtual memory
- * dynamically, so we need a place to store that address.
- * Note that this field could be 16 bits on x86 ... ;)
- *
- * Architectures with slow multiplication can define
- * WANT_PAGE_VIRTUAL in asm/page.h
- */
- #if defined(WANT_PAGE_VIRTUAL)
- void *virtual; /* Kernel virtual address (NULL if
- not kmapped, ie. highmem) */
- #endif /* WANT_PAGE_VIRTUAL */
- };
page_cache_get() 主要是调用函数get_page
- static inline void get_page(struct page *page)
- {
- if (unlikely(PageCompound(page)))
- page = (struct page *)page_private(page);
- atomic_inc(&page->_count);
- }
主要page里的计数器+1,表示page引用的reference 次数
page_cache_release() 的核心函数 put_page_testzero
- static inline int put_page_testzero(struct page *page)
- {
- BUG_ON(atomic_read(&page->_count) == 0);
- return atomic_dec_and_test(&page->_count);
- }
显然是page的计数器-1, page的引用被释放
Linux RAMDisk 源码分析Linux Tmpfs 源码分析相关资讯 Linux基础教程
- Linux基础教程:对文件打包压缩 (03月08日)
- 基础教程:Linux 新手应该知道的 (09/06/2015 21:17:20)
- Linux基础教程:find 与 xargs (04/05/2015 10:20:11)
| - Linux基础教程:tar 命令使用介绍 (12/03/2015 13:19:47)
- Linux基础教程(1)操作系统基础 (08/15/2015 20:44:01)
- Linux基础教程:从源码安装软件 (04/05/2015 10:14:45)
|
本文评论 查看全部评论 (0)