# Io\_splice - zero-copy pipe I/O for Linux

**URL:** <https://www.ruby-forum.com/t/io-splice-zero-copy-pipe-i-o-for-linux/183473>\
**Category:** Ruby\
**Created:** [February 15, 2010, 9:45am UTC](https://www.ruby-forum.com/t/io-splice-zero-copy-pipe-i-o-for-linux/183473 "2010-02-15T09:45:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [February 15, 2010, 9:45am UTC](https://www.ruby-forum.com/t/io-splice-zero-copy-pipe-i-o-for-linux/183473/1 "2010-02-15T09:45:27Z")

</div>

The splice family of Linux system calls can transfer data between file  
descriptors without the need to copy data into userspace. Instead of a  
userspace buffer, they rely on an ordinary Unix pipe as a kernel-level  
buffer.

- [io\_splice - zero-copy pipe I/O for Linux and Ruby](http://bogomips.org/ruby_io_splice/)
- removed\_email\_address@domain.invalid
- git://git.bogomips.org/ruby\_io\_splice.git

== Features

- Efficient zero-copy I/O avoids data copies into userspace,  
reducing garbage for the Ruby garbage collector as a side effect.

- More flexible than sendfile, may be used to enable copies between  
arbitrary file descriptors (assuming kernel support), not just  
socket-to-file.

- Thread-safe blocking operations under Ruby 1.9, releases GVL  
if blocking operations are used.

- Safely usable with non-blocking I/O frameworks (unlike IO.copy\_stream)  
when combined with the IO::Splice::F\_NONBLOCK flag.

- Fully-documented library API and  
{examples}[[Index of /ruby\_io\_splice/examples/](http://bogomips.org/ruby_io_splice/examples/)]

== Install

Operating system support for the splice(2), tee(2) and vmsplice(2)  
system calls is required. Currently, only Linux 2.6.17 or later with a  
modern C library (glibc 2.5 or later) support these system calls. Using  
the latest stable Linux kernel is _HIGHLY_ recommended as there have  
been numerous bugs in the early releases of these system calls.

If you’re using a packaged Ruby distribution, make sure you have a C  
compiler and the matching Ruby development libraries and headers.

If you use RubyGems:

```
gem install io_splice

```

Otherwise grab the latest tarball from:

[http://bogomips.org/ruby\_io\_splice/files/](http://bogomips.org/ruby_io_splice/files/)

Unpack it, and run “ruby setup.rb”

== Usage

Our API matches the C API closely, see the RDoc for full API  
documentation and the Linux manpages for more details.

All of these system calls are fairly new have seen limited usage  
anywhere, even outside of the Ruby world.

If you encounter problems (privilege escalation, memory leaks (in the  
kernel), poor performance, corrupt data, etc…), try upgrading the Linux  
kernel to the latest stable version.

These system calls have a lot of potential, and will hopefully be  
standardized and available in non-Linux kernels some day.

== Development

You can get the latest source via git from the following locations:

git://git.bogomips.org/ruby\_io\_splice.git  
git://repo.or.cz/ruby\_io\_splice.git (mirror)

You may browse the code from the web and download the latest snapshot  
tarballs here:

- [zero-copy pipe I/O for Linux and Ruby](http://git.bogomips.org/cgit/ruby_io_splice.git) (cgit)
- [Public Git Hosting - ruby\_io\_splice.git/summary](http://repo.or.cz/w/ruby_io_splice.git) (gitweb)

Inline patches (from “git format-patch”) to the mailing list are  
preferred because they allow code review and comments in the reply to  
the patch.

We will adhere to mostly the same conventions for patch submissions as  
git itself. See the Documentation/SubmittingPatches document  
distributed with git on on patch submission guidelines to follow. Just  
don’t email the git mailing list or maintainer with io\_splice patches.

== Contact

All feedback (bug reports, user/development discussion, patches, pull  
requests) go to the mailing list: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
