From patchwork Tue Nov 6 21:35:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 10671537 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DCB215A6 for ; Tue, 6 Nov 2018 21:56:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C2B428FE3 for ; Tue, 6 Nov 2018 21:56:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4059A29168; Tue, 6 Nov 2018 21:56:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B1AF428FE3 for ; Tue, 6 Nov 2018 21:56:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8895C3082AF5; Tue, 6 Nov 2018 21:56:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 407ED101F94C; Tue, 6 Nov 2018 21:56:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 027DD180B5B7; Tue, 6 Nov 2018 21:56:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA6Ld7lT004259 for ; Tue, 6 Nov 2018 16:39:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2C30A6129B; Tue, 6 Nov 2018 21:39:07 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from leontynka.twibright.com (ovpn-204-55.brq.redhat.com [10.40.204.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 49532607D5; Tue, 6 Nov 2018 21:39:03 +0000 (UTC) Received: from debian-a64.vm ([192.168.208.2]) by leontynka.twibright.com with smtp (Exim 4.89) (envelope-from ) id 1gK93s-0005Nb-Ov; Tue, 06 Nov 2018 22:39:01 +0100 Received: by debian-a64.vm (sSMTP sendmail emulation); Tue, 06 Nov 2018 22:38:56 +0100 Message-Id: <20181106213855.868640480@debian-a64.vm> User-Agent: quilt/0.65 Date: Tue, 06 Nov 2018 22:35:01 +0100 From: Mikulas Patocka To: Mike Snitzer , "Alasdair G. Kergon" MIME-Version: 1.0 Content-Disposition: inline; filename=dm-remove-pending.patch X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Mikulas Patocka Subject: [dm-devel] [patch 3/5] dm: remove the pending variable X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 06 Nov 2018 21:56:19 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Remove the "pending" variable and use dm_disk(md)->part0.in_flight. These variables hold identical values. Signed-off-by: Mikulas Patocka --- drivers/md/dm-core.h | 1 - drivers/md/dm-rq.c | 4 ++-- drivers/md/dm.c | 34 ++++++++++++++++------------------ 3 files changed, 18 insertions(+), 21 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-2.6/drivers/md/dm-core.h =================================================================== --- linux-2.6.orig/drivers/md/dm-core.h 2018-10-25 00:47:12.000000000 +0200 +++ linux-2.6/drivers/md/dm-core.h 2018-10-25 00:47:12.000000000 +0200 @@ -65,7 +65,6 @@ struct mapped_device { */ struct work_struct work; wait_queue_head_t wait; - atomic_t pending[2]; spinlock_t deferred_lock; struct bio_list deferred; Index: linux-2.6/drivers/md/dm.c =================================================================== --- linux-2.6.orig/drivers/md/dm.c 2018-10-25 00:47:12.000000000 +0200 +++ linux-2.6/drivers/md/dm.c 2018-10-25 00:47:28.000000000 +0200 @@ -597,23 +597,20 @@ static void free_tio(struct dm_target_io int md_in_flight(struct mapped_device *md) { - return atomic_read(&md->pending[READ]) + - atomic_read(&md->pending[WRITE]); + return atomic_read(&dm_disk(md)->part0.in_flight[READ]) + + atomic_read(&dm_disk(md)->part0.in_flight[WRITE]); } static void start_io_acct(struct dm_io *io) { struct mapped_device *md = io->md; struct bio *bio = io->orig_bio; - int rw = bio_data_dir(bio); io->start_time = jiffies; generic_start_io_acct(md->queue, bio_op(bio), bio_sectors(bio), &dm_disk(md)->part0); - atomic_inc(&md->pending[rw]); - if (unlikely(dm_stats_used(&md->stats))) dm_stats_account_io(&md->stats, bio_data_dir(bio), bio->bi_iter.bi_sector, bio_sectors(bio), @@ -625,27 +622,30 @@ static void end_io_acct(struct dm_io *io struct mapped_device *md = io->md; struct bio *bio = io->orig_bio; unsigned long duration = jiffies - io->start_time; - int pending; - int rw = bio_data_dir(bio); + /* + * make sure that atomic_dec in generic_end_io_acct is not reordered + * with previous writes + */ + smp_mb__before_atomic(); generic_end_io_acct(md->queue, bio_op(bio), &dm_disk(md)->part0, io->start_time); + /* + * generic_end_io_acct does atomic_dec, this barrier makes sure that + * atomic_dec is not reordered with waitqueue_active + */ + smp_mb__after_atomic(); if (unlikely(dm_stats_used(&md->stats))) dm_stats_account_io(&md->stats, bio_data_dir(bio), bio->bi_iter.bi_sector, bio_sectors(bio), true, duration, &io->stats_aux); - /* - * After this is decremented the bio must not be touched if it is - * a flush. - */ - pending = atomic_dec_return(&md->pending[rw]); - pending += atomic_read(&md->pending[rw^0x1]); - /* nudge anyone waiting on suspend queue */ - if (!pending) - wake_up(&md->wait); + if (unlikely(waitqueue_active(&md->wait))) { + if (!md_in_flight(md)) + wake_up(&md->wait); + } } /* @@ -1899,8 +1899,6 @@ static struct mapped_device *alloc_dev(i if (!md->disk) goto bad; - atomic_set(&md->pending[0], 0); - atomic_set(&md->pending[1], 0); init_waitqueue_head(&md->wait); INIT_WORK(&md->work, dm_wq_work); init_waitqueue_head(&md->eventq); Index: linux-2.6/drivers/md/dm-rq.c =================================================================== --- linux-2.6.orig/drivers/md/dm-rq.c 2018-10-25 00:47:12.000000000 +0200 +++ linux-2.6/drivers/md/dm-rq.c 2018-10-25 00:47:12.000000000 +0200 @@ -182,7 +182,7 @@ static void rq_completed(struct mapped_d struct request_queue *q = md->queue; unsigned long flags; - atomic_dec(&md->pending[rw]); + atomic_dec(&dm_disk(md)->part0.in_flight[rw]); /* nudge anyone waiting on suspend queue */ if (!md_in_flight(md)) @@ -536,7 +536,7 @@ static void dm_start_request(struct mapp blk_start_request(orig); else blk_mq_start_request(orig); - atomic_inc(&md->pending[rq_data_dir(orig)]); + atomic_inc(&dm_disk(md)->part0.in_flight[rq_data_dir(orig)]); if (md->seq_rq_merge_deadline_usecs) { md->last_rq_pos = rq_end_sector(orig);