|
|
Log in / Subscribe / Register

VFS write barriers

Please consider subscribing to LWN

Subscriptions are the lifeblood of LWN.net. If you appreciate this content and would like to see more of it, your subscription will help to ensure that LWN continues to thrive. Please visit this page to join up and keep LWN on the net.

By Jake Edge
April 23, 2025

LSFMM+BPF

In the filesystem track at the 2025 Linux Storage, Filesystem, Memory Management, and BPF Summit (LSFMM+BPF), Amir Goldstein wanted to resume discussing a feature that he had briefly introduced at the end of a 2023 summit session: filesystem "write barriers". The idea is to have an operation that would wait for any in-flight write() system calls, but not block any new write() calls as bigger hammers, such as freezing the filesystem, would do. His prototype implementation is used by a hierarchical storage management (HSM) system to create a crash-consistent change log, but there may be other use cases to consider. He wanted to discuss implementation options and the possibility of providing an API for user-space applications.

[Amir Goldstein]

Goldstein began by saying that he is working on a persistent change journal that is similar to what NTFS and Lustre provide; it records file changes, like events from inotify and fanotify provide, but they are written to disk so that they survive a reboot or crash. He would like to work on a generic solution that is independent of any specific filesystem. He implemented the feature several years ago, as overlayfs watch, which his employer is using in production; overlayfs is not tied to a specific filesystem for its lower layers, so the feature is filesystem-independent. He never thought it made sense to get overlayfs watch into the upstream kernel, but that could perhaps be an option as well.

It came later in the session, after a question from Jeff Layton, that Goldstein's use case is for users with a "very large data set" who need cloud synchronization, replication, and other features. The typical application wants to be able to do something, "it doesn't matter what", whenever there is a change to the filesystem; his company's application uses it to sync data to and from the cloud. In his application, the change journal records information to ensure that all filesystem changes are noted; it is used to avoid scanning the whole filesystem when the system is rebooted.

He wants to make it possible to create the change journal from user space, perhaps implemented as a library that can provide the facility for any filesystem. There are a few requirements for such a journal, he said. It is meant to track changes, such as when a file is created in a directory. User space needs to get a blocking notification (which blocks further progress on the operation until user space responds) before the change is written to disk, as a kind of "intent to change" event, so that it can be written to the journal. After that, there needs to be an event indicating that the change has been done, which consumers can only see after the requisite filesystem changes have been made. He would like to do this with a VFS API so that it is independent of the filesystem type.

His first proposed mechanism is with two new fanotify events. The first is FAN_PRE_MODIFY that is the "intent to change" event; it has sufficient information for recording the change in the journal. It is rare that only a single change is being done, he said; typically, there are multiple changes, to both metadata and file data, that are all signaled with the event. Once the changes are actually made, the "intent to change" has been completed and gets signaled with a FAN_POST_MODIFY event; then any consumer can read the changed data.

Part of the information that gets sent with the event is a sequence number, which is needed so that the server can match up the events. Multiple threads could be making changes affecting the same directories, so a sequence number is needed to distinguish pairs of events.

A different way to implement the feature was suggested by Jan Kara, Goldstein said; it would not require a sequence number because there is no need to notify user space that the change event has completed. Instead, the FAN_PRE_MODIFY is sent and the filesystem changes are made using sleepable read-copy-update (RCU); when user space wants to read, it makes a system call (perhaps called vfs_write_barrier()), which waits for all of the changes that were notified to complete. User space can then consume the batch of changes that have been made, without blocking any new changes from happening.

David Howells asked what would happen if one of the changes failed after it had been notified. Goldstein said that false notifications are not a problem, as the server does not "need to get the truth". The change journal is not a journal that gets replayed, it simply records that something may have changed in the directory. It is not recording any data, just the directory where changes may have happened. In his application, there are millions of files, so scanning for changes is not practical; "you need to not miss changes and you need to not have races".

James Bottomley asked what was consuming the change journal. It can be used in various ways, Goldstein said, and there are filesystems that have the feature already. His application uses the journal after a reboot to ensure that the state of the filesystem is known; the journal is also periodically cleared once its entries have been processed. The pre-modification event is needed to ensure that changes get into the journal before the filesystem is modified, he said.

He believes there is a need for the feature beyond his use case. There are likely others doing similar things, he said, using unreliable or probabilistic ways to detect that changes have occurred. He noted that the file change time (ctime) is modified in a way that is problematic for NFS; it is done before the change is made on disk, so the client may observe the change before it has actually occurred, which means it can get out of sync. Layton agreed, suggesting that it would make sense to bump the ctime before and after a change, since the second operation will generally be a no-op.

Concerns about performance were raised by several attendees. Goldstein said that there is some overhead, but that it is not large. If the feature is not of general interest, though, he can keep maintaining it in his tree. He does think there are other use cases for it, however; right now, filesystem indexing is relying on luck to a certain extent. He could not find another mechanism in Linux to ensure that the list of changes is consistent, which is why he has been working on it. He asked for preferences between the two options, a second event for change completion or a write barrier using sleepable RCU, but got crickets in response.

An attendee asked about network filesystems and whether the notifications would work in that environment. There is a general problem with any kind of file notifications (inotify, fanotify) on the client side, Goldstein said, which needs to be solved at some point. On the server side, the usual mechanisms can be used, and the change-journal notification could also be used if it gets merged, but there is no way to communicate notification information to a client.


Index entries for this article
KernelFilesystems
ConferenceStorage, Filesystem, Memory-Management and BPF Summit/2025


to post comments

Pretty useful feature

Posted Apr 23, 2025 20:50 UTC (Wed) by bearstech (subscriber, #160755) [Link] (4 responses)

I stumbled upon large RAID5/6 arrays with rotating disks where the +1 million directories barrier is a big problem. I really mean directories, not files, VFS operations are hard to scale wrt. directories. For tasks like syncing/backuping, maintaining stats, etc : taking +10 hours, killing prod perf even ioniced+1-depth-queue.

I think the feature discussed in this article would greatly help.

And you can't slip a drbd underneath an already existing fs, while you often face a system that was not planned with the feature. Note that even drbd only solves the sync problem, not the other ones (I'd really love to be able to maintain specific stats, or even maybe a sqlite-based view of the directories to be able to make general queries about large storages, or a top-like tool to show/analyze fs activity, etc).

You also can't slip LVM underneath an existing blockdev, where LVM snapshot could be useful to work directly on a frozen image of the fs. And LVM snapshots cost more write ops. I once used this trick (snapshot) with libe2fs where you can easily scan linearly the fs structure, build a full fs/dirent view in a few dozen seconds instead of a few dozen hours via the VFS API. That's both an interesting and frustrating experience, since it seems to be kind of doable to traverse your whole filesystem in a snap, while it's _very_ hard with the VFS API.

SSD caching?

Posted Apr 23, 2025 22:12 UTC (Wed) by DemiMarie (subscriber, #164188) [Link] (3 responses)

Does it really make sense to have such a large filesystem entirely on spinning disks? Would dm-cache help?

SSD caching?

Posted Apr 24, 2025 7:56 UTC (Thu) by bearstech (subscriber, #160755) [Link] (2 responses)

In my world large and slow RAID arrays do exist, even in a virtual form (like a VM with a +10 TB attached volume, where the networked nature of those volumes do not help with op latency, and serialization on directory ops neither). It can be complex or expensive to change those legacy systems (quite often they should move to object storage but that's a massive overhaul all over the codebase).

In one case I used bcache, but it has the same problem : it must be configured before the volume goes live, you can't slip ip later underneath an existing blockdev. And bcache did help with the prodution workload, but did not make a difference for regular fs maintenance task, AFAIK because precisely there are 1/ low frequency thus uncached ops, 2/ traverse all metadata (thus even those which are never used by the production workload) and 3/ only once. In the end, I tend to use fadvise-once for those low freq ops to try not to pollute the production cache and its hot dataset.

I don't think caching can solve those "fs maintenance tasks", unless I could make sure I could dedicate a cache for dirents. I have a few storage systems with lots of RAM and tried to put vm.vfs_cache_pressure low but it barely helped, Linux did not kept all dirent in cache altough it would mathematically fit on those systems. And if it worked, I woud stil be left with an horrible experience for the first fs traversal after a reboot.

SSD caching?

Posted Apr 24, 2025 21:02 UTC (Thu) by zdzichu (subscriber, #17118) [Link] (1 responses)

Note that you CAN add LVM or bcache to existing devices - https://github.com/g2p/blocks

Sometimes you need to shrink the fs, but it's trivial.

SSD caching?

Posted Apr 24, 2025 21:31 UTC (Thu) by koverstreet (subscriber, #4296) [Link]

That thing scares me...

rsync

Posted Apr 24, 2025 5:46 UTC (Thu) by pabs (subscriber, #43278) [Link] (1 responses)

The change journal idea sounds useful for repeated rsync of a large directory, like mirroring a distro or set of git trees.

There is also the lsyncd daemon, but it obviously doesn't work across reboots or daemon restarts and uses inotify rather than fanotify.

https://github.com/axkibe/lsyncd

rsync

Posted Apr 24, 2025 8:03 UTC (Thu) by bearstech (subscriber, #160755) [Link]

I've used lsyncd, it does use inotify wich needs 1/ one watch per dir, 2/ to add/remove watches as dir go and leave. It does not scale well with large fs withs lots of dirs and lots of activity.

And when you restart it, you don't know how many changes you missed, thus you have to rescan the whole fs, which does even make it less useful (have a libc/lua/rsync security update ? Boom, restart, filer load goes up to the sky for hours)

Scaling and not missing events is the key, and I hope what's discussed in this article is a proper solution :).

Not block barriers again?

Posted Apr 24, 2025 12:02 UTC (Thu) by joib (subscriber, #8541) [Link]

First I thought this was an attempt to reintroduce block barriers, which were ejected from the kernel with much fanfare roughly a decade and a half ago (https://lwn.net/Articles/400541/ ). But it seems this is a higher level concept, and doesn't touch the block layer at all.

bcachefs is going to have this, and you really want this baked into the filesystem

Posted Apr 24, 2025 14:09 UTC (Thu) by koverstreet (subscriber, #4296) [Link] (2 responses)

trying to maintain one database based on hooks from another database, and maintain any sort of transactional correctness - yeesh.

We've already got "change tracking" today, in the form of the rebalance_work btree. It's fast, low overhead, and it works at extent granularity.

We're going to need to generalize this for send/recv, and there's real demand for user defined auxiliary indices in the filesystem, for a variety of purposes (user defined indices on xattrs is another that's on my radar).

bcachefs is going to have this, and you really want this baked into the filesystem

Posted Apr 24, 2025 16:34 UTC (Thu) by DemiMarie (subscriber, #164188) [Link] (1 responses)

Could this be used for desktop search?

bcachefs is going to have this, and you really want this baked into the filesystem

Posted Apr 24, 2025 17:19 UTC (Thu) by koverstreet (subscriber, #4296) [Link]

user defined indexes on xattrs? yep.

BeFS pioneered them, and I know of people with massive archival datasets who use them as well.


Copyright © 2025, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds