summaryrefslogtreecommitdiffstats
path: root/sys/vm
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2017-06-21 14:36:25 +0000
committerjhb <jhb@FreeBSD.org>2017-06-21 14:36:25 +0000
commit7c3be1ddf9d67cc3fcb6634019a3b17fe794c9b4 (patch)
tree54e956871cc3cee95b5017f7f5d02df4671d6e32 /sys/vm
parent97b72fdc537ee98a3ab11fd37160d91ee463f929 (diff)
downloadFreeBSD-src-7c3be1ddf9d67cc3fcb6634019a3b17fe794c9b4.zip
FreeBSD-src-7c3be1ddf9d67cc3fcb6634019a3b17fe794c9b4.tar.gz
MFC 319702: Fix an off-by-one error in the VM page array on some systems.
r313186 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[]. Approved by: re (kib)
Diffstat (limited to 'sys/vm')
-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 feb30cc..ec721b2 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -561,8 +561,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
@@ -570,14 +575,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;
/*
OpenPOWER on IntegriCloud