Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Nov 2014 13:06:48 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r275037 - projects/sendfile/sys/kern
Message-ID:  <201411251306.sAPD6mRk051680@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411251306.sAPD6mRk051680>