summaryrefslogtreecommitdiff
path: root/source3/modules/vfs_readahead.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-04-06 18:56:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:19:13 -0500
commitd946a78dde42c1d3a554862a4c62b5c241c20364 (patch)
tree1a7478a49fc40f759ef48b31a9e87069f69dcf14 /source3/modules/vfs_readahead.c
parenta1e72969d571d6b12f4cfa8c6dc16d7d982daa51 (diff)
downloadsamba-d946a78dde42c1d3a554862a4c62b5c241c20364.tar.gz
samba-d946a78dde42c1d3a554862a4c62b5c241c20364.tar.bz2
samba-d946a78dde42c1d3a554862a4c62b5c241c20364.zip
r22105: Added vfs_readahead module that appears to do wonderful things
for copying files from Samba when using Windows Vista Windows explorer.... :-). By default if you add this I can go on my vmware sessions from 7MB/sec to 12MB/sec (+1 extra MB/sec if I turn sendfile on). Jeremy. (This used to be commit 97fdd67e83bb2706106a9bae95b32d8d9f8b4066)
Diffstat (limited to 'source3/modules/vfs_readahead.c')
-rw-r--r--source3/modules/vfs_readahead.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/source3/modules/vfs_readahead.c b/source3/modules/vfs_readahead.c
new file mode 100644
index 0000000000..5b08f004c4
--- /dev/null
+++ b/source3/modules/vfs_readahead.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) Jeremy Allison 2007.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "includes.h"
+
+#if !defined(HAVE_LINUX_READAHEAD) && !defined(HAVE_POSIX_FADVISE)
+static BOOL didmsg;
+#endif
+
+/*
+ * This module copes with Vista AIO read requests on Linux
+ * by detecting the initial 0x80000 boundary reads and causing
+ * the buffer cache to be filled in advance.
+ */
+
+static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
+ int tofd,
+ files_struct *fsp,
+ int fromfd,
+ const DATA_BLOB *header,
+ SMB_OFF_T offset,
+ size_t count)
+{
+ unsigned long off_bound = lp_parm_ulong(SNUM(handle->conn), "readahead", "offset", 0x80000);
+ if ( offset % off_bound == 0) {
+ unsigned long len = lp_parm_ulong(SNUM(handle->conn), "readahead", "length", off_bound);
+#if defined(HAVE_LINUX_READAHEAD)
+ int err = readahead(fromfd, offset, (size_t)len);
+ DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fromfd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ err ));
+#elif defined(HAVE_POSIX_FADVISE)
+ int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+ DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fromfd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ err ));
+#else
+ if (!didmsg) {
+ DEBUG(0,("readahead_sendfile: no readahead on this platform\n"));
+ didmsg = True;
+ }
+#endif
+ }
+ return SMB_VFS_NEXT_SENDFILE(handle,
+ tofd,
+ fsp,
+ fromfd,
+ header,
+ offset,
+ count);
+}
+
+static ssize_t readahead_pread(vfs_handle_struct *handle,
+ files_struct *fsp,
+ int fd,
+ void *data,
+ size_t count,
+ SMB_OFF_T offset)
+{
+ unsigned long off_bound = lp_parm_ulong(SNUM(handle->conn), "readahead", "offset", 0x80000);
+ if ( offset % off_bound == 0) {
+ unsigned long len = lp_parm_ulong(SNUM(handle->conn), "readahead", "length", off_bound);
+#if defined(HAVE_LINUX_READAHEAD)
+ int err = readahead(fd, offset, (size_t)len);
+ DEBUG(10,("readahead_pread: readahead on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ err ));
+#elif defined(HAVE_POSIX_FADVISE)
+ int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+ DEBUG(10,("readahead_pread: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ (err ));
+#else
+ if (!didmsg) {
+ DEBUG(0,("readahead_pread: no readahead on this platform\n"));
+ didmsg = True;
+ }
+#endif
+ }
+ return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset);
+}
+
+static vfs_op_tuple readahead_ops [] =
+{
+ {SMB_VFS_OP(readahead_sendfile), SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(readahead_pread), SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+};
+
+NTSTATUS vfs_readahead_init(void);
+NTSTATUS vfs_readahead_init(void)
+{
+ return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "readahead", readahead_ops);
+}