Repository navigation
fuse: io-uring: copy large write payloads into the ring on several CPUs (RED-54743) - #286
Conversation
…Us (RED-54743) A synchronous write copies each request payload into the pinned ring pages in the calling process, on one CPU. On a 4-node EPYC 9534 client that copy takes 0.5-1.6 ms per 4 MiB request, depending on where the source and the ring pages live, about as long as redfsd and the servers need for the request (1.96 ms). It caps one stream at about 1.2 GB/s, and once the chunks of a request are sent in parallel it remains the serial part. fuse_uring_args_to_ring_pages() now copies the page argument in segments: the caller copies the first, the others run on unbound workers of the caller's NUMA node, and the caller waits for all of them. Only payloads of at least two segments are split, at most 16 segments. The segment size is the module parameter uring_copy_split_kb (default 1024, 0 disables it). The unpinned ring path, which copies with copy_to_user() into the server's address space, is unchanged. This is a first step of RED-54743. Removing the copy altogether needs the server to RDMA-register memory it does not own (the ring buffer is registered memory today), so it requires a protocol and redfsd change.
|
@hbirth, could you take this one over and drive it further (RED-54743)?
Decisions for you are listed under "Decisions for Horst" in the description: default on/off, worker placement, the phase-2 approach and the stable-data policy, and ports to the other branches. |
|
@cryptosven76 there will not be a 'true' zero copy. This is a security problem. You should not remap memory from the user app to the redfsd space. And even then it is not zero copy, since we still have to copy it once ... now either we do it cleverly in the kernel as this PR and other changes already do, or in redfsd when send to the net. I have zero copy implemented in the 7.3 kernel (together with fusex and io-uring support) for large write operations with the help of two new io-uring commands that were added in 7.3. We can now add an io-uring BUFFPOOL for small operations and use the mapping to uring space for large ones. This isn't complete zero copy either since the io-uring cannot map the memory directly (this is a design decision) but write into a provided fd, which we then can make a pool of in redfsd and have those fd be memory backed entities. |
RED-54743 (follow-up of RED-54742). Draft for @hbirth to take over: phase 1 code plus the design for zero-copy.
Problem
A synchronous write on a redfs mount copies each request payload into the io-uring ring buffer in the calling process (
fuse_uring_copy_to_ring()→fuse_uring_args_to_ring_pages()), one CPU, before redfsd sees it. Measured on tyan-h3-u24 (EPYC 9534, 4 NUMA nodes, kernel 6.17.0-42) against 2.5.2 servers, one 4 MiB O_DIRECT write request, p50 over 540 samples:The copy is ~44 % of a synchronous 4 MiB request and caps one stream at ~1.2 GB/s. With requests sent in parallel (RED-54742) it becomes the cap of a single stream, because every chunk is still copied serially by the caller.
Phase 1 (this PR): split the copy across CPUs
fuse_uring_args_to_ring_pages()copies the page argument of a request into the pinned ring pages in segments: the caller copies the first, the others run onsystem_unbound_wqworkers of the caller's NUMA node, and the caller waits for all of them. Only the pinned-ring path (privileged server, which redfsd is) and only payloads of at least two segments. Module parameteruring_copy_split_kb(default 1024, 0 = off, at most 16 segments); changeable at runtime. No protocol change, no redfsd change.Results on tyan-h3-u24, same patched module,
uring_copy_split_kbtoggled at runtime between 0 and 1024, alternating, 3 rounds; fio psync, one job, one request at a time, 15 s each, writeback-cache mount of dataset bp25t (2.5.2 servers):fuse_uring_copy_to_ring()time per request (bpftrace, 16 MiB O_DIRECT writes, so 4 MiB requests): average 1691 µs with the installed module, 656 µs with this change (2834 and 3584 requests).The 4 MiB case gains nothing measurable in a single run and its p50 rises: with one request in flight, the worker wake-up adds latency where the copy alone is short. Larger requests (above
max_write, several requests per call) gain the most. With RED-54742 (#285) the requests of one call are sent together; this change then shortens the serial part each of them still has.Why not zero-copy right away
redfs_payload_alloc():red_client_iomem_alloc()+client_get_net_region(), i.e.ibv_reg_mrper network poller). A non-ODP MR keeps the physical pages it was registered with, so remapping other pages behind the ring VA is invisible to the NIC.vm_insert_pages()refuses anonymous pages, and O_DIRECT user buffers are anonymous. AVM_PFNMAPwindow works for CPU access, but cannot be registered as an MR.Phase 2 design: per-entry dma-buf window
FUSE_URING_ZERO_COPY; redfs bits are allocated downward from 61). Off unless the server opts in.max_payload_szplus one page, created atFUSE_IO_URING_CMD_REGISTERand handed to the server. Per request, the sg table is the request's already pinned pages (O_DIRECTargs->user_pages). At request enddma_buf_move_notify()under the reservation lock, beforefuse_request_end()lets the writer unpin.fuse_uring_ent_in_out.flagsgets a ZC bit; the offset of the first byte goes into the unusedpadding/reservedfields, so the header layout stays.VM_PFNMAP | VM_DONTCOPYvma whose PTEs point to the current pages and are zapped at request end.ibv_reg_dmabuf_mr()once per entry (mlx5 dynamic dma-buf MR, ODP-backed), registered on every poller likeredfs_payload_alloc()does today. When the ZC bit is set, use the window and its keys instead of the ring buffer. Fall back to the copy when the flag is not negotiated or the registration fails.fuse_uring_copy_from_ring()skips the copy (0.41 ms per 4 MiB today, in a reactor).Risks of phase 2:
SB_I_STABLE_WRITES) before they can go zero-copy; first target O_DIRECT only.ibv_advise_mrprefetch) must stay well below the 1.55 ms copy; measure first.redfs_init_fork): window vmas needVM_DONTCOPY. No extraRLIMIT_MEMLOCK/VmPin accounting, since the writer already holds the pin for the request.Decisions for Horst
system_unbound_wqon the caller's node vs a dedicated workqueue. The total copy CPU stays the same, it is only spread.src/redfs/redfs.cpp, network region registration), and the stable-data policy.redfs-*branches.Tests
All on tyan-h3-u24 (kernel 6.17.0-42) against the 2.5.2 servers, with the patch applied to the 2.5.3~alpha.1 DKMS source (same code, redfs names); this branch also compiles out of tree (
fs/fuse, against the 6.17.0-42 headers). The installed module was restored afterwards (srcversion 2F3E6334DE7BE1BF24BB0E7).dd bs=16M oflag=directand withbs=64Mbuffered, plus a file of 40 random-size pieces written in odd sizes (1 B to 13 MiB + 77) at unaligned offsets, all on the writeback-cache mount; read back through a second mount without writeback cache after dropping caches: md5 identical for all three.-q -e 1), split on: 3 ×-N 100000(generic/363 command) and 4 ×-N 3000with 16 MiB ops, on the writeback-cache mount and on a mount without it: 14 runs, all rc 0. The 16 MiB-op runs were capped by fsx's 256 KiB default file size, so in addition 8 runs with-l 128M -o 32M -N 2000(buffered, and-Z -r 4096 -w 4096), with and without writeback cache: all rc 0.uring_copy_split_kb=0at runtime gives the old path (the "off" column above).Raw data: u24:/var/tmp/soehme/h5prof/zc/ (fio JSON, bpftrace, fsx logs, scripts).
Agent changes:
c445ff93d3ba0a42d5-92a3-5fb9-add0-ec19337acecfcd /mnt/red/.claude/worktrees/bridge-cse_0131UunFqmmGzVMrbF7wkLFu && claude --resume ba0a42d5-92a3-5fb9-add0-ec19337acecf