From patchwork Wed Nov 11 13:00:42 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: 11897699 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 4CCC6C56201 for ; Wed, 11 Nov 2020 13:00:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E434120709 for ; Wed, 11 Nov 2020 13:00:55 +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="dYCeqQlC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgKKNAy (ORCPT ); Wed, 11 Nov 2020 08:00:54 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32529 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726012AbgKKNAy (ORCPT ); Wed, 11 Nov 2020 08:00:54 -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=1605099653; x=1636635653; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=JOR9OCgi505NbzwoU1BeXfqpiMr1MNIpYwwmtuMKfVA=; b=dYCeqQlCJG8Av8D8QiO48ha5Vbvg8pbPjW/gvvRG/9r1rtC5RqF9dWrO IFfr3SzNoWmC/OVsuGvcQhCO1yRO/nC299Q4yQ4r43GJP2PhXYJzJxIIZ AkyvBPpzxm62icVzFzM4B63VDEEnhQW3qRRs3fq6RUrM0OZ89jEjvcrOa 7wp22fVp/3SGnxrpbB660QP3JW0ck4CvkdwkWk2/GGY5C8U570ag7Lz8n +cpscN4kvhJpv5klcaIjxf7iymbnDwZ5gIb2zJjSdNQORDv0F6f6N+ZDi 5ofD9Sifa9wK9S2ThN9gTZojv61cvSon22L6MIyIpDK9/VK1bY/FbQpVl Q==; IronPort-SDR: sI2ZGZqMKkA/AZppjmEFy1nnk7jH3djOZgrGze907CALDCdn7EgH9HhAedfY3TJEShsQnQSP6p v/H5tGWTyLIIFVfxKzuZFMWltJe/HRYeqCFs3FEwhz6fnqwvay5K0WMRFdaetUoZVdXyagpEwA 22Zwpv/BZibViOQmJrjQha+ZWT9jDizFyDTn/FA0lX9+YPKdCx9kbjMGdQdtcedh3h5nCRQszv hwnwLq6KxuizjoE1h5liRalDViiw2rTfxZVlnCH2yM266iojJOoSt2T0x02A23dLye1s/HvS63 Gzw= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283537" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:53 +0800 IronPort-SDR: kTTIz4zMVhdHs57+JsCH4CuBLd5mYumcXDq2Kqtf6Bm8GiHwWr42Mkj0mc6dYMoXqFgOLWLN0N 8BvsWWsi8ayb+drTRK60l5VyoFAOreLq7sNtior00z+aK1FvexaoFI9nmSCZuYG+3BmrNBFBAC 5wPJ3UfNXusJlLMK+3mBAEG8s7toqPB41hUAW4PlnFGH9xA6tRUWT3RjCEmKDbWna77tW3b5I0 C6NGxYzbJ9wCO65jPTOcFl344T/Z0Q1PxyAVjloMxMdtF7E9ZO3MIyT+IOo4eMmfiguX3edgTC 02lxZ7/h/x9lVvCBr8BUDUbi Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:36 -0800 IronPort-SDR: sc+D+Wox4Y+51APTy3PcvdeZHLHZ/XWM5Y6fdX9MkDDAu36cARMJ9DcsT4/aHg3HNHb4/Br3n/ Ih1klLvgQeAD8RL64UltEQOKA7SFxVLHpYZmdI2AmlmlrGtI9svE201K42Nwb6FLxno5x3s4aN 3nMANCnz2ATKoWz4iFp32+e0TV9OJhofXPlgiYUS6n8A+tEMyApKpyCcAu27BlnO8Ko6TBpq4k 5ZZ7uYHRKUyYWFmzXqo/ABRcIS3YmlrFLdmJJvdmPvmnTzRlPZgHU/pgIcOVkSeuzcanXg8lHs BdE= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:54 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 2/9] null_blk: Fail zone append to conventional zones Date: Wed, 11 Nov 2020 22:00:42 +0900 Message-Id: <20201111130049.967902-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Conventional zones do not have a write pointer and so cannot accept zone append writes. Make sure to fail any zone append write command issued to a conventional zone. Reported-by: Naohiro Aota Fixes: e0489ed5daeb ("null_blk: Support REQ_OP_ZONE_APPEND") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/block/null_blk_zoned.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index 1d0370d91fe7..172f720b8d63 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -339,8 +339,11 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, trace_nullb_zone_op(cmd, zno, zone->cond); - if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) + if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) { + if (append) + return BLK_STS_IOERR; return null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors); + } null_lock_zone(dev, zno); From patchwork Wed Nov 11 13:00:44 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: 11897697 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 C883DC55ABD for ; Wed, 11 Nov 2020 13:00:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44D6820809 for ; Wed, 11 Nov 2020 13:00:59 +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="LK/bpd7R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbgKKNA5 (ORCPT ); Wed, 11 Nov 2020 08:00:57 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32529 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726012AbgKKNA4 (ORCPT ); Wed, 11 Nov 2020 08:00:56 -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=1605099655; x=1636635655; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=qcYCwdTa7MEOA2G0DIVgHokzSg7yN1zFCVytEw1esTw=; b=LK/bpd7RFRZmy+UotoH0FDyO83I3N2Iyd9Df/A6UhpR+sAAMafQZUhfl qeb8W5fcRZ9yr1oJDqiR92aJ5xEUn+PKCvQTzVp/seP1Xt+jcywxS/4TK C0J+w0G5M2cGxjqDc0n830eOujZGko3NAEY4zGPJU5I6qocM4U79pR2Li JDzMe80qdJRS1DxaPEqoD9AjmmAMRHTQ0CywZ4uUx4X5lu/pft5ja2Gk2 I5pW+khnEwjjqTJoq2bfm0MpkP+TbZvZeIl41r54mDei8j1U9MRDZx9sA KKPlTNuyo9WlH/hchNZsEYrC+zk1f1zdzXsBJzPVq7nucx8zyr4u9y4CS Q==; IronPort-SDR: Tx+k23CiCYTgAJBHvYqvBcOJtmsOQVdpkuNi/0S/Cs8Ktj9SEAiBqIWd4j7Lo4mdKAOMv/Fd6X V9cJMPz6iuGcmuwwMM7wSZaq2sm5By0HKuQQBVMjWZx3KyW8aLTCDxmUuq7q9YPM+9bPbDArwS nwHX730CtPXs2a1coDedaelSWELcBODbyJ9jZpFyoEeg1nZ3SPDaJ1xRfIZIzFlIX0Y4aC8RE4 8gmEB/uv4vPSyddfLtIkEe8ZhNFIeRN2eX0IQSz4fnpze6IaJAm2i6atOmaZs7n0M7pvtttajb oDc= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283542" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:55 +0800 IronPort-SDR: sbc3toky+0arMAQz7yiulTN+6+OIa95VyOcGlj1Cd6BBO96q7tkodcBPBWh6Zk2o0wK7j3ULB7 y5208Ha5fa1VHZJN9teuWzwVlAjO1Xw823N6ekqT6u4QUoEe4ZfZ+yY4rTuYKBFmH8eQJ/YRYR mOhjRxEAS9sX2RdzOm3XXPs8EYjPOoM47tVroSY0DClmwuO+VjFsbN18KWk4ioNtU59JyrJiut QWFeCwTwHQnlLsWV5H9w989MFiMFgA5jUsICtPx6xPCSytnFNdr3Y5dskPWy+3mY0cTNadaD19 0kc5q3FrkTtYOXy0hkxSY6bw Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:38 -0800 IronPort-SDR: 86fDaH7RmEtndHArRttWHbZsG9VVoE1QCQK8fIjNGZXfq4Suk/DmrtiBMJj1O8Tb5tRDKut29W xTaulQcWyKUO446PhUUdXD0UuqujG1kydyi8Ya2k8RrDYWm7XiVN2zvurh0uBpa4wdHL9E2uTl AMR5/0X6ir7OolQlat3oYrzbZ8md2ldODvrmgi8MWvgAviJQZK+rff3c7DKybEVrt/Slebp+EZ inrmWAojlRnbcujdbwY11DZu7VQkl1IUA1zBTzGQ1dj/ANZCkw8EDPLi/ze6iQfZUSswsnT1Fn e90= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:55 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 4/9] null_blk: improve zone locking Date: Wed, 11 Nov 2020 22:00:44 +0900 Message-Id: <20201111130049.967902-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-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 prevents 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 open and active zones, accounting for zone resource management is not necessary. From these observations, zone locking is changed as follows 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. 2) With memory backing disabled, per zone locking is changed to a spinlock per zone. 3) Introduce the structure nullb_zone to replace the use of struct blk_zone for zone information. This new structure includes a union of a spinlock and a mutex for zone locking. The spinlock is used when memory backing is disabled and the mutex is used with memory backing. 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) = 456 KIOPS read (libaio@qd=8 x 96 jobs) = 4096 KIOPS Write performance remains mostly unchanged but read performance is three times higher. 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 Reviewed-by: Christoph Hellwig --- drivers/block/null_blk.h | 28 +++- drivers/block/null_blk_zoned.c | 288 +++++++++++++++++++-------------- 2 files changed, 196 insertions(+), 120 deletions(-) diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h index c24d9b5ad81a..14546ead1d66 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include struct nullb_cmd { struct request *rq; @@ -32,6 +34,26 @@ struct nullb_queue { struct nullb_cmd *cmds; }; +struct nullb_zone { + /* + * Zone lock to prevent concurrent modification of a zone write + * pointer position and condition: with memory backing, a write + * command execution may sleep on memory allocation. For this case, + * use mutex as the zone lock. Otherwise, use the spinlock for + * locking the zone. + */ + union { + spinlock_t spinlock; + struct mutex mutex; + }; + enum blk_zone_type type; + enum blk_zone_cond cond; + sector_t start; + sector_t wp; + unsigned int len; + unsigned int capacity; +}; + struct nullb_device { struct nullb *nullb; struct config_item item; @@ -45,10 +67,10 @@ struct nullb_device { unsigned int nr_zones_imp_open; unsigned int nr_zones_exp_open; unsigned int nr_zones_closed; - struct blk_zone *zones; + struct nullb_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; 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 172f720b8d63..2c746221e8e6 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -13,9 +13,51 @@ static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) return sect >> ilog2(dev->zone_size_sects); } +#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_init_zone_lock(struct nullb_device *dev, + struct nullb_zone *zone) +{ + if (!dev->memory_backed) + spin_lock_init(&zone->spinlock); + else + mutex_init(&zone->mutex); +} + +static inline void null_lock_zone(struct nullb_device *dev, + struct nullb_zone *zone) +{ + if (!dev->memory_backed) + spin_lock_irq(&zone->spinlock); + else + mutex_lock(&zone->mutex); +} + +static inline void null_unlock_zone(struct nullb_device *dev, + struct nullb_zone *zone) +{ + if (!dev->memory_backed) + spin_unlock_irq(&zone->spinlock); + else + mutex_unlock(&zone->mutex); +} + int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) { sector_t dev_capacity_sects, zone_capacity_sects; + struct nullb_zone *zone; sector_t sector = 0; unsigned int i; @@ -44,26 +86,12 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) if (dev_capacity_sects & (dev->zone_size_sects - 1)) dev->nr_zones++; - dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct blk_zone), - GFP_KERNEL | __GFP_ZERO); + dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone), + GFP_KERNEL | __GFP_ZERO); if (!dev->zones) return -ENOMEM; - /* - * With memory backing, the zone_lock spinlock needs to be temporarily - * released to avoid scheduling in atomic context. To guarantee zone - * information protection, use a bitmap to lock zones with - * 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) { - dev->zone_locks = bitmap_zalloc(dev->nr_zones, GFP_KERNEL); - if (!dev->zone_locks) { - kvfree(dev->zones); - return -ENOMEM; - } - } + spin_lock_init(&dev->zone_res_lock); if (dev->zone_nr_conv >= dev->nr_zones) { dev->zone_nr_conv = dev->nr_zones - 1; @@ -86,10 +114,12 @@ 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]; + zone = &dev->zones[i]; + null_init_zone_lock(dev, zone); zone->start = sector; zone->len = dev->zone_size_sects; zone->capacity = zone->len; @@ -101,8 +131,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]; + zone = &dev->zones[i]; + null_init_zone_lock(dev, zone); zone->start = zone->wp = sector; if (zone->start + dev->zone_size_sects > dev_capacity_sects) zone->len = dev_capacity_sects - zone->start; @@ -147,32 +178,17 @@ int null_register_zoned_dev(struct nullb *nullb) void null_free_zoned_dev(struct nullb_device *dev) { - bitmap_free(dev->zone_locks); kvfree(dev->zones); } -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); -} - -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); -} - int null_report_zones(struct gendisk *disk, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data) { struct nullb *nullb = disk->private_data; struct nullb_device *dev = nullb->dev; - unsigned int first_zone, i, zno; - struct blk_zone zone; + unsigned int first_zone, i; + struct nullb_zone *zone; + struct blk_zone blkz; int error; first_zone = null_zone_no(dev, sector); @@ -182,19 +198,25 @@ int null_report_zones(struct gendisk *disk, sector_t sector, nr_zones = min(nr_zones, dev->nr_zones - first_zone); trace_nullb_report_zones(nullb, nr_zones); - zno = first_zone; - for (i = 0; i < nr_zones; i++, zno++) { + memset(&blkz, 0, sizeof(struct blk_zone)); + zone = &dev->zones[first_zone]; + for (i = 0; i < nr_zones; i++, zone++) { /* * Stacked DM target drivers will remap the zone information by * modifying the zone information passed to the report callback. * So use a local copy to avoid corruption of the device zone * array. */ - null_lock_zone(dev, zno); - memcpy(&zone, &dev->zones[zno], sizeof(struct blk_zone)); - null_unlock_zone(dev, zno); - - error = cb(&zone, i, data); + null_lock_zone(dev, zone); + blkz.start = zone->start; + blkz.len = zone->len; + blkz.wp = zone->wp; + blkz.type = zone->type; + blkz.cond = zone->cond; + blkz.capacity = zone->capacity; + null_unlock_zone(dev, zone); + + error = cb(&blkz, i, data); if (error) return error; } @@ -210,7 +232,7 @@ size_t null_zone_valid_read_len(struct nullb *nullb, sector_t sector, unsigned int len) { struct nullb_device *dev = nullb->dev; - struct blk_zone *zone = &dev->zones[null_zone_no(dev, sector)]; + struct nullb_zone *zone = &dev->zones[null_zone_no(dev, sector)]; unsigned int nr_sectors = len >> SECTOR_SHIFT; /* Read must be below the write pointer position */ @@ -224,11 +246,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 nullb_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 */ @@ -261,7 +281,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; } } @@ -310,7 +330,8 @@ static blk_status_t null_check_open(struct nullb_device *dev) * it is not certain that closing an implicit open zone will allow a new zone * to be opened, since we might already be at the active limit capacity. */ -static blk_status_t null_check_zone_resources(struct nullb_device *dev, struct blk_zone *zone) +static blk_status_t null_check_zone_resources(struct nullb_device *dev, + struct nullb_zone *zone) { blk_status_t ret; @@ -334,7 +355,8 @@ 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]; + struct nullb_zone *zone = &dev->zones[zno]; + unsigned long flags; blk_status_t ret; trace_nullb_zone_op(cmd, zno, zone->cond); @@ -345,26 +367,12 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, return null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors); } - null_lock_zone(dev, zno); + null_lock_zone(dev, zone); - 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; } /* @@ -389,60 +397,70 @@ 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: - null_unlock_zone(dev, zno); + null_unlock_zone(dev, zone); return ret; } -static blk_status_t null_open_zone(struct nullb_device *dev, struct blk_zone *zone) +static blk_status_t null_open_zone(struct nullb_device *dev, + struct nullb_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--; @@ -450,35 +468,59 @@ 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 nullb_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 nullb_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--; @@ -489,27 +531,37 @@ 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) +static blk_status_t null_reset_zone(struct nullb_device *dev, + struct nullb_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--; @@ -523,12 +575,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; } @@ -537,19 +592,19 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op, { struct nullb_device *dev = cmd->nq->dev; unsigned int zone_no; - struct blk_zone *zone; + struct nullb_zone *zone; blk_status_t ret; size_t i; if (op == REQ_OP_ZONE_RESET_ALL) { for (i = dev->zone_nr_conv; i < dev->nr_zones; i++) { - null_lock_zone(dev, i); zone = &dev->zones[i]; + null_lock_zone(dev, zone); if (zone->cond != BLK_ZONE_COND_EMPTY) { null_reset_zone(dev, zone); trace_nullb_zone_op(cmd, i, zone->cond); } - null_unlock_zone(dev, i); + null_unlock_zone(dev, zone); } return BLK_STS_OK; } @@ -557,7 +612,7 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op, zone_no = null_zone_no(dev, sector); zone = &dev->zones[zone_no]; - null_lock_zone(dev, zone_no); + null_lock_zone(dev, zone); switch (op) { case REQ_OP_ZONE_RESET: @@ -580,7 +635,7 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op, if (ret == BLK_STS_OK) trace_nullb_zone_op(cmd, zone_no, zone->cond); - null_unlock_zone(dev, zone_no); + null_unlock_zone(dev, zone); return ret; } @@ -588,29 +643,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; + struct nullb_zone *zone; 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: - null_lock_zone(dev, zno); + dev = cmd->nq->dev; + zone = &dev->zones[null_zone_no(dev, sector)]; + + null_lock_zone(dev, zone); sts = null_process_cmd(cmd, op, sector, nr_sectors); - null_unlock_zone(dev, zno); + null_unlock_zone(dev, zone); + return sts; } - - return sts; } From patchwork Wed Nov 11 13:00:45 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: 11897691 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 6458FC388F9 for ; Wed, 11 Nov 2020 13:00:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0F4A2074B for ; Wed, 11 Nov 2020 13:00:58 +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="hXh/XRHU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbgKKNA5 (ORCPT ); Wed, 11 Nov 2020 08:00:57 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32526 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgKKNA4 (ORCPT ); Wed, 11 Nov 2020 08:00:56 -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=1605099656; x=1636635656; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=febnZMc+ZcEATUd+fQ+StiriaPbiiTsmXj9REODG4hE=; b=hXh/XRHUSiA0VQ50zS8Ee/aWyjYTwmlcjBWPHxVGwym2SDzCAEi1heap G9LVV2NfFG8yFy/WYsF2GumnVXqiLbiC8cMAkO0+CknQH/rv5RjwfCTgl R+kwKic+k5zpVQMGKA/l9REvU/+jToyWd03RQ9sRjEBmdTT4xaYgQeLka wzg6/zXiO28Yu02DiOdk76YET76KcYB0nUNZqomXUknSVcOM4aoWUKz5o SQloQ1b1JTW8+r7xsPEWsSjWpJVtcay0zPWDsMSNmiYyVQu9q6jipZjSq Xg5mToj1p0MQELdJij6gDCicLhCfFb1YAYytxeGSh6sy5uBxMDdiKhrg2 g==; IronPort-SDR: 3N7zaaq5JWdkoUNIQSU2fXFiXnAQZI+PUubTCsP0wJ14Afkl8FE51z3IjdOPmNlgTMmmtmk8Zc tVYDWAuPDcnJXwHzeRXTg9GbqFtDEBuZ2faZcHDVKtDWmcjGK/KrU2Vrc2K9KvSKv1zYlw92Pp bh/xpULL7j+Fz48Ja892hAZ/emX0G6bK7yRlCVThHhR/bx8ishe00c+u2hx2B3cmvj2CDAVXnJ Ry+N6JXBGB1AGFaJ1AIb0198kQPnMb7nPjmrlvB9ZuqYNdCZfj5AodgMPiZBUG0ZuNlSJhwRR8 008= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283545" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:56 +0800 IronPort-SDR: 2X/3HP7IiZZLgD7HnkDVw1jGYtSzIujzSme0EhLzZOKXbAIvA/o7fWHvnlnyfInfecqkw1f4G8 sHkLos3mfcAzCcLC9fg8DSIpfcXvQ8h4NuKWv2c+o1pm1wMy7tJ3j8ehkH6kE6Qa5AcRxAiqKg ZR/jHC5g52AQEp7pa5sRF0wwSCUu+X6n6NldhFmGkHc5atWPx+p8WCFURGnVrxCFxGkzm4qS7Q QCpO/HpqWCQzTIK2tSktK4oW1blJ+IQSJxQrkqCfsSmZUUOlxQOd8YTmqlrsveIlcWGjOIuoyg b03NcaXcd9eYhDFx72/Zx2wS Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:38 -0800 IronPort-SDR: 5d5UY53nodr3tK2Z8hP9kYZ4+UD9/G81vEw5Tt9CF5xkEDvtAWq4konzt2bPDafgVcglQMDZt5 +Ysg8jEPNZefSvaNxWRCy3TrBlz3YBAqyR92o8CjdbuankIt1Mg7LaPnG5tSmPqLvYb+MA+2ef gBFmofSNy4VpLhhXCnnvtisqOutGOf1VWWfKWbpa6QJQEv8BtNLAOpC1xni65+41iikMlURUKd NQSyTGN3PXwDSNqvGkuYxu6p00k3GIVDBfcwcPRFF9kYqLVXCI/7mjHS30E6brg/W2pXttn9Dr UXo= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:56 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 5/9] null_blk: Improve implicit zone close Date: Wed, 11 Nov 2020 22:00:45 +0900 Message-Id: <20201111130049.967902-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-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 Reviewed-by: Johannes Thumshirn --- 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 14546ead1d66..29a8817fadfc 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -67,6 +67,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 nullb_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 2c746221e8e6..cd773af5f186 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -115,6 +115,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++) { zone = &dev->zones[i]; @@ -275,13 +276,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 nullb_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; } } @@ -309,7 +321,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 Wed Nov 11 13:00:46 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: 11897703 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 BC268C5517A for ; Wed, 11 Nov 2020 13:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5041720795 for ; Wed, 11 Nov 2020 13:01:00 +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="RDl9VBB3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726588AbgKKNA7 (ORCPT ); Wed, 11 Nov 2020 08:00:59 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32534 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726570AbgKKNA5 (ORCPT ); Wed, 11 Nov 2020 08:00:57 -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=1605099657; x=1636635657; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=y0W/n85ooYUiGlOlhPN+jwG9olh1vpEoNQl3W0xc0iA=; b=RDl9VBB3yBCh6LCi00JfPJ20fc7SrTfn36VkUBhkabE+30KurUAHXCq0 oF2sC7sQ8aiFe1M5FtMudffvGp5J6ZLMQVuzTtzaoLLd1X/ctBPss+Byv 3BukVXe839uXgBqWE9QBv/tq2F7zoQyzLr5F8IRlFHrRcvDnkRPlwu5Rg Y66q394VQOfDYKXGr+IRUR8tfd9GKVQ4X9rk0B9kJ5vE6K3IJ5p/TM/ww PuQWdVx4vzhFRxTH1gUKONEGAxJlbpLhrWgvtgNocnsZUKYZl6BRynK9r wVO2FDiaVlLMR/4QBbiVochNqHaJMoMdb5bBZAjZAqctVJSR+9dxoeL7o Q==; IronPort-SDR: bra0mJxE+ox3192rCRn+vdNh3xVtxiSMGLU0Um0jAndwkeSzvYV7Osp5jQVswGyEeK5kaxBb/O xyKHKNWnKMb1+N75K8HS1WVDKf423+2Hg+rjaM+kD2L9RY5PlAAZR+qepO2159TR+o3eSDhbNg dwUkwN2OZKrMaKop04vhjDFNEV4gKN+AOvPaP7W7lsVlCusHJ+L7LlDErR10XTskHk6/+kQ1J2 PScm/mfy7ZNASVZrSQX42h4Lnrf35dgYNMz4jbwzv6LT8Jff+WYwPJ++IgEBH/NSu5/FmsykW2 VMo= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283546" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:56 +0800 IronPort-SDR: TZ/C9nqtLdhc8yG4jEISrAExmieY6+kdV89PGePzcdMBsEnCkm7a7TSUUn1T4J3TzcZZCB9VX7 1ny886KTYAeT2adEY+rbWc1RoMRJkRRYT+TU1DuhzGgudQ9tXxUJNwDWgKIZrtZ491vg6Yq+JT pck0encuztWFIXviIaSf+K5VCiHUE/TbefQ2YFN7gpbaqJ3yC4NHrENg8rHvcGmM8CXhaKagOp Il6MHxogNDstGw0kB5+PZcghrgLzdI8WAFVIXBauFxMkovBMlBee4fv9QMWbtyeJEqq9hgrVko uuPjMBJdBhU/fK049mBXvdsj Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:39 -0800 IronPort-SDR: U+RCYwqQU4ZGKqJfswcqrX187A+FXkY1ustA1xnDABmgeIizQSxDAXt6wbTIx6Fky++3hteVKi 8zEP8+ld0Fql/SLKk+M7i6Fb2Iuz2bOY3S07IayXiC+JAgvikI1Hv+mLM5J7/nIM960RZ4L2OW qZKNd3B6PMdU1nOKBMpr2nLVVJyjZfev1gBfZtd3aLD+ZlqrnFsvOsmsYQzbsLigAkrQFhIFF7 BFdmoMM0fsIxHVdXNl/PDpfstmqbCmzbGn4leUOa81dBFS49NEi2k0wDB8NVPYN+iNBMVTWytH v9A= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:57 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 6/9] null_blk: cleanup discard handling Date: Wed, 11 Nov 2020 22:00:46 +0900 Message-Id: <20201111130049.967902-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-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 Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- 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..a223bee24e76 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 blk_status_t 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); @@ -1090,6 +1093,8 @@ static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n) n -= temp; } spin_unlock_irq(&nullb->lock); + + return BLK_STS_OK; } static int null_handle_flush(struct nullb *nullb) @@ -1149,17 +1154,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 +1181,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 +1253,16 @@ 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) + return null_handle_discard(dev, sector, nr_sectors); + 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 Wed Nov 11 13:00:47 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: 11897705 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 9AB9BC56201 for ; Wed, 11 Nov 2020 13:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3531420795 for ; Wed, 11 Nov 2020 13:01:01 +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="LHmyRSG7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726592AbgKKNA7 (ORCPT ); Wed, 11 Nov 2020 08:00:59 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32534 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726012AbgKKNA6 (ORCPT ); Wed, 11 Nov 2020 08:00:58 -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=1605099658; x=1636635658; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=y3e4ZFya6DkOkgL7LvEcCQhBPogsum+cpdPQulZCH40=; b=LHmyRSG7BfmaWHOsYoArLxOrREK8YX3xog24JwSDHVq5M6vAywBhacPQ HVtvC834wX7YGWhGYdCrkMPqrADtMoaYMZ6hxY5GObdCc60ocTWsTpm1o 8+yXSXlbB1xJBPZjfLbJnDukNciMZgH7UWgAG6TzJJ5DoNQ0ybPU9bV3J /zwJ0VRGTSmB7g+KNgHvNU1aSCwx+SbAHmSUZjY8mI2Ls3WfvmdIzBUfJ ilWR61vDKjPwQNx8sQoZf289cWcwno2EO1c1VaLiPCYRJbIPLWCzvg65j vdXTghheWle1/tUhU1vyhZYGfPz7a72RywqYM2lBgeM4tGJYDhjYva/hI g==; IronPort-SDR: 4jgAu75nQFHZuhSZ98JP+7Bx0KPY1gsPlx6rMhGjv67PKbzuelWsVu/8M3Xk0DTL6QUxyo92MG 3Hpz/AjEf3Era81biqDzGBXgl1EqNrb0Eb2Dof8ShgmU4hWxL9AeajiCnU57K3ucrY1+9czcWt SOpLwlD/8J29evvYPU5V4ExuknKkvGkUrvmzsw5zhcumE/vwkFeEw6U1W05IZh87NevYnF++st 3bt5pcHx1Ayr1lJ9AA5VyzaRHLd2NFoVEPoPrtiMivvfQL55/idIMy0yvAw3QnOD9dXB/YRFgi yAs= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283549" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:57 +0800 IronPort-SDR: JQsRuS6AmoeqcdQgAtMEOZSDg6apMHckEYZmeaoh1grFxGgT1OVFzdPgXaTck6SX/lMDxhpSfI osvWnaztR+gDjRyKSkEZ6wWm1Z3RtkuxQACppXNmZh2Tf3i04uLQ79QMLvD/ryl0LMGVuex1Fr OwkIqi48ByiZvykZQeBgdEq8drFkIAHazMoqzO6NXeWASS85sb7yogFTEM7y3qp1BhfCDfZ2Ur yY4xYqQYvajPM1gLc34vPR3WoivhtWFCKOpbmqjQjHnjXXEikJmxN8Rr+ToVd9fYY7xbv35OYc OPOkLetjeL741tJ/7/RVsEfO Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:40 -0800 IronPort-SDR: b3rJdRpdMFy4q7yRurxmhxQmTRz88yzEftl0/vWrf4ZEEZQNO683X7/pcslifYq3fATAYoO1SY WuaqlMndPVvRGdS29HHIRaQRohUx095ghPoQzv/Q7a8BaNs5IZKfmX/2j0yC/dtq5MjYDxH8mx BYkQdNmDkm0B6BjuM9/65/OCNXx+3C/xUvXTQeqwoRbRQPoZrC1Ct9aa5bvEhXzvVHS5jwBaJ+ iJWo/poR83hi/sJNik3EAfC11uQBmjvdAJYwvFWnlkXpWkozLxr6ThpkHurF1dTjV9bhdEc8Ga 9vE= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:58 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 7/9] null_blk: discard zones on reset Date: Wed, 11 Nov 2020 22:00:47 +0900 Message-Id: <20201111130049.967902-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org When memory backing is enabled, use null_handle_discard() to free the backing memory used by a zone when the zone is being reset. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/block/null_blk.h | 2 ++ drivers/block/null_blk_main.c | 4 ++-- drivers/block/null_blk_zoned.c | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h index 29a8817fadfc..63000aeeb2f3 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -116,6 +116,8 @@ struct nullb { char disk_name[DISK_NAME_LEN]; }; +blk_status_t null_handle_discard(struct nullb_device *dev, sector_t sector, + sector_t nr_sectors); blk_status_t null_process_cmd(struct nullb_cmd *cmd, enum req_opf op, sector_t sector, unsigned int nr_sectors); diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index a223bee24e76..b758b9366630 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1076,8 +1076,8 @@ static void nullb_fill_pattern(struct nullb *nullb, struct page *page, kunmap_atomic(dst); } -static blk_status_t null_handle_discard(struct nullb_device *dev, - sector_t sector, sector_t nr_sectors) +blk_status_t 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; diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index cd773af5f186..2fd8c825d70b 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -596,6 +596,9 @@ static blk_status_t null_reset_zone(struct nullb_device *dev, null_unlock_zone_res(dev, flags); + if (dev->memory_backed) + return null_handle_discard(dev, zone->start, zone->len); + return BLK_STS_OK; } From patchwork Wed Nov 11 13:00:48 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: 11897701 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 91517C388F9 for ; Wed, 11 Nov 2020 13:01:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 359D32074B for ; Wed, 11 Nov 2020 13:01:05 +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="Psd2VZRK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726600AbgKKNBA (ORCPT ); Wed, 11 Nov 2020 08:01:00 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32534 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726570AbgKKNA7 (ORCPT ); Wed, 11 Nov 2020 08:00:59 -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=1605099659; x=1636635659; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=kmiiJbhUyC22YQgPw/gfrmzkz4MvpWwRC2dUGM9fdm0=; b=Psd2VZRKlE1ALZMabtYufCu7XbxRzD6al2Z7jSWJNhSiP0y+ySU769ME 1Fw7wYs4GHyJsTdGKwsRzOif2YsI6JhYsIvtkw1RJJ9Y403k8KNq2TUEb H86nA2BBf6PjD4D3HCj39OIoCH0JumALasghh21X5wim6apD6PiZSj4Um qCXRvwDqurjS4joSlcZ/+XgPSEoQ5Sr+vsOgW3YfaQiT/EgRRwndK3U9m p3+wSkPcYaqLCYLcoKDAuxOCth7S9ioUAX39Oc2sk2iLE7HWiC/xMC7ME bVDuX5hBaXYbJo1zgBhzpq1ntyETCn6yjLyoRY/BduQYXSZnN3YPmrGjx w==; IronPort-SDR: pozfVQWVhQ5ez853dKsMJZO40mOB9BgEMUaG9BTuE9JUJ99wuQcrTrr3dibIHKbb513C6kNubX Z0z5qItGq8NpzLa8dNzgW75N7NnHSVkimuNIcCSBM436c+LWbJFASJeaErBvVp3dZeddjAohho Z0NSpo5dtp7ZhG+OhgRziECWkSfSY6/iPlZHnq8Jx9EoI9iHzIJh2oWskcgA954SliJKPJ8IJ/ IXVn7nHMLhNYGFR+96UMjZthcigdHd9mnTzm2kyivpvZE6LCnfoLqiokaQxyd9pb4DtKeRqobX ffs= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283550" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:58 +0800 IronPort-SDR: 1RbK8KDfWFMrUPkYQCaNuBbrwVRq2naY6XSLTE/d4icN0DF2YWgTBJgV+RTxd+KQbEEalM3kZr wbnrpmpZUzLyz47IfamL2Buf0NYMDrvFvBFhEWGPq7v+vMgynWiOHY44JwNGpG6g4SpZrJ+Q6e fzquYuvnjg7vaAu4sMINWJPcZlFsdm/B26bDGa8YCY8fuhN4KerpnI6ARFe00vKZuKH/1cN9AS hbOWYBlOPsLafhePmDD5V8Aij7+CEMuLVgUmgU+YDHY1PeF3MJGUBEZVcX7KZIrFGtoM2VRHkL lPMepw2ZSqVqBigKSjeioo29 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:41 -0800 IronPort-SDR: 8Ut604kcAfqRDPOiGmVlp3ZcHPDwemwUjcmXYzfX/cnFuL3wUDydF8buoyazGienuYT3yIVh9U 1bnV/LsTqYnbpbH0VKTXoBepZR9nXxjH3R1Bydkq7XRGQrrQBX7bsAwE2ReiHHcBL7W4HqRwkY ePBc4H2pSkPDI8Vj8ws9DCT8uX8LqorypuLH/pyRBq54QrOSdlETi26suB2ik+z+84X7I8S9xV RNybr4SS/E2emAhwQzul2BgaajJGXaKusxzxQHhI9rUbMKX1xe+tLH/NBXZeJk1Y1+vV2Tjym5 cqw= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:58 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 8/9] null_blk: Allow controlling max_hw_sectors limit Date: Wed, 11 Nov 2020 22:00:48 +0900 Message-Id: <20201111130049.967902-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add the module option and configfs attribute max_sectors to allow configuring the maximum size of a command issued to a null_blk device. This allows exercising the block layer BIO splitting with different limits than the default BLK_SAFE_MAX_SECTORS. This is also useful for testing the zone append write path of file systems as the max_hw_sectors limit value is also used for the max_zone_append_sectors limit. Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- drivers/block/null_blk.h | 1 + drivers/block/null_blk_main.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h index 63000aeeb2f3..83504f3cc9d6 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -85,6 +85,7 @@ struct nullb_device { unsigned int home_node; /* home node for the device */ unsigned int queue_mode; /* block interface */ unsigned int blocksize; /* block size */ + unsigned int max_sectors; /* Max sectors per command */ unsigned int irqmode; /* IRQ completion handler */ unsigned int hw_queue_depth; /* queue depth */ unsigned int index; /* index of the disk, only valid with a disk */ diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index b758b9366630..5357c3a4a36f 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -152,6 +152,10 @@ static int g_bs = 512; module_param_named(bs, g_bs, int, 0444); MODULE_PARM_DESC(bs, "Block size (in bytes)"); +static int g_max_sectors; +module_param_named(max_sectors, g_max_sectors, int, 0444); +MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); + static unsigned int nr_devices = 1; module_param(nr_devices, uint, 0444); MODULE_PARM_DESC(nr_devices, "Number of devices to register"); @@ -346,6 +350,7 @@ NULLB_DEVICE_ATTR(submit_queues, uint, nullb_apply_submit_queues); NULLB_DEVICE_ATTR(home_node, uint, NULL); NULLB_DEVICE_ATTR(queue_mode, uint, NULL); NULLB_DEVICE_ATTR(blocksize, uint, NULL); +NULLB_DEVICE_ATTR(max_sectors, uint, NULL); NULLB_DEVICE_ATTR(irqmode, uint, NULL); NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); NULLB_DEVICE_ATTR(index, uint, NULL); @@ -463,6 +468,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_home_node, &nullb_device_attr_queue_mode, &nullb_device_attr_blocksize, + &nullb_device_attr_max_sectors, &nullb_device_attr_irqmode, &nullb_device_attr_hw_queue_depth, &nullb_device_attr_index, @@ -533,7 +539,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item) static ssize_t memb_group_features_show(struct config_item *item, char *page) { return snprintf(page, PAGE_SIZE, - "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active\n"); + "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active,blocksize,max_sectors\n"); } CONFIGFS_ATTR_RO(memb_group_, features); @@ -588,6 +594,7 @@ static struct nullb_device *null_alloc_dev(void) dev->home_node = g_home_node; dev->queue_mode = g_queue_mode; dev->blocksize = g_bs; + dev->max_sectors = g_max_sectors; dev->irqmode = g_irqmode; dev->hw_queue_depth = g_hw_queue_depth; dev->blocking = g_blocking; @@ -1867,6 +1874,11 @@ static int null_add_dev(struct nullb_device *dev) blk_queue_logical_block_size(nullb->q, dev->blocksize); blk_queue_physical_block_size(nullb->q, dev->blocksize); + if (!dev->max_sectors) + dev->max_sectors = queue_max_hw_sectors(nullb->q); + dev->max_sectors = min_t(unsigned int, dev->max_sectors, + BLK_DEF_MAX_SECTORS); + blk_queue_max_hw_sectors(nullb->q, dev->max_sectors); null_config_discard(nullb); @@ -1910,6 +1922,12 @@ static int __init null_init(void) g_bs = PAGE_SIZE; } + if (g_max_sectors > BLK_DEF_MAX_SECTORS) { + pr_warn("invalid max sectors\n"); + pr_warn("defaults max sectors to %u\n", BLK_DEF_MAX_SECTORS); + g_max_sectors = BLK_DEF_MAX_SECTORS; + } + if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) { pr_err("invalid home_node value\n"); g_home_node = NUMA_NO_NODE; From patchwork Wed Nov 11 13:00:49 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: 11897707 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 3BD4EC55ABD for ; Wed, 11 Nov 2020 13:01:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D60542074B for ; Wed, 11 Nov 2020 13:01:05 +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="eNwMyid6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726570AbgKKNBB (ORCPT ); Wed, 11 Nov 2020 08:01:01 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:32534 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726012AbgKKNBA (ORCPT ); Wed, 11 Nov 2020 08:01:00 -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=1605099660; x=1636635660; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=o+1lVTW/q7+3AX2JW2198Em9/z+xjLCGpSgs/dHrLYg=; b=eNwMyid67oboWqK+w4Qs8OHPJMCHr3qxoTz5SJLx9Ih1t44IcyQ8p8AR NEi8joJuVaoK/8oWSvdWcsNQhBCCHQsP5P6no49V/cP3EfZsvwyVs/qvJ EptMzCrTQfAi/cEskgOO7f6g6RybWkb7Zte9yHFdb/3x9e9TQbIm+8mfg GxAwkRX43R+vGgaVYsMdqjfS7ZaYfhn9xfHMCFC3/VDkQPmKR2ObvXkFS Z7UwwaKL+xAJ1bz2KZddQbgy5YYfuJI3fhoGnvk5IGD+xF9lCBMsyOGq/ wGpJnP0u9LPJDZJJxJf4D0kOTGLA+uEZXcc4vcTv5aMspFzAq6TLH6mmC Q==; IronPort-SDR: Vx+6RvZMU4Vli5BQszjbRUG3spbIfP66UF7rewtZ0cC0TTxRCSR5alisjriX3gQvhEVZtsLZ4D BCKlXzHq7AswaaCm3FVIHTsqVcBxpjDLVR0vVnz3Jvx8fNloVp4neBkM9Q5oJifUs1CGzUtw8U IhMD+DcEwyjdwbdhzJ9jESGk5fV0IiBQkUo63OC/72jE6rH+BN3dk70g0NvAAasJPMy4D4nLqi n42RO2w2o1/PVfjbxjAPkbY59Q0FuBthgBYxoDW9PXN+iWOHQB3ds651Rqh4V2tdwDgO1gRbU9 cUA= X-IronPort-AV: E=Sophos;i="5.77,469,1596470400"; d="scan'208";a="152283554" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Nov 2020 21:00:59 +0800 IronPort-SDR: TrgsLCeiwBALmVSRs30QoQKyw6AQm7X2BvlPk1INPxTjoAwu76nCiAYbivWpZ9I9QRj3PuXzzo JhWDsB66Gv/nPBPr/bANycOSU2mksfZLa5qrwH6FJS7TiDwxySj6bfwMxOpG73uEov3pq4/bh3 8/e676zLgAkaIceUvYZM/25N6W7pXqJ0/UgjlSiMa0vXE8878AG0VPFBQym/NuIo12bRucIEUo BoouVUWlc4raAO4msE6hQbFf9Bs2m+3Ji1ZrLjkuOE4JxmyKJGWZ/IL97/wFhO5DTi/L26ZxRV 52ZRn+5XSReq3Uk9zpZ4lhTy Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 04:45:41 -0800 IronPort-SDR: m1NBzDfYd7RUbpCRne6tPWqrAHfpKuAUvJFz2FgfvJ3+k8HNB0CevCZUxNj3EVBSGyuY+9j822 9OD3vStqDnFu2SwJ939bsyM/IP2Beoim2PmpMZYFg14OQ9JsOjXMUSaHmy1kJ941e63XYbJPlK /zQFQemfb0lTtTOt1ftfCaXLEu4mYhzJXlq7qEA02gHYywMrg7ohgsmYrlwdWdz7NVCiEH0M71 xmloV4RM82bSevAqYsDEj4sr5WRBc34Y8el8q//8QQLi+qLfy8esCZiQv8OXzlXExVbgvXK/cO 7Wk= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Nov 2020 05:00:59 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v3 9/9] null_blk: Move driver into its own directory Date: Wed, 11 Nov 2020 22:00:49 +0900 Message-Id: <20201111130049.967902-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111130049.967902-1-damien.lemoal@wdc.com> References: <20201111130049.967902-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. Suggested-by: Bart Van Assche Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- drivers/block/Kconfig | 8 +------- drivers/block/Makefile | 7 +------ drivers/block/null_blk/Kconfig | 12 ++++++++++++ drivers/block/null_blk/Makefile | 11 +++++++++++ drivers/block/{null_blk_main.c => null_blk/main.c} | 0 drivers/block/{ => null_blk}/null_blk.h | 0 drivers/block/{null_blk_trace.c => null_blk/trace.c} | 2 +- drivers/block/{null_blk_trace.h => null_blk/trace.h} | 2 +- drivers/block/{null_blk_zoned.c => null_blk/zoned.c} | 2 +- 9 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 drivers/block/null_blk/Kconfig create mode 100644 drivers/block/null_blk/Makefile rename drivers/block/{null_blk_main.c => null_blk/main.c} (100%) rename drivers/block/{ => null_blk}/null_blk.h (100%) rename drivers/block/{null_blk_trace.c => null_blk/trace.c} (93%) rename drivers/block/{null_blk_trace.h => null_blk/trace.h} (97%) rename drivers/block/{null_blk_zoned.c => null_blk/zoned.c} (99%) diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index ecceaaa1a66f..262326973ee0 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -16,13 +16,7 @@ menuconfig BLK_DEV if BLK_DEV -config BLK_DEV_NULL_BLK - tristate "Null test block driver" - select CONFIGFS_FS - -config BLK_DEV_NULL_BLK_FAULT_INJECTION - bool "Support fault injection for Null test block driver" - depends on BLK_DEV_NULL_BLK && FAULT_INJECTION +source "drivers/block/null_blk/Kconfig" config BLK_DEV_FD tristate "Normal floppy disk support" 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/Kconfig b/drivers/block/null_blk/Kconfig new file mode 100644 index 000000000000..6bf1f8ca20a2 --- /dev/null +++ b/drivers/block/null_blk/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Null block device driver configuration +# + +config BLK_DEV_NULL_BLK + tristate "Null test block driver" + select CONFIGFS_FS + +config BLK_DEV_NULL_BLK_FAULT_INJECTION + bool "Support fault injection for Null test block driver" + depends on BLK_DEV_NULL_BLK && FAULT_INJECTION diff --git a/drivers/block/null_blk/Makefile b/drivers/block/null_blk/Makefile new file mode 100644 index 000000000000..84c36e512ab8 --- /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 := main.o +ifeq ($(CONFIG_BLK_DEV_ZONED), y) +null_blk-$(CONFIG_TRACING) += trace.o +endif +null_blk-$(CONFIG_BLK_DEV_ZONED) += zoned.o diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk/main.c similarity index 100% rename from drivers/block/null_blk_main.c rename to drivers/block/null_blk/main.c 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_trace.c b/drivers/block/null_blk/trace.c similarity index 93% rename from drivers/block/null_blk_trace.c rename to drivers/block/null_blk/trace.c index f246e7bff698..3711cba16071 100644 --- a/drivers/block/null_blk_trace.c +++ b/drivers/block/null_blk/trace.c @@ -4,7 +4,7 @@ * * Copyright (C) 2020 Western Digital Corporation or its affiliates. */ -#include "null_blk_trace.h" +#include "trace.h" /* * Helper to use for all null_blk traces to extract disk name. diff --git a/drivers/block/null_blk_trace.h b/drivers/block/null_blk/trace.h similarity index 97% rename from drivers/block/null_blk_trace.h rename to drivers/block/null_blk/trace.h index 4f83032eb544..ce3b430e88c5 100644 --- a/drivers/block/null_blk_trace.h +++ b/drivers/block/null_blk/trace.h @@ -73,7 +73,7 @@ TRACE_EVENT(nullb_report_zones, #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -#define TRACE_INCLUDE_FILE null_blk_trace +#define TRACE_INCLUDE_FILE trace /* This part must be outside protection */ #include diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk/zoned.c similarity index 99% rename from drivers/block/null_blk_zoned.c rename to drivers/block/null_blk/zoned.c index 2fd8c825d70b..375ef63adcd3 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -4,7 +4,7 @@ #include "null_blk.h" #define CREATE_TRACE_POINTS -#include "null_blk_trace.h" +#include "trace.h" #define MB_TO_SECTS(mb) (((sector_t)mb * SZ_1M) >> SECTOR_SHIFT)