注意
本文档适用于 Ceph 开发版本。
懒惰 I/O
LazyIO 放松了 POSIX 语义。即使文件被多个应用程序在多个客户端上打开,也允许缓冲读取/写入。应用程序需要自行管理缓存一致性。
Libcephfs 自 nautilus 版本起支持 LazyIO。
启用 LazyIO
LazyIO 可以通过以下方式启用。
client_force_lazyio
该选项为 libcephfs 和 ceph-fuse 挂载启用全局 LAZY_IO。ceph_lazyio(...)
和ceph_ll_lazyio(...)
为 libcephfs 中的文件句柄启用 LAZY_IO。
使用 LazyIO
LazyIO 包括两种方法。lazyio_propagate()
和lazyio_synchronize()
.lazyio_propagate()
时才会可见。读取可能来自本地缓存(无论其他客户端对文件所做的更改),直到调用lazyio_synchronize()
时才会从更新后的文件中读取。
lazyio_propagate(int fd, loff_t offset, size_t count)
- 确保客户端在特定区域(偏移量到偏移量+计数)的任何缓冲写入都已传播到共享文件。如果偏移量和计数都为 0,则操作将在整个文件上执行。目前仅支持此操作。lazyio_synchronize(int fd, loff_t offset, size_t count)
- 确保客户端在后续的读取调用中能够读取所有其他客户端传播的写入的更新文件。在 CephFS 中,这是通过使无效与 inode 相关的文件缓存来实现的,从而迫使客户端从更新后的文件中重新获取/缓存数据。此外,如果调用客户端的写入缓存是脏的(未传播),lazyio_synchronize() 也会将其刷新。
下面给出一个使用 libcephfs 的示例用法。这是一个并行应用程序中特定客户端/文件描述符的示例 I/O 循环:
/* Client a (ca) opens the shared file file.txt */
int fda = ceph_open(ca, "shared_file.txt", O_CREAT|O_RDWR, 0644);
/* Enable LazyIO for fda */
ceph_lazyio(ca, fda, 1));
for(i = 0; i < num_iters; i++) {
char out_buf[] = "fooooooooo";
ceph_write(ca, fda, out_buf, sizeof(out_buf), i);
/* Propagate the writes associated with fda to the backing storage*/
ceph_propagate(ca, fda, 0, 0);
/* The barrier makes sure changes associated with all file descriptors
are propagated so that there is certainty that the backing file
is up to date */
application_specific_barrier();
char in_buf[40];
/* Calling ceph_lazyio_synchronize here will ascertain that ca will
read the updated file with the propagated changes and not read
stale cached data */
ceph_lazyio_synchronize(ca, fda, 0, 0);
ceph_read(ca, fda, in_buf, sizeof(in_buf), 0);
/* A barrier is required here before returning to the next write
phase so as to avoid overwriting the portion of the shared file still
being read by another file descriptor */
application_specific_barrier();
}
由 Ceph 基金会带给您
Ceph 文档是一个社区资源,由非盈利的 Ceph 基金会资助和托管Ceph Foundation. 如果您想支持这一点和我们的其他工作,请考虑加入现在加入.