diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2020-11-28 12:12:51 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2020-11-28 12:12:51 +0000 |
commit | cd8537910406e68d4719136a5b0cf6d23bb1b23b (patch) | |
tree | 7859126225cf7d9249711825e217dceba9857d59 /sys/vm/vnode_pager.c | |
parent | 1b9c78611d9de31ed2f942552549f2b6f7891185 (diff) |
Make MAXPHYS tunable. Bump MAXPHYS to 1M.
Replace MAXPHYS by runtime variable maxphys. It is initialized from
MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys.
Make b_pages[] array in struct buf flexible. Size b_pages[] for buffer
cache buffers exactly to atop(maxbcachebuf) (currently it is sized to
atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1.
The +1 for pbufs allow several pbuf consumers, among them vmapbuf(),
to use unaligned buffers still sized to maxphys, esp. when such
buffers come from userspace (*). Overall, we save significant amount
of otherwise wasted memory in b_pages[] for buffer cache buffers,
while bumping MAXPHYS to desired high value.
Eliminate all direct uses of the MAXPHYS constant in kernel and driver
sources, except a place which initialize maxphys. Some random (and
arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted
straight. Some drivers, which use MAXPHYS to size embeded structures,
get private MAXPHYS-like constant; their convertion is out of scope
for this work.
Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs,
dev/siis, where either submitted by, or based on changes by mav.
Suggested by: mav (*)
Reviewed by: imp, mav, imp, mckusick, scottl (intermediate versions)
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D27225
Notes
Notes:
svn path=/head/; revision=368124
Diffstat (limited to 'sys/vm/vnode_pager.c')
-rw-r--r-- | sys/vm/vnode_pager.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c index 0c67a3785ea2..e75c6fb6b5d7 100644 --- a/sys/vm/vnode_pager.c +++ b/sys/vm/vnode_pager.c @@ -817,7 +817,7 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count, KASSERT(foff < object->un_pager.vnp.vnp_size, ("%s: page %p offset beyond vp %p size", __func__, m[0], vp)); - KASSERT(count <= nitems(bp->b_pages), + KASSERT(count <= atop(maxphys), ("%s: requested %d pages", __func__, count)); /* @@ -832,6 +832,7 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count, } bp = uma_zalloc(vnode_pbuf_zone, M_WAITOK); + MPASS((bp->b_flags & B_MAXPHYS) != 0); /* * Get the underlying device blocks for the file with VOP_BMAP(). @@ -916,10 +917,10 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count, * Check that total amount of pages fit into buf. Trim rbehind and * rahead evenly if not. */ - if (rbehind + rahead + count > nitems(bp->b_pages)) { + if (rbehind + rahead + count > atop(maxphys)) { int trim, sum; - trim = rbehind + rahead + count - nitems(bp->b_pages) + 1; + trim = rbehind + rahead + count - atop(maxphys) + 1; sum = rbehind + rahead; if (rbehind == before) { /* Roundup rbehind trim to block size. */ @@ -930,9 +931,9 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count, rbehind -= trim * rbehind / sum; rahead -= trim * rahead / sum; } - KASSERT(rbehind + rahead + count <= nitems(bp->b_pages), - ("%s: behind %d ahead %d count %d", __func__, - rbehind, rahead, count)); + KASSERT(rbehind + rahead + count <= atop(maxphys), + ("%s: behind %d ahead %d count %d maxphys %lu", __func__, + rbehind, rahead, count, maxphys)); /* * Fill in the bp->b_pages[] array with requested and optional @@ -1014,7 +1015,7 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count, *a_rahead = bp->b_pgafter; #ifdef INVARIANTS - KASSERT(bp->b_npages <= nitems(bp->b_pages), + KASSERT(bp->b_npages <= atop(maxphys), ("%s: buf %p overflowed", __func__, bp)); for (int j = 1, prev = 0; j < bp->b_npages; j++) { if (bp->b_pages[j] == bogus_page) |