From owner-svn-src-head@freebsd.org Tue Feb 4 19:03:38 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 941A42301CA; Tue, 4 Feb 2020 19:03:38 +0000 (UTC) (envelope-from kib@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 48BvHG3SMdz4Mqb; Tue, 4 Feb 2020 19:03:38 +0000 (UTC) (envelope-from kib@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 71FAA1E77F; Tue, 4 Feb 2020 19:03:38 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 014J3cXJ040035; Tue, 4 Feb 2020 19:03:38 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 014J3cIZ040033; Tue, 4 Feb 2020 19:03:38 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202002041903.014J3cIZ040033@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 4 Feb 2020 19:03:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357514 - head/sys/vm X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/vm X-SVN-Commit-Revision: 357514 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Tue, 04 Feb 2020 19:03:38 -0000 Author: kib Date: Tue Feb 4 19:03:37 2020 New Revision: 357514 URL: https://svnweb.freebsd.org/changeset/base/357514 Log: Enable vm_object_mightbedirty() and vm_object_page_clean() for swap objects backing tmpfs vnodes data. The clean scan is limited to only remove write permissions from the mapped pages of the objects. This fixes the issue that tmpfs vnode mtime is not updated from writes to the mmaped area after the initial page-in. Noted by: mjg Reviewed by: markj Discussed with: jeff Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D23432 Modified: head/sys/vm/vm_object.c head/sys/vm/vm_object.h Modified: head/sys/vm/vm_object.c ============================================================================== --- head/sys/vm/vm_object.c Tue Feb 4 19:01:17 2020 (r357513) +++ head/sys/vm/vm_object.c Tue Feb 4 19:03:37 2020 (r357514) @@ -1017,6 +1017,10 @@ vm_object_page_remove_write(vm_page_t p, int flags, bo * write out pages with PGA_NOSYNC set (originally comes from MAP_NOSYNC), * leaving the object dirty. * + * For swap objects backing tmpfs regular files, do not flush anything, + * but remove write protection on the mapped pages to update mtime through + * mmaped writes. + * * When stuffing pages asynchronously, allow clustering. XXX we need a * synchronous clustering mode implementation. * @@ -1038,8 +1042,7 @@ vm_object_page_clean(vm_object_t object, vm_ooffset_t VM_OBJECT_ASSERT_WLOCKED(object); - if (object->type != OBJT_VNODE || !vm_object_mightbedirty(object) || - object->resident_page_count == 0) + if (!vm_object_mightbedirty(object) || object->resident_page_count == 0) return (TRUE); pagerflags = (flags & (OBJPC_SYNC | OBJPC_INVAL)) != 0 ? @@ -1072,32 +1075,36 @@ rescan: vm_page_xunbusy(p); continue; } + if (object->type == OBJT_VNODE) { + n = vm_object_page_collect_flush(object, p, pagerflags, + flags, &allclean, &eio); + if (eio) { + res = FALSE; + allclean = FALSE; + } + if (object->generation != curgeneration && + (flags & OBJPC_SYNC) != 0) + goto rescan; - n = vm_object_page_collect_flush(object, p, pagerflags, - flags, &allclean, &eio); - if (eio) { - res = FALSE; - allclean = FALSE; - } - if (object->generation != curgeneration && - (flags & OBJPC_SYNC) != 0) - goto rescan; - - /* - * If the VOP_PUTPAGES() did a truncated write, so - * that even the first page of the run is not fully - * written, vm_pageout_flush() returns 0 as the run - * length. Since the condition that caused truncated - * write may be permanent, e.g. exhausted free space, - * accepting n == 0 would cause an infinite loop. - * - * Forwarding the iterator leaves the unwritten page - * behind, but there is not much we can do there if - * filesystem refuses to write it. - */ - if (n == 0) { + /* + * If the VOP_PUTPAGES() did a truncated write, so + * that even the first page of the run is not fully + * written, vm_pageout_flush() returns 0 as the run + * length. Since the condition that caused truncated + * write may be permanent, e.g. exhausted free space, + * accepting n == 0 would cause an infinite loop. + * + * Forwarding the iterator leaves the unwritten page + * behind, but there is not much we can do there if + * filesystem refuses to write it. + */ + if (n == 0) { + n = 1; + allclean = FALSE; + } + } else { n = 1; - allclean = FALSE; + vm_page_xunbusy(p); } np = vm_page_find_least(object, pi + n); } @@ -1105,7 +1112,12 @@ rescan: VOP_FSYNC(vp, (pagerflags & VM_PAGER_PUT_SYNC) ? MNT_WAIT : 0); #endif - if (allclean) + /* + * Leave updating cleangeneration for tmpfs objects to tmpfs + * scan. It needs to update mtime, which happens for other + * filesystems during page writeouts. + */ + if (allclean && object->type == OBJT_VNODE) object->cleangeneration = curgeneration; return (res); } Modified: head/sys/vm/vm_object.h ============================================================================== --- head/sys/vm/vm_object.h Tue Feb 4 19:01:17 2020 (r357513) +++ head/sys/vm/vm_object.h Tue Feb 4 19:03:37 2020 (r357514) @@ -322,8 +322,15 @@ static __inline bool vm_object_mightbedirty(vm_object_t object) { - return (object->type == OBJT_VNODE && - object->generation != object->cleangeneration); + if (object->type != OBJT_VNODE) { + if ((object->flags & OBJ_TMPFS_NODE) == 0) + return (false); +#ifdef KASSERT + KASSERT(object->type == OBJT_SWAP, + ("TMPFS_NODE obj %p is not swap", object)); +#endif + } + return (object->generation != object->cleangeneration); } void vm_object_clear_flag(vm_object_t object, u_short bits);