From patchwork Mon Nov 9 12:51:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11891495 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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 66D9CC4741F for ; Mon, 9 Nov 2020 12:51:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AAB520684 for ; Mon, 9 Nov 2020 12:51:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nlMJaraq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729715AbgKIMvg (ORCPT ); Mon, 9 Nov 2020 07:51:36 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:43848 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729247AbgKIMvQ (ORCPT ); Mon, 9 Nov 2020 07:51:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1604926276; x=1636462276; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=Gs91s4H9n0Om7t/enpIZtfjgR6t6tdaBBQzqDFdHcec=; b=nlMJaraq4vYXk+F5ObBlme8YTJbVV41mzmJXgdS7nUvhkfFWI8XRc57v ZPZ9x3BF/k8EX+aqzaMF6thv36WfB/MW+yetKYFmrvbAbRoeBtqY9w4UU Ao6I8KdI60Jep95daMshzDGmTaoAec2/IuOWCnd2VhDvP/K8aGYop2XgH GEs3FEh0wrRuesy3jmSi75by45SukGJZCw5jH9ZVNTGa0GFqFW0gZbHXv AmmViKDPtSng9H6ME8psYR9jPns59EeIV3dv2cGpCAJRFjhfngXIuC/R2 uKUfUHVEDu16l86crjUaXEZvP71GjH8B+CiwBtkuteO/VCFGGkWSieqsh A==; IronPort-SDR: 5FhWByMkcdKjGc86z2pAmBqP9NzY+c1F1BdafH6pYAQhutDpjquvWgdrOmneorVl/IgIKshSsz jfh9zucGZh3+6HXcxxkZf1QEDi6NU6N02g84aous89GqzXXihyHrozcdxv9qVUTr6IB1oG5Kcs 2jUaf1m6Jczp7rkTYffdOg2Ginb+37oDq7uMRn5dQYheRLLQXV8Pmsgmy/6s/xSbtw//oqVPWm xe9qNfJmz9SGGv2fXvE2tAr0KyeFJagjDnrXWqn6tUjLtOM78cKpZziv2RrQtexrFFG0xvoqwY J9Y= X-IronPort-AV: E=Sophos;i="5.77,463,1596470400"; d="scan'208";a="156668397" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2020 20:51:09 +0800 IronPort-SDR: 7Xr9ECur7IybXBQoYbY4wT7BYzs+Q++Qmq1iQc0JKVAKhAmPN+K9a5uLeLSge7OLJrj5AXNDFr Gyq/lfYw+xNQMMiIhv6sCyx0k1EVgt2uVAEd4iC7xtRAtDw5HGPP9X40sV6ZhlvY3uAMrNsEbl 40STqTJQAQGXEnRFFN5vnlkNrMSYNBpC62HCxSyTtmk/Wot3h50MYVtjASh2OvvIQ76sgYn7YC 2K/c+11mWWlHbxGeo1rW9vcXt6vkXuiqqhf/gHPMgrB76PNtz59Do3Tnzxc5ruxWeRPrRBv8ZX ySwr9FPsO+cuYtwoh+uIutJv Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2020 04:37:11 -0800 IronPort-SDR: Cd7BY1YjA9p/r+0TuewdZgVD0xyyfUWnYlkD++a+gMoxhmtwmVVqlCXg6uaHJ3LckJgA7lgZ1M DsA7CBtlKiSRCxwtbokaAAGCWesNhV2uaWX9z30p3DoEtko17MiUywIlW7zf8Hn95NigkaLspo 3sw/kr8qHc8duVETfdEmyvcJUJozt9fsZPTB+Lx7V1nIw6rUUnLLZAcWQ9vrG8gp+9Aes9jrLO I1WIF5OtF2SgY10FS1R2T9eHZniyBJyioVPhWFDZjT/0bWKO+9mABRpSo6b9Fdds0XOcL2GMJQ Ju0= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Nov 2020 04:51:09 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 1/6] null_blk: Fix zone size initialization Date: Mon, 9 Nov 2020 21:51:00 +0900 Message-Id: <20201109125105.551734-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109125105.551734-1-damien.lemoal@wdc.com> References: <20201109125105.551734-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org All zones of a zoned null_blk device are currently initialized with the same size. However, if the specified size (capacity) of the null_blk device is not a multiple of the zone size, the last zone becomes too large and read/write accesses to it can cause out of bound errors. Fix this by correctly setting the size of the last zone of the device to the remainder of the disk capacity if this capacity is not a multiple of the zone size. For such smaller last zone, the zone capacity is also checked so that it does not exceed the smaller zone size. Reported-by: Naohiro Aota Signed-off-by: Damien Le Moal --- drivers/block/null_blk_zoned.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index beb34b4f76b0..18911e67f792 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -16,7 +16,7 @@ static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) { - sector_t dev_size = (sector_t)dev->size * 1024 * 1024; + sector_t dev_capacity, zone_capacity; sector_t sector = 0; unsigned int i; @@ -38,9 +38,14 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) return -EINVAL; } + zone_capacity = dev->zone_capacity << ZONE_SIZE_SHIFT; + dev_capacity = ((sector_t)dev->size * SZ_1M) >> SECTOR_SHIFT; + dev->zone_size_sects = dev->zone_size << ZONE_SIZE_SHIFT; - dev->nr_zones = dev_size >> - (SECTOR_SHIFT + ilog2(dev->zone_size_sects)); + dev->nr_zones = dev_capacity >> ilog2(dev->zone_size_sects); + if (dev_capacity & (dev->zone_size_sects - 1)) + dev->nr_zones++; + dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct blk_zone), GFP_KERNEL | __GFP_ZERO); if (!dev->zones) @@ -101,8 +106,12 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) struct blk_zone *zone = &dev->zones[i]; zone->start = zone->wp = sector; - zone->len = dev->zone_size_sects; - zone->capacity = dev->zone_capacity << ZONE_SIZE_SHIFT; + if (zone->start + dev->zone_size_sects > dev_capacity) + zone->len = dev_capacity - zone->start; + else + zone->len = dev->zone_size_sects; + zone->capacity = + min_t(sector_t, zone->len, zone_capacity); zone->type = BLK_ZONE_TYPE_SEQWRITE_REQ; zone->cond = BLK_ZONE_COND_EMPTY; From patchwork Mon Nov 9 12:51:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11891501 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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 F1812C2D0A3 for ; Mon, 9 Nov 2020 12:51:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 862DE20657 for ; Mon, 9 Nov 2020 12:51:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="UDBj8eHE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729045AbgKIMvg (ORCPT ); Mon, 9 Nov 2020 07:51:36 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:43853 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729432AbgKIMvR (ORCPT ); Mon, 9 Nov 2020 07:51:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1604926276; x=1636462276; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=/sqLQMfQYenx55jJTXo6s06gN8iuh66SJUBivy49YyU=; b=UDBj8eHElw+gjHvP0v/i3pidz9+EccgfHQTf4FLqaP8OsjyrWoicRMl5 wuvdy3rWCy/wRogE9U5fZh8F8Zjw7RID+QNA7DdwCvJ1wM+kIm5RDsWYi vot5PCFAMpW26+6JmKm2PxQPEPAj2H4Vb8x19QRk0386KpGZmCxp7uWqi VHU2RcpWA5/W6HgqbbEczODqS3pDx79u0z/gBlK5FUCeFP2wubcEluY6z JCsIOImU+fAUkVcucIrjCI6meKdW7s/FteXAG5W60vXAmEHTMuzJtQdV9 CIExS3pBth8Ft+8i3cyE9YP6wbz5vMQkkwTPqsFI4YvfbYTrcDJlMPL9U w==; IronPort-SDR: LCtefJWtbe7/wpNcoeWY+hTIIhKM1upcutmfByfpSIzvlycrPLuuKchrdygisR5aXqq804or1Q BTJJNLrKJMwRCyvUktC788eziphMZRFoVvgy9cxZF7QunzeODPFYPEmOOqih19TNJ1OFJU5ZOv LZTqQ6ktyDsd1RTNz5YjDcYl2YCgkd6bnCzE6hg/jZVtCkeYmewxDFtzLk2XY1usOMg1alvhv7 MNw9vBE8P6LkSdFXubOVKiXRFxNDq79jAqZwOw968pqlDGaT71HLpmgswSQ/y/SuruiGpDOMQ9 l+M= X-IronPort-AV: E=Sophos;i="5.77,463,1596470400"; d="scan'208";a="156668399" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2020 20:51:10 +0800 IronPort-SDR: NlPyOZ3ZbXhmVq7guy/PhCzyOdXmYNeXfdJTBP8dUcjl+6ynNwJebbu9YaMj07rQ6Mo15g+sdE hXzDqniaOOf4KFfWiAp545MyexnJFBZYGsjjBlNkCDvQPMBPKtInBHsILNmS1grrINQEDi3Za+ XQrIARfl2BYVCHNzV25WmowoSPegvsG/jIL54WsecNpopp2aQk0OnZs5PJXf4oH7D/jj9LOdI7 ypc6C+Kq2JCOeFjebdH4e1eEHuJ8iAI85yv1pSABt0aEDUqyTXcp3cqZ1rULFU4yCYc0gN52t1 KPnX5DyUEVPVJv+PDxJ+TpmS Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2020 04:37:12 -0800 IronPort-SDR: qoRODy154LBciMFwfeqQY4IPNT4eBZNd0t5C/HcvEsLZdN/A8kc3hL7RjX5hF5cSTRFZcm+vKM ObrLeC3DrZ7CjPDbzDM9v+plR5F3UPDCMnvay/WXMJexQDP4goceHIYPtuU1qvJlpRW8owwHqi U7m6KVSzz8uJkjyRPU2zzWJSGeSjWxE7XRJvG2sS2+qFC2Xq2SUoXQNL04DEzKYecHDNhnwJdm cXU8+K5I/lcnyp1UesxoIGC/tofOJGnBCJ6lVUWXH+ZPW1wRNXJhPGGboT1Q/kNc8vfLe69Isb qeU= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Nov 2020 04:51:10 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 2/6] null_blk: improve zone locking Date: Mon, 9 Nov 2020 21:51:01 +0900 Message-Id: <20201109125105.551734-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109125105.551734-1-damien.lemoal@wdc.com> References: <20201109125105.551734-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With memory backing disabled, using a single spinlock for protecting zone information and zone resource management prevent the parallel execution on multiple queue of IO requests to different zones. Furthermore, regardless of the use of memory backing, if a null_blk device is created without limits on the number of opn and active zones, accounting for zone resource management is not necessary. From these observations, zone locking is changed as follow to improve performance: 1) the zone_lock spinlock is renamed zone_res_lock and used only if zone resource management is necessary, that is, if either zone_max_open or zone_max_active are not 0. This is indicated using the new boolean need_zone_res_mgmt in the nullb_device structure. null_zone_write() is modified to reduce the amount of code executed with the zone_res_lock spinlock held. null_zone_valid_read_len() is also modified to avoid taking the zone lock before calling null_process_cmd() for read operations in null_process_zoned_cmd(). 2) With memory backing disabled, per zone locking is changed to a spinlock per zone. With these changes, fio performance with zonemode=zbd for 4K random read and random write on a dual socket (24 cores per socket) machine using the none schedulder is as follows: before patch: write (psync x 96 jobs) = 465 KIOPS read (libaio@qd=8 x 96 jobs) = 1361 KIOPS after patch: write (psync x 96 jobs) = 468 KIOPS read (libaio@qd=8 x 96 jobs) = 3340 KIOPS Write performance remains mostly unchanged but read performance more than double. Performance when using the mq-deadline scheduler is not changed by this patch as mq-deadline becomes the bottleneck for a multi-queue device. Signed-off-by: Damien Le Moal --- drivers/block/null_blk.h | 5 +- drivers/block/null_blk_zoned.c | 192 +++++++++++++++++++++------------ 2 files changed, 126 insertions(+), 71 deletions(-) diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h index c24d9b5ad81a..4c101c39c3d1 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -47,8 +47,9 @@ struct nullb_device { unsigned int nr_zones_closed; struct blk_zone *zones; sector_t zone_size_sects; - spinlock_t zone_lock; - unsigned long *zone_locks; + bool need_zone_res_mgmt; + spinlock_t zone_res_lock; + void *zone_locks; unsigned long size; /* device size in MB */ unsigned long completion_nsec; /* time in ns to complete a request */ diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index 18911e67f792..b2812ee01d3d 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -58,13 +58,15 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) * wait_on_bit_lock_io(). Sleeping on the lock is OK as memory backing * implies that the queue is marked with BLK_MQ_F_BLOCKING. */ - spin_lock_init(&dev->zone_lock); - if (dev->memory_backed) { + spin_lock_init(&dev->zone_res_lock); + if (dev->memory_backed) dev->zone_locks = bitmap_zalloc(dev->nr_zones, GFP_KERNEL); - if (!dev->zone_locks) { - kvfree(dev->zones); - return -ENOMEM; - } + else + dev->zone_locks = kmalloc_array(dev->nr_zones, + sizeof(spinlock_t), GFP_KERNEL); + if (!dev->zone_locks) { + kvfree(dev->zones); + return -ENOMEM; } if (dev->zone_nr_conv >= dev->nr_zones) { @@ -88,10 +90,14 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) dev->zone_max_open = 0; pr_info("zone_max_open limit disabled, limit >= zone count\n"); } + dev->need_zone_res_mgmt = dev->zone_max_active || dev->zone_max_open; for (i = 0; i < dev->zone_nr_conv; i++) { struct blk_zone *zone = &dev->zones[i]; + if (!dev->memory_backed) + spin_lock_init((spinlock_t *)dev->zone_locks + i); + zone->start = sector; zone->len = dev->zone_size_sects; zone->capacity = zone->len; @@ -105,6 +111,9 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) for (i = dev->zone_nr_conv; i < dev->nr_zones; i++) { struct blk_zone *zone = &dev->zones[i]; + if (!dev->memory_backed) + spin_lock_init((spinlock_t *)dev->zone_locks + i); + zone->start = zone->wp = sector; if (zone->start + dev->zone_size_sects > dev_capacity) zone->len = dev_capacity - zone->start; @@ -149,23 +158,41 @@ int null_register_zoned_dev(struct nullb *nullb) void null_free_zoned_dev(struct nullb_device *dev) { - bitmap_free(dev->zone_locks); + if (dev->memory_backed) + bitmap_free(dev->zone_locks); + else + kfree(dev->zone_locks); kvfree(dev->zones); } +#define null_lock_zone_res(dev, flags) \ + do { \ + if ((dev)->need_zone_res_mgmt) \ + spin_lock_irqsave(&(dev)->zone_res_lock, \ + (flags)); \ + } while (0) + +#define null_unlock_zone_res(dev, flags) \ + do { \ + if ((dev)->need_zone_res_mgmt) \ + spin_unlock_irqrestore(&(dev)->zone_res_lock, \ + (flags)); \ + } while (0) + static inline void null_lock_zone(struct nullb_device *dev, unsigned int zno) { if (dev->memory_backed) wait_on_bit_lock_io(dev->zone_locks, zno, TASK_UNINTERRUPTIBLE); - spin_lock_irq(&dev->zone_lock); + else + spin_lock_irq((spinlock_t *)dev->zone_locks + zno); } static inline void null_unlock_zone(struct nullb_device *dev, unsigned int zno) { - spin_unlock_irq(&dev->zone_lock); - if (dev->memory_backed) clear_and_wake_up_bit(zno, dev->zone_locks); + else + spin_unlock_irq((spinlock_t *)dev->zone_locks + zno); } int null_report_zones(struct gendisk *disk, sector_t sector, @@ -226,11 +253,9 @@ size_t null_zone_valid_read_len(struct nullb *nullb, return (zone->wp - sector) << SECTOR_SHIFT; } -static blk_status_t null_close_zone(struct nullb_device *dev, struct blk_zone *zone) +static blk_status_t __null_close_zone(struct nullb_device *dev, + struct blk_zone *zone) { - if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) - return BLK_STS_IOERR; - switch (zone->cond) { case BLK_ZONE_COND_CLOSED: /* close operation on closed is not an error */ @@ -263,7 +288,7 @@ static void null_close_first_imp_zone(struct nullb_device *dev) for (i = dev->zone_nr_conv; i < dev->nr_zones; i++) { if (dev->zones[i].cond == BLK_ZONE_COND_IMP_OPEN) { - null_close_zone(dev, &dev->zones[i]); + __null_close_zone(dev, &dev->zones[i]); return; } } @@ -337,6 +362,7 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, struct nullb_device *dev = cmd->nq->dev; unsigned int zno = null_zone_no(dev, sector); struct blk_zone *zone = &dev->zones[zno]; + unsigned long flags; blk_status_t ret; trace_nullb_zone_op(cmd, zno, zone->cond); @@ -346,24 +372,10 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, null_lock_zone(dev, zno); - switch (zone->cond) { - case BLK_ZONE_COND_FULL: + if (zone->cond == BLK_ZONE_COND_FULL) { /* Cannot write to a full zone */ ret = BLK_STS_IOERR; goto unlock; - case BLK_ZONE_COND_EMPTY: - case BLK_ZONE_COND_CLOSED: - ret = null_check_zone_resources(dev, zone); - if (ret != BLK_STS_OK) - goto unlock; - break; - case BLK_ZONE_COND_IMP_OPEN: - case BLK_ZONE_COND_EXP_OPEN: - break; - default: - /* Invalid zone condition */ - ret = BLK_STS_IOERR; - goto unlock; } /* @@ -388,37 +400,43 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, goto unlock; } - if (zone->cond == BLK_ZONE_COND_CLOSED) { - dev->nr_zones_closed--; - dev->nr_zones_imp_open++; - } else if (zone->cond == BLK_ZONE_COND_EMPTY) { - dev->nr_zones_imp_open++; + if (zone->cond == BLK_ZONE_COND_CLOSED || + zone->cond == BLK_ZONE_COND_EMPTY) { + null_lock_zone_res(dev, flags); + + ret = null_check_zone_resources(dev, zone); + if (ret != BLK_STS_OK) { + null_unlock_zone_res(dev, flags); + goto unlock; + } + if (zone->cond == BLK_ZONE_COND_CLOSED) { + dev->nr_zones_closed--; + dev->nr_zones_imp_open++; + } else if (zone->cond == BLK_ZONE_COND_EMPTY) { + dev->nr_zones_imp_open++; + } + + if (zone->cond != BLK_ZONE_COND_EXP_OPEN) + zone->cond = BLK_ZONE_COND_IMP_OPEN; + + null_unlock_zone_res(dev, flags); } - if (zone->cond != BLK_ZONE_COND_EXP_OPEN) - zone->cond = BLK_ZONE_COND_IMP_OPEN; - /* - * Memory backing allocation may sleep: release the zone_lock spinlock - * to avoid scheduling in atomic context. Zone operation atomicity is - * still guaranteed through the zone_locks bitmap. - */ - if (dev->memory_backed) - spin_unlock_irq(&dev->zone_lock); ret = null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors); - if (dev->memory_backed) - spin_lock_irq(&dev->zone_lock); - if (ret != BLK_STS_OK) goto unlock; zone->wp += nr_sectors; if (zone->wp == zone->start + zone->capacity) { + null_lock_zone_res(dev, flags); if (zone->cond == BLK_ZONE_COND_EXP_OPEN) dev->nr_zones_exp_open--; else if (zone->cond == BLK_ZONE_COND_IMP_OPEN) dev->nr_zones_imp_open--; zone->cond = BLK_ZONE_COND_FULL; + null_unlock_zone_res(dev, flags); } + ret = BLK_STS_OK; unlock: @@ -429,19 +447,22 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, static blk_status_t null_open_zone(struct nullb_device *dev, struct blk_zone *zone) { - blk_status_t ret; + blk_status_t ret = BLK_STS_OK; + unsigned long flags; if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) return BLK_STS_IOERR; + null_lock_zone_res(dev, flags); + switch (zone->cond) { case BLK_ZONE_COND_EXP_OPEN: /* open operation on exp open is not an error */ - return BLK_STS_OK; + goto unlock; case BLK_ZONE_COND_EMPTY: ret = null_check_zone_resources(dev, zone); if (ret != BLK_STS_OK) - return ret; + goto unlock; break; case BLK_ZONE_COND_IMP_OPEN: dev->nr_zones_imp_open--; @@ -449,35 +470,57 @@ static blk_status_t null_open_zone(struct nullb_device *dev, struct blk_zone *zo case BLK_ZONE_COND_CLOSED: ret = null_check_zone_resources(dev, zone); if (ret != BLK_STS_OK) - return ret; + goto unlock; dev->nr_zones_closed--; break; case BLK_ZONE_COND_FULL: default: - return BLK_STS_IOERR; + ret = BLK_STS_IOERR; + goto unlock; } zone->cond = BLK_ZONE_COND_EXP_OPEN; dev->nr_zones_exp_open++; - return BLK_STS_OK; +unlock: + null_unlock_zone_res(dev, flags); + + return ret; } -static blk_status_t null_finish_zone(struct nullb_device *dev, struct blk_zone *zone) +static blk_status_t null_close_zone(struct nullb_device *dev, struct blk_zone *zone) { + unsigned long flags; blk_status_t ret; if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) return BLK_STS_IOERR; + null_lock_zone_res(dev, flags); + ret = __null_close_zone(dev, zone); + null_unlock_zone_res(dev, flags); + + return ret; +} + +static blk_status_t null_finish_zone(struct nullb_device *dev, struct blk_zone *zone) +{ + blk_status_t ret = BLK_STS_OK; + unsigned long flags; + + if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) + return BLK_STS_IOERR; + + null_lock_zone_res(dev, flags); + switch (zone->cond) { case BLK_ZONE_COND_FULL: /* finish operation on full is not an error */ - return BLK_STS_OK; + goto unlock; case BLK_ZONE_COND_EMPTY: ret = null_check_zone_resources(dev, zone); if (ret != BLK_STS_OK) - return ret; + goto unlock; break; case BLK_ZONE_COND_IMP_OPEN: dev->nr_zones_imp_open--; @@ -488,27 +531,36 @@ static blk_status_t null_finish_zone(struct nullb_device *dev, struct blk_zone * case BLK_ZONE_COND_CLOSED: ret = null_check_zone_resources(dev, zone); if (ret != BLK_STS_OK) - return ret; + goto unlock; dev->nr_zones_closed--; break; default: - return BLK_STS_IOERR; + ret = BLK_STS_IOERR; + goto unlock; } zone->cond = BLK_ZONE_COND_FULL; zone->wp = zone->start + zone->len; - return BLK_STS_OK; +unlock: + null_unlock_zone_res(dev, flags); + + return ret; } static blk_status_t null_reset_zone(struct nullb_device *dev, struct blk_zone *zone) { + unsigned long flags; + if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) return BLK_STS_IOERR; + null_lock_zone_res(dev, flags); + switch (zone->cond) { case BLK_ZONE_COND_EMPTY: /* reset operation on empty is not an error */ + null_unlock_zone_res(dev, flags); return BLK_STS_OK; case BLK_ZONE_COND_IMP_OPEN: dev->nr_zones_imp_open--; @@ -522,12 +574,15 @@ static blk_status_t null_reset_zone(struct nullb_device *dev, struct blk_zone *z case BLK_ZONE_COND_FULL: break; default: + null_unlock_zone_res(dev, flags); return BLK_STS_IOERR; } zone->cond = BLK_ZONE_COND_EMPTY; zone->wp = zone->start; + null_unlock_zone_res(dev, flags); + return BLK_STS_OK; } @@ -587,29 +642,28 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op, blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_opf op, sector_t sector, sector_t nr_sectors) { - struct nullb_device *dev = cmd->nq->dev; - unsigned int zno = null_zone_no(dev, sector); + struct nullb_device *dev; + unsigned int zno; blk_status_t sts; switch (op) { case REQ_OP_WRITE: - sts = null_zone_write(cmd, sector, nr_sectors, false); - break; + return null_zone_write(cmd, sector, nr_sectors, false); case REQ_OP_ZONE_APPEND: - sts = null_zone_write(cmd, sector, nr_sectors, true); - break; + return null_zone_write(cmd, sector, nr_sectors, true); case REQ_OP_ZONE_RESET: case REQ_OP_ZONE_RESET_ALL: case REQ_OP_ZONE_OPEN: case REQ_OP_ZONE_CLOSE: case REQ_OP_ZONE_FINISH: - sts = null_zone_mgmt(cmd, op, sector); - break; + return null_zone_mgmt(cmd, op, sector); default: + dev = cmd->nq->dev; + zno = null_zone_no(dev, sector); + null_lock_zone(dev, zno); sts = null_process_cmd(cmd, op, sector, nr_sectors); null_unlock_zone(dev, zno); + return sts; } - - return sts; } From patchwork Mon Nov 9 12:51:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11891497 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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 7686BC4741F for ; Mon, 9 Nov 2020 12:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11DA320789 for ; Mon, 9 Nov 2020 12:51:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="O5FBzsmu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729499AbgKIMvc (ORCPT ); Mon, 9 Nov 2020 07:51:32 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:43846 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729673AbgKIMvV (ORCPT ); Mon, 9 Nov 2020 07:51:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1604926281; x=1636462281; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=t3J9BSpdpmukqpsDr084sd8dljMOfuJUKhBo9IZmVgc=; b=O5FBzsmuyNpzkEJB/91lUTuzk0IIjK5GTrO0AMvwX9SKUu8NUHooeUbg tFqR8E/8N9DCLKQ4uPRNh4yPRbftWP/VhkaWgKhy6BSwmYF6occgn1hFv lbUyDbiClOJOI89GvFAyflQi/bsA7GRaLLsbpabcnNZlRsklCBfk4k+6b AxZPRTEX0M0MJooUTd66F0B1HRS1o3s9WjQmVYH53A8Uzi1zvDpBzJ2CN mtuzKIGQni2DL8kQCvbz1ULHy1t54ERQ/OcUiwZPQD5+0lwwIFUsjO7VU kLzEGJy9Y3IdpetwrSnXNXiUQXoLbJB1vgABASrlcxTFuLnU+WeLU/sUw g==; IronPort-SDR: zQVuRx048lTp4jYjJElT5Au37bAbN04E/fh9IzJrV4ebZgf9AKDIBnLNGVZY+Hdw5707OQ4KgC /VBp7BJLFeFIPgfxINFO3okOWM9roOLG+XCybNRSzSUKuVRO0o0kc7W9iZUxgjvY+4YcqxgxRW FmEUoMyu5asnbfLVN5r6IDTwLB3COrHBlMONg65mhKNB9pFTr/adHGPmGXnt8A9knXfFL19tEF +QmFt91n/JyGwprDBlvou5F/K4CJEf4tNbLsLDbM97mBxxaBZfBCHnqkLP5Y467Az6Nncbfo5c gNg= X-IronPort-AV: E=Sophos;i="5.77,463,1596470400"; d="scan'208";a="156668402" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2020 20:51:11 +0800 IronPort-SDR: s2nlFwKvAZWxOEY1EMHMMhyOBmuf/VOVixvmQbQc2aKRHdruQZ7vjAnbiuERs6zM1RB4IwzdjA SeHRS1bQEl6mkRIWl+DOdDiaDQdB23eIjnhWLzWV8nD+xUVLJpNnHwLA+LQibBwiU93bEuVG8R lU6CSyLL3T1vDHbl9zQRL7h7akaow9O8VQvgvL4fra68pHPKMgJIDAU3QlK61T9kgTj7g14Atl Xp82whz4y91ALrOcfnknbJcnRc1a5nbr5POCP3/9Li3g/1ccaOZ3ygmsoZgSWrAQX/YUHerRJJ yhe1lGFjQrPzcnzAZk3HIhw5 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2020 04:37:13 -0800 IronPort-SDR: PmaatJAMDasfmulYQAgj84EDIBB0PAaIyBzMEEiAyymEDyQY2s24zOUrxOvKXFKRTM4fBaTklX F6Y4J5cGzU5jIIP1kNGDoDADU9cLP9b2gWEY4kNUO3bJfpR7jCrsySqjd+hoXYZTGie7Kvwr6c l8yuSty+eEQuGrDc1EAwQjb/xXsh2e/IXI/g40Ra1aUhCoC1ZWv8fHSWbFUfgYN3YWgZe4mU4M EPlYz8aBcgJ97NcyHJeM9F5j+bo/jsMKrS8clorrPZg3qHF/chFTi9ObTx7TJoKsOOVACCtfnR IAA= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Nov 2020 04:51:11 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 3/6] null_blk: Improve implicit zone close Date: Mon, 9 Nov 2020 21:51:02 +0900 Message-Id: <20201109125105.551734-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109125105.551734-1-damien.lemoal@wdc.com> References: <20201109125105.551734-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org When open zone resource management is enabled, that is, when a null_blk zoned device is created with zone_max_open different than 0, implicitly or explicitly opening a zone may require implicitly closing a zone that is already implicitly open. This operation is done using the function null_close_first_imp_zone(), which search for an implicitly open zone to close starting from the first sequential zone. This implementation is simple but may result in the same being constantly implicitly closed and then implicitly reopened on write, namely, the lowest numbered zone that is being written. Avoid this by starting the search for an implicitly open zone starting from the zone following the last zone that was implicitly closed. The function null_close_first_imp_zone() is renamed null_close_imp_open_zone(). Signed-off-by: Damien Le Moal --- drivers/block/null_blk.h | 1 + drivers/block/null_blk_zoned.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h index 4c101c39c3d1..683b573b7e14 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -45,6 +45,7 @@ struct nullb_device { unsigned int nr_zones_imp_open; unsigned int nr_zones_exp_open; unsigned int nr_zones_closed; + unsigned int imp_close_zone_no; struct blk_zone *zones; sector_t zone_size_sects; bool need_zone_res_mgmt; diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index b2812ee01d3d..6f2ad14ef213 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -91,6 +91,7 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) pr_info("zone_max_open limit disabled, limit >= zone count\n"); } dev->need_zone_res_mgmt = dev->zone_max_active || dev->zone_max_open; + dev->imp_close_zone_no = dev->zone_nr_conv; for (i = 0; i < dev->zone_nr_conv; i++) { struct blk_zone *zone = &dev->zones[i]; @@ -282,13 +283,24 @@ static blk_status_t __null_close_zone(struct nullb_device *dev, return BLK_STS_OK; } -static void null_close_first_imp_zone(struct nullb_device *dev) +static void null_close_imp_open_zone(struct nullb_device *dev) { - unsigned int i; + struct blk_zone *zone; + unsigned int zno, i; + + zno = dev->imp_close_zone_no; + if (zno >= dev->nr_zones) + zno = dev->zone_nr_conv; for (i = dev->zone_nr_conv; i < dev->nr_zones; i++) { - if (dev->zones[i].cond == BLK_ZONE_COND_IMP_OPEN) { - __null_close_zone(dev, &dev->zones[i]); + zone = &dev->zones[zno]; + zno++; + if (zno >= dev->nr_zones) + zno = dev->zone_nr_conv; + + if (zone->cond == BLK_ZONE_COND_IMP_OPEN) { + __null_close_zone(dev, zone); + dev->imp_close_zone_no = zno; return; } } @@ -316,7 +328,7 @@ static blk_status_t null_check_open(struct nullb_device *dev) if (dev->nr_zones_imp_open) { if (null_check_active(dev) == BLK_STS_OK) { - null_close_first_imp_zone(dev); + null_close_imp_open_zone(dev); return BLK_STS_OK; } } From patchwork Mon Nov 9 12:51:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11891491 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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 ED169C56201 for ; Mon, 9 Nov 2020 12:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A49DC206B6 for ; Mon, 9 Nov 2020 12:51:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Bh7n/ap6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729493AbgKIMvc (ORCPT ); Mon, 9 Nov 2020 07:51:32 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:43853 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729715AbgKIMvY (ORCPT ); Mon, 9 Nov 2020 07:51:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1604926283; x=1636462283; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=V53lZ6HRaKMK0GTUP2mNLfYo0n0b5X2xdLQJ2wUFowE=; b=Bh7n/ap6PxS/BwSFJDZ7YrLYFZuCAqkfreYMC5G7MZCNk7XyOxou028i jkT7hbHXyS/klrFqk7yNWe4pRXM+ZWYZMQEaHtVSA0zFkWhmIofGqZV5D IKCS9R2JdheCW5jVl2gi8wBqF6hC3JQfOYcNX6yZLEBPXKc/aa+a7At8m IJk365fLDvFfY6yykT/KRlXxzwyeI8YuH6xI/fF3u1UNY37udUvwsvobG ctkZcaASh3Vx9gPedkuZSIpiA0KS2eA8A/czCxK5P3fwDVZD94Yb2WIcl nDHZqeAjtysuBlLt6KjGZn0tImm91hNOwXOlLyAI+42D6vKbdQr8Kivik Q==; IronPort-SDR: 0ulmYk/JbzyCfOm9+TqNSuC62OVtddv7OvLbFzkdoRItxAfrKAwUeM4zkHyZeAu1p6LVY/9i1Z G8ro3IyqDGED4enrrizwrAdDjDYXxpeLQz4Tf301hLO+p0iC3afYN8E50CJtIn3KWvOqqXxf8y 023lK29onIdJ83djwYx6P5UIEpD3PaI4QPw5puVsc02Z9wMy+E3OtqInDIERNXkDEwZtRGVKvu hdw7kN6zMZphsR7+6A/EPSjadDfv4z2tQuVhC6dm4+tyu7ndG6ce/X1jUlmMGhqNbC9bRuKty4 Rfk= X-IronPort-AV: E=Sophos;i="5.77,463,1596470400"; d="scan'208";a="156668404" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2020 20:51:11 +0800 IronPort-SDR: eBj2Dh8P4m+wqggWquuhwUokdDIAbOoEKaNoVZnNHL4gT2KlQgvtcGobfyQpuXmrS/BCiWYp2z +mnvR/V9BWDRMF3W4hgg8xnTmXgdMyn34OUIrYLgJz1+Ta/NP5NBM9YDTp77kYMHY4d2BPimsU LCIBIFA2JXvjLUavdbxr4tZWmkzbSJe7gQDrJC2rSXUIQ8vkFywgZsQU8NBp/XzHYJvUHa0VGi +GXMelST56SNg3h5kPCHeyvca+LgT/4NwlYGf9aBBT0wm46Kosv18lm0OzGLQloubjBoPtdMXh VdLC22a9GBb54QAi6xs+yyNz Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2020 04:37:14 -0800 IronPort-SDR: UE9cq56IjtAl++0momAxXUK6pfM41ShkffuODmzxT+JT2jJbXXmb2/4zUsFGlKYx0eNqPgpc1V SweYEjHRvMUalDWqtcc2cByq0KicR40FE5SHBzUdCH80yNaJZfqEz4JoEk57TsGBWLPQmKlcsn Hi7FPmWbz7OX/edwxunwzJAtxvlhLzWSD0lcyi6SwjIO6rIeMr+fA7g2JuHGOXmm4UkySpTLVC BMtl/OtEsjI+yctqXqxXBzi/Bw5K173tdVsU+YTa+yHzArF/Xi+PF7Tv8wqoRe+iskpLwjAfTr Qgs= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Nov 2020 04:51:11 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 4/6] null_blk: cleanup discard handling Date: Mon, 9 Nov 2020 21:51:03 +0900 Message-Id: <20201109125105.551734-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109125105.551734-1-damien.lemoal@wdc.com> References: <20201109125105.551734-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org null_handle_discard() is called from both null_handle_rq() and null_handle_bio(). As these functions are only passed a nullb_cmd structure, this forces pointer dereferences to identiify the discard operation code and to access the sector range to be discarded. Simplify all this by changing the interface of the functions null_handle_discard() and null_handle_memory_backed() to pass along the operation code, operation start sector and number of sectors. With this change null_handle_discard() can be called directly from null_handle_memory_backed(). Also add a message warning that the discard configuration attribute has no effect when memory backing is disabled. No functional change is introduced by this patch. Signed-off-by: Damien Le Moal --- drivers/block/null_blk_main.c | 43 ++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 4685ea401d5b..1483413a81da 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1076,13 +1076,16 @@ static void nullb_fill_pattern(struct nullb *nullb, struct page *page, kunmap_atomic(dst); } -static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n) +static void null_handle_discard(struct nullb_device *dev, sector_t sector, + sector_t nr_sectors) { + struct nullb *nullb = dev->nullb; + size_t n = nr_sectors << SECTOR_SHIFT; size_t temp; spin_lock_irq(&nullb->lock); while (n > 0) { - temp = min_t(size_t, n, nullb->dev->blocksize); + temp = min_t(size_t, n, dev->blocksize); null_free_sector(nullb, sector, false); if (null_cache_active(nullb)) null_free_sector(nullb, sector, true); @@ -1149,17 +1152,10 @@ static int null_handle_rq(struct nullb_cmd *cmd) struct nullb *nullb = cmd->nq->dev->nullb; int err; unsigned int len; - sector_t sector; + sector_t sector = blk_rq_pos(rq); struct req_iterator iter; struct bio_vec bvec; - sector = blk_rq_pos(rq); - - if (req_op(rq) == REQ_OP_DISCARD) { - null_handle_discard(nullb, sector, blk_rq_bytes(rq)); - return 0; - } - spin_lock_irq(&nullb->lock); rq_for_each_segment(bvec, rq, iter) { len = bvec.bv_len; @@ -1183,18 +1179,10 @@ static int null_handle_bio(struct nullb_cmd *cmd) struct nullb *nullb = cmd->nq->dev->nullb; int err; unsigned int len; - sector_t sector; + sector_t sector = bio->bi_iter.bi_sector; struct bio_vec bvec; struct bvec_iter iter; - sector = bio->bi_iter.bi_sector; - - if (bio_op(bio) == REQ_OP_DISCARD) { - null_handle_discard(nullb, sector, - bio_sectors(bio) << SECTOR_SHIFT); - return 0; - } - spin_lock_irq(&nullb->lock); bio_for_each_segment(bvec, bio, iter) { len = bvec.bv_len; @@ -1263,11 +1251,18 @@ static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd, } static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, - enum req_opf op) + enum req_opf op, sector_t sector, + sector_t nr_sectors) + { struct nullb_device *dev = cmd->nq->dev; int err; + if (op == REQ_OP_DISCARD) { + null_handle_discard(dev, sector, nr_sectors); + return 0; + } + if (dev->queue_mode == NULL_Q_BIO) err = null_handle_bio(cmd); else @@ -1343,7 +1338,7 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd, } if (dev->memory_backed) - return null_handle_memory_backed(cmd, op); + return null_handle_memory_backed(cmd, op, sector, nr_sectors); return BLK_STS_OK; } @@ -1589,6 +1584,12 @@ static void null_config_discard(struct nullb *nullb) if (nullb->dev->discard == false) return; + if (!nullb->dev->memory_backed) { + nullb->dev->discard = false; + pr_info("discard option is ignored without memory backing\n"); + return; + } + if (nullb->dev->zoned) { nullb->dev->discard = false; pr_info("discard option is ignored in zoned mode\n"); From patchwork Mon Nov 9 12:51:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11891499 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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 2FFB9C2D0A3 for ; Mon, 9 Nov 2020 12:51:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0F8720657 for ; Mon, 9 Nov 2020 12:51:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="XIQdILbX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729666AbgKIMvg (ORCPT ); Mon, 9 Nov 2020 07:51:36 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:43846 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729761AbgKIMvc (ORCPT ); Mon, 9 Nov 2020 07:51:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1604926292; x=1636462292; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=q8DjSz449Eh2eqGNWYjeij7/XMqlOG4JLg1vETD36aM=; b=XIQdILbXmAFUTymJCUKMz15XPNKPxn9JWKoq5LhzSPW1LliAuQnXXu6D 6py2Va8NMRcpGoxInASbhM3guDzJVmJwfFqkUBpqidHCKnGDNnzL7iC1t JSUgS4Z9PcGIsj8OTvXxxcCH24njWyCj8Us+e/950261mtQ6vsPczAUvY 6aOY+jnoJEfb7tONAWOQjimKwr9JXZIVrfQGek2iEcBR5BqkRFGAOcfRQ hu4q7fEI+pC4w39APubNTfJae+nyTl+8eM95HhWkU4MtTN+KgLa7KiePF oqRfVxYWHC8zpC2uDPNdjGWVJJwFJmey5Suuk4x2meEuVkrTm+tlgMyWl g==; IronPort-SDR: SbUqUbWNANQUwk4Xg85Z7DdqSFJGETDjgXQet7rsS2w1l1KThsUXauLj/fze9LTDSdC+wHtZ3H A1DW5o0yPcWw1b30ljihhz6JwX7ibvpLkMWHpJQ2xLiJPvJcdrJ8pWa13SmpPn30zU/i7TyN/k WeM6qu/mACkELL2XWRzg3IHlsRMvLUwIqSkqvaI7t2mGRtIwGxu5WdJMocpVEXH5AaDOYpqQ8E ijUN3FGZMXA2mPOKbAQRyMPAO4ulq9MCvVc1RlgLkDAOq/mv86PWDO/2hS2M1+IHbzMEOEILo6 LOk= X-IronPort-AV: E=Sophos;i="5.77,463,1596470400"; d="scan'208";a="156668406" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2020 20:51:13 +0800 IronPort-SDR: h/GjOC7HrkEdejFjV93mQEbHg2fruFA369XS5QrS5hZb/Qsto4j8xA2V76iuGIsW10kRNMDAjR Jje1ejpiqU6JFb5K11zUymHSIbB4GSrLeUp1T41fyEDjPY2Y8KSgZHHK85JlkYIpGN4R8Vk/ra c/2odUwO4S/pwY2SFVN2LUDukWPrWBzKFwbavR8Ogip0LaEMTvf9hVEJn4pyxer0tG42pDttCt CWKYJp3JKvkWzi7dnxZJuY5MCN95Hdp5Wcrhk+YRfAf+axW+jVYq2yuqGy63KQhDw/AGot/8nM y2iWnNUmJddswMllVoTwpP70 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2020 04:37:15 -0800 IronPort-SDR: oXnPxcYX6aTq9Kqd6RwveqpIm+vJ4a324ZYo5WH5XvjO1uj5sbOcslH+JMdHiRfZ7vuKuKKDZ8 FlOuUCsNJe+X+rSzdx8MraX6/GsWZZemMoQfcYAqdiSMO7BeXt5aXEfiw0GiI1Izdc2grPJlo5 8I7SJ4gjh9UBpukzbaLW+gNf1D+i+A+zWxutSKiqbWdj/CC1RLQAK9AE8G8L9xe2AAwCAPNVgm zCwvdbH2beBhKV3CTaajJNl5flXT0x1DAR/CWl3TwRmCNPi1FHQnbtvp3RIHQJ0H9uqUf7bo7m 3G8= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Nov 2020 04:51:13 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 6/6] null_blk: Move driver into its own directory Date: Mon, 9 Nov 2020 21:51:05 +0900 Message-Id: <20201109125105.551734-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109125105.551734-1-damien.lemoal@wdc.com> References: <20201109125105.551734-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move null_blk driver code into the new sub-directory drivers/block/null_blk. Signed-off-by: Damien Le Moal --- drivers/block/Makefile | 7 +------ drivers/block/null_blk/Makefile | 11 +++++++++++ drivers/block/{ => null_blk}/null_blk.h | 0 drivers/block/{ => null_blk}/null_blk_main.c | 0 drivers/block/{ => null_blk}/null_blk_trace.c | 0 drivers/block/{ => null_blk}/null_blk_trace.h | 0 drivers/block/{ => null_blk}/null_blk_zoned.c | 0 7 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 drivers/block/null_blk/Makefile rename drivers/block/{ => null_blk}/null_blk.h (100%) rename drivers/block/{ => null_blk}/null_blk_main.c (100%) rename drivers/block/{ => null_blk}/null_blk_trace.c (100%) rename drivers/block/{ => null_blk}/null_blk_trace.h (100%) rename drivers/block/{ => null_blk}/null_blk_zoned.c (100%) diff --git a/drivers/block/Makefile b/drivers/block/Makefile index e1f63117ee94..a3170859e01d 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -41,12 +41,7 @@ obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ obj-$(CONFIG_ZRAM) += zram/ obj-$(CONFIG_BLK_DEV_RNBD) += rnbd/ -obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o -null_blk-objs := null_blk_main.o -ifeq ($(CONFIG_BLK_DEV_ZONED), y) -null_blk-$(CONFIG_TRACING) += null_blk_trace.o -endif -null_blk-$(CONFIG_BLK_DEV_ZONED) += null_blk_zoned.o +obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk/ skd-y := skd_main.o swim_mod-y := swim.o swim_asm.o diff --git a/drivers/block/null_blk/Makefile b/drivers/block/null_blk/Makefile new file mode 100644 index 000000000000..a0b7bd066fea --- /dev/null +++ b/drivers/block/null_blk/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +# needed for trace events +ccflags-y += -I$(src) + +obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o +null_blk-objs := null_blk_main.o +ifeq ($(CONFIG_BLK_DEV_ZONED), y) +null_blk-$(CONFIG_TRACING) += null_blk_trace.o +endif +null_blk-$(CONFIG_BLK_DEV_ZONED) += null_blk_zoned.o diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk/null_blk.h similarity index 100% rename from drivers/block/null_blk.h rename to drivers/block/null_blk/null_blk.h diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk/null_blk_main.c similarity index 100% rename from drivers/block/null_blk_main.c rename to drivers/block/null_blk/null_blk_main.c diff --git a/drivers/block/null_blk_trace.c b/drivers/block/null_blk/null_blk_trace.c similarity index 100% rename from drivers/block/null_blk_trace.c rename to drivers/block/null_blk/null_blk_trace.c diff --git a/drivers/block/null_blk_trace.h b/drivers/block/null_blk/null_blk_trace.h similarity index 100% rename from drivers/block/null_blk_trace.h rename to drivers/block/null_blk/null_blk_trace.h diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk/null_blk_zoned.c similarity index 100% rename from drivers/block/null_blk_zoned.c rename to drivers/block/null_blk/null_blk_zoned.c