From owner-svn-src-projects@FreeBSD.ORG Tue Nov 25 13:06:48 2014 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CAD9B142; Tue, 25 Nov 2014 13:06:48 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 B77B67F4; Tue, 25 Nov 2014 13:06:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sAPD6mdu051681; Tue, 25 Nov 2014 13:06:48 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sAPD6mRk051680; Tue, 25 Nov 2014 13:06:48 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201411251306.sAPD6mRk051680@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Tue, 25 Nov 2014 13:06:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r275037 - projects/sendfile/sys/kern X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2014 13:06:48 -0000 Author: glebius Date: Tue Nov 25 13:06:47 2014 New Revision: 275037 URL: https://svnweb.freebsd.org/changeset/base/275037 Log: - Provide better code to calculate npages and rhpages. - Put a comment explaining logic behind rhpages. Sponsored by: Netflix Sponsored by: Nginx, Inc. Modified: projects/sendfile/sys/kern/uipc_syscalls.c Modified: projects/sendfile/sys/kern/uipc_syscalls.c ============================================================================== --- projects/sendfile/sys/kern/uipc_syscalls.c Tue Nov 25 12:58:21 2014 (r275036) +++ projects/sendfile/sys/kern/uipc_syscalls.c Tue Nov 25 13:06:47 2014 (r275037) @@ -2462,16 +2462,18 @@ retry_space: if (space > rem) space = rem; - if (off & PAGE_MASK) - npages = 1 + howmany(space - - (PAGE_SIZE - (off & PAGE_MASK)), PAGE_SIZE); - else - npages = howmany(space, PAGE_SIZE); - - rhpages = SF_READAHEAD(flags) ? - SF_READAHEAD(flags) : roundup2(rem - space, PAGE_SIZE); - rhpages = min(howmany(obj_size - (off & ~PAGE_MASK) - - (npages * PAGE_SIZE), PAGE_SIZE), rhpages); + npages = howmany(space + (off & PAGE_MASK), PAGE_SIZE); + + /* + * Calculate maximum allowed number of pages for readahead + * at this iteration. First, we allow readahead up to "rem". + * If application wants more, let it be. But check against + * "obj_size", since vm_pager_has_page() can hint beyond EOF. + */ + rhpages = howmany(rem + (off & PAGE_MASK), PAGE_SIZE) - npages; + rhpages = max(SF_READAHEAD(flags), rhpages); + rhpages = min(howmany(obj_size - trunc_page(off), PAGE_SIZE) - + npages, rhpages); sfio = malloc(sizeof(struct sf_io) + (rhpages + npages) * sizeof(vm_page_t), M_TEMP, M_WAITOK);