vmsplice(2)

๐Ÿ’– vmsplice(2) ๐Ÿ’–

okay bestie, welcome to the System Calls Manual, section 2. this is the one, this is the girl. let's get into it ๐Ÿซถ


โœจ NAME โœจ

vmsplice โ€” splice user pages to/from a pipe


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <fcntl.h>

ssize_t vmsplice(int fd, const struct iovec *iov,
                 size_t nr_segs, unsigned int flags);

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so here's the tea, bestie. if fd is opened for writing, vmsplice() takes nr_segs ranges of your user memory โ€” the ones described by iov โ€” and maps them into a pipe. and if fd is opened for reading, it does the opposite: it fills nr_segs ranges of user memory described by iov from a pipe. ๐Ÿฆ‹

the file descriptor fd must refer to a pipe. no pipe, no party. ๐Ÿ’…

the pointer iov points at an array of iovec structures, exactly as described in iovec(3type).

the flags argument is a bit mask that you build by ORing together zero or more of these values:

SPLICE_F_MOVE

unused for vmsplice(). literally just hanging out. go read splice(2) if you're curious. ๐Ÿ™ˆ

SPLICE_F_NONBLOCK

do not block on I/O. that's it, that's the vibe. more deets in splice(2).

SPLICE_F_MORE

currently has no effect for vmsplice(), but it might get implemented in the future. she's booked but not confirmed. see splice(2).

SPLICE_F_GIFT

ok this one's the main character. ๐Ÿ‘‘

the user pages are a gift to the kernel. and when i say gift i mean it โ€” the application may not modify this memory ever, otherwise the page cache and on-disk data may differ. no takebacks, no regifting, no editing. ๐Ÿ˜ญ

why would you do this? because gifting pages to the kernel means a subsequent splice(2) SPLICE_F_MOVE can actually move the pages. if you don't specify this flag, then a subsequent splice(2) SPLICE_F_MOVE has to copy the pages instead. move > copy, obviously.

also, data must be properly page aligned โ€” both in memory and in length. both!! if your length is off, we have a problem.


๐Ÿซถ RETURN VALUE ๐Ÿซถ

on a successful slay, vmsplice() returns the number of bytes transferred to the pipe.

on error, it returns -1 and errno is set to tell you what went wrong. ๐Ÿ’€


๐Ÿšจ ERRORS ๐Ÿšจ

  • EAGAIN โ€” SPLICE_F_NONBLOCK was specified in flags, and the operation would block.
  • EBADF โ€” fd is either not valid, or doesn't refer to a pipe.
  • EINVAL โ€” nr_segs is greater than IOV_MAX; or memory not aligned if SPLICE_F_GIFT set.
  • ENOMEM โ€” out of memory.

โญ STANDARDS โญ

Linux. that's the whole list, bestie.


๐ŸŒˆ HISTORY ๐ŸŒˆ

Linux 2.6.17, glibc 2.5. a classic, an icon, a legend. โœจ


๐Ÿ’œ NOTES ๐Ÿ’œ

vmsplice() follows the other vectorized read/write type functions when it comes to limitations on the number of segments being passed in. that limit is IOV_MAX, as defined in <limits.h>. and currently? that limit is 1024. periodt.

and here's the plot twist ๐Ÿ“ โ€” vmsplice() really supports true splicing only from user memory to a pipe. in the opposite direction, it actually just copies the data to user space. it's not actually splicing, it's cosplaying as splicing. ๐Ÿ™ˆ

but lowkey that's fine, because it makes the interface nice and symmetric and enables people to build on vmsplice() with room for future improvement in performance. she's got potential, okay?? ๐Ÿ‘‘


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

splice(2), tee(2), pipe(7)


and that's the whole page, bestie!! this was pulled from Linux man-pages 6.20, dated 2026-02-08, and it's the vmsplice(2) page itself. go forth and splice responsibly. no cap. ๐Ÿ’…๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms