git: 420e2f8a74df - main - vnode_pager: simplify loop, avoid overflow
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 02 Mar 2025 08:14:22 UTC
The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=420e2f8a74df4be1237244a4ef222d2ceae6823d commit 420e2f8a74df4be1237244a4ef222d2ceae6823d Author: Doug Moore <dougm@FreeBSD.org> AuthorDate: 2025-03-02 08:13:24 +0000 Commit: Doug Moore <dougm@FreeBSD.org> CommitDate: 2025-03-02 08:13:24 +0000 vnode_pager: simplify loop, avoid overflow Filling in read-behind pages in vnode_pager_generic_getpages() is made very slightly simpler here, by avoiding overflowing the startpindex variable and then avoiding an extra test in the allocation loop that handles the overflow case. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49200 --- sys/vm/vnode_pager.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c index d5d312b3cf71..69509fe8948a 100644 --- a/sys/vm/vnode_pager.c +++ b/sys/vm/vnode_pager.c @@ -1045,18 +1045,13 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count, vm_page_t mpred, p; VM_OBJECT_WLOCK(object); - startpindex = m[0]->pindex - rbehind; - if ((mpred = TAILQ_PREV(m[0], pglist, listq)) != NULL && - mpred->pindex >= startpindex) - startpindex = mpred->pindex + 1; + tpindex = m[0]->pindex; + startpindex = MAX(tpindex, rbehind) - rbehind; + if ((mpred = TAILQ_PREV(m[0], pglist, listq)) != NULL) + startpindex = MAX(startpindex, mpred->pindex + 1); - /* - * tpindex is unsigned; beware of numeric underflow. - * Stepping backward from pindex, mpred doesn't change. - */ - for (tpindex = m[0]->pindex - 1; - tpindex >= startpindex && tpindex < m[0]->pindex; - tpindex--, i++) { + /* Stepping backward from pindex, mpred doesn't change. */ + for (; tpindex-- > startpindex; i++) { p = vm_page_alloc_after(object, tpindex, VM_ALLOC_NORMAL, mpred); if (p == NULL) {