[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch to eliminate user space memory copying in 'cp'
From: |
Spinka, Kristofer |
Subject: |
Patch to eliminate user space memory copying in 'cp' |
Date: |
Mon, 24 Mar 2003 02:31:58 -0500 |
You will have to incorporate the check for sendfile, but otherwise
this patch should avoid the most common kernel<->user space read/write
transitions.
m4/sendfile.m4:
===============
#serial 1
dnl From Kristofer Spinka <address@hidden>.
dnl Find out if this platform has sendfile support.
dnl
AC_CHECK_HEADER([sys/sendfile.h],
[AC_DEFINE([HAVE_SYS_SENDFILE_H])],
[AC_MSG_ERROR([No sendfile() system call support :(])])
===============
src/copy.c:
===========
--- copy.c 2003-03-24 02:33:07.000000000 -0500
+++ copy-sendfile.c 2003-03-24 02:31:24.000000000 -0500
@@ -217,6 +217,8 @@
int *ip;
int return_val = 0;
off_t n_read_total = 0;
+ off_t always_zero_offset = 0;
+ ssize_t sendfile_bytes_written;
int last_write_made_hole = 0;
int make_holes = (x->sparse_mode == SPARSE_ALWAYS);
@@ -279,6 +281,26 @@
goto close_src_desc;
}
+#ifdef HAVE_SYS_SENDFILE_H
+ /* This is the way all copies should happen, let's try to avoid being
+ a Mexican jumping bean between the kernel and user spaces.
+ We need to have a sendfile() system call to make this possible.
+ Kristofer Spinka <address@hidden> */
+
+ sendfile_bytes_written = sendfile (dest_desc, source_desc,
&always_zero_offset, src_open_sb.st_size);
+
+ if (sendfile_bytes_written == -1)
+ {
+ error (0, errno, _("sendfile zero-copy failed."));
+ return_val = -1;
+ goto close_src_and_dst_desc;
+ }
+ else
+ {
+ goto close_src_and_dst_desc;
+ }
+#endif
+
/* Determine the optimal buffer size. */
if (fstat (dest_desc, &sb))
===========
/kristofer
- Patch to eliminate user space memory copying in 'cp',
Spinka, Kristofer <=