Date: Thu, 8 Jun 2017 16:18:41 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319702 - head/sys/vm Message-ID: <201706081618.v58GIfZi066106@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Thu Jun 8 16:18:41 2017 New Revision: 319702 URL: https://svnweb.freebsd.org/changeset/base/319702 Log: 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 Modified: head/sys/vm/vm_page.c Modified: head/sys/vm/vm_page.c ============================================================================== --- head/sys/vm/vm_page.c Thu Jun 8 16:04:13 2017 (r319701) +++ head/sys/vm/vm_page.c Thu Jun 8 16:18:41 2017 (r319702) @@ -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; /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706081618.v58GIfZi066106>