From d39cb654b847104b75668101dfc57d439c5c4d6e Mon Sep 17 00:00:00 2001 From: ad Date: Sat, 14 Mar 2020 13:39:36 +0000 Subject: [PATCH] tmpfs_inactive(): do like other file systems and truncate the file if it has been deleted. Otherwise VFS will try to write cached data "back to disc", which in the case of a UAO means needless page deactivations and the resulting TLB shootdowns. --- sys/fs/tmpfs/tmpfs_vnops.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 51972b3212db..00b2cd3f5cc8 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: tmpfs_vnops.c,v 1.134 2020/02/23 15:46:40 ad Exp $ */ +/* $NetBSD: tmpfs_vnops.c,v 1.135 2020/03/14 13:39:36 ad Exp $ */ /* * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.134 2020/02/23 15:46:40 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.135 2020/03/14 13:39:36 ad Exp $"); #include #include @@ -1040,6 +1040,7 @@ tmpfs_inactive(void *v) } */ *ap = v; vnode_t *vp = ap->a_vp; tmpfs_node_t *node; + int error = 0; KASSERT(VOP_ISLOCKED(vp)); @@ -1049,12 +1050,21 @@ tmpfs_inactive(void *v) * Mark node as dead by setting its generation to zero. */ atomic_and_32(&node->tn_gen, ~TMPFS_NODE_GEN_MASK); + + /* + * If the file has been deleted, truncate it, otherwise VFS + * will quite rightly try to write back dirty data, which in + * the case of tmpfs/UAO means needless page deactivations. + */ + if (vp->v_type == VREG) { + error = tmpfs_reg_resize(vp, 0); + } *ap->a_recycle = true; } else { *ap->a_recycle = false; } - return 0; + return error; } int