From patchwork Wed May 23 17:35:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10421965 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 188066054D for ; Wed, 23 May 2018 17:38:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07DA428CBC for ; Wed, 23 May 2018 17:38:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0E6328D5F; Wed, 23 May 2018 17:37:59 +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,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 8DB822912C for ; Wed, 23 May 2018 17:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933797AbeEWRgD (ORCPT ); Wed, 23 May 2018 13:36:03 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:45327 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932667AbeEWRgC (ORCPT ); Wed, 23 May 2018 13:36:02 -0400 Received: by mail-qt0-f195.google.com with SMTP id j42-v6so29097986qtj.12 for ; Wed, 23 May 2018 10:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=C1IU+VjSp6xZwNawK9MmXtwl4+rBDFN5syb3yTRFrjY=; b=tg8k8cEVgYFVisD/CO6/LR7sCWisuRyAhS8B/leOnQz6GeyVR65oGIbuxmYvnHq17n rR/1i0MG7TkfJ/cLWMdiUR8vxLwJVpH2c+rDPtcBjliWfJSvhIvokE6YLbfKneyYRQU8 nEN0efTMVr6zaRkHBZfMI3y/620V9kUhxdHXQiXmUhBk/d3OCfzCf0xhMTkthUfBisd6 toX+boiqdMih2uu+sLDeBx2Le9rrXDyAYpRbW+rMEpQQg8uS9YEcV99I1/ryzt7gj9z5 8/ZXb8dTKjD9y/Q4E+4+/Gp0vMuCdzck62b06mO8Xax8MzkmpsGKRUJp2a93F5ib8nqI xU6A== 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; bh=C1IU+VjSp6xZwNawK9MmXtwl4+rBDFN5syb3yTRFrjY=; b=f5ycw2gU+8boj3ZduH9lM5IOYCEOPWHQ13R7ttVjoFstCQLKK5QDbcTqVrqd0AiI0/ w2JQAVQVn1I7RVcmhzANz464Z7fdf3/PvLv49WzmDIvPAHQJcjMjxUzywHGUTzUooGRx +EAyifa5KTVxjKT+v2/mGRuhUmQvpPlNSJJdzT+5CrwMtXlM6+qBT4FXaYtsXRqX6wmw jq0+Rst7cbm5o66NlyQ8zdEO4gvI+egO0gF7jQTD5K/WLIwvNnhOuS/EP75cDr3zJco/ yg7p9tC2tZyJjABZ1AH4vl9zaxy/scxS1JmmI2VwU3IEfskwVigRHhzrz7yRhEPxXpqz ZvPA== X-Gm-Message-State: ALKqPwfH3l1zi4PHnTJHLdm5J1pFDLkkbg7RUTpLu9HZx5CCudW82T9b v4Eq2AWNVqC6JK6/BsF57anMtg== X-Google-Smtp-Source: ADUXVKIAcbrgwSw1VjxBTn53zVySJBOCbbYt2ZN9RiWTUIpHHZt0bpUFNzDNmsWaNSi1cGpX+GHkBQ== X-Received: by 2002:ac8:21cd:: with SMTP id 13-v6mr3728347qtz.406.1527096961574; Wed, 23 May 2018 10:36:01 -0700 (PDT) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id m53-v6sm15124839qtf.33.2018.05.23.10.36.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 10:36:00 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, nbd@other.debian.org, linux-block@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH] nbd: set discard granularity properly Date: Wed, 23 May 2018 13:35:59 -0400 Message-Id: <20180523173559.6336-1-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 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 From: Josef Bacik For some reason we had discard granularity set to 512 always even when discards were disabled. Fix this by having the default be 0, and then if we turn it on set the discard granularity to the blocksize. Signed-off-by: Josef Bacik Reviewed-by: Martin K. Petersen --- drivers/block/nbd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 1147e4680c80..bdfbb2a7018c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -236,6 +236,10 @@ static void nbd_size_update(struct nbd_device *nbd) struct nbd_config *config = nbd->config; struct block_device *bdev = bdget_disk(nbd->disk, 0); + if (config->flags & NBD_FLAG_SEND_TRIM) { + nbd->disk->queue->limits.discard_granularity = config->blksize; + blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); + } blk_queue_logical_block_size(nbd->disk->queue, config->blksize); blk_queue_physical_block_size(nbd->disk->queue, config->blksize); set_capacity(nbd->disk, config->bytesize >> 9); @@ -1050,6 +1054,8 @@ static void nbd_config_put(struct nbd_device *nbd) nbd->config = NULL; nbd->tag_set.timeout = 0; + nbd->disk->queue->limits.discard_granularity = 0; + blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); blk_queue_flag_clear(QUEUE_FLAG_DISCARD, nbd->disk->queue); mutex_unlock(&nbd->config_lock); @@ -1502,8 +1508,8 @@ static int nbd_dev_add(int index) */ blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue); - disk->queue->limits.discard_granularity = 512; - blk_queue_max_discard_sectors(disk->queue, UINT_MAX); + disk->queue->limits.discard_granularity = 0; + blk_queue_max_discard_sectors(disk->queue, 0); blk_queue_max_segment_size(disk->queue, UINT_MAX); blk_queue_max_segments(disk->queue, USHRT_MAX); blk_queue_max_hw_sectors(disk->queue, 65536);