Linux块设备IO子系统(二)(3)

page就是内核中页描述符,通过radix树的操作,我们最终可以找到一组page,这组page归属于一个inode。我们可以看到其中的pgoff_t index成员,用来表示当前页在整组高速缓存页中的索引。至此,我们就通过一个文件的inode找到了它拥有的页高速缓存,接接下来就是使用块设备驱动实现相应的页缓存和磁盘的数据交互。

44 struct page { 48 union { 49 struct address_space *mapping; /* If low bit clear, points to 57 }; 59 /* Second double word */ 60 struct { 61 union { 62 pgoff_t index; /* Our offset within mapping. */ 73 }; 121 }; 198 }

页高速缓存的基本操作是增删查更,在此基础上可以封装更高级的API

增加page static inline int add_to_page_cache(struct page *page, struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask) 删除page void delete_from_page_cache(struct page *page) 查找page struct page *find_get_page(struct address_space *mapping, pgoff_t offset) unsigned find_get_pages(struct address_space *mapping, pgoff_t start,unsigned int nr_pages, struct page **pages) //抢不到锁会阻塞 struct page *find_lock_page(struct address_space *mapping, pgoff_t offset) //抢不到锁立即返回try??? //抢不到锁会阻塞,但是如果页不存在就创建新的 struct page *find_or_create_page(struct address_space *mapping,pgoff_t index, gfp_t gfp_mask) 更新page truct page *read_cache_page(struct address_space *mapping,pgoff_t index,int (*filler)(void *, struct page *),void *data) 从page 到 block

block即是那个VFS或文件系统中的最小逻辑操作单位,一个页高速缓存可以由几个block构成,他们之间的关系如下:

Linux块设备IO子系统(二)

buffer_head

每个块缓冲区都有相应的buffer_head对象描述,该描述符包含内核必须了解的,有关如何处理块的所有信息,

62 struct buffer_head { 63 unsigned long b_state; /* buffer state bitmap (see above) */ 64 struct buffer_head *b_this_page;/* circular list of page's buffers */ 65 struct page *b_page; /* the page this bh is mapped to */ 66 67 sector_t b_blocknr; /* start block number */ 68 size_t b_size; /* size of mapping */ 69 char *b_data; /* pointer to data within the page */ 70 71 struct block_device *b_bdev; 72 bh_end_io_t *b_end_io; /* I/O completion */ 73 void *b_private; /* reserved for b_end_io */ 74 struct list_head b_assoc_buffers; /* associated with another mapping */ 75 struct address_space *b_assoc_map; /* mapping this buffer is 76 associated with */ 77 atomic_t b_count; /* users using this buffer_head */ 78 };

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4ca64b8b1a5f9dbca329cf4c31e7b0aa.html