From patchwork Sun Dec 6 05:53:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11953643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3650DC4167B for ; Sun, 6 Dec 2020 05:54:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0482E22D2A for ; Sun, 6 Dec 2020 05:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725787AbgLFFyV (ORCPT ); Sun, 6 Dec 2020 00:54:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgLFFyU (ORCPT ); Sun, 6 Dec 2020 00:54:20 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23251C0613D0; Sat, 5 Dec 2020 21:53:40 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id o9so6772220pfd.10; Sat, 05 Dec 2020 21:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9L0GtDNu2fUqJk744rzWyv0yzJxmbFB3ZB4AjTTF2jc=; b=ehusSpJtnwJUk31sQfeWJneoT+tSVYKoY+ATGVszaHUw/2vM5dhTt0EIuRG2yyNME+ YF8DR3nZVsJfroMcgvRceWxgh/KWSs7cyPSD+YOMjutd5pB/AFMKM/VJrB+Gz+SLuI/g f8o6tXC6GqnFjzgJLWzIgz68vG0faUoInMNyPKLxVrtcD01x/AzkNjYzz4iE16UEIfct 1imFqED9/vKeedACnZ0akioXkbJiZEww0X3cloQ8aE6VEZotvu3w9TXqx/GEUtnEKCmi Az+UXSrpTxZprBOYUJbtcuRjBqaqw99dMKhdD2lpl6sYU1grLr6AQJDPqpn4L3QbeSbd xLgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9L0GtDNu2fUqJk744rzWyv0yzJxmbFB3ZB4AjTTF2jc=; b=pv16WwzvJCvTN6Zz7VRSdeUD6EmRIQDcOC5jb6kvqr4ctRXsr2MCB5/3Mpahi2pmxS is9ymCmfZpnyafS1jwqhBTKZgJnYtpb4zFSboYnAm8l7JxqefkUdbtLDMfF30G0jJAhp 5KpctNKJBVhfj9fvu5ll9r6svZl8LLKSvFpQyQV+TYxkBV9yAn5tIt+pYK8pyUXFDVSU 8TXH6QAwu97BME8brZgFlZK3SgpnB3TEq89rL6zzXySgD44VUXySaRMy3aYXjo1aU3p2 B7cZsiKo6oCYLNpeZEHXnQRiPsBjUXcRuld3+4RoVUoXjRjLBYzxABP9K9G+qnBwdPNQ eXow== X-Gm-Message-State: AOAM531fBTMruTqg0qRYmCZFWaInfMuV4jL6Kn4fk3cbXFjBk0aWdZGT PQJzuKvhgNFk5Lmm2vElaYXaC7mWgzM= X-Google-Smtp-Source: ABdhPJxGJ78q3nDdLEGu5CirSZLC4KB5o/g9YYvOFkV48RmdtVqsTp9q9JWcCFtW3zubabieU2MUZg== X-Received: by 2002:a62:8708:0:b029:19d:ea95:5ac4 with SMTP id i8-20020a6287080000b029019dea955ac4mr2123976pfe.46.1607234019210; Sat, 05 Dec 2020 21:53:39 -0800 (PST) Received: from archlinux.. ([161.81.68.216]) by smtp.gmail.com with ESMTPSA id a14sm4360094pfl.141.2020.12.05.21.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 21:53:38 -0800 (PST) From: Tom Yan To: linux-block@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH 1/3] block: try one write zeroes request before going further Date: Sun, 6 Dec 2020 13:53:30 +0800 Message-Id: <20201206055332.3144-1-tom.ty89@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org At least the SCSI disk driver is "benevolent" when it try to decide whether the device actually supports write zeroes, i.e. unless the device explicity report otherwise, it assumes it does at first. Therefore before we pile up bios that would fail at the end, we try the command/request once, as not doing so could trigger quite a disaster in at least certain case. For example, the host controller can be messed up entirely when one does `blkdiscard -z` a UAS drive. Signed-off-by: Tom Yan --- block/blk-lib.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index e90614fd8d6a..c1e9388a8fb8 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -250,6 +250,7 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, struct bio *bio = *biop; unsigned int max_write_zeroes_sectors; struct request_queue *q = bdev_get_queue(bdev); + int i = 0; if (!q) return -ENXIO; @@ -264,7 +265,17 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, return -EOPNOTSUPP; while (nr_sects) { - bio = blk_next_bio(bio, 0, gfp_mask); + if (i != 1) { + bio = blk_next_bio(bio, 0, gfp_mask); + } else { + submit_bio_wait(bio); + bio_put(bio); + + if (bdev_write_zeroes_sectors(bdev) == 0) + return -EOPNOTSUPP; + else + bio = bio_alloc(gfp_mask, 0); + } bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio->bi_opf = REQ_OP_WRITE_ZEROES; @@ -280,6 +291,7 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, nr_sects = 0; } cond_resched(); + i++; } *biop = bio; From patchwork Sun Dec 6 05:53:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11953645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F4B3C19425 for ; Sun, 6 Dec 2020 05:54:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FE96230FA for ; Sun, 6 Dec 2020 05:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725823AbgLFFyY (ORCPT ); Sun, 6 Dec 2020 00:54:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgLFFyW (ORCPT ); Sun, 6 Dec 2020 00:54:22 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0AC9C0613D1; Sat, 5 Dec 2020 21:53:42 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id s21so6770918pfu.13; Sat, 05 Dec 2020 21:53:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6eSXOV4bceIVLvD3mBDcQt09QEEaRRGrlPLz+3Rl92M=; b=IG3XWfSq1T49jj3UASunoVAmIJPCMuPAfYCnONCc6QBpIT66IyXTx2AGgykru8QVRK wfS8T/pd4LEIpVeHvGkr8NdWyTI9rgUqSsZQyRq5I4NFbGy1h/sSAP+mqFFuwFsqZxJA LFk/fb6fMYvQNyngGUtOpu3AuTp2qCBGeJL0vJU9Wvg1ovpkxyIlVhS5G1Pd/oiwgPtU cjja0jcqzTWNk6pqnXjHOc2Ur4dxj9/Zb2obui9P4ag/LKXv8/yy9Kll6+QNmaEaPKK1 zd+IRjObgrebSP3sKVtNnVm4FRYWejg5jkQPWWONm6Supze7vdjttUULh2aRHVaQ3A7h voTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6eSXOV4bceIVLvD3mBDcQt09QEEaRRGrlPLz+3Rl92M=; b=L2DM9q6486YSWhIPzghV9KO57LwB5xZhrOIeDnhUUtaZc8bmSi6myUvR5bzzl+rts4 HspgERRnSZjLFOFGXmqdI82IXa6qJxrpfWWqngIwFFO09vi5TWPQHUGq667WkMgW87Rg eneeI+pEdkP/tMDHUoa8dwHU8pVDHBWUXlpcErLQFDgdJRAQdTGJlbcOSqPAy+Sw/cho ISkvrGNaYHWJt3jeBgBzm3z9NChRizkSmVUl6efhkc5mdztMR8dklXI2ty6HESJLjILq jb8JKfociEcJ+PXGtQ4hsQ4g2CD+xCm4gdOS2UPpV/MXYgR8Gmp+p/M2Da/CE37kIchj FOsQ== X-Gm-Message-State: AOAM533/QgckS8nM9iA1JQ8JJdlCsWUvd0+vi6pylSpEw1PaJc5sRx0w nE1sBmA5SEc1ubecWFTuNUUHiM4EmBo= X-Google-Smtp-Source: ABdhPJz3emla1vmSPTrWHQS6ll66TPvn9tJSW6jaAdGOBLdyPzdBwSV4vuEgAvqF7qoAfeTBm8PUOw== X-Received: by 2002:a05:6a00:84a:b029:19e:4cc:dc6f with SMTP id q10-20020a056a00084ab029019e04ccdc6fmr401740pfk.33.1607234021932; Sat, 05 Dec 2020 21:53:41 -0800 (PST) Received: from archlinux.. ([161.81.68.216]) by smtp.gmail.com with ESMTPSA id a14sm4360094pfl.141.2020.12.05.21.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 21:53:41 -0800 (PST) From: Tom Yan To: linux-block@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH 2/3] block: make __blkdev_issue_zero_pages() less confusing Date: Sun, 6 Dec 2020 13:53:31 +0800 Message-Id: <20201206055332.3144-2-tom.ty89@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206055332.3144-1-tom.ty89@gmail.com> References: <20201206055332.3144-1-tom.ty89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of using the same check for the two layers of loops, count bio pages in the inner loop instead. Signed-off-by: Tom Yan --- block/blk-lib.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index c1e9388a8fb8..354dcab760c7 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -318,7 +318,7 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, struct request_queue *q = bdev_get_queue(bdev); struct bio *bio = *biop; int bi_size = 0; - unsigned int sz; + unsigned int sz, bio_nr_pages; if (!q) return -ENXIO; @@ -327,19 +327,18 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, return -EPERM; while (nr_sects != 0) { - bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), - gfp_mask); + bio_nr_pages = __blkdev_sectors_to_bio_pages(nr_sects); + bio = blk_next_bio(bio, bio_nr_pages, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - while (nr_sects != 0) { + while (bio_nr_pages != 0) { sz = min((sector_t) PAGE_SIZE, nr_sects << 9); bi_size = bio_add_page(bio, ZERO_PAGE(0), sz, 0); nr_sects -= bi_size >> 9; sector += bi_size >> 9; - if (bi_size < sz) - break; + bio_nr_pages--; } cond_resched(); } From patchwork Sun Dec 6 05:53:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11953647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88725C433FE for ; Sun, 6 Dec 2020 05:54:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63737230FA for ; Sun, 6 Dec 2020 05:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725863AbgLFFy0 (ORCPT ); Sun, 6 Dec 2020 00:54:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgLFFyZ (ORCPT ); Sun, 6 Dec 2020 00:54:25 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53469C0613D4; Sat, 5 Dec 2020 21:53:45 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id f1so5402112plt.12; Sat, 05 Dec 2020 21:53:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QQbA5rQ723r8QeqL5SQIpU3wuJWTt34+LMrl2zPvWzI=; b=kEeaItSLHlONkaJv0x51eFsNJj+NF0gxMzrjGqxHmMXWUn4fhrQmrltG9lMTdzE0cc VgoAV2apKcoA/2tVCuNLWtdfAASidy1m4haZysfQUux1KrW/dsHl4ThAXcxy4Z9evrEo F8H/9TcI4Puhr14HVGRqQCOxey25iyCW3Lz2+MQKN2NiGBffl6xp/WM2P37ZqCRK86w1 7eh6K/6Docy2w2Keq1YuoOor3VngiMXreSB6Xat2Pn+ncun+BkouyTjWOLhsN6IFcsZY ClgN7ME7RngwyxYnT1jI3/475WitQv72EsHzgbELBgTusfajZZRTFX9t5ONflArOHiD8 Kp0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QQbA5rQ723r8QeqL5SQIpU3wuJWTt34+LMrl2zPvWzI=; b=ujeHulEC+rQ6f8hQ4vGSv9Dpny9QsIYAygY51b7aQLMoburO76yWw7qItTsseLLAIO HOIN3CJ4OI1ALURC9g9qA8XVw/tnOnsjKdu//A5ghffn21rt2xyYe3Qag7jLuNURtuTe 3gwoM259814s9KvHb9D38ghIpPqnr77Dg8SR9Vf+qekhpoXJVS0rGvBoXRHklYBcs7nG 1Bmv4BpF+Zfb9XBN32x4O12M7xzA22vFKgIrYjgsCRUoWh4NAsJaDDBmgEe+5M56q4HN AVDtCxqOIS1/ACtuG3+l18mcaY3QcpRyoXaapTpJ99pPpcut9daUcsRwcvhTnvRwF65O JR6Q== X-Gm-Message-State: AOAM5325OhInw8ETc8mUSoBYE3/7uvrsJGs8D79lRLHF5++FKAMKferY GKA9SOz/pvqlm/VeP5DQHANyMQjgr6g= X-Google-Smtp-Source: ABdhPJwgyllaAJUxLtjj7f/qRUGt0E4nRD+cNxYj3JetskReH7WtO788wO3U4+IY2vTy0vb3HywHHA== X-Received: by 2002:a17:902:6a87:b029:da:e253:dd6a with SMTP id n7-20020a1709026a87b02900dae253dd6amr4399704plk.81.1607234024592; Sat, 05 Dec 2020 21:53:44 -0800 (PST) Received: from archlinux.. ([161.81.68.216]) by smtp.gmail.com with ESMTPSA id a14sm4360094pfl.141.2020.12.05.21.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 21:53:44 -0800 (PST) From: Tom Yan To: linux-block@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH 3/3] block: set REQ_PREFLUSH to the final bio from __blkdev_issue_zero_pages() Date: Sun, 6 Dec 2020 13:53:32 +0800 Message-Id: <20201206055332.3144-3-tom.ty89@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206055332.3144-1-tom.ty89@gmail.com> References: <20201206055332.3144-1-tom.ty89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Mimicking blkdev_issue_flush(). Seems like a right thing to do, as they are a bunch of REQ_OP_WRITE. Signed-off-by: Tom Yan --- block/blk-lib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index 354dcab760c7..5579fdea893d 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -422,6 +422,8 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, } else if (!(flags & BLKDEV_ZERO_NOFALLBACK)) { ret = __blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp_mask, &bio); + if (bio) + bio->bi_opf |= REQ_PREFLUSH; } else { /* No zeroing offload support */ ret = -EOPNOTSUPP;