From owner-freebsd-fs@freebsd.org Mon May 16 21:54:37 2016 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D47D5B387D4 for ; Mon, 16 May 2016 21:54:37 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mailman.ysv.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id C46E518E0 for ; Mon, 16 May 2016 21:54:37 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: by mailman.ysv.freebsd.org (Postfix) id C008EB387D3; Mon, 16 May 2016 21:54:37 +0000 (UTC) Delivered-To: fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BFAECB387D2 for ; Mon, 16 May 2016 21:54:37 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by mx1.freebsd.org (Postfix) with ESMTP id 8D6FA18DF for ; Mon, 16 May 2016 21:54:37 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id E24C64271DC for ; Tue, 17 May 2016 07:54:28 +1000 (AEST) Date: Tue, 17 May 2016 07:54:27 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: fs@freebsd.org Subject: quick fix for slow directory shrinking in ffs Message-ID: <20160517072705.F2157@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=TuMb/2jh c=1 sm=1 tr=0 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=pubc52WGR5en7ZIXB40A:9 a=CjuIK1q_8ugA:10 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2016 21:54:37 -0000 ffs does very slow shrinking of directories after removing some files leaves unused blocks at the end, by always doing synchronous truncation. This often happens in my normal usage: medium size builds expand /tmp from 512 to 1024 to hold a few more hundred bytes of file names; expansion is async and fast, but shrinking is sync and slow, and with a certain size of build the boundary is crossed back and forth very often. My /tmp directory is always on an async-mounted file system, so this quick fix of always doing an async truncation for async mounts works for me. Using IO_SYNC when not asked to is a bug for async mounts in all cases anyway. The file system has block size 8192 and frag size 1024, so it is also wrong to shrink to size DIRBLKSIZE = 512. The shrinkage seems to be considered at every DIRBLKSIZE boundary, so not only small directories are affected. The patch fixes an unrelated typo in a message. X Index: ufs_lookup.c X =================================================================== X --- ufs_lookup.c (revision 299263) X +++ ufs_lookup.c (working copy) X @@ -1131,9 +1131,9 @@ X if (tvp != NULL) X VOP_UNLOCK(tvp, 0); X error = UFS_TRUNCATE(dvp, (off_t)dp->i_endoff, X - IO_NORMAL | IO_SYNC, cr); X + IO_NORMAL | (DOINGASYNC(dvp) ? 0 : IO_SYNC), cr); X if (error != 0) X - vprint("ufs_direnter: failted to truncate", dvp); X + vprint("ufs_direnter: failed to truncate", dvp); X #ifdef UFS_DIRHASH X if (error == 0 && dp->i_dirhash != NULL) X ufsdirhash_dirtrunc(dp, dp->i_endoff); Bruce