From owner-svn-src-head@freebsd.org Fri Dec 21 04:58:00 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 37568133D571; Fri, 21 Dec 2018 04:58:00 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D09A6860C2; Fri, 21 Dec 2018 04:57:59 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A4FB88740; Fri, 21 Dec 2018 04:57:59 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBL4vxHt011867; Fri, 21 Dec 2018 04:57:59 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBL4vxBR011866; Fri, 21 Dec 2018 04:57:59 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201812210457.wBL4vxBR011866@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Fri, 21 Dec 2018 04:57:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342295 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: bde X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 342295 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D09A6860C2 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.948,0]; NEURAL_HAM_LONG(-1.00)[-0.999,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2018 04:58:00 -0000 Author: bde Date: Fri Dec 21 04:57:59 2018 New Revision: 342295 URL: https://svnweb.freebsd.org/changeset/base/342295 Log: Fix rounding in vop_stdadvise() for POSIX_FADV_NOREUSE (really POSIX_FADV_DONTNEED). The most broken case was for applications that advise for the whole file and then do block-aligned i/o's 1 block at a time. Then advice is sent to VOP_ADVISE() 1 block at a time, but in vop_stdadvise() the 1-block advice was turned into 0-block advice for the buffer cache part. The bugs were caused partly by callers representing the region as (a_start, a_end), where a_end is actually the maximum, and everything else representing the region as (start, end) where 'end' is actually the end (1 after the maximum). The maximum a_end must be rounded up, but was rounded down. Also, rounding to page boundaries was inconsistent. The bugs and fixes have no effect for zfs and other file systems that don't use the buffer cache or the page cache. Most or all file systems currently use the default VOP_FADVISE(), but it finds a null buffer cache and a null page cache for file systems that don't use normal methods. Reviewed by: kib Modified: head/sys/kern/vfs_default.c Modified: head/sys/kern/vfs_default.c ============================================================================== --- head/sys/kern/vfs_default.c Fri Dec 21 02:26:08 2018 (r342294) +++ head/sys/kern/vfs_default.c Fri Dec 21 04:57:59 2018 (r342295) @@ -1063,7 +1063,7 @@ vop_stdadvise(struct vop_advise_args *ap) struct vnode *vp; struct bufobj *bo; daddr_t startn, endn; - off_t start, end; + off_t bstart, bend, start, end; int bsize, error; vp = ap->a_vp; @@ -1085,14 +1085,27 @@ vop_stdadvise(struct vop_advise_args *ap) } /* + * Round to block boundaries (and later possibly further to + * page boundaries). Applications cannot reasonably be aware + * of the boundaries, and the rounding must be to expand at + * both extremities to cover enough. It still doesn't cover + * read-ahead. For partial blocks, this gives unnecessary + * discarding of buffers but is efficient enough since the + * pages usually remain in VMIO for some time. + */ + bsize = vp->v_bufobj.bo_bsize; + bstart = roundup(ap->a_start, bsize); + bend = roundup(ap->a_end, bsize); + + /* * Deactivate pages in the specified range from the backing VM * object. Pages that are resident in the buffer cache will * remain wired until their corresponding buffers are released * below. */ if (vp->v_object != NULL) { - start = trunc_page(ap->a_start); - end = round_page(ap->a_end); + start = trunc_page(bstart); + end = round_page(bend); VM_OBJECT_RLOCK(vp->v_object); vm_object_page_noreuse(vp->v_object, OFF_TO_IDX(start), OFF_TO_IDX(end)); @@ -1101,9 +1114,8 @@ vop_stdadvise(struct vop_advise_args *ap) bo = &vp->v_bufobj; BO_RLOCK(bo); - bsize = vp->v_bufobj.bo_bsize; - startn = ap->a_start / bsize; - endn = ap->a_end / bsize; + startn = bstart / bsize; + endn = bend / bsize; error = bnoreuselist(&bo->bo_clean, bo, startn, endn); if (error == 0) error = bnoreuselist(&bo->bo_dirty, bo, startn, endn);