|
|
Log in / Subscribe / Register

Supporting larger block sizes in filesystems

By Jake Edge
May 22, 2024

LSFMM+BPF

In a combined storage and filesystem session at the 2024 Linux Storage, Filesystem, Memory Management, and BPF Summit, Luis Chamberlain led a discussion on filesystem support for block sizes larger than the usual 4KB page size, which followed up on discussion from last year. While the session was meant to look at the intersection of larger block sizes with atomic block writes that avoid torn (partial) writes (which was also discussed last year), it mostly focused on the filesystem side. Over time, the block sizes offered by storage devices have risen from the original 512 bytes; Chamberlain wanted to discuss filesystem support for block sizes larger than 4KB.

[Luis Chamberlain]

Chamberlain started by saying that he wanted to gauge the interest of filesystem developers in adding large-block support to their filesystems; in order to do so, a filesystem needs to be able to support large folios. The next obvious targets for this work are bcachefs and EROFS. Matthew Wilcox said that the large-folio support for EROFS is mostly done at this point, though there are a few places where it still uses struct page, for decompression in particular. For supporting large block sizes, EROFS is ready, he said, but the full folio-conversion job is not yet complete.

Adding this support will require a lot of testing, Chamberlain said; beyond that, fstests has some baked-in assumptions about block size that need to be fixed. Some of those problems were found when testing with page sizes larger than 4KB, so they have been fixed at this point, but others may be lurking. He warned that filesystems with their own test suites may also have those kinds of assumptions.

Damien Le Moal said that zonefs developers are also interested in adding support for large block sizes. There are no fstests for zonefs, which Chamberlain suggested would be a useful addition to the suite. But Wilcox noted that zonefs uses iomap, so there is probably little work that needs to be done. It is mostly a matter of making a few calls to tell iomap that zonefs wants to use large folios. Le Moal said that large-folio support was being actively worked on for zonefs and was close to being ready.

Iomap only handles the data path, Jan Kara pointed out, not the metadata path, which will still need more work for large blocks. Chamberlain agreed that was an outstanding problem. He wondered if filesystem developers even wanted to tackle it, because if they did not, there was not much point in going down the large-block path.

Josef Bacik said that Btrfs is backward from other filesystems; by default it uses 16KB blocks for metadata, so it is the data path that needs converting. The plan is for Btrfs to switch to using iomap, then to turn on support for large folios "and pray". At that point, though, Btrfs should be able to use larger blocks. The iomap conversion is in progress, with direct I/O working now; buffered I/O is next. The support for the metadata follows what XFS has done, Bacik said.

That led Dave Chinner to suggest that the XFS buffer-cache code be turned into a library that other filesystems can also use. Iomap came out of a similar process. Chamberlain wondered what other filesystems could benefit. Chinner said that any filesystem that uses the (deprecated) buffer heads API; the XFS buffer cache can support up to 64KB block sizes and already uses large folios. It could be pulled out of XFS, as it is already fairly generic; it is a wrapper around the page and slab allocators that provides compound buffers, which are made up of multiple discontiguous blocks but treated as a single contiguous buffer. Filesystems like ext4 that use buffer heads could be adapted to use this buffer cache in a fairly straightforward way.

Neal Gompa thanked the developers working on making it easier to support larger block sizes in more filesystems, in part because he works on different distributions. He has encountered lots of problems trying to use filesystems that were created on distributions that use a different page size or block size on other distributions that made different choices. But, the terms he used for larger groups of pages, a superblock or superpage, were not popular; James Bottomley said that "superblock" was confusing because of its long-established use for filesystems, while Wilcox pointed out that a superpage should simply be called a folio.

Ritesh Harjani asked about the benefits of supporting larger block sizes in filesystems, apart from the portability considerations. Chamberlain said that the hardware vendors are driving the move to larger blocks, but that he wanted to stick with the software side. He thinks larger blocks will help reduce file fragmentation, but deferred to the filesystem developers in the room.

Darrick Wong said that he would actually like to get rid of discontiguous buffers for XFS because they are difficult to work with and to test, since they "cause all sorts of weird bugs to show up" in fstests. His advice to the other filesystem developers is: "try not to do that". It is not truly desirable to have metadata scattered in memory that way anyway.

He has some patches for fs-verity support for XFS "stuck in the three-mile freight train of everything that's in my development tree that's blocking traffic all over the city". As part of that, he found a need for a buffer cache, so he reused some of the XFS code for it. That work could be used as the basis of a new library for filesystem metadata handling as Chinner had suggested. He is trying to figure out how to integrate ("staple") that work onto the jbd2 journal layer; doing that would mean that ext4 could use it, but that also requires porting OCFS2 to use the new buffer cache. Since he believes no one actually uses OCFS2, perhaps the filesystem could just be deprecated instead.

Before even setting up iomap, though, there needs to be a mechanism to read from the disk, Hannes Reinecke said. Chamberlain suggested using iomap to read that data, but Reinecke insisted that it cannot read the data for the superblock, from which iomap can be configured. That requires buffer heads. But Chamberlain said that block-device operations can be used to retrieve the needed superblock data, thus buffer heads were not required. He agreed that more discussion on that was needed, however.


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


to post comments

Supporting larger block sizes in filesystems

Posted May 22, 2024 20:56 UTC (Wed) by koverstreet (subscriber, #4296) [Link] (1 responses)

bcachefs support will be trivial once the pagecache has an option for 'folios must be >= order n"

Supporting larger block sizes in filesystems

Posted May 22, 2024 21:59 UTC (Wed) by willy (subscriber, #9762) [Link]

That's part of the patchset; I think it's #2/n.

Supporting larger block sizes in filesystems

Posted May 22, 2024 21:58 UTC (Wed) by willy (subscriber, #9762) [Link]

> Le Moal said that large-folio support was being actively worked on for zonefs and was close to being ready.

It's a one-line patch; posted later that day: https://lore.kernel.org/linux-fsdevel/20240513223718.2965...

I hadn't added it because I lack the testing to say it's good.

Supporting larger block sizes in filesystems

Posted May 23, 2024 2:23 UTC (Thu) by hsiangkao (subscriber, #123981) [Link] (2 responses)

> though there are a few places where it still uses struct page, for decompression in particular.

Just side note: some `struct page` use cases are expected even in the final form since I assume `struct folio` is not an alias of `struct page` at the end of the folio project. For EROFS, all pages that can be mapped into userspace or page-cache based will be converted into folios (They are almost done. The end goal is that users are free to use any-valid-order file-backed folios to balance between performance and memory footprints.), and the other use cases will be kept as `struct page`.

I will try my best to enable large folio support for compressed data in the next one or two cycles as mentioned in
https://lore.kernel.org/r/c25a6d0d-735f-4e6e-85c2-183e240...
But EROFS just takes limited time of my paid job, I always need to squeeze more free time for this.

Supporting larger block sizes in filesystems

Posted May 23, 2024 19:30 UTC (Thu) by willy (subscriber, #9762) [Link] (1 responses)

Yes, some uses of struct page should be left as struct page. This is the perfect example; it's temporary data with no metadata. We'll free it once the operation is complete.

The only change we might want to consider is setting the minimum folio order for a filesystem to be the size of the block that you compress. That way we wouldn't need any of this code as we'd age the entire folio as a single unit. Maybe that's a bad tradeoff; I'm not in a position to judge.

Supporting larger block sizes in filesystems

Posted May 24, 2024 4:48 UTC (Fri) by hsiangkao (subscriber, #123981) [Link]

> The only change we might want to consider is setting the minimum folio order for a filesystem to be the size of the block that you compress. That way we wouldn't need any of this code as we'd age the entire folio as a single unit. Maybe that's a bad tradeoff; I'm not in a position to judge.

There is no such limitation though on EROFS. Even the block size is e.g. 4KiB, the compressed cluster can be 1MiB at most by on-disk definition (in that case, the uncompressed size of such cluster can be several MiBs). EROFS will still stick to block size (e.g. 4KiB) as the minimum folio order. However, if users like to use large block sizes instead, that would be their own choice though.
If some other fses have some other tendency, I hope EROFS can still have choice to use smaller folio orders (at least block size folio) instead, because it's important to the extreme preformance under constant memory pressure, and I don't want to bring such regression to end users later.

Supporting larger block sizes in filesystems

Posted May 23, 2024 6:34 UTC (Thu) by Conan_Kudo (subscriber, #103240) [Link] (2 responses)

FYI, I never said "superblock", only "superpage". That directly was caused by multiple filesystems referring to "smaller blocksize than page size" as "subpage".

Yes, I know that we call those large folios now, but that's a very new term...

Supporting larger block sizes in filesystems

Posted May 23, 2024 14:17 UTC (Thu) by willy (subscriber, #9762) [Link] (1 responses)

Somebody said superblock. Not saying it was you; think it was somebody who came up to the microphone. Large folios have been a term since November 2021 (commit 9c3252152e8a).

Supporting larger block sizes in filesystems

Posted May 23, 2024 14:22 UTC (Thu) by Conan_Kudo (subscriber, #103240) [Link]

Yes, it's true the term has been around for a few years, but it wasn't being used in any of my circles significantly until last year.

Supporting larger block sizes in filesystems

Posted May 24, 2024 9:44 UTC (Fri) by walex (guest, #69836) [Link] (1 responses)

Larger block sizes for filesystem is the usual idea that "clever" people re-invent every now and then:

  • It is unnecessary:
    • It is much better to have small block sizes and have larger "reservations" of space beyond logical end of space for files being written, trimmed when the file is closed (similarly for random-write files). Doing larger allocations as a rough way to do larger reservations is rather stupid.
    • The on-disk block sizes does not need to be the same as the in-memory buffer size, also because it is rather stupid to ignore that scatter-gather IO was invented several decades ago (and again with reservations it is not often needed).
  • It is harmful: there are plenty of papers that show that optimal logical IO sizes (except for the case of purely sequential IO which is handled by read-head and write-behind) are quite small, usually in the 128-256 byte range (in part because most programs are badly written without care for locality of access and assuming IO operations don't have fixed costs), and that a lot of large-block IO simply wastes bandwidth and memory.

That said hardware trends are not favourable, and sometimes I think that log-based (plus compactors) filesystems will become inevitable. But at least the logical design should not be tightly coupled to hardware trends.

Supporting larger block sizes in filesystems

Posted May 24, 2024 17:10 UTC (Fri) by willy (subscriber, #9762) [Link]

This really isn't about running a 16KiB block size filesystem on top of a 4KiB block size device. It's about making drives more efficient by using 16KiB blocks. That forces the filesystem to use 16KiB blocks because you can't do writes smaller than 16KiB.

What you're missing is the _cost_ of keeping track of 256 byte writes. Your argument that it's "optimal" to do IO in these tiny sizes (which haven't been supported on Linux _ever_) completely ignores this.

We can't even afford to track memory usage in 4KiB chunks any more. We certainly can't afford to track storage in 4KiB chunks either. There's just too much metadata (and when you cross the boundary of 4 billion blocks in a device, it doubles in size).

Storage devices are large, bandwidth is plentiful. Latency is the problem to solve, not "waste".


Copyright © 2024, 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