From patchwork Wed Oct 26 08:57:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9396401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 442DA60234 for ; Wed, 26 Oct 2016 09:02:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00AFA297CD for ; Wed, 26 Oct 2016 09:02:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E92D7297D3; Wed, 26 Oct 2016 09:02:04 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A938E29852 for ; Wed, 26 Oct 2016 09:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757407AbcJZI6U (ORCPT ); Wed, 26 Oct 2016 04:58:20 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34053 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756895AbcJZI55 (ORCPT ); Wed, 26 Oct 2016 04:57:57 -0400 Received: by mail-pf0-f175.google.com with SMTP id n85so19855695pfi.1; Wed, 26 Oct 2016 01:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=1YbR6hvaZuqbxDjx/nVwvvln6Ky5s3sCyPS3ipcJnCw=; b=WQ2HgZnzhQ5gQPFRVQ3TQp80SqXrQ/lmaxRk5nvXGuqzLFBIGfiX15LwJQ19d7j30O Dxr2AHmNz5UHOAGdMmB3c9W2KGYpDBNzopDEGI8N8/TutP4BEG2Nr+2EFXyBlrbtnVRk 06bK/9bXhx+yFOvD8rG1pSm/AgpwQaRzdJo8u77vA6qqb2iyDXiOIx7+qVq0Mqw8hyir nUSovnBjq/JvV3r8XbQSm72lMp3hgaaEhBSyleqi/vDtXhJY7idwkUPx5JUsOFQj7nYm gwyflHYozZfu+2mfDFTjLBCF/9+vZshfBFHbDkQzP2l7bPEU9vOKZl6gGhtfpmH0sBF9 bu6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1YbR6hvaZuqbxDjx/nVwvvln6Ky5s3sCyPS3ipcJnCw=; b=XSEXe+OCFnsLYKqzKwY341N5JmTm11nkivrCr8O4n75ns6UbdKQcRTMHL1Lye1tHXy mV3DYUAZahzQnjVD2eU2MMo7bwFcTeVrnWOmaBgDoSgEjSzq6kJXa9V7PfbwXSYhtT+I uMt5zLHetOLzr/g5kdoOkqTWsenBKrUAV09W48NyoOlh+p4HPPLf7GjmR0BUWlL4r7hL OtDWrbMKfCSGihlmsDjjp0MwQIokH1eIQcy2fuvMbmLc43teFuQ8Zomvgqpe5TxRAKao /VPLVLEujd4bH/JSXAzTo8an5qiJYuMY1b4SV0cXvX++ZEdwITHhFqiHo0XrwLPVsu1q RWAw== X-Gm-Message-State: ABUngveVzGiyzluXnNWnPJSDc2X0+x3W2xN5wvwRfQIg+DnluJ02xblghjHrcdpuTjPGVQ== X-Received: by 10.98.9.147 with SMTP id 19mr2225176pfj.68.1477472276525; Wed, 26 Oct 2016 01:57:56 -0700 (PDT) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id a141sm2485104pfa.38.2016.10.26.01.57.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Oct 2016 01:57:55 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Kent Overstreet , Ming Lei , Jens Axboe Subject: [PATCH] block: flush: fix IO hang in case of flood fua req Date: Wed, 26 Oct 2016 16:57:15 +0800 Message-Id: <1477472235-22845-1-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes one issue reported by Kent, which can be triggered in bcachefs over sata disk. Actually it is a generic issue in block flush vs. blk-tag. Cc: Christoph Hellwig Reported-by: Kent Overstreet Signed-off-by: Ming Lei --- block/blk-flush.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/block/blk-flush.c b/block/blk-flush.c index 6a14b68b9135..3c882cbc7541 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -343,6 +343,34 @@ static void flush_data_end_io(struct request *rq, int error) struct blk_flush_queue *fq = blk_get_flush_queue(q, NULL); /* + * Updating q->in_flight[] here for making this tag usable + * early. Because in blk_queue_start_tag(), + * q->in_flight[BLK_RW_ASYNC] is used to limit async I/O and + * reserve tags for sync I/O. + * + * More importantly this way can avoid the following I/O + * deadlock: + * + * - suppose there are 40 fua requests comming to flush queue + * and queue depth is 31 + * - 30 rqs are scheduled then blk_queue_start_tag() can't alloc + * tag for async I/O any more + * - all the 30 rqs are completed before FLUSH_PENDING_TIMEOUT + * and flush_data_end_io() is called + * - the other rqs still can't go ahead if not updating + * q->in_flight[BLK_RW_ASYNC] here, meantime these rqs + * are held in flush data queue and make no progress of + * handling post flush rq + * - only after the post flush rq is handled, all these rqs + * can be completed + */ + + elv_completed_request(q, rq); + + /* for avoiding double accounting */ + rq->cmd_flags &= ~REQ_STARTED; + + /* * After populating an empty queue, kick it to avoid stall. Read * the comment in flush_end_io(). */