Repository navigation
Linux 6.12: port the latest changes for parallel DIO to 6.12 - #290
Conversation
A synchronous read or write on a FOPEN_DIRECT_IO open went through fuse_direct_io() with FUSE_IO_PRIV_SYNC, which sends one max_read or max_write piece and waits for its reply before it sends the next. With the 4 MiB pieces redfs uses, that caps one stream at the latency of one piece: 16 MiB O_DIRECT writes ran at 1.4 GB/s and 32 MiB reads at 2.0 GB/s on a 6.17 client, while the same requests through libaio, which sends all pieces before waiting, ran at 3.3 and 5.7 GB/s. With async_dio, synchronous calls now take __fuse_direct_IO() as well. It already handles a blocking kiocb: it sends every piece as a background request and waits on io->done. The caller advances ki_pos, as generic_file_direct_write() and generic_file_read_iter() do for ->direct_IO. Without async_dio nothing changes. The completion is the aio one, so a short write reply now fails the call with -EIO, as it already did for aio, instead of returning the short count. Signed-off-by: Sven Oehme <soehme@ddn.com>
…4742) fuse_perform_write() filled up to max_write bytes of folios, sent them with fuse_simple_request() and waited for the reply before it filled the next piece. A single buffered writer was capped at the round trip of one piece: 16 MiB writes ran at 0.85 GB/s with a 4 MiB max_write, while the daemon and servers could take several pieces at once. One MPI-IO aggregator writing an HDF5 file through glibc's POSIX aio issues exactly such synchronous pwrites. Each piece is now sent as a background request, and up to FUSE_WRITE_PAGES_INFLIGHT (8) are outstanding before the oldest is waited for. The reply handler does what fuse_send_write_pages() did after the request: it clears uptodate on a failed or short write, unlocks the last folio if it was left locked and drops the folio references. Replies are accounted in file order, so the result and ki_pos cover only the bytes before the first failed or short piece, as before. The pieces cover disjoint ranges and keep uring_critical, so under the writeback cache a background one does not wait for the background budget either. Signed-off-by: Sven Oehme <soehme@ddn.com>
…nd the wait (RED-54742) Synchronous direct I/O through __fuse_direct_IO() changed two things the one-piece-at-a-time path did. A call that failed part-way returned the error instead of the bytes before the failed piece, so a 64 MiB write that hit ENOSPC on its third piece returned -ENOSPC instead of 8 MiB, and an extending write under the exclusive lock was then truncated back. And the caller waited in wait_for_completion(), so a stalled server left it unkillable. With sync_result, set for synchronous calls from fuse_direct_read_iter() and fuse_direct_write_iter(), a failed piece records its start as the end of the result, fuse_get_res_by_io() returns the bytes before the first failed or short piece, or the error if there are none, i_size follows the returned count and nothing is truncated. The pieces after the failed one were applied by the server all the same, as noted at __fuse_direct_IO(). The cached O_DIRECT path, fuse_direct_IO(), and aio keep their result. The caller now waits killably. On a fatal signal it clears io->done under io->lock, drops its reference and returns -EINTR; the pieces in flight hold references on io and the last completion frees it. Signed-off-by: Sven Oehme <soehme@ddn.com>
…-54742) A buffered write of a single max_write piece became 16-26 % slower with pieces sent in the background: ior-easy with 4 MiB transfers on a writeback_cache mount went from 1.13 to 0.84 GB/s with one process. A background request goes to the queue of the next CPU, and that queue's ring task copies the payload, 482 us per 4 MiB piece, while a foreground request is copied by the caller; the call waits for the hand-off as well. The piece nothing is sent after is now sent with fuse_simple_request(), as before the series, so a one-piece call takes the old path and the last piece of a longer one overlaps with the pieces in flight. The wait for a piece is killable. On a fatal signal no further piece is sent and the pieces in flight are still waited for, since they reference the request and the folios; fuse_simple_request() also waits for a request once the server has it. Under DLM the server takes the DLM lock for a write without FUSE_WRITE_CACHE, which can wait on a revoke. Such pieces are uring_critical and would hold up to eight critical entries of the queue. A writer like that, a write dropping suid/sgid, keeps a single piece in flight, as before the series. FUSE_WRITE_CACHE writes, and mounts without the writeback cache, where no entry is critical, keep eight. The comment now says that the pieces after a failed one have been applied by the server, so its file can hold data and a size past the returned count. Signed-off-by: Sven Oehme <soehme@ddn.com> Signed-off-by: Horst Birthelmer <hbirthelmer@ddn.com>
fuse_perform_write() saw a fatal signal only in wait_for_completion_killable(), which tests for one only while it sleeps. A piece complete by the time it is waited for, as every foreground piece is, never ended the loop, and a killed writer sent the rest of its buffer. Test for the signal before each piece is sent. A writer killed before its first piece now returns -EINTR. The pieces still waited for after the signal include those the server has not received yet. Say so in the comment. fuse_direct_io() sent every piece of a killed synchronous caller, as no background request ends on a signal. Stop sending there too. __fuse_direct_IO() then returned -EINTR with pieces still at the server, and the caller dropped the inode lock and could release the file under them. Wait for them uninterruptibly instead, as fuse_perform_write() does, and drop the io->done handshake. Signed-off-by: Horst Birthelmer <hbirthelmer@ddn.com>
cryptosven76
left a comment
There was a problem hiding this comment.
Read at fdfdd8f against the originals in #287 (e4bd6a0, 947e21c, 04aa09d, bf96029, c3c668f); nothing built or run. The port is faithful: no 6.12-specific bug found.
Interdiff, commit by commit (changed lines only):
- 1 (send DIO pieces together): the only semantic difference. The 6.12 base gates the aio path on
IOCB_DIRECT, and the port keeps that gate, so aio without O_DIRECT on a FOPEN_DIRECT_IO open stays on the per-piece path, where the 6.17 original sends it through__fuse_direct_IO(). Keeping the base behaviour is right for a port (nit inline). - 2 (several page writes in flight): folio to page renames only (
num_pages,page_locked,fuse_pages_alloc,ClearPageUptodate).folio_wait_writeback()becamefuse_wait_on_page_writeback(), which in this tree isfind_get_page()pluswait_on_page_writeback(), so the same wait. - 3, 4, 5: identical changed lines; only a comment says pages instead of folios.
Checked against the 6.12 base:
__fuse_direct_IO(),fuse_aio_complete(),fuse_aio_complete_req(),fuse_get_res_by_io()andfuse_direct_io()at this head match the 6.17 head line for line, apart from page/folio names.fuse_simple_background()(dev.c:640) andfuse_uring_req_critical()(dev_uring.c:101) are the same as on 6.17, so the critical-entry reasoning behindmax_inflight = 1holds here; io-uring also setsmax_backgroundto UINT_MAX here (dev.c:2275, 2355).- The writeback-cache caller passes
FUSE_WRITE_CACHE(file.c:2688), the writethrough callers pass 0 (2747, 2756), as on 6.17. struct fuse_io_privgainssync_result(fuse_i.h:550) as on 6.17.
Carried over from #287, still open here:
- The third commit's subject and body describe a killable direct I/O wait and the
io->donehandshake, which the fifth commit removes (yongzech's point 3 on #287). Same on this branch. - The PR description has one line. Please name the source commits (#287) and the one adapted condition, and carry over #285's behaviour notes and measurements.
- Testing: nothing says this ran on a RHEL 10 / 6.12 kernel. The kernel-build job is still pending.
| if ((!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) || | ||
| (is_sync_kiocb(iocb) && ff->fm->fc->async_dio)) { |
There was a problem hiding this comment.
Nit: this condition is is_sync_kiocb(iocb) ? async_dio : IOCB_DIRECT. It keeps the 6.12 gate on IOCB_DIRECT for aio, which the 6.17 original no longer has, so aio without O_DIRECT on a FOPEN_DIRECT_IO open stays on the per-piece path. That is right for a port; the ternary says it more plainly (same at line 3057):
| if ((!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) || | |
| (is_sync_kiocb(iocb) && ff->fm->fc->async_dio)) { | |
| if (is_sync_kiocb(iocb) ? ff->fm->fc->async_dio : | |
| !!(iocb->ki_flags & IOCB_DIRECT)) { |
| int err; | ||
|
|
||
| for (i = 0; i < ap->num_pages; i++) | ||
| fuse_wait_on_page_writeback(file_inode(file), ap->pages[i]->index); |
There was a problem hiding this comment.
Nit: in this tree fuse_wait_on_page_writeback() is find_get_page() plus wait_on_page_writeback() (file.c:618), so this looks up a page already held in ap->pages[i]. It is the right adaptation of folio_wait_writeback(); calling wait_on_page_writeback(ap->pages[i]) would skip the lookup per page per piece:
| fuse_wait_on_page_writeback(file_inode(file), ap->pages[i]->index); | |
| wait_on_page_writeback(ap->pages[i]); |
|
@cryptosven76 @hbirth As I mentioned in yesterday's call, this change would improve the performance, but would also change the write semantics? For example, a 16MB write request, before this change, the write would be split into 4 4MB write requests, if one 4MB write requests fails, it will stop the remaining 4MB writes and return to users with the file size updated as the done 4MB writes (sequentially); now with this change, 4 4MB writes will be initiated in parallel, if the last 4MB write is done successfully, but the other 4MB writes failed, then we will update the file size to the largest offset 4MB write. This is one behavior change, and we accept this, then we may need to document this behavior? |
This is the backport of that change. What is your proposal? We should not backport, or revert the change? |
I'm just wondering whether we need to document this behavior change. |
aah .. in that case, could you please approve this backport and we can create a ticket for the documentation update? This is the kernel repo anyway. |
Since the patches did not apply cleanly, I created another PR for another review