Skip to content

fuse: io-uring: copy large write payloads into the ring on several CPUs (RED-54743) - #286

Draft
cryptosven76 wants to merge 1 commit into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-54743-uring-payload-copy-split
Draft

cryptosven76 wants to merge 1 commit into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-54743-uring-payload-copy-split

Conversation

@cryptosven76

Copy link
Copy Markdown

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:

Step Time
copy into the ring, caller 1.55 ms (0.5–1.6 ms, depends on NUMA placement)
redfsd + servers 1.96 ms

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 on system_unbound_wq workers 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 parameter uring_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_kb toggled 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):

Workload split off, MB/s (median) split on, MB/s (median) Change p50 latency off → on
4 MiB O_DIRECT write 2624 / 1447 / 947 (1447) 1389 / 1515 / 1536 (1515) +5 % (noise) 1.81 → 2.87 ms
16 MiB O_DIRECT write 1040 / 921 / 950 (950) 1909 / 1327 / 1343 (1343) +41 % 16.1 → 11.7 ms
64 MiB O_DIRECT write 1413 / 1017 / 1076 (1076) 2516 / 1976 / 2137 (2137) +99 % 59.5 → 23.2 ms
16 MiB buffered write 743 / 764 / 1046 (764) 930 / 908 / 828 (908) +19 % 19.5 → 18.2 ms

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

  • redfsd sends a write payload straight from the ring buffer, which it allocated as RDMA-registered memory (redfs_payload_alloc(): red_client_iomem_alloc() + client_get_net_region(), i.e. ibv_reg_mr per 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. A VM_PFNMAP window works for CPU access, but cannot be registered as an MR.
  • So zero-copy needs redfsd to register memory it does not own. Kernel changes alone cannot deliver it.

Phase 2 design: per-entry dma-buf window

  1. New INIT flag (proposal: bit 57, FUSE_URING_ZERO_COPY; redfs bits are allocated downward from 61). Off unless the server opts in.
  2. Kernel: one dynamic dma-buf exporter per ring entry, size max_payload_sz plus one page, created at FUSE_IO_URING_CMD_REGISTER and handed to the server. Per request, the sg table is the request's already pinned pages (O_DIRECT args->user_pages). At request end dma_buf_move_notify() under the reservation lock, before fuse_request_end() lets the writer unpin. fuse_uring_ent_in_out.flags gets a ZC bit; the offset of the first byte goes into the unused padding/reserved fields, so the header layout stays.
  3. CPU access for redfsd (EC parity, checksums, TCP fallback): mmap of the dma-buf, a VM_PFNMAP | VM_DONTCOPY vma whose PTEs point to the current pages and are zapped at request end.
  4. redfsd: ibv_reg_dmabuf_mr() once per entry (mlx5 dynamic dma-buf MR, ODP-backed), registered on every poller like redfs_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.
  5. Reads: the same window with writable pages; the server's RDMA lands in the user pages, and fuse_uring_copy_from_ring() skips the copy (0.41 ms per 4 MiB today, in a reactor).

Risks of phase 2:

  • An application that changes its buffer during an O_DIRECT write: today the copy is a snapshot. Without it, redfsd can compute EC parity and checksums from different bytes than the NIC sends, which leaves an inconsistent stripe, not only undefined file content. Either one pass that computes and sends from the same read, or keep copying for such writes (policy decision).
  • Page-cache (writeback) pages need stable writes (SB_I_STABLE_WRITES) before they can go zero-copy; first target O_DIRECT only.
  • Partial first and last pages expose neighbouring bytes of the caller's page to redfsd (a root daemon); restrict to page-aligned buffers or accept it.
  • Ordering: the request must not complete until the importer has dropped its mapping and no RDMA is outstanding.
  • Per-request cost of ODP invalidation and NIC page faults (ibv_advise_mr prefetch) must stay well below the 1.55 ms copy; measure first.
  • fork() of redfsd (redfs_init_fork): window vmas need VM_DONTCOPY. No extra RLIMIT_MEMLOCK/VmPin accounting, since the writer already holds the pin for the request.

Decisions for Horst

  • Phase 1: keep it on by default (1 MiB segments, max 16), ship it off by default, or drop it in favour of phase 2.
  • Worker placement: system_unbound_wq on the caller's node vs a dedicated workqueue. The total copy CPU stays the same, it is only spread.
  • Phase 2: dma-buf approach, INIT bit allocation, who owns the redfsd half (red/red src/redfs/redfs.cpp, network region registration), and the stable-data policy.
  • Ports to the other 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).

  • Integrity, split on: 1 GiB random data written with dd bs=16M oflag=direct and with bs=64M buffered, 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.
  • fsx (-q -e 1), split on: 3 × -N 100000 (generic/363 command) and 4 × -N 3000 with 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=0 at runtime gives the old path (the "off" column above).
  • Not done: other kernels, the unpinned ring path (unchanged), lockdep/KASAN kernel, many parallel streams (CPU cost of the workers), combination with fuse: send the pieces of a synchronous large read or write together (RED-54742) #285.

Raw data: u24:/var/tmp/soehme/h5prof/zc/ (fio JSON, bpftrace, fsx logs, scripts).

Agent changes:

Date (UTC) Head (short SHA) Host Session Internal session Resume
2026-11-11 23:08 c445ff93d3 tyan-h3-u24 2.5 release list ba0a42d5-92a3-5fb9-add0-ec19337acecf cd /mnt/red/.claude/worktrees/bridge-cse_0131UunFqmmGzVMrbF7wkLFu && claude --resume ba0a42d5-92a3-5fb9-add0-ec19337acecf

…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.
@cryptosven76
cryptosven76 requested a review from hbirth November 11, 2026 23:08
@cryptosven76

Copy link
Copy Markdown
Author

@hbirth, could you take this one over and drive it further (RED-54743)?

  • Phase 1 (this PR): a kernel-only, opt-out split of the ring copy. 16 MiB O_DIRECT writes +41 %, 64 MiB +99 %, copy_to_ring 1691 → 656 µs. It is independent of fuse: send the pieces of a synchronous large read or write together (RED-54742) #285 (file.c only) and stacks with it.
  • Real zero-copy (phase 2, design in the description): this can't be done in the kernel alone. redfsd sends from its RDMA-registered ring buffer, and vm_insert_pages() rejects the anonymous O_DIRECT pages. The proposal is a per-entry dma-buf window, which redfsd registers with ibv_reg_dmabuf_mr(). That needs a new INIT bit and a redfsd change.

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.

@hbirth

hbirth commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants