aboutsummaryrefslogtreecommitdiff
path: root/sys/vm/vm_page.c
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2017-06-08 16:18:41 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2017-06-08 16:18:41 +0000
commit4bd7e351f1bebaa86b851f0cbc43f8d46be50a86 (patch)
tree77b27f6a85d48c1cd30f7a17f3cb96e6c4d05925 /sys/vm/vm_page.c
parent86dd278f036d78d54e407fa6b41d61571fc5fdb8 (diff)
downloadsrc-4bd7e351f1bebaa86b851f0cbc43f8d46be50a86.tar.gz
src-4bd7e351f1bebaa86b851f0cbc43f8d46be50a86.zip
Fix an off-by-one error in the VM page array on some systems.
r31386 changed how the size of the VM page array was calculated to be less wasteful. For most systems, the amount of memory is divided by the overhead required by each page (a page of data plus a struct vm_page) to determine the maximum number of available pages. However, if the remainder for the first non-available page was at least a page of data (so that the only memory missing was a struct vm_page), this last page was left in phys_avail[] but was not allocated an entry in the VM page array. Handle this case by explicitly excluding the page from phys_avail[]. Reviewed by: alc Sponsored by: DARPA / AFRL Differential Revision: https://reviews.freebsd.org/D11000
Notes
Notes: svn path=/head/; revision=319702
Diffstat (limited to 'sys/vm/vm_page.c')
-rw-r--r--sys/vm/vm_page.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
index e6befe15b915..66279a243c6e 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -573,8 +573,13 @@ vm_page_startup(vm_offset_t vaddr)
size += vm_phys_segs[i].end - vm_phys_segs[i].start;
for (i = 0; phys_avail[i + 1] != 0; i += 2)
size += phys_avail[i + 1] - phys_avail[i];
- page_range = size / (PAGE_SIZE + sizeof(struct vm_page));
#elif defined(VM_PHYSSEG_DENSE)
+ size = high_avail - low_avail;
+#else
+#error "Either VM_PHYSSEG_DENSE or VM_PHYSSEG_SPARSE must be defined."
+#endif
+
+#ifdef VM_PHYSSEG_DENSE
/*
* In the VM_PHYSSEG_DENSE case, the number of pages can account for
* the overhead of a page structure per page only if vm_page_array is
@@ -582,14 +587,27 @@ vm_page_startup(vm_offset_t vaddr)
* allocate page structures representing the physical memory
* underlying vm_page_array, even though they will not be used.
*/
- if (new_end == high_avail)
- page_range = (high_avail - low_avail) / (PAGE_SIZE +
- sizeof(struct vm_page));
+ if (new_end != high_avail)
+ page_range = size / PAGE_SIZE;
else
- page_range = high_avail / PAGE_SIZE - first_page;
-#else
-#error "Either VM_PHYSSEG_DENSE or VM_PHYSSEG_SPARSE must be defined."
#endif
+ {
+ page_range = size / (PAGE_SIZE + sizeof(struct vm_page));
+
+ /*
+ * If the partial bytes remaining are large enough for
+ * a page (PAGE_SIZE) without a corresponding
+ * 'struct vm_page', then new_end will contain an
+ * extra page after subtracting the length of the VM
+ * page array. Compensate by subtracting an extra
+ * page from new_end.
+ */
+ if (size % (PAGE_SIZE + sizeof(struct vm_page)) >= PAGE_SIZE) {
+ if (new_end == high_avail)
+ high_avail -= PAGE_SIZE;
+ new_end -= PAGE_SIZE;
+ }
+ }
end = new_end;
/*