svn commit: r275037 - projects/sendfile/sys/kern
Gleb Smirnoff
glebius at FreeBSD.org
Tue Nov 25 13:06:48 UTC 2014
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);
More information about the svn-src-projects
mailing list