Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751777AbdDEEeA (ORCPT ); Wed, 5 Apr 2017 00:34:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:60414 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750871AbdDEEd6 (ORCPT ); Wed, 5 Apr 2017 00:33:58 -0400 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "Cc" From: NeilBrown To: Jens Axboe Date: Wed, 05 Apr 2017 14:33:50 +1000 Cc: linux-block@vger.kernel.org, linux-mm@kvack.org, LKML Subject: [PATCH v2] loop: Add PF_LESS_THROTTLE to block/loop device thread. In-Reply-To: <871staffus.fsf@notabene.neil.brown.name> References: <871staffus.fsf@notabene.neil.brown.name> cc: Ming Lei Message-ID: <87wpazh3rl.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3183 Lines: 89 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable When a filesystem is mounted from a loop device, writes are throttled by balance_dirty_pages() twice: once when writing to the filesystem and once when the loop_handle_cmd() writes to the backing file. This double-throttling can trigger positive feedback loops that create significant delays. The throttling at the lower level is seen by the upper level as a slow device, so it throttles extra hard. The PF_LESS_THROTTLE flag was created to handle exactly this circumstance, though with an NFS filesystem mounted from a local NFS server. It reduces the throttling on the lower layer so that it can proceed largely unthrottled. To demonstrate this, create a filesystem on a loop device and write (e.g. with dd) several large files which combine to consume significantly more than the limit set by /proc/sys/vm/dirty_ratio or dirty_bytes. Measure the total time taken. When I do this directly on a device (no loop device) the total time for several runs (mkfs, mount, write 200 files, umount) is fairly stable: 28-35 seconds. When I do this over a loop device the times are much worse and less stable. 52-460 seconds. Half below 100seconds, half above. When I apply this patch, the times become stable again, though not as fast as the no-loop-back case: 53-72 seconds. There may be room for further improvement as the total overhead still seems too high, but this is a big improvement. Reviewed-by: Christoph Hellwig Acked-by: Michal Hocko Signed-off-by: NeilBrown =2D-- I moved where the flag is set, thanks to suggestion from Ming Lei. I've preserved the *-by: tags I was offered despite the code being different, as the concept is identical. Thanks, NeilBrown drivers/block/loop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 0ecb6461ed81..44b3506fd086 100644 =2D-- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -852,6 +852,7 @@ static int loop_prepare_queue(struct loop_device *lo) if (IS_ERR(lo->worker_task)) return -ENOMEM; set_user_nice(lo->worker_task, MIN_NICE); + lo->worker_task->flags |=3D PF_LESS_THROTTLE; return 0; } =20 =2D-=20 2.12.2 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAljkc64ACgkQOeye3VZi gbnVGRAAm447mJ9FGwuu/YvHatsA5po34D2bCIOnY/UKUyPPioo1IEUxPI4OvBlc Y7fBt4LX5S8MTV/DnxtzKNiQrCw80uHlOVW9tZG7ohoRGFher3t6PB044bjN9gD7 jfyStD22FoZCUy3qjCqeClom4noz0TyBep43gqoqIL1t1ko3CQLQ9y3w8SgL2b7f HKoP0BhmIWfvmpPxv+PzthU9ShsD6sleYvV6X7IifiLoccuUD6/laqYv7AQSKT9A 8XSC8TKFvwRtp/ur86bhoWD9ksle9AwowiFuvQRjZVOUqgE79HazEdBm523TI+Hv o3BDEQMiKOKMTsxq6azbEh75NEAQkkxrMxew5c0ar90p9qUfJYJtiOsq5XdUxd2X 5W+NcqhEkFl081FEEk/vQeZcTW4KzKF9i5wFpx5T44ta90h7rPxWsUy5dL7iU6f/ D1hbpDzDQpu4l7SUl9sSUb9Sy6RA4iBNfe42KQfiSJfz5vbFFx7nEYQE3GXNcAys N08W6lmQUmKKrRbEE3OFFprgnkq/JdKr+ZegBzFQYCW0Crswfxf+ZpTGVf2E4mT5 7KYeEXg9YSHUy/nXnUYbujRwGSK6Yotub7Yv1pOmIVJiVxCPVOLQz0uX/xmQ+t1T syRGEtjdoI0z5BVbEd49wdcYDzpONM8mETsSYrd+0fgYn3U/kcE= =FW4L -----END PGP SIGNATURE----- --=-=-=--