From owner-svn-src-head@freebsd.org Tue Apr 9 19:55:03 2019 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 B77BD156BC9C; Tue, 9 Apr 2019 19:55:03 +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 5AA7F772D7; Tue, 9 Apr 2019 19:55:03 +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 33400FE9F; Tue, 9 Apr 2019 19:55:03 +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 x39Jt3pS068855; Tue, 9 Apr 2019 19:55:03 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x39Jt35P068854; Tue, 9 Apr 2019 19:55:03 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904091955.x39Jt35P068854@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 9 Apr 2019 19:55:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346064 - head/sys/fs/msdosfs X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/fs/msdosfs X-SVN-Commit-Revision: 346064 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5AA7F772D7 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(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,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: Tue, 09 Apr 2019 19:55:04 -0000 Author: kib Date: Tue Apr 9 19:55:02 2019 New Revision: 346064 URL: https://svnweb.freebsd.org/changeset/base/346064 Log: Fix dirty buf exhaustion easily triggered with msdosfs. If truncate(2) is performed on msdosfs file, which extends the file by system-depended large amount, fs creates corresponding amount of dirty delayed-write buffers, which can consume all buffers. Such buffers cannot be flushed by the bufdaemon because the ftruncate() thread owns the vnode lock. So the system runs out of free buffers, and even truncate() thread starves, which means deadlock because it owns the vnode lock. Fix this by doing vnode fsync in extendfile() when low memory or low buffers condition detected, which flushes all dirty buffers belonging to the file being extended. Note that the more usual fallback to bawrite() does not work acceptable in this situation, because it would only allow one buffer to be recycled. Other filesystems, most important UFS, do not allow userspace to create arbitrary amount of dirty delayed-write buffers without feedback, so bawrite() is good enough for them. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/fs/msdosfs/msdosfs_fat.c Modified: head/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- head/sys/fs/msdosfs/msdosfs_fat.c Tue Apr 9 19:22:08 2019 (r346063) +++ head/sys/fs/msdosfs/msdosfs_fat.c Tue Apr 9 19:55:02 2019 (r346064) @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -979,6 +980,7 @@ extendfile(struct denode *dep, u_long count, struct bu u_long cn, got; struct msdosfsmount *pmp = dep->de_pmp; struct buf *bp; + struct vop_fsync_args fsync_ap; daddr_t blkno; /* @@ -1086,8 +1088,16 @@ extendfile(struct denode *dep, u_long count, struct bu if (bpp) { *bpp = bp; bpp = NULL; - } else + } else { bdwrite(bp); + } + if (vm_page_count_severe() || + buf_dirty_count_severe()) { + fsync_ap.a_vp = DETOV(dep); + fsync_ap.a_waitfor = MNT_WAIT; + fsync_ap.a_td = curthread; + vop_stdfsync(&fsync_ap); + } } } }