From patchwork Mon May 28 07:49:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10430007 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 12BB2602CC for ; Mon, 28 May 2018 07:50:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 044E128B6F for ; Mon, 28 May 2018 07:50:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED01128B79; Mon, 28 May 2018 07:50:16 +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.4 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_WEB 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 BFF5428B73 for ; Mon, 28 May 2018 07:50:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753815AbeE1HuN (ORCPT ); Mon, 28 May 2018 03:50:13 -0400 Received: from lucky1.263xmail.com ([211.157.147.135]:42988 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753734AbeE1HuN (ORCPT ); Mon, 28 May 2018 03:50:13 -0400 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.223]) by lucky1.263xmail.com (Postfix) with ESMTP id 8807C6A3B; Mon, 28 May 2018 15:49:55 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 45DD3383; Mon, 28 May 2018 15:49:52 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: ulf.hansson@linaro.org X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <036b95095f2699fe185154d75ce46ddb> X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 15244ZKE4GF; Mon, 28 May 2018 15:49:53 +0800 (CST) From: Shawn Lin To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, Shawn Lin , Faiz Abbas , Christoph Hellwig Subject: [RFT PATCH] mmc: block: implement REQ_OP_WRITE_ZEROES Date: Mon, 28 May 2018 15:49:26 +0800 Message-Id: <1527493766-15487-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP card->erased_byte read from SCR(for SD cards) or EXT_CSD[181](for eMMC) indicates whether the TRIM or ERASE make the erased data content zeros, but DISCARD doesn't. Use the fact to implement REQ_OP_WRITE_ZEROES. Cc: Faiz Abbas Cc: Christoph Hellwig Signed-off-by: Shawn Lin --- Hi Faiz, Would you like to test this patch to see if it could solve your performance drop on the first write after filesystem creation? drivers/mmc/core/block.c | 10 +++++++++- drivers/mmc/core/queue.c | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index a0b9102..7d59887 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1132,7 +1132,14 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) from = blk_rq_pos(req); nr = blk_rq_sectors(req); - if (mmc_can_discard(card)) + /* + * DISCARD says the contents of a write block where the discard + * function has been applied shold be 'don't care'. But TRIM and + * ERASE should have explicit '1' or '0' indicated by + * card->erased_byte. So REQ_OP_WRITE_ZEROES should use TRIM/ERASE + * instead. + */ + if (mmc_can_discard(card) && req_op(req) != REQ_OP_WRITE_ZEROES) arg = MMC_DISCARD_ARG; else if (mmc_can_trim(card)) arg = MMC_TRIM_ARG; @@ -2228,6 +2235,7 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req) mmc_blk_issue_drv_op(mq, req); break; case REQ_OP_DISCARD: + case REQ_OP_WRITE_ZEROES: mmc_blk_issue_discard_rq(mq, req); break; case REQ_OP_SECURE_ERASE: diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index 56e9a80..2657a46 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -51,6 +51,7 @@ static enum mmc_issue_type mmc_cqe_issue_type(struct mmc_host *host, case REQ_OP_DRV_OUT: case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: + case REQ_OP_WRITE_ZEROES: return MMC_ISSUE_SYNC; case REQ_OP_FLUSH: return mmc_cqe_can_dcmd(host) ? MMC_ISSUE_DCMD : MMC_ISSUE_SYNC; @@ -193,6 +194,8 @@ static void mmc_queue_setup_discard(struct request_queue *q, q->limits.discard_granularity = 0; if (mmc_can_secure_erase_trim(card)) blk_queue_flag_set(QUEUE_FLAG_SECERASE, q); + if (!card->erased_byte) + q->limits.max_write_zeroes_sectors = max_discard; } /**