Splice (system call)
   HOME

TheInfoList



OR:

is a
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
-specific
system call In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
that moves data between a
file descriptor In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket. File descriptors typically have ...
and a pipe without a round trip to user space. The related system call moves or copies data between a pipe and user space. Ideally, splice and vmsplice work by remapping pages and do not actually copy any data, which may improve I/O performance. As linear addresses do not necessarily correspond to contiguous physical addresses, this may not be possible in all cases and on all hardware combinations.


Workings

With , one can move data from one file descriptor to another without incurring any copies from user space into kernel space, which is usually required to enforce system security and also to keep a simple interface for processes to read and write to files. works by using the pipe buffer. A pipe buffer is an in-kernel memory buffer that is opaque to the user space process. A user process can splice the contents of a source file into this pipe buffer, then splice the pipe buffer into the destination file, all without moving any data through userspace.
Linus Torvalds Linus Benedict Torvalds ( , ; born 28 December 1969) is a Finnish software engineer who is the creator and, historically, the lead developer of the Linux kernel, used by Linux distributions and other operating systems such as Android. He also c ...
described in a 2006 email, which was included in a
KernelTrap KernelTrap was a computing news website which covered topics related to the development of free and open source operating system kernels, and especially, the Linux kernel. News stories usually consisted of a summary of a recent discussion from a ...
article.


Origins

The
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
splice implementation borrows some ideas from an original proposal by
Larry McVoy Larry McVoy (born 1962 in Concord, Massachusetts, United States) is the CEO of BitMover, the company that makes BitKeeper, a version control system that was used from February 2002 to early 2005 to manage the source code of the Linux kernel. ...
in 1998. The splice system calls first appeared in
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
kernel version 2.6.17 and were written by
Jens Axboe Jens Axboe (born circa 1976) is a Linux kernel hacker. Work Axboe is the current Linux kernel maintainer of the block layer and other block devices, along with contributing the CFQ I/O scheduler, Noop scheduler, Deadline scheduler, io_uri ...
.


Prototype

ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags); Some constants that are of interest are: /* Splice flags (not laid down in stone yet). */ #ifndef SPLICE_F_MOVE #define SPLICE_F_MOVE 0x01 #endif #ifndef SPLICE_F_NONBLOCK #define SPLICE_F_NONBLOCK 0x02 #endif #ifndef SPLICE_F_MORE #define SPLICE_F_MORE 0x04 #endif #ifndef SPLICE_F_GIFT #define SPLICE_F_GIFT 0x08 #endif


Example

This is an example of splice in action: /* Transfer from disk to a log. */ int log_blocks (struct log_handle * handle, int fd, loff_t offset, size_t size)


Complementary system calls

is one of three system calls that complete the architecture. can map an application data area into a pipe (or vice versa), thus allowing transfers between pipes and user memory where transfers between a file descriptor and a pipe. is the last part of the trilogy. It duplicates one pipe to another, enabling forks in the way applications are connected with pipes.


Requirements

When using with sockets, the network controller (NIC) should support DMA, otherwise splice() will not deliver a large performance improvement. The reason for this is that each page of the pipe will just fill up to frame size (1460 bytes of the available 4096 bytes per page). Not all filesystem types support . Also, sockets do not support .


See also

*
System calls In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
*
Zero-copy "Zero-copy" describes computer operations in which the CPU does not perform the task of copying data from one memory area to another or in which unnecessary data copies are avoided. This is frequently used to save CPU cycles and memory bandwid ...


References

{{Reflist


External links


Linux kernel 2.6.17
(kernelnewbies.org)
Two new system calls: splice() and sync_file_range()
(
LWN.net LWN.net is a computing webzine with an emphasis on free software and software for Linux and other Unix-like operating systems. It consists of a weekly issue, separate stories which are published most days, and threaded discussion attached to ...
)
Some new system calls
(LWN.net) Linux kernel features System calls