Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Mar 2012 20:19:21 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Svatopluk Kraus <onwahe@gmail.com>
Cc:        hackers@freebsd.org
Subject:   Re: [vfs] buf_daemon() slows down write() severely on low-speed CPU
Message-ID:  <20120312181921.GF75778@deviant.kiev.zoral.com.ua>
In-Reply-To: <CAFHCsPVqNCYj-obQqS4iyKR-xK0AaRJU_6KX=fccEK4U8NaktQ@mail.gmail.com>
References:  <CAFHCsPVqNCYj-obQqS4iyKR-xK0AaRJU_6KX=fccEK4U8NaktQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120312181921.GF75778>