发新话题
打印

缓存的问题

缓存的问题

  陈老师能不能谈谈buffer cache 和page cache的区别和联系!
在学习的过程中,对这两个缓存比较模糊,希望陈老师能联系个具体的例子谈谈。
谢谢!

TOP

buffer cache:当一个块被调入内存时,它首先存放在一个缓冲区中,每个缓冲区与一个块对应,它相当于磁盘块在内存中的表示,每个缓冲区都有一个对应的描述符,叫做buffer_head。缓冲区头的目的在于描述磁盘块和物理内存缓冲区之间的映射关系。因此,缓冲区头作为I/O操作的单元,不仅描述了从磁盘到物理内存的映射,而且还是所有块I/O操作的容器。但是,2。6中,I/O操作系统基本容器变为bio结构了。

Page Cache是由内存中的物理页组成的,缓存中的每一页对应着磁盘中的多个块。其核心数据结构为address_space。在执行I/O操作,比如 read()操作,内核首先会检查数据是否已经在页高速缓存中,如果在,那么内核就可以马上从页高速缓存中得到所需要的页,而不需要从磁盘中读取数据了。

从中你可以体会到二者之间的区别了吗?
透析真谛,似拨云穿雾;共享智慧,如春风沐浴
http://www.kerneltravel.net

TOP

注意逻辑页与物理页的区别;
buffer cache 和page cache的联系:page cache它是VFS的需要,buffer cache它是面向设备的,buffer cache是以块为单位的,属于设备驱动层,page cache是以页为 单位的,属于文件系统层,策略不同,联系不同,还可能没联系,内核中在多处使用了page cache策略,比如页面交换、磁盘 文件的读取。
swap cache ?????研究吧

TOP

系统在读磁盘文件时,是以块为单位读取,并放在内存中(buffer cache),由buffer_head或bio记录其映射信息。由几个快构成一页(page cache),由address space记录页内容和inode(文件)之间的联系。这样理解对不对?请陈老师指点!谢谢!

TOP

你的理解加上黄富强的解释,方向对了。更深入的理解还是要看bio结构和address_space结构。
透析真谛,似拨云穿雾;共享智慧,如春风沐浴
http://www.kerneltravel.net

TOP

struct address_space {
385         struct inode            *host;          /* owner: inode, block_device */
386         struct radix_tree_root  page_tree;      /* radix tree of all pages */
387         rwlock_t                tree_lock;      /* and rwlock protecting it */
388         unsigned int            i_mmap_writable;/* count VM_SHARED mappings */
389         struct prio_tree_root   i_mmap;         /* tree of private and shared mappings */
390         struct list_head        i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
391         spinlock_t              i_mmap_lock;    /* protect tree, count, list */
392         unsigned int            truncate_count; /* Cover race condition with truncate */
393         unsigned long           nrpages;        /* number of total pages */
394         pgoff_t                 writeback_index;/* writeback starts here */
395         struct address_space_operations *a_ops; /* methods */
396         unsigned long           flags;          /* error bits/gfp mask */
397         struct backing_dev_info *backing_dev_info; /* device readahead, etc */
398         spinlock_t              private_lock;   /* for use by the address_space */
399         struct list_head        private_list;   /* ditto */
400         struct address_space    *assoc_mapping; /* ditto */
401 }
struct buffer_head {
58         unsigned long b_state;          /* buffer state bitmap (see above) */
59         struct buffer_head *b_this_page;/* circular list of page's buffers */
60         struct page *b_page;            /* the page this bh is mapped to */
61
62         sector_t b_blocknr;             /* start block number */
63         size_t b_size;                  /* size of mapping */
64         char *b_data;                   /* pointer to data within the page */
65
66         struct block_device *b_bdev;
67         bh_end_io_t *b_end_io;          /* I/O completion */
68         void *b_private;                /* reserved for b_end_io */
69         struct list_head b_assoc_buffers; /* associated with another mapping */
70         atomic_t b_count;               /* users using this buffer_head */
71 }
struct bio {
73         sector_t                bi_sector;
74         struct bio              *bi_next;       /* request queue link */
75         struct block_device     *bi_bdev;
76         unsigned long           bi_flags;       /* status, command, etc */
77         unsigned long           bi_rw;          /* bottom bits READ/WRITE,
78                                                  * top bits priority
79                                                  */
80
81         unsigned short          bi_vcnt;        /* how many bio_vec's */
82         unsigned short          bi_idx;         /* current index into bvl_vec */
83
84         /* Number of segments in this BIO after
85          * physical address coalescing is performed.
86          */
87         unsigned short          bi_phys_segments;
88
89         /* Number of segments after physical and DMA remapping
90          * hardware coalescing is performed.
91          */
92         unsigned short          bi_hw_segments;
93
94         unsigned int            bi_size;        /* residual I/O count */
95
96         /*
97          * To keep track of the max hw size, we account for the
98          * sizes of the first and last virtually mergeable segments
99          * in this bio
100          */
101         unsigned int            bi_hw_front_size;
102         unsigned int            bi_hw_back_size;
103
104         unsigned int            bi_max_vecs;    /* max bvl_vecs we can hold */
105
106         struct bio_vec          *bi_io_vec;     /* the actual vec list */
107
108         bio_end_io_t            *bi_end_io;
109         atomic_t                bi_cnt;         /* pin count */
110
111         void                    *bi_private;
112
113         bio_destructor_t        *bi_destructor; /* destructor */
114 }
**********
http://lxr.linux.no/source/block/?v=2.6.18
redesigned block layer:2.6......>技术改进提升I/O性能。
The kernel eliminates the bounce buffer used when performing I/O into high memory.
It uses per-request queue lock in replace of the global I/O requst lock.
The buffer_head structure, which represents I/O requests, is replaced by new data structure named bio.

TOP

很深奥,要一点点学

TOP

发新话题