From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 12 18:19:30 2012 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 511B7106566C for ; Mon, 12 Mar 2012 18:19:30 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id D78348FC0A for ; Mon, 12 Mar 2012 18:19:29 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q2CIJMX7030536; Mon, 12 Mar 2012 20:19:22 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q2CIJL0W031582; Mon, 12 Mar 2012 20:19:21 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q2CIJLkQ031581; Mon, 12 Mar 2012 20:19:21 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 12 Mar 2012 20:19:21 +0200 From: Konstantin Belousov To: Svatopluk Kraus Message-ID: <20120312181921.GF75778@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sFvwHbI2VNbToG61" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: hackers@freebsd.org Subject: Re: [vfs] buf_daemon() slows down write() severely on low-speed CPU X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Mar 2012 18:19:30 -0000 --sFvwHbI2VNbToG61 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 12, 2012 at 04:00:58PM +0100, Svatopluk Kraus wrote: > Hi, >=20 > I have solved a following problem. If a big file (according to > 'hidirtybuffers') is being written, the write speed is very poor. >=20 > It's observed on system with elan 486 and 32MB RAM (i.e., low speed > CPU and not too much memory) running FreeBSD-9. >=20 > Analysis: A file is being written. All or almost all dirty buffers > belong to the file. The file vnode is almost all time locked by > writing process. The buf_daemon() can not flush any dirty buffer as a > chance to acquire the file vnode lock is very low. A number of dirty > buffers grows up very slow and with each new dirty buffer slower, > because buf_daemon() eats more and more CPU time by looping on dirty > buffers queue (with very low or no effect). >=20 > This slowing down effect is started by buf_daemon() itself, when > 'numdirtybuffers' reaches 'lodirtybuffers' threshold and buf_daemon() > is waked up by own timeout. The timeout fires at 'hz' period, but > starts to fire at 'hz/10' immediately as buf_daemon() fails to reach > 'lodirtybuffers' threshold. When 'numdirtybuffers' (now slowly) > reaches ((lodirtybuffers + hidirtybuffers) / 2) threshold, the > buf_daemon() can be waked up within bdwrite() too and it's much worse. > Finally and with very slow speed, the 'hidirtybuffers' or > 'dirtybufthresh' is reached, the dirty buffers are flushed, and > everything starts from beginning... Note that for some time, bufdaemon work is distributed among bufdaemon thread itself and any thread that fails to allocate a buffer, esp. a thread that owns vnode lock and covers long queue of dirty buffers. >=20 > On the system, a buffer size is 512 bytes and the default > thresholds are following: >=20 > vfs.hidirtybuffers =3D 134 > vfs.lodirtybuffers =3D 67 > vfs.dirtybufthresh =3D 120 >=20 > For example, a 2MB file is copied into flash disk in about 3 > minutes and 15 second. If dirtybufthresh is set to 40, the copy time > is about 20 seconds. >=20 > My solution is a mix of three things: > 1. Suppresion of buf_daemon() wakeup by setting bd_request to 1 in > the main buf_daemon() loop. I cannot understand this. Please provide a patch that shows what do you mean there. > 2. Increment of buf_daemon() fast timeout from hz/10 to hz/4. > 3. Tuning dirtybufthresh to (((lodirtybuffers + hidirtybuffers) / > 2) - 15) magic. Even hz / 10 is awfully long time on modern hardware. The dirtybufthresh is already the sysctl that you can change. The 32MB is indeed around the lowest amount of memory where recent FreeBSD can make an illusion of being useful. I am not sure how much should the system be tuned by default for such configuration. >=20 > The mention copy time is about 30 seconds now. >=20 > The described problem is just for information to anyone who can be > interested in. Comments are welcome. However, the bd_request thing is > more general. >=20 > bd_request (despite its description) should be 0 only when > buf_daemon() is in sleep(). Otherwise, wakeup() on &bd_request channel > is useless. Therefore, setting bd_request to 1 in the main > buf_daemon() loop is correct and better as it saves time spent by > wakeup() on not existing channel. >=20 > Svata > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" --sFvwHbI2VNbToG61 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk9ePikACgkQC3+MBN1Mb4g94ACdHGCcO1o/TXTmOUMrra7wJpJF lh8Anj+gEcJVhbFMnNi3o8mIFbbV7790 =J4sI -----END PGP SIGNATURE----- --sFvwHbI2VNbToG61--