From owner-svn-src-head@freebsd.org Thu Nov 17 21:36:20 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1CC8DC468B4; Thu, 17 Nov 2016 21:36:20 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EDED57C5; Thu, 17 Nov 2016 21:36:19 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAHLaJvH024217; Thu, 17 Nov 2016 21:36:19 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAHLaI6m024214; Thu, 17 Nov 2016 21:36:18 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201611172136.uAHLaI6m024214@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 17 Nov 2016 21:36:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r308784 - in head: lib/libc/sys sys/kern sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Nov 2016 21:36:20 -0000 Author: glebius Date: Thu Nov 17 21:36:18 2016 New Revision: 308784 URL: https://svnweb.freebsd.org/changeset/base/308784 Log: Add flag SF_USER_READAHEAD to sendfile(2). When specified, the syscall won't do any speculations about readahead, and use exactly the amount of readahead specified by user. E.g. setting SF_FLAGS(0, SF_USER_READAHEAD) will guarantee that no readahead at all will be performed. Modified: head/lib/libc/sys/sendfile.2 head/sys/kern/kern_sendfile.c head/sys/sys/socket.h Modified: head/lib/libc/sys/sendfile.2 ============================================================================== --- head/lib/libc/sys/sendfile.2 Thu Nov 17 21:02:55 2016 (r308783) +++ head/lib/libc/sys/sendfile.2 Thu Nov 17 21:36:18 2016 (r308784) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 7, 2016 +.Dd November 17, 2016 .Dt SENDFILE 2 .Os .Sh NAME @@ -155,8 +155,33 @@ sleeps until the network stack no longer of the file, making subsequent modifications to it safe. Please note that this is not a guarantee that the data has actually been sent. +.It Dv SF_USER_READAHEAD +.Nm +has some internal heuristics to do readahead when sending data. +This flag forces +.Nm +to override any heuristically calculated readahead and use exactly the +application specified readahead. +See +.Sx SETTING READAHEAD +for more details on readahead. .El .Pp +When using a socket marked for non-blocking I/O, +.Fn sendfile +may send fewer bytes than requested. +In this case, the number of bytes successfully +written is returned in +.Fa *sbytes +(if specified), +and the error +.Er EAGAIN +is returned. +.Sh SETTING READAHEAD +.Nm +uses internal heuristics based on request size and file system layout +to do readahead. +Additionally application may request extra readahead. The most significant 16 bits of .Fa flags specify amount of pages that @@ -173,16 +198,13 @@ flag: SF_FLAGS(16, SF_NOCACHE) .Ed .Pp -When using a socket marked for non-blocking I/O, -.Fn sendfile -may send fewer bytes than requested. -In this case, the number of bytes successfully -written is returned in -.Fa *sbytes -(if specified), -and the error -.Er EAGAIN -is returned. +.Nm +will use either application specified readahead or internally calculated, +whichever is bigger. +Setting flag +.Dv SF_USER_READAHEAD +would turn off any heuristics and set maximum possible readahead length to +the number of pages specified via flags. .Sh IMPLEMENTATION NOTES The .Fx Modified: head/sys/kern/kern_sendfile.c ============================================================================== --- head/sys/kern/kern_sendfile.c Thu Nov 17 21:02:55 2016 (r308783) +++ head/sys/kern/kern_sendfile.c Thu Nov 17 21:36:18 2016 (r308784) @@ -706,13 +706,20 @@ retry_space: /* * Calculate maximum allowed number of pages for readahead - * at this iteration. First, we allow readahead up to "rem". + * at this iteration. If SF_USER_READAHEAD was set, we don't + * do any heuristics and use exactly the value supplied by + * application. Otherwise, we allow readahead up to "rem". * If application wants more, let it be, but there is no * reason to go above MAXPHYS. Also check against "obj_size", * since vm_pager_has_page() can hint beyond EOF. */ - rhpages = howmany(rem + (off & PAGE_MASK), PAGE_SIZE) - npages; - rhpages += SF_READAHEAD(flags); + if (flags & SF_USER_READAHEAD) { + rhpages = SF_READAHEAD(flags); + } else { + rhpages = howmany(rem + (off & PAGE_MASK), PAGE_SIZE) - + npages; + rhpages += SF_READAHEAD(flags); + } rhpages = min(howmany(MAXPHYS, PAGE_SIZE), rhpages); rhpages = min(howmany(obj_size - trunc_page(off), PAGE_SIZE) - npages, rhpages); Modified: head/sys/sys/socket.h ============================================================================== --- head/sys/sys/socket.h Thu Nov 17 21:02:55 2016 (r308783) +++ head/sys/sys/socket.h Thu Nov 17 21:36:18 2016 (r308784) @@ -590,6 +590,7 @@ struct sf_hdtr { #define SF_NODISKIO 0x00000001 #define SF_MNOWAIT 0x00000002 /* obsolete */ #define SF_SYNC 0x00000004 +#define SF_USER_READAHEAD 0x00000008 #define SF_NOCACHE 0x00000010 #define SF_FLAGS(rh, flags) (((rh) << 16) | (flags))