简体   繁体   English

如何在文件系统中执行条件 IO?

[英]How to perform conditional IO in the file system?

I'm trying to implement a multi-user key-value store over the file system, such as the local Linux or Windows file system, or a network-based one (SMB or NFS).我正在尝试在文件系统上实现多用户键值存储,例如本地 Linux 或 Windows 文件系统,或基于网络的文件系统(SMB 或 NFS)。 My intent is to fully avoid the need of a server because servers require some VM, deployment, upgrades, etc. And filesystems are typically readily available.我的意图是完全避免对服务器的需求,因为服务器需要一些 VM、部署、升级等。文件系统通常很容易获得。

The engine returns the timestamp of when the value was set.引擎返回设置值的时间戳。 One operation that uses the timestamp is "put if not modified since", which is similar to compare-and-swap and supports synchronization among processes.使用时间戳的一种操作是“put if not modified since”,类似于比较和交换,支持进程之间的同步。 It turns out that this is quite costly to implement without a server.事实证明,在没有服务器的情况下实现这一点非常昂贵。

It seems that no file system supports "write if not modified" or any form of conditional write semantics.似乎没有文件系统支持“不修改就写入”或任何形式的条件写入语义。 At best I can lock a file, but then I need to read the date and compare inside the process, and only then write the new content and release the lock.充其量我可以锁定一个文件,但是我需要读取日期并在进程内部进行比较,然后才写入新内容并释放锁定。 The minimum number of IOs to implement is four: 1) lock entire file; IOs 的最小实现数是四个: 1) 锁定整个文件; 2) read modification date and compare locally; 2)读取修改日期并在本地进行比较; 3) write the new content; 3)编写新内容; 4) unlock. 4) 解锁。 And this ignores the IOs to open and close the file, which are pooled so they will be less frequent.这忽略了 IOs 来打开和关闭文件,这些文件是池化的,因此它们的频率会降低。

Is there any OS or filesystem facility, or algorithm that could reduce the number of IOs?是否有任何操作系统或文件系统工具或算法可以减少 IOs 的数量? Please remember that I need the solution to work over NFS or SMB...请记住,我需要通过 NFS 或 SMB 工作的解决方案......

Thanks谢谢

Filesystems already do read-ahead and write avoidance, so I/O calls will only block for disk when read data is not in cache or write cache is full and a flush is required.文件系统已经做了预读和写避免,所以 I/O 调用只会在读取数据不在缓存中或写入缓存已满并且需要刷新时才会阻塞磁盘。 The performance problem with the "write if not modified since" is the 4 syscalls, which can get expensive. “如果不修改则写入”的性能问题是 4 个系统调用,这可能会变得昂贵。 One way to fix this would be to add a conditional write kernel module.解决此问题的一种方法是添加条件写入 kernel 模块。 You would pass it the timestamp, file name, and data.您将向它传递时间戳、文件名和数据。 It would do the conditional write using internal calls and callbacks, and return the status and new timestamp, reducing the overhead to a single syscall.它将使用内部调用和回调进行条件写入,并返回状态和新时间戳,从而减少单个系统调用的开销。 Properly written, it should be filesystem-agnostic.正确编写,它应该与文件系统无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅在文件存在且仅在文件不存在时才如何在Linux中执行开放系统调用? - How to perform open system call in linux only if file exists and only if file doesn't exists? unix域套接字执行任何文件系统读写吗? - does unix domain socket perform any file system read write? 为什么使用fio后我的文件系统已满(flexible IO) - why my file system is full after use fio(flexible IO) System.IO.DirectoryNotFoundException 在 Linux 中保存文件时 - System.IO.DirectoryNotFoundException when saving file in Linux 如何初始化文件系统? - How to initialize a file system? 停电期间文件操作如何执行 - How file manipulations perform during power outage 通过另一个程序读取文件并执行操作,并使用系统调用将 output 保存在单独的文件中 - read a file and perform operation through another program and save the output in a separate file using system calls 如何将system()的输出重定向到文件? - How to redirect the output of system() to a file? System.IO.FileNotFoundException:无法加载文件或程序集'FluentAssertions,版本 = 5.10.3.0 - System.IO.FileNotFoundException: Could not load file or assembly 'FluentAssertions, Version=5.10.3.0 如何在文件系统中找到循环? - how to find a loop in the file system?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM