Date: Fri, 21 Oct 2011 17:48:11 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 200534 for review Message-ID: <201110211748.p9LHmBji041821@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@200534?ac=10 Change 200534 by jhb@jhb_jhbbsd on 2011/10/21 17:47:20 - A nit from mdf. - Rework FADV_DONTNEED. vm_object_sync() did not work because the buffer cache still had buffers holding onto the pages, so vm_object_page_remove() did not actually remove any pages. vinvalbuf() will flush all the open buffers (though it is a bit heavy-handed as it does all of the buffers and not just buffers for the requested range). Affected files ... .. //depot/projects/fadvise/sys/kern/vfs_syscalls.c#7 edit Differences ... ==== //depot/projects/fadvise/sys/kern/vfs_syscalls.c#7 (text+ko) ==== @@ -61,6 +61,7 @@ #include <sys/filio.h> #include <sys/limits.h> #include <sys/linker.h> +#include <sys/mman.h> #include <sys/sdt.h> #include <sys/stat.h> #include <sys/sx.h> @@ -4861,7 +4862,7 @@ int error, vfslocked; if (uap->offset < 0 || uap->len < 0 || - uap->offset + uap->len < uap->offset) + uap->offset > OFF_MAX - uap->len) return (EINVAL); switch (uap->advice) { case FADV_NORMAL: @@ -4959,12 +4960,24 @@ break; case FADV_DONTNEED: /* - * Invalidate pages from the backing VM object similar - * to msync(MS_INVALIDATE). + * Flush any open FS buffers and then remove pages + * from the backing VM object. */ - if (vp->v_object != NULL) - vm_object_sync(vp->v_object, uap->offset, end - uap->offset, - FALSE, TRUE); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + if (vp->v_iflag & VI_DOOMED) { + VOP_UNLOCK(vp, 0); + break; + } + vinvalbuf(vp, V_NORMAL, 0, 0); + if (vp->v_object != NULL) { + start = trunc_page(uap->offset); + end = round_page(end); + VM_OBJECT_LOCK(vp->v_object); + vm_object_page_remove(vp->v_object, OFF_TO_IDX(start), + OFF_TO_IDX(end), OBJPR_CLEANONLY | OBJPR_DEBUG); + VM_OBJECT_UNLOCK(vp->v_object); + } + VOP_UNLOCK(vp, 0); break; } out:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110211748.p9LHmBji041821>