From patchwork Mon May 16 16:54:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EB4BC433F5 for ; Mon, 16 May 2022 16:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343928AbiEPQyf (ORCPT ); Mon, 16 May 2022 12:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244324AbiEPQy3 (ORCPT ); Mon, 16 May 2022 12:54:29 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E44FD27B39 for ; Mon, 16 May 2022 09:54:23 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165422euoutp01d3e4a39c45528af125ee5878913c276b~vpCPeo3rk2836328363euoutp01J for ; Mon, 16 May 2022 16:54:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165422euoutp01d3e4a39c45528af125ee5878913c276b~vpCPeo3rk2836328363euoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720062; bh=lp2K3w6bYU/ZGZyfjOrT9sOG4NQYsIr+x+HLsdgsemk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gao6kZNXJCA2SyuQGlCnltENjf2JuoRrXfzpZ9zap0nqz68eWU+dTIb+g2u01N8Dq 5kR+8EWzwRKgRheByVLoD4sTh+/BxZ2nLbvBWq3GPJc4zTkNw297OMLUBxLNe+btal y7ay2+cWGrzwAWUPcZWIjgvIO7TF+1jqqXS1ZTe8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165420eucas1p1bcc0f0bd3a9d48f46d084febc883e0cc~vpCNyNJtW3183531835eucas1p1K; Mon, 16 May 2022 16:54:20 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9E.D6.10260.CB182826; Mon, 16 May 2022 17:54:20 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b~vpCNYo_z33185231852eucas1p1L; Mon, 16 May 2022 16:54:19 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165419eusmtrp1da80ad51c871b452d6f5500bc402eb7f~vpCNXvW_c2961829618eusmtrp1E; Mon, 16 May 2022 16:54:19 +0000 (GMT) X-AuditID: cbfec7f5-bf3ff70000002814-3e-628281bc9a2c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4B.89.09522.BB182826; Mon, 16 May 2022 17:54:19 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165419eusmtip17f050be3da427ead4fb6b476c789280b~vpCNDBYCX2383023830eusmtip1X; Mon, 16 May 2022 16:54:19 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain , Hannes Reinecke Subject: [PATCH v4 01/13] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Mon, 16 May 2022 18:54:04 +0200 Message-Id: <20220516165416.171196-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBKsWRmVeSWpSXmKPExsWy7djP87p7GpuSDK53CFqsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJoufABxaLvbe0LS49XsFusWfvSRaLy7vmsFnM X/aU3eLGhKeMFp+XtrBbrLn5lMVBwOPfiTVsHjtn3WX3uHy21GPTqk42j81L6j1232wACrfe Z/V4v+8qm0ffllWMHuu3XGXx2Hy62uPzJrkAnigum5TUnMyy1CJ9uwSujL7FixgLZopUHPg8 mamB8ZZAFyMnh4SAicSN7uusXYxcHEICKxgl/l3YxwSSEBL4wihxvF8dwv7MKHFwlitMw9KZ v1kg4ssZJWb0u0A0P2eUWPbqBGMXIwcHm4CWRGMnO0iNiECWxLQTDxlBapgFDjNJPD86nxWk RlggWeLScmOQGhYBVYndsxvZQGxeASuJF5uns0PskpeYeek7O0g5p4C1xOoubogSQYmTM5+A ncAMVNK8dTYzyHgJgeWcEqcP/GKD6HWROPHzFROELSzx6vgWqJkyEqcn97BA2NUST2/8hmpu YZTo37meDWSZBNCyvjM5ICazgKbE+l36EOWOEituvGeBqOCTuPFWEOIEPolJ26YzQ4R5JTra hCCqlSR2/nwCtVRC4nLTHKilHhJ/5jxnmcCoOAvJM7OQPDMLYe8CRuZVjOKppcW56anFxnmp 5XrFibnFpXnpesn5uZsYgYnv9L/jX3cwrnj1Ue8QIxMH4yFGCQ5mJRFeg4qGJCHelMTKqtSi /Pii0pzU4kOM0hwsSuK8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OanFhxhNgc6eyCwlmpwPTBV5JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6Yklqdmp qQWpRTB9TBycUg1M7Pcbb0tJiolxsB7lSj8p7O2mczzNa6/e03UhRcc/ZTV7T12oVKO1tmLB 5k+7z9gd7FoZfeVKzbaD6cYzWpdJmPY9dPz867vTiyfPZK8+CDr/XvzALNdV/DcDu20XHDeo cfig/vuHTtQqtX39O3oMf87gSa1tdk2YMGdLf+SLEyXpqepFZkLSS9PbXjqza64469h0NiLS 5N71KXy8Gmlpe3+3/j/4ItlCNvD7E4F7vw/sLvivvTV54aq/DssuJIns/mL2SuIq84tb8/Zw 3Fe4vWGzrmKwxL0Z13W+f3dSmrWn2dB4wcOFsc2VNyLfBt2dULbGqySWK0BW/6HJzXuvthp9 n28zeQlr9ossmQxPEyWW4oxEQy3mouJEALGUZ2ldAwAA X-CMS-MailID: 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b X-Msg-Generator: CA X-RootMTR: 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Adapt blkdev_nr_zones and blk_queue_zone_no function so that it can also work for non-power-of-2 zone sizes. As the existing deployments of zoned devices had power-of-2 assumption, power-of-2 optimized calculation is kept for those devices. There are no direct hot paths modified and the changes just introduce one new branch per call. Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav --- block/blk-zoned.c | 13 ++++++++++--- include/linux/blkdev.h | 8 +++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8..140230134 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,16 +111,23 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); * blkdev_nr_zones - Get number of zones * @disk: Target gendisk * - * Return the total number of zones of a zoned block device. For a block - * device without zone capabilities, the number of zones is always 0. + * Return the total number of zones of a zoned block device, including the + * eventual small last zone if present. For a block device without zone + * capabilities, the number of zones is always 0. */ unsigned int blkdev_nr_zones(struct gendisk *disk) { sector_t zone_sectors = blk_queue_zone_sectors(disk->queue); + sector_t capacity = get_capacity(disk); if (!blk_queue_is_zoned(disk->queue)) return 0; - return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors); + + if (is_power_of_2(zone_sectors)) + return (capacity + zone_sectors - 1) >> + ilog2(zone_sectors); + + return div64_u64(capacity + zone_sectors - 1, zone_sectors); } EXPORT_SYMBOL_GPL(blkdev_nr_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1b24c1fb3..22fe512ee 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -675,9 +675,15 @@ static inline unsigned int blk_queue_nr_zones(struct request_queue *q) static inline unsigned int blk_queue_zone_no(struct request_queue *q, sector_t sector) { + sector_t zone_sectors = blk_queue_zone_sectors(q); + if (!blk_queue_is_zoned(q)) return 0; - return sector >> ilog2(q->limits.chunk_sectors); + + if (is_power_of_2(zone_sectors)) + return sector >> ilog2(zone_sectors); + + return div64_u64(sector, zone_sectors); } static inline bool blk_queue_zone_is_seq(struct request_queue *q, From patchwork Mon May 16 16:54:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73EE7C433FE for ; Mon, 16 May 2022 16:54:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243906AbiEPQyy (ORCPT ); Mon, 16 May 2022 12:54:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343877AbiEPQyc (ORCPT ); Mon, 16 May 2022 12:54:32 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48D16381AA for ; Mon, 16 May 2022 09:54:28 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165423euoutp01a9fbc73d99ad06fdcae3fb88e0c804f1~vpCQqDQpl2837628376euoutp01F for ; Mon, 16 May 2022 16:54:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165423euoutp01a9fbc73d99ad06fdcae3fb88e0c804f1~vpCQqDQpl2837628376euoutp01F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720063; bh=qm0Anrgo2LRVYYSLS0+cudW9OU5s2MlxyVDAMmEqCV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZBmjxMwULUxzXs3JDSjBA2k6MT+1QDpOhDbrGJnKoKuyxJAG7E1+E1qmdz6pBUth XPRyeQBnWyNb+UGuz3+9grsag73H9wxczoV4nEQt4saIBQP3EM+OsmFxrNV/k8bN4j f1RqWTJS3BlB65UfOGtiLGOMZDF9i4LsGcLwE97E= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165422eucas1p1162a8ccdd29e06f930ca66dececc3667~vpCPT6nb52560525605eucas1p1W; Mon, 16 May 2022 16:54:22 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 33.40.10009.DB182826; Mon, 16 May 2022 17:54:21 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220516165421eucas1p2515446ac290987bdb9af24ffb835b287~vpCO3QdmY2457324573eucas1p2W; Mon, 16 May 2022 16:54:21 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220516165421eusmtrp214587cb0a00813fc775c1106b7d30871~vpCO2blGP1030710307eusmtrp2q; Mon, 16 May 2022 16:54:21 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-42-628281bd5f1f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 9B.00.09404.DB182826; Mon, 16 May 2022 17:54:21 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165421eusmtip1899df696a585dc3044e16754fe6b8fbb~vpCOd7A2K2383023830eusmtip1Y; Mon, 16 May 2022 16:54:21 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 02/13] block: allow blk-zoned devices to have non-power-of-2 zone size Date: Mon, 16 May 2022 18:54:05 +0200 Message-Id: <20220516165416.171196-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAKsWRmVeSWpSXmKPExsWy7djP87p7G5uSDL4+s7RYfbefzeL32fPM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/4wuN 1w9eKx+LFgvwKBHOrPn19l6yHG9q+439U9ht96+f+bCl0JFJhvHmk+zoB5odt/fpr33QsDVu poJelBJLcUaioRZzUXEiAD2Ugp9TAwAA X-CMS-MailID: 20220516165421eucas1p2515446ac290987bdb9af24ffb835b287 X-Msg-Generator: CA X-RootMTR: 20220516165421eucas1p2515446ac290987bdb9af24ffb835b287 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165421eucas1p2515446ac290987bdb9af24ffb835b287 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Checking if a given sector is aligned to a zone is a common operation that is performed for zoned devices. Add blk_queue_is_zone_start helper to check for this instead of opencoding it everywhere. Convert the calculations on zone size to be generic instead of relying on power_of_2 based logic in the block layer using the helpers wherever possible. The only hot path affected by this change for power_of_2 zoned devices is in blk_check_zone_append() but blk_queue_is_zone_start() helper is used to optimize the calculation for po2 zone sizes. Note that the append path cannot be accessed by direct raw access to the block device but only through a filesystem abstraction. Finally, allow non power of 2 zoned devices provided that their zone capacity and zone size are equal. The main motivation to allow non power_of_2 zoned device is to remove the unmapped LBA between zcap and zsze for devices that cannot have a power_of_2 zcap. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- block/blk-core.c | 3 +-- block/blk-zoned.c | 27 +++++++++++++++++++++------ include/linux/blkdev.h | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index f305cb66c..b7051b7ea 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -634,8 +634,7 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_NOTSUPP; /* The bio sector must point to the start of a sequential zone */ - if (pos & (blk_queue_zone_sectors(q) - 1) || - !blk_queue_zone_is_seq(q, pos)) + if (!blk_queue_is_zone_start(q, pos) || !blk_queue_zone_is_seq(q, pos)) return BLK_STS_IOERR; /* diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 140230134..cfc2fb804 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -289,10 +289,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, return -EINVAL; /* Check alignment (handle eventual smaller last zone) */ - if (sector & (zone_sectors - 1)) + if (!blk_queue_is_zone_start(q, sector)) return -EINVAL; - if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity) + if (!blk_queue_is_zone_start(q, nr_sectors) && end_sector != capacity) return -EINVAL; /* @@ -490,14 +490,29 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, * smaller last zone. */ if (zone->start == 0) { - if (zone->len == 0 || !is_power_of_2(zone->len)) { - pr_warn("%s: Invalid zoned device with non power of two zone size (%llu)\n", - disk->disk_name, zone->len); + if (zone->len == 0) { + pr_warn("%s: Invalid zone size", + disk->disk_name); + return -ENODEV; + } + + /* + * Don't allow zoned device with non power_of_2 zone size with + * zone capacity less than zone size. + */ + if (!is_power_of_2(zone->len) && + zone->capacity < zone->len) { + pr_warn("%s: Invalid zoned size with non power of 2 zone size and zone capacity < zone size", + disk->disk_name); return -ENODEV; } args->zone_sectors = zone->len; - args->nr_zones = (capacity + zone->len - 1) >> ilog2(zone->len); + /* + * Division is used to calculate nr_zones for both power_of_2 + * and non power_of_2 zone sizes as it is not in the hot path. + */ + args->nr_zones = div64_u64(capacity + zone->len - 1, zone->len); } else if (zone->start + args->zone_sectors < capacity) { if (zone->len != args->zone_sectors) { pr_warn("%s: Invalid zoned device with non constant zone size\n", diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 22fe512ee..32d7bd7b1 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -686,6 +686,22 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, return div64_u64(sector, zone_sectors); } +static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec) +{ + sector_t zone_sectors = blk_queue_zone_sectors(q); + u64 remainder = 0; + + if (!blk_queue_is_zoned(q)) + return false; + + if (is_power_of_2(zone_sectors)) + return IS_ALIGNED(sec, zone_sectors); + + div64_u64_rem(sec, zone_sectors, &remainder); + /* if there is a remainder, then the sector is not aligned */ + return remainder == 0; +} + static inline bool blk_queue_zone_is_seq(struct request_queue *q, sector_t sector) { @@ -732,6 +748,12 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, { return 0; } + +static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec) +{ + return false; +} + static inline unsigned int queue_max_open_zones(const struct request_queue *q) { return 0; From patchwork Mon May 16 16:54:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FE28C433EF for ; Mon, 16 May 2022 16:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343852AbiEPQyf (ORCPT ); Mon, 16 May 2022 12:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343879AbiEPQyc (ORCPT ); Mon, 16 May 2022 12:54:32 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4924F3C711 for ; Mon, 16 May 2022 09:54:29 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165425euoutp017b6b25e027eafa04aa184c230f9439a2~vpCSHJq4R2836428364euoutp01H for ; Mon, 16 May 2022 16:54:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165425euoutp017b6b25e027eafa04aa184c230f9439a2~vpCSHJq4R2836428364euoutp01H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720065; bh=IJFvu7Txlqq4QbkiUAdYp5LUxrFDgYD73zO+DTftg+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UPRV74XvfZD/Srf4Pvh5UdLPS71mZCRWcuLS8bADEtZ4NDs7z4mhxzR1HpYYOJ6Au T+fX2nb5z5DQsUXAbGWUQCst5by+1zvFZ5dyE+MP0xafrP4vSPFJl/SY++6+K8lrHv Cgohay58NbarWtGqihLFMWOWK6tMFdM5JX6fPmgU= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165423eucas1p158930326081e188da90c844c41449d67~vpCQpqA1T3100231002eucas1p1G; Mon, 16 May 2022 16:54:23 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id B4.40.10009.FB182826; Mon, 16 May 2022 17:54:23 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165422eucas1p174acec28848a9c2178376f092af3fa1c~vpCQK_Iy22562625626eucas1p1X; Mon, 16 May 2022 16:54:22 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220516165422eusmtrp2535ec901b9fcfc699f53e88d7145bca3~vpCQKB3a51030710307eusmtrp2r; Mon, 16 May 2022 16:54:22 +0000 (GMT) X-AuditID: cbfec7f2-e95ff70000002719-45-628281bf30ff Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 9C.00.09404.EB182826; Mon, 16 May 2022 17:54:22 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165422eusmtip15250a2577700f87549716a5010c26ef5~vpCP3mI__2390423904eusmtip1u; Mon, 16 May 2022 16:54:22 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 03/13] nvme: zns: Allow ZNS drives that have non-power_of_2 zone size Date: Mon, 16 May 2022 18:54:06 +0200 Message-Id: <20220516165416.171196-4-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEKsWRmVeSWpSXmKPExsWy7djP87r7G5uSDKbckLRYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBYrVx9lsug58IHFYu8tbYtLj1ewW+zZe5LF4vKuOWwW85c9Zbe4 MeEpo8XnpS3sFmtuPmVx4Pf4d2INm8fOWXfZPS6fLfXYtKqTzWPzknqP3TcbgMKt91k93u+7 yubRt2UVo8f6LVdZPD5vkgvgjuKySUnNySxLLdK3S+DK2LpgClPBFrGKj7cOsDQwrhXqYuTk kBAwkXj05BhbFyMXh5DACkaJH00vWCCcL4wSSze3MUM4nxklDt/tYodpOXQOJrGcUeLJ9i5G COc5o8Tytf+B+jk42AS0JBo7wRpEBLIkpp14CFbDLLCYSWLlnslgNcICURJXNjmA1LAIqEo8 +7KQFcTmFbCS+LyxlxVimbzEzEvf2UHKOQWsJVZ3cUOUCEqcnPmEBcRmBipp3job7B4Jgfmc EjPffGWG6HWR6DsBM0dY4tX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n+udbFBFD1llGg5fBkowcHBJqAl0dgJVi8iUCAxp38LC0gNs8Ba JonXP96DNQsLREhcfL6AGcRmEVCVePZlISuIzStgJfF5Yy8rxAJ5iZmXvrODzOQUsJZY3cUN EhYCKvn65BY7RLmgxMmZT1hAbGag8uats5knMArMQpKahSS1gJFpFaNIamlxbnpusZFecWJu cWleul5yfu4mRmBkbjv2c8sOxpWvPuodYmTiYDzEKMHBrCTCa1DRkCTEm5JYWZValB9fVJqT WnyI0RTo7InMUqLJ+cDUkFcSb2hmYGpoYmZpYGppZqwkzutZ0JEoJJCeWJKanZpakFoE08fE wSnVwJTtXWfCzMs3t5YrfM+9w/OKrcv3FO1V59/Sb6jNqWZquEXvqunu1BANBrf32ZNnSc58 2ir+pox31e2OH6/8itJvXeiZsNLpwLvdO74xp5xZnN1Sa/nBrzyZbffZLTfjArW3svwsWNjT 9tH+w8zTrAu6bnDPvfxgavqvxOBpF6e/jgt4M+WWuIvYb58dMma3Ckt4Pt7Z7WL+jPUyT9fv sy8eiN/dcPfV1/7l1+V9bsydIPTGN+RwX2PDsWYp7nVVCcf3srf8iBLZtPmZ5Kqqx2lbVrDN v3nSQs7vmuEMPgWOvqRjFUWilwOP77GUvLo9lXdO+eGVntIfXV5kFfqesBWb6J05vWurUtXr 3rAPrPxKLMUZiYZazEXFiQCIvkauVQMAAA== X-CMS-MailID: 20220516165422eucas1p174acec28848a9c2178376f092af3fa1c X-Msg-Generator: CA X-RootMTR: 20220516165422eucas1p174acec28848a9c2178376f092af3fa1c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165422eucas1p174acec28848a9c2178376f092af3fa1c References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Remove the condition which disallows non-power_of_2 zone size ZNS drive to be updated and use generic method to calculate number of zones instead of relying on log and shift based calculation on zone size. The power_of_2 calculation has been replaced directly with generic calculation without special handling. Both modified functions are not used in hot paths, they are only used during initialization & revalidation of the ZNS device. Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Signed-off-by: Pankaj Raghav --- drivers/nvme/host/zns.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 9f81beb4d..65d2aa68a 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -101,13 +101,6 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf) } ns->zsze = nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); - if (!is_power_of_2(ns->zsze)) { - dev_warn(ns->ctrl->device, - "invalid zone size:%llu for namespace:%u\n", - ns->zsze, ns->head->ns_id); - status = -ENODEV; - goto free_data; - } blk_queue_set_zoned(ns->disk, BLK_ZONED_HM); blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); @@ -128,8 +121,13 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns, const size_t min_bufsize = sizeof(struct nvme_zone_report) + sizeof(struct nvme_zone_descriptor); + /* + * Division is used to calculate nr_zones with no special handling + * for power of 2 zone sizes as this function is not invoked in a + * hot path + */ nr_zones = min_t(unsigned int, nr_zones, - get_capacity(ns->disk) >> ilog2(ns->zsze)); + div64_u64(get_capacity(ns->disk), ns->zsze)); bufsize = sizeof(struct nvme_zone_report) + nr_zones * sizeof(struct nvme_zone_descriptor); @@ -182,6 +180,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector, int ret, zone_idx = 0; unsigned int nz, i; size_t buflen; + u64 remainder = 0; if (ns->head->ids.csi != NVME_CSI_ZNS) return -EINVAL; @@ -197,7 +196,14 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector, c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL; c.zmr.pr = NVME_REPORT_ZONE_PARTIAL; - sector &= ~(ns->zsze - 1); + /* + * rounddown the sector value to the nearest zone size. roundown macro + * provided in math.h will not work for 32 bit architectures. + * Division is used here with no special handling for power of 2 + * zone sizes as this function is not invoked in a hot path + */ + div64_u64_rem(sector, ns->zsze, &remainder); + sector -= remainder; while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); From patchwork Mon May 16 16:54:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB132C433F5 for ; Mon, 16 May 2022 16:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343923AbiEPQyr (ORCPT ); Mon, 16 May 2022 12:54:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343905AbiEPQyd (ORCPT ); Mon, 16 May 2022 12:54:33 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A081B3C71E for ; Mon, 16 May 2022 09:54:29 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165427euoutp01cbe93df31ea93d6b67f8dfa9206bafa4~vpCUJdQUL2240822408euoutp01E for ; Mon, 16 May 2022 16:54:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165427euoutp01cbe93df31ea93d6b67f8dfa9206bafa4~vpCUJdQUL2240822408euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720067; bh=vrYMM/cTOrW0/UYYWyRRUQC9LsDHx9p6dz/qEYyG7Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OcjFX/6VTfW4eS0d1ITEjlNboJdt1GniClcUR+Az5gY/MZNL620y5CjcEaJJ2aS0n dEJjXeVKBQ6RANh0JlY8Fy/YaLPHemEcqlWBlY5DpuISs+4iJnWSFWk8KnxHuLMoGB 9hlAmwf6YusA6Qxs2HmYNtlftA98D7rwv+Q5MT18= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165425eucas1p202583878951ecf13abff73433caed273~vpCSLKaCf2458224582eucas1p2a; Mon, 16 May 2022 16:54:25 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id FD.3A.09887.0C182826; Mon, 16 May 2022 17:54:25 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220516165424eucas1p2ee38cd64260539e5cac8d1fa4d0cba38~vpCRkEAod2458324583eucas1p2a; Mon, 16 May 2022 16:54:24 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220516165424eusmtrp2e805a2cfc6551f0fbfbd804b04689d96~vpCRdqqyG1030710307eusmtrp2s; Mon, 16 May 2022 16:54:24 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-33-628281c097a2 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 9D.00.09404.0C182826; Mon, 16 May 2022 17:54:24 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165424eusmtip1eac074d106663fe373f8f11517faf1da~vpCRLXgoG2383023830eusmtip1a; Mon, 16 May 2022 16:54:24 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Bart Van Assche , Hannes Reinecke , Luis Chamberlain Subject: [PATCH v4 04/13] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Date: Mon, 16 May 2022 18:54:07 +0200 Message-Id: <20220516165416.171196-5-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMKsWRmVeSWpSXmKPExsWy7djPc7oHG5uSDG6rW6y+289mMe3DT2aL 32fPM1vsfTeb1eLCj0Ymi5sHdjJZ7Fk0icli5eqjTBY9Bz6wWOy9pW1x6fEKdos9e0+yWFze NYfNYv6yp+wWNyY8ZbT4vLSF3WLNzacsDoIel694e/w7sYbNY+esu+wel8+Wemxa1cnmsXlJ vcfumw1A4db7rB7v911l8+jbsorRY/2Wqywem09Xe3zeJBfAG8Vlk5Kak1mWWqRvl8CVcf7t BaaC/3wVM2/eY2xgvMnTxcjJISFgIjGzYx57FyMXh5DACkaJRXf6mCGcL4wSXdvPskA4nxkl dix9xgzTcnb2XyaIxHJGibmfj0E5zxklvp6YBORwcLAJaEk0drKDNIgIZElMO/GQEaSGWeA1 k8SZzjusIAlhgQiJHW8bWEDqWQRUJf5syQMJ8wpYSTS+WAy1TF5i5qXv7CAlnALWEqu7uCFK BCVOznzCAmIzA5U0b50NdrWEwGZOibsLZ7ND9LpINE87AmULS7w6vgXKlpH4v3M+E4RdLfH0 xm+o5hZGif6d69lAlkkALes7kwNiMgtoSqzfpQ9R7iix8c4JqAo+iRtvBSFO4JOYtG06M0SY V6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qk0VAVeLPljyQCl4BK4nGF4uZ IabLS8y89J0dpIRTwFpidRc3SFgIqOTrk1vsEOWCEidnPoEaLi/RvHU28wRGgVlIUrOQpBYw Mq1iFEktLc5Nzy020itOzC0uzUvXS87P3cQIjNttx35u2cG48tVHvUOMTByMhxglOJiVRHgN KhqShHhTEiurUovy44tKc1KLDzGaAl09kVlKNDkfmDjySuINzQxMDU3MLA1MLc2MlcR5PQs6 EoUE0hNLUrNTUwtSi2D6mDg4pRqYuL75WAmfOFCabszqIbKKT+eu9cGyAzP25tguja7YNclD 3tYrrTCq2u2jki2P7i9N5qw5MxsyXdaLKG+Q6ymKTND02CVw+dL/qV+m87Te6Hmy799kfrFr Lx7u6lvIbiO87Zi+exVDg/7uyCUSr9e1ysxZmT3JyzHq6z6ZF8fm3V62zSCq0rJ3op7p+3mr 3619dvjAtqc8orKnlq+6HjbhnmrwNabgrUH+6xZrtUxvqHl6x9/87qsvIS1GzcKOf9/wb5un +ZBp027PlrRpx5JVX/6Pe2U8e5XaMkZn99y6liaBkyfka19och3wfrlh15IJ1ftYWjifbLOJ 5pefbF658qeYdn2oxePzExYFui/7qMRSnJFoqMVcVJwIAGIunbBkAwAA X-CMS-MailID: 20220516165424eucas1p2ee38cd64260539e5cac8d1fa4d0cba38 X-Msg-Generator: CA X-RootMTR: 20220516165424eucas1p2ee38cd64260539e5cac8d1fa4d0cba38 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165424eucas1p2ee38cd64260539e5cac8d1fa4d0cba38 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org A generic bdev_zone_no helper is added to calculate zone number for a given sector in a block device. This helper internally uses blk_queue_zone_no to find the zone number. Use the helper bdev_zone_no() to calculate nr of zones. This let's us make modifications to the math if needed in one place and adds now support for npo2 zone devices. Reviewed by: Adam Manzanares Reviewed-by: Bart Van Assche Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Johannes Thumshirn --- drivers/nvme/target/zns.c | 2 +- include/linux/blkdev.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 82b61acf7..5516dd6cc 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -242,7 +242,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req) unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba); return blkdev_nr_zones(req->ns->bdev->bd_disk) - - (sect >> ilog2(bdev_zone_sectors(req->ns->bdev))); + bdev_zone_no(req->ns->bdev, sect); } static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 32d7bd7b1..967790f51 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1370,6 +1370,13 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) return 0; } +static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec) +{ + struct request_queue *q = bdev_get_queue(bdev); + + return blk_queue_zone_no(q, sec); +} + static inline unsigned int bdev_max_open_zones(struct block_device *bdev) { struct request_queue *q = bdev_get_queue(bdev); From patchwork Mon May 16 16:54:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9610DC433F5 for ; Mon, 16 May 2022 16:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239281AbiEPQyu (ORCPT ); Mon, 16 May 2022 12:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343889AbiEPQyc (ORCPT ); Mon, 16 May 2022 12:54:32 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48FEE3C4A7 for ; Mon, 16 May 2022 09:54:29 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165427euoutp0238e8a3b1586f357430dd52c72747177b~vpCUkhpYA2209122091euoutp02E for ; Mon, 16 May 2022 16:54:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220516165427euoutp0238e8a3b1586f357430dd52c72747177b~vpCUkhpYA2209122091euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720067; bh=U9RzqUijJL5PmqUeIybgHDju5FpS85GPewMJfUjtd+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IN62OkIhN5o+kavxdh0Ge0egk1f4KwjShLynxaWCaLEhPR8H4CAHORMnNaqBvSBvp nyoCdqHbeFBec///IPpUiIJOZd6jLUkXSmUl06zMSa9Ei6diOw9DkkREbhhXb9TB0h 3evbgEE5hBfaD9uScIOekJL5kgQsTGjYlQojF0o0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165426eucas1p22e48539c1842dfe465d51988e5d8d7c3~vpCTS2WST2458324583eucas1p2b; Mon, 16 May 2022 16:54:26 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 1F.3A.09887.2C182826; Mon, 16 May 2022 17:54:26 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220516165425eucas1p29fcd11d7051d9d3a9a9efc17cd3b6999~vpCSuPtbz2457724577eucas1p2W; Mon, 16 May 2022 16:54:25 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165425eusmtrp1a1b2c812009ed084ac50bf44b3ff450d~vpCSrm8wt2961829618eusmtrp1J; Mon, 16 May 2022 16:54:25 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-35-628281c24bd2 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 3D.89.09522.1C182826; Mon, 16 May 2022 17:54:25 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220516165425eusmtip23750993d6d829aa7eb563f0768582ffe~vpCSVIM863184631846eusmtip2C; Mon, 16 May 2022 16:54:25 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 05/13] btrfs: zoned: Cache superblock location in btrfs_zoned_device_info Date: Mon, 16 May 2022 18:54:08 +0200 Message-Id: <20220516165416.171196-6-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAKsWRmVeSWpSXmKPExsWy7djP87qHGpuSDKZu5LNYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBYrVx9lsug58IHFYu8tbYtLj1ewW+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5LObVnext2ubGvAdVmbxZvx3NnmbLn51YptvLNvdtmobi7c 1VZUosRSnJFoqMVcVJwIADq56hhVAwAA X-CMS-MailID: 20220516165425eucas1p29fcd11d7051d9d3a9a9efc17cd3b6999 X-Msg-Generator: CA X-RootMTR: 20220516165425eucas1p29fcd11d7051d9d3a9a9efc17cd3b6999 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165425eucas1p29fcd11d7051d9d3a9a9efc17cd3b6999 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of calculating the superblock location every time, cache the superblock zone location in btrfs_zoned_device_info struct and use it to locate the zone index. The functions such as btrfs_sb_log_location_bdev() and btrfs_reset_sb_log_zones() which work directly on block_device shall continue to use the sb_zone_number because btrfs_zoned_device_info struct might not have been initialized at that point. This patch will enable non power-of-2 zoned devices to not perform division to lookup superblock and its mirror location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 13 +++++++++---- fs/btrfs/zoned.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 06f22c021..e8c7cebb2 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -511,6 +511,11 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) max_active_zones - nactive); } + /* Cache the sb zone number */ + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { + zone_info->sb_zone_location[i] = + sb_zone_number(zone_info->zone_size_shift, i); + } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { @@ -518,7 +523,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) u64 sb_wp; int sb_pos = BTRFS_NR_SB_LOG_ZONES * i; - sb_zone = sb_zone_number(zone_info->zone_size_shift, i); + sb_zone = zone_info->sb_zone_location[i]; if (sb_zone + 1 >= zone_info->nr_zones) continue; @@ -866,7 +871,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, return 0; } - zone_num = sb_zone_number(zinfo->zone_size_shift, mirror); + zone_num = zinfo->sb_zone_location[mirror]; if (zone_num + 1 >= zinfo->nr_zones) return -ENOENT; @@ -883,7 +888,7 @@ static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo, if (!zinfo) return false; - zone_num = sb_zone_number(zinfo->zone_size_shift, mirror); + zone_num = zinfo->sb_zone_location[mirror]; if (zone_num + 1 >= zinfo->nr_zones) return false; @@ -1011,7 +1016,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u32 sb_zone; u64 sb_pos; - sb_zone = sb_zone_number(shift, i); + sb_zone = zinfo->sb_zone_location[i]; if (!(end <= sb_zone || sb_zone + BTRFS_NR_SB_LOG_ZONES <= begin)) { have_sb = true; diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 10f31d1c8..694ab6d1e 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -27,6 +27,7 @@ struct btrfs_zoned_device_info { unsigned long *active_zones; struct blk_zone *zone_cache; struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX]; + u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; #ifdef CONFIG_BLK_DEV_ZONED From patchwork Mon May 16 16:54:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B28DC43217 for ; Mon, 16 May 2022 16:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343984AbiEPQyp (ORCPT ); Mon, 16 May 2022 12:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343923AbiEPQye (ORCPT ); Mon, 16 May 2022 12:54:34 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 030B033EB2 for ; Mon, 16 May 2022 09:54:30 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165429euoutp02865b1145814b3a33b46fba6cb8dcf07b~vpCWJAg9K2209122091euoutp02G for ; Mon, 16 May 2022 16:54:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220516165429euoutp02865b1145814b3a33b46fba6cb8dcf07b~vpCWJAg9K2209122091euoutp02G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720069; bh=LMzILViEYGl7DXa37dpeTA+tqVrqwK5EcVpc6Ix2yY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0c8uYz+W5tocQRMiMunWf0GDS6Tq/DOaWfbk6yR6QKHl8AvCRU16JTyHy4AWjsBq Zq9oRlSwREqbSpwn//0BmARib60MbhD6xwPE5IEK+QyexLwF2lWBuV/NYpAvcKskuB pbvgrCxMOBCgxBXG1YM6cM3O7d1wXjhUBdm4EQuk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165427eucas1p1b7937c8e93a50f9ab55b194314c0ebb2~vpCUkQ-KR3100231002eucas1p1I; Mon, 16 May 2022 16:54:27 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id D6.40.10009.3C182826; Mon, 16 May 2022 17:54:27 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165427eucas1p1cfd87ca44ec314ea1d2ddc8ece7259f9~vpCT-y5rM1659616596eucas1p1t; Mon, 16 May 2022 16:54:27 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165427eusmtrp19cc052b58b95fdd70c470b667b9eaf31~vpCT-DoC-2961829618eusmtrp1K; Mon, 16 May 2022 16:54:27 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-4e-628281c36dfb Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 3E.89.09522.2C182826; Mon, 16 May 2022 17:54:26 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165426eusmtip112dc0f7e69af738ccc790922191cbea1~vpCTmyPXE2383423834eusmtip1p; Mon, 16 May 2022 16:54:26 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 06/13] btrfs: zoned: Make sb_zone_number function non power of 2 compatible Date: Mon, 16 May 2022 18:54:09 +0200 Message-Id: <20220516165416.171196-7-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEKsWRmVeS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Ib220m4uL8ouhv9csmM82Hy88JzeFJVpNTsamccO7naQ+PLmiyF+LKz2bfvebE0e7Kd /LTwvUje9Rv1VuXml/R/J8X/uxD+7MmGlXUJrL32e+3UUzYvFPp/u+Xh3mSWZimeEEsGHYeV cQJKLMUZiYZazEXFiQCKFWZPVAMAAA== X-CMS-MailID: 20220516165427eucas1p1cfd87ca44ec314ea1d2ddc8ece7259f9 X-Msg-Generator: CA X-RootMTR: 20220516165427eucas1p1cfd87ca44ec314ea1d2ddc8ece7259f9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165427eucas1p1cfd87ca44ec314ea1d2ddc8ece7259f9 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Make the calculation in sb_zone_number function to be generic and work for both power-of-2 and non power-of-2 zone sizes. The function signature has been modified to take block device and mirror as input as this function is only invoked from callers that have access to the block device. This enables to use the generic bdev_zone_no function provided by the block layer to calculate the zone number. Even though division is used to calculate the zone index for non power-of-2 zone sizes, this function will not be used in the fast path as the sb_zone_location cache is used for the superblock zone location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index e8c7cebb2..5be2ef7bb 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -34,9 +34,6 @@ #define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G) #define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G) -#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET) -#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET) - /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 @@ -153,15 +150,23 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, /* * Get the first zone number of the superblock mirror */ -static inline u32 sb_zone_number(int shift, int mirror) +static inline u32 sb_zone_number(struct block_device *bdev, int mirror) { u64 zone; ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX); switch (mirror) { - case 0: zone = 0; break; - case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; - case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; + case 0: + zone = 0; + break; + case 1: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_FIRST_OFFSET >> SECTOR_SHIFT); + break; + case 2: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_SECOND_OFFSET >> SECTOR_SHIFT); + break; } ASSERT(zone <= U32_MAX); @@ -514,7 +519,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) /* Cache the sb zone number */ for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { zone_info->sb_zone_location[i] = - sb_zone_number(zone_info->zone_size_shift, i); + sb_zone_number(bdev, i); } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; @@ -839,7 +844,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; @@ -963,7 +968,7 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; From patchwork Mon May 16 16:54:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABB45C433EF for ; Mon, 16 May 2022 16:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344032AbiEPQzC (ORCPT ); Mon, 16 May 2022 12:55:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343952AbiEPQyg (ORCPT ); Mon, 16 May 2022 12:54:36 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CD13C73E for ; Mon, 16 May 2022 09:54:33 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165430euoutp01ac372e64cac5a3aeef572c28c56e5d45~vpCW6g1ux2241022410euoutp01_ for ; Mon, 16 May 2022 16:54:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165430euoutp01ac372e64cac5a3aeef572c28c56e5d45~vpCW6g1ux2241022410euoutp01_ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720070; bh=v9pKtSXVKfv3MO12A+XlAy96VR3If9OGCSyPe0WYtqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AJyUg3Xx7d/T05JlQboNVpDnuD2C0HyQC4NZQ9nteyVg+/0/W8f3WysP3dg4guis/ rAFPDeaJu/pmznm1jOkRI/pVT2vITqtKA5ZG29QKrS3/gY4O/6i3ZSJZfBi9NTLKsx e4eBs4VwWmxLp0AXVwvdEWsnGWOKahfp0o3eD7Fw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165428eucas1p22c7c8955b8a9ceced9cab91a9c65ceaa~vpCViJXK00201202012eucas1p2M; Mon, 16 May 2022 16:54:28 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 50.4A.09887.4C182826; Mon, 16 May 2022 17:54:28 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165428eucas1p1374b5f9592db3ca6a6551aff975537ce~vpCVM0dkm0955109551eucas1p1q; Mon, 16 May 2022 16:54:28 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220516165428eusmtrp2e56d4a6f4333117d0ef788ccef02efe7~vpCVMGoNz1030710307eusmtrp2v; Mon, 16 May 2022 16:54:28 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-3b-628281c4732b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2F.00.09404.4C182826; Mon, 16 May 2022 17:54:28 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220516165427eusmtip26b6dcee5944cdacbd76773df89c38a05~vpCU2E_4h0611206112eusmtip24; Mon, 16 May 2022 16:54:27 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 07/13] btrfs: zoned: use generic btrfs zone helpers to support npo2 zoned devices Date: Mon, 16 May 2022 18:54:10 +0200 Message-Id: <20220516165416.171196-8-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrIKsWRmVeSWpSXmKPExsWy7djPc7pHGpuSDN50alqsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJouVq48yWfQc+MBisfeWtsWlxyvYLfbsPclicXnXHDaL+cueslvc mPCU0eLz0hZ2izU3n7I48Hv8O7GGzWPnrLvsHpfPlnpsWtXJ5rF5Sb3H7psNQOHW+6we7/dd ZfPo27KK0WP9lqssHp83yQVwR3HZpKTmZJalFunbJXBlTF/SyVxwtKLi88tv7A2MV5O7GDk5 JARMJD4d2sbUxcjFISSwglFi6blX7CAJIYEvjBKXvhdC2J8ZJS43ssI0HDv/gQ2iYTmjxL// rSwQznNGid4Ts4EcDg42AS2Jxk6wQSICWRLTTjxkBKlhFljMJLFyz2QWkISwQJrEtOfTwGwW AVWJtiNn2EBsXgEriUv/zrBDbJOXmHnpOzvITE4Ba4nVXdwQJYISJ2c+AWtlBipp3jqbGWS+ hMBsTolDUzuZIHpdJFZfOQ5lC0u8Or4FaqaMxP+d86Hi1RJPb/yGam5hlOjfuZ4NZJkE0LK+ MzkgJrOApsT6XfoQ5Y4SMx7vZYWo4JO48VYQ4gQ+iUnbpjNDhHklOtqEIKqVJHb+fAK1VELi ctMcFgjbQ2JW632mCYyKs5A8MwvJM7MQ9i5gZF7FKJ5aWpybnlpslJdarlecmFtcmpeul5yf u4kRmOpO/zv+ZQfj8lcf9Q4xMnEwHmKU4GBWEuE1qGhIEuJNSaysSi3Kjy8qzUktPsQozcGi JM6bnLkhUUggPbEkNTs1tSC1CCbLxMEp1cAkn2+TEzDr6wL96UFpSaX/wp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HpiSWp2ampBahFMHxMH p1QDUxzXzm+6D7RW+vB3LH1ey3b/h0wtzxf2PUZTBRL+MLbF2X++bPinapPR2nLWNYnZRrqd U8pnMQuLzzpV4yl/cuHD3qlHjMwfvp+VLnLx3f3vh07GLXib9SKohO9DTKDlrtyYl2+3Bqsu WrJCRD3tXP/E85EHUixUvz8XOHXfVTuHr0n1LP9a5ROLeyfJLtm0Lbe6ahd3e3zuTHWnGduf LFbfb5e5YeEnXsegD/K6zYozdLJ2ml2Nb1NZ+uKHRqiTUEtvyxrzRetW/rk+y7BfrUTXjH+p o+T67q4d8x4XhCyUMhRMVWX3i/C8wfuwW3HifIP9N1e9W1DStHe2oa6jwKf1gn+W7J/eqHfb +93PNCWW4oxEQy3mouJEALkRar9VAwAA X-CMS-MailID: 20220516165428eucas1p1374b5f9592db3ca6a6551aff975537ce X-Msg-Generator: CA X-RootMTR: 20220516165428eucas1p1374b5f9592db3ca6a6551aff975537ce X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165428eucas1p1374b5f9592db3ca6a6551aff975537ce References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add helpers to calculate alignment, round up and round down for zoned devices. These helpers encapsulates the necessary handling for power_of_2 and non-power_of_2 zone sizes. Optimized calculations are performed for zone sizes that are power_of_2 with log and shifts. btrfs_zoned_is_aligned() is added instead of reusing bdev_zone_aligned() helper due to some use cases in btrfs where zone alignment is checked before having access to the underlying block device such as in this function: btrfs_load_block_group_zone_info(). Use the generic btrfs zone helpers to calculate zone index, check zone alignment, round up and round down operations. The zone_size_shift field is not needed anymore as generic helpers are used for calculation. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/volumes.c | 24 +++++++++------- fs/btrfs/zoned.c | 72 ++++++++++++++++++++++------------------------ fs/btrfs/zoned.h | 43 +++++++++++++++++++++++---- 3 files changed, 85 insertions(+), 54 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 94f851592..3d6b9a25a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1408,7 +1408,7 @@ static u64 dev_extent_search_start(struct btrfs_device *device, u64 start) * allocator, because we anyway use/reserve the first two zones * for superblock logging. */ - return ALIGN(start, device->zone_info->zone_size); + return btrfs_zoned_roundup(start, device->zone_info->zone_size); default: BUG(); } @@ -1423,7 +1423,7 @@ static bool dev_extent_hole_check_zoned(struct btrfs_device *device, int ret; bool changed = false; - ASSERT(IS_ALIGNED(*hole_start, zone_size)); + ASSERT(btrfs_zoned_is_aligned(*hole_start, zone_size)); while (*hole_size > 0) { pos = btrfs_find_allocatable_zones(device, *hole_start, @@ -1560,7 +1560,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, search_start = dev_extent_search_start(device, search_start); WARN_ON(device->zone_info && - !IS_ALIGNED(num_bytes, device->zone_info->zone_size)); + !btrfs_zoned_is_aligned(num_bytes, device->zone_info->zone_size)); path = btrfs_alloc_path(); if (!path) @@ -5111,8 +5111,8 @@ static void init_alloc_chunk_ctl_policy_zoned( ctl->max_stripe_size = zone_size; if (type & BTRFS_BLOCK_GROUP_DATA) { - ctl->max_chunk_size = round_down(BTRFS_MAX_DATA_CHUNK_SIZE, - zone_size); + ctl->max_chunk_size = btrfs_zoned_rounddown( + BTRFS_MAX_DATA_CHUNK_SIZE, zone_size); } else if (type & BTRFS_BLOCK_GROUP_METADATA) { ctl->max_chunk_size = ctl->max_stripe_size; } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { @@ -5124,9 +5124,10 @@ static void init_alloc_chunk_ctl_policy_zoned( } /* We don't want a chunk larger than 10% of writable space */ - limit = max(round_down(div_factor(fs_devices->total_rw_bytes, 1), - zone_size), - min_chunk_size); + limit = max( + btrfs_zoned_rounddown(div_factor(fs_devices->total_rw_bytes, 1), + zone_size), + min_chunk_size); ctl->max_chunk_size = min(limit, ctl->max_chunk_size); ctl->dev_extent_min = zone_size * ctl->dev_stripes; } @@ -6729,7 +6730,8 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc, */ if (bio_op(bio) == REQ_OP_ZONE_APPEND) { if (btrfs_dev_is_sequential(dev, physical)) { - u64 zone_start = round_down(physical, fs_info->zone_size); + u64 zone_start = btrfs_zoned_rounddown(physical, + fs_info->zone_size); bio->bi_iter.bi_sector = zone_start >> SECTOR_SHIFT; } else { @@ -8051,8 +8053,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, if (dev->zone_info) { u64 zone_size = dev->zone_info->zone_size; - if (!IS_ALIGNED(physical_offset, zone_size) || - !IS_ALIGNED(physical_len, zone_size)) { + if (!btrfs_zoned_is_aligned(physical_offset, zone_size) || + !btrfs_zoned_is_aligned(physical_len, zone_size)) { btrfs_err(fs_info, "zoned: dev extent devid %llu physical offset %llu len %llu is not aligned to device zone", devid, physical_offset, physical_len); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 5be2ef7bb..3023c871e 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -177,13 +177,13 @@ static inline u32 sb_zone_number(struct block_device *bdev, int mirror) static inline sector_t zone_start_sector(u32 zone_number, struct block_device *bdev) { - return (sector_t)zone_number << ilog2(bdev_zone_sectors(bdev)); + return zone_number * bdev_zone_sectors(bdev); } static inline u64 zone_start_physical(u32 zone_number, struct btrfs_zoned_device_info *zone_info) { - return (u64)zone_number << zone_info->zone_size_shift; + return zone_number * zone_info->zone_size; } /* @@ -236,8 +236,8 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, if (zinfo->zone_cache) { unsigned int i; - ASSERT(IS_ALIGNED(pos, zinfo->zone_size)); - zno = pos >> zinfo->zone_size_shift; + ASSERT(btrfs_zoned_is_aligned(pos, zinfo->zone_size)); + zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* * We cannot report zones beyond the zone end. So, it is OK to * cap *nr_zones to at the end. @@ -409,9 +409,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) } nr_sectors = bdev_nr_sectors(bdev); - zone_info->zone_size_shift = ilog2(zone_info->zone_size); - zone_info->nr_zones = nr_sectors >> ilog2(zone_sectors); - if (!IS_ALIGNED(nr_sectors, zone_sectors)) + zone_info->nr_zones = bdev_zone_no(bdev, nr_sectors); + if (!btrfs_zoned_is_aligned(nr_sectors, zone_sectors)) zone_info->nr_zones++; max_active_zones = bdev_max_active_zones(bdev); @@ -823,10 +822,8 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, u64 *bytenr_ret) { struct blk_zone zones[BTRFS_NR_SB_LOG_ZONES]; - sector_t zone_sectors; u32 sb_zone; int ret; - u8 zone_sectors_shift; sector_t nr_sectors; u32 nr_zones; @@ -837,12 +834,10 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, ASSERT(rw == READ || rw == WRITE); - zone_sectors = bdev_zone_sectors(bdev); - if (!is_power_of_2(zone_sectors)) + if (!is_power_of_2(bdev_zone_sectors(bdev))) return -EINVAL; - zone_sectors_shift = ilog2(zone_sectors); nr_sectors = bdev_nr_sectors(bdev); - nr_zones = nr_sectors >> zone_sectors_shift; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) @@ -959,14 +954,12 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) { sector_t zone_sectors; sector_t nr_sectors; - u8 zone_sectors_shift; u32 sb_zone; u32 nr_zones; zone_sectors = bdev_zone_sectors(bdev); - zone_sectors_shift = ilog2(zone_sectors); nr_sectors = bdev_nr_sectors(bdev); - nr_zones = nr_sectors >> zone_sectors_shift; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) @@ -992,18 +985,17 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u64 hole_end, u64 num_bytes) { struct btrfs_zoned_device_info *zinfo = device->zone_info; - const u8 shift = zinfo->zone_size_shift; - u64 nzones = num_bytes >> shift; + u64 nzones = bdev_zone_no(device->bdev, num_bytes >> SECTOR_SHIFT); u64 pos = hole_start; u64 begin, end; bool have_sb; int i; - ASSERT(IS_ALIGNED(hole_start, zinfo->zone_size)); - ASSERT(IS_ALIGNED(num_bytes, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(hole_start, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(num_bytes, zinfo->zone_size)); while (pos < hole_end) { - begin = pos >> shift; + begin = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); end = begin + nzones; if (end > zinfo->nr_zones) @@ -1035,8 +1027,9 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, if (!(pos + num_bytes <= sb_pos || sb_pos + BTRFS_SUPER_INFO_SIZE <= pos)) { have_sb = true; - pos = ALIGN(sb_pos + BTRFS_SUPER_INFO_SIZE, - zinfo->zone_size); + pos = btrfs_zoned_roundup( + sb_pos + BTRFS_SUPER_INFO_SIZE, + zinfo->zone_size); break; } } @@ -1050,7 +1043,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; - unsigned int zno = (pos >> zone_info->zone_size_shift); + unsigned int zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) @@ -1072,7 +1065,7 @@ static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) static void btrfs_dev_clear_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; - unsigned int zno = (pos >> zone_info->zone_size_shift); + unsigned int zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) @@ -1108,14 +1101,14 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size) { struct btrfs_zoned_device_info *zinfo = device->zone_info; - const u8 shift = zinfo->zone_size_shift; - unsigned long begin = start >> shift; - unsigned long end = (start + size) >> shift; + unsigned long begin = bdev_zone_no(device->bdev, start >> SECTOR_SHIFT); + unsigned long end = + bdev_zone_no(device->bdev, (start + size) >> SECTOR_SHIFT); u64 pos; int ret; - ASSERT(IS_ALIGNED(start, zinfo->zone_size)); - ASSERT(IS_ALIGNED(size, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(start, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(size, zinfo->zone_size)); if (end > zinfo->nr_zones) return -ERANGE; @@ -1139,8 +1132,9 @@ int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size) /* Free regions should be empty */ btrfs_warn_in_rcu( device->fs_info, - "zoned: resetting device %s (devid %llu) zone %llu for allocation", - rcu_str_deref(device->name), device->devid, pos >> shift); + "zoned: resetting device %s (devid %llu) zone %u for allocation", + rcu_str_deref(device->name), device->devid, + bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT)); WARN_ON_ONCE(1); ret = btrfs_reset_device_zone(device, pos, zinfo->zone_size, @@ -1237,7 +1231,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) return 0; /* Sanity check */ - if (!IS_ALIGNED(length, fs_info->zone_size)) { + if (!btrfs_zoned_is_aligned(length, fs_info->zone_size)) { btrfs_err(fs_info, "zoned: block group %llu len %llu unaligned to zone size %llu", logical, length, fs_info->zone_size); @@ -1325,7 +1319,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) * The group is mapped to a sequential zone. Get the zone write * pointer to determine the allocation offset within the zone. */ - WARN_ON(!IS_ALIGNED(physical[i], fs_info->zone_size)); + WARN_ON(!btrfs_zoned_is_aligned(physical[i], fs_info->zone_size)); nofs_flag = memalloc_nofs_save(); ret = btrfs_get_dev_zone(device, physical[i], &zone); memalloc_nofs_restore(nofs_flag); @@ -1351,10 +1345,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) switch (zone.cond) { case BLK_ZONE_COND_OFFLINE: case BLK_ZONE_COND_READONLY: - btrfs_err(fs_info, - "zoned: offline/readonly zone %llu on device %s (devid %llu)", - physical[i] >> device->zone_info->zone_size_shift, - rcu_str_deref(device->name), device->devid); + btrfs_err( + fs_info, + "zoned: offline/readonly zone %u on device %s (devid %llu)", + bdev_zone_no(device->bdev, + physical[i] >> SECTOR_SHIFT), + rcu_str_deref(device->name), device->devid); alloc_offsets[i] = WP_MISSING_DEV; break; case BLK_ZONE_COND_EMPTY: diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 694ab6d1e..b94ce4d1f 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -9,6 +9,7 @@ #include "disk-io.h" #include "block-group.h" #include "btrfs_inode.h" +#include "misc.h" #define BTRFS_DEFAULT_RECLAIM_THRESH (75) @@ -18,7 +19,6 @@ struct btrfs_zoned_device_info { * zoned block device. */ u64 zone_size; - u8 zone_size_shift; u32 nr_zones; unsigned int max_active_zones; atomic_t active_zones_left; @@ -30,6 +30,36 @@ struct btrfs_zoned_device_info { u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; +static inline bool btrfs_zoned_is_aligned(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + + if (is_power_of_two_u64(zone_size)) + return IS_ALIGNED(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + return remainder == 0; +} + +static inline u64 btrfs_zoned_roundup(u64 pos, u64 zone_size) +{ + if (is_power_of_two_u64(zone_size)) + return ALIGN(pos, zone_size); + + return div64_u64(pos + zone_size - 1, zone_size) * zone_size; +} + +static inline u64 btrfs_zoned_rounddown(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + if (is_power_of_two_u64(zone_size)) + return round_down(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + pos -= remainder; + return pos; +} + #ifdef CONFIG_BLK_DEV_ZONED int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone); @@ -253,7 +283,8 @@ static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) if (!zone_info) return false; - return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones); + return test_bit(bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT), + zone_info->seq_zones); } static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) @@ -263,7 +294,8 @@ static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) if (!zone_info) return true; - return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones); + return test_bit(bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT), + zone_info->empty_zones); } static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, @@ -275,7 +307,7 @@ static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, if (!zone_info) return; - zno = pos >> zone_info->zone_size_shift; + zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); if (set) set_bit(zno, zone_info->empty_zones); else @@ -329,7 +361,8 @@ static inline bool btrfs_can_zone_reset(struct btrfs_device *device, return false; zone_size = device->zone_info->zone_size; - if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size)) + if (!btrfs_zoned_is_aligned(physical, zone_size) || + !btrfs_zoned_is_aligned(length, zone_size)) return false; return true; From patchwork Mon May 16 16:54:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3356C4321E for ; Mon, 16 May 2022 16:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343979AbiEPQym (ORCPT ); Mon, 16 May 2022 12:54:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343914AbiEPQyf (ORCPT ); Mon, 16 May 2022 12:54:35 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 750413CA42 for ; Mon, 16 May 2022 09:54:33 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165431euoutp015732ff8fe96c92753179d448e5d6ecc5~vpCYLA7OJ2836428364euoutp01N for ; Mon, 16 May 2022 16:54:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165431euoutp015732ff8fe96c92753179d448e5d6ecc5~vpCYLA7OJ2836428364euoutp01N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720071; bh=bvw6RhJqyk6cpxv/AsypEgXjWF1fz2EYC8nTp3xSTNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fBADAfmmxh9dDQD7Su+WpQrvk2tmYG/PM3mOU/mbQWSn5kz7gig8P+wjljL89kThR BwOqBso/YXncG8bNrDGvQ/FjX69RHlAJ9katHFiGlWNmQmRsV+hYm+3akUxkcF3WcL YblblXIAq4Aa9d2vod5dCET4szojykqblqvk4Qak= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165430eucas1p121f4df66d6ce57ba399426c27d51d7b1~vpCW2mLfQ3183531835eucas1p1U; Mon, 16 May 2022 16:54:30 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id F1.E6.10260.6C182826; Mon, 16 May 2022 17:54:30 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220516165429eucas1p272c8b4325a488675f08f2d7016aa6230~vpCWbT6kq0201202012eucas1p2O; Mon, 16 May 2022 16:54:29 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165429eusmtrp199c722809802237e5a9f8a60f6f61fdf~vpCWaWz5_2961829618eusmtrp1O; Mon, 16 May 2022 16:54:29 +0000 (GMT) X-AuditID: cbfec7f5-bf3ff70000002814-50-628281c6ce2b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 10.99.09522.5C182826; Mon, 16 May 2022 17:54:29 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220516165429eusmtip21e540dfc6bbca12792d8c5e43ca34a89~vpCWHpK430678106781eusmtip2z; Mon, 16 May 2022 16:54:29 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com Subject: [PATCH v4 08/13] btrfs:zoned: make sb for npo2 zone devices align with sb log offsets Date: Mon, 16 May 2022 18:54:11 +0200 Message-Id: <20220516165416.171196-9-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-T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RPmfnmYZzP75CY2M0Wu3y686VJtYpO5Z55Q7AqVe/BfmzN494FLVYfi/l4rfDr1g9bKG4vi 8w4KvwrvTAiYsF3h7FuL16YK10/z3bFIDBCeGl4bURm7w+a3gX03W7Yue0yg1aW9nEosxRmJ hlrMRcWJAGnHloFLAwAA X-CMS-MailID: 20220516165429eucas1p272c8b4325a488675f08f2d7016aa6230 X-Msg-Generator: CA X-RootMTR: 20220516165429eucas1p272c8b4325a488675f08f2d7016aa6230 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165429eucas1p272c8b4325a488675f08f2d7016aa6230 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Superblocks for zoned devices are fixed as 2 zones at 0, 512GB and 4TB. These are fixed at these locations so that recovery tools can reliably retrieve the superblocks even if one of the mirror gets corrupted. power of 2 zone sizes align at these offsets irrespective of their value but non power of 2 zone sizes will not align. To make sure the first zone at mirror 1 and mirror 2 align, write zero operation is performed to move the write pointer of the first zone to the expected offset. This operation is performed only after a zone reset of the first zone, i.e., when the second zone that contains the sb is FULL. Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 68 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 3023c871e..805aeaa76 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -760,11 +760,44 @@ int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info) return 0; } +static int fill_sb_wp_offset(struct block_device *bdev, struct blk_zone *zone, + int mirror, u64 *wp_ret) +{ + u64 offset = 0; + int ret = 0; + + ASSERT(!is_power_of_two_u64(zone->len)); + ASSERT(zone->wp == zone->start); + ASSERT(mirror != 0); + + switch (mirror) { + case 1: + div64_u64_rem(BTRFS_SB_LOG_FIRST_OFFSET >> SECTOR_SHIFT, + zone->len, &offset); + break; + case 2: + div64_u64_rem(BTRFS_SB_LOG_SECOND_OFFSET >> SECTOR_SHIFT, + zone->len, &offset); + break; + } + + ret = blkdev_issue_zeroout(bdev, zone->start, offset, GFP_NOFS, 0); + if (ret) + return ret; + + zone->wp += offset; + zone->cond = BLK_ZONE_COND_IMP_OPEN; + *wp_ret = zone->wp << SECTOR_SHIFT; + + return 0; +} + static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, - int rw, u64 *bytenr_ret) + int rw, int mirror, u64 *bytenr_ret) { u64 wp; int ret; + bool zones_empty = false; if (zones[0].type == BLK_ZONE_TYPE_CONVENTIONAL) { *bytenr_ret = zones[0].start << SECTOR_SHIFT; @@ -775,13 +808,31 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, if (ret != -ENOENT && ret < 0) return ret; + if (ret == -ENOENT) + zones_empty = true; + if (rw == WRITE) { struct blk_zone *reset = NULL; + bool is_sb_offset_write_req = false; + u32 reset_zone_nr = -1; - if (wp == zones[0].start << SECTOR_SHIFT) + if (wp == zones[0].start << SECTOR_SHIFT) { reset = &zones[0]; - else if (wp == zones[1].start << SECTOR_SHIFT) + reset_zone_nr = 0; + } else if (wp == zones[1].start << SECTOR_SHIFT) { reset = &zones[1]; + reset_zone_nr = 1; + } + + /* + * Non po2 zone sizes will not align naturally at + * mirror 1 (512GB) and mirror 2 (4TB). The wp of the + * 1st zone in those superblock mirrors need to be + * moved to align at those offsets. + */ + is_sb_offset_write_req = + (zones_empty || (reset_zone_nr == 0)) && mirror && + !is_power_of_2(zones[0].len); if (reset && reset->cond != BLK_ZONE_COND_EMPTY) { ASSERT(sb_zone_is_full(reset)); @@ -795,6 +846,13 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, reset->cond = BLK_ZONE_COND_EMPTY; reset->wp = reset->start; } + + if (is_sb_offset_write_req) { + ret = fill_sb_wp_offset(bdev, &zones[0], mirror, &wp); + if (ret) + return ret; + } + } else if (ret != -ENOENT) { /* * For READ, we want the previous one. Move write pointer to @@ -851,7 +909,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, if (ret != BTRFS_NR_SB_LOG_ZONES) return -EIO; - return sb_log_location(bdev, zones, rw, bytenr_ret); + return sb_log_location(bdev, zones, rw, mirror, bytenr_ret); } int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, @@ -877,7 +935,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, return sb_log_location(device->bdev, &zinfo->sb_zones[BTRFS_NR_SB_LOG_ZONES * mirror], - rw, bytenr_ret); + rw, mirror, bytenr_ret); } static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo, From patchwork Mon May 16 16:54:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C128C433F5 for ; Mon, 16 May 2022 16:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344000AbiEPQy5 (ORCPT ); Mon, 16 May 2022 12:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343951AbiEPQyg (ORCPT ); Mon, 16 May 2022 12:54:36 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2F827B3C for ; Mon, 16 May 2022 09:54:34 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165433euoutp02579ffaac729dfd62bb5aadab367a6406~vpCZmTV192422624226euoutp026 for ; Mon, 16 May 2022 16:54:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220516165433euoutp02579ffaac729dfd62bb5aadab367a6406~vpCZmTV192422624226euoutp026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720073; bh=weFwL7xym8S1evRk+xjCjruPIjnMSz8gBoIh9GRufdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Unhk6pcoM2TFZ0M6d6oXLlb26kbT8YXZ8XlqktJssA7S17Cm44Sqx4K8lGU46anl5 vtAdIB48ZVKoXnfLTFObrmGcYink6e20OiSfxI0JbGirPwRjEker/rtbiGDJREfq8O 847qdXbY+fbPEcjD/Vv0S+VkSbFpCoHoQ+rfsMFw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165431eucas1p2517dac253453b1c09e2970df07cb1f97~vpCX9VyfF2458324583eucas1p2f; Mon, 16 May 2022 16:54:31 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A1.4A.09887.7C182826; Mon, 16 May 2022 17:54:31 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220516165430eucas1p214cca8eaba1db2c98d947444cad4f18f~vpCXitI0O1887918879eucas1p2m; Mon, 16 May 2022 16:54:30 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165430eusmtrp168eccddedb796e98be32574b8f4eaee0~vpCXh9pjv2961829618eusmtrp1P; Mon, 16 May 2022 16:54:30 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-40-628281c75ba4 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 01.99.09522.6C182826; Mon, 16 May 2022 17:54:30 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165430eusmtip1d0239fefcd561e73f10f2837d4e5e5f2~vpCXRAz320975309753eusmtip1e; Mon, 16 May 2022 16:54:30 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 09/13] btrfs: zoned: relax the alignment constraint for zoned devices Date: Mon, 16 May 2022 18:54:12 +0200 Message-Id: <20220516165416.171196-10-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMKsWRmVeSWpSXmKPExsWy7djPc7rHG5uSDGZf4bNYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBYrVx9lsug58IHFYu8tbYtLj1ewW+zZe5LF4vKuOWwW85c9Zbe4 MeEpo8XnpS3sFmtuPmVx4Pf4d2INm8fOWXfZPS6fLfXYtKqTzWPzknqP3TcbgMKt91k93u+7 yubRt2UVo8f6LVdZPD5vkgvgjuKySUnNySxLLdK3S+DKuLPnInvBY4GKC32/WBoY7/J2MXJy SAiYSNw4v4a5i5GLQ0hgBaNEw7zfjBDOF0aJuQ/fQDmfGSV2LbzGDtOyb+0edojEckaJv/9X sUA4zxkl3i45BNTCwcEmoCXR2AnWICKQJTHtxEOwScwCi5kkVu6ZzAKSEBaIkpg1s58ZxGYR UJWYdXknG4jNK2Atcb73KBPENnmJmZe+s4PM5ASKr+7ih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C32/WBoY7/J2MXJySAiYSOxbu4e9i5GLQ0hgKaPE rCk32SASEhK3FzYxQtjCEn+udbFBFD1llGjsnc7axcjBwSagJdHYyQ5SIyJQIDGnfwsLSA2z wFomidc/3oM1CwtESEz/OpcZxGYRUJWYdXkn2AJeAWuJ871HmSAWyEvMvPSdHWQmJ1B8dRc3 SFhIwEri65Nb7BDlghInZz5hAbGZgcqbt85mnsAoMAtJahaS1AJGplWMIqmlxbnpucWGesWJ ucWleel6yfm5mxiBkbnt2M/NOxjnvfqod4iRiYPxEKMEB7OSCK9BRUOSEG9KYmVValF+fFFp TmrxIUZToLMnMkuJJucDU0NeSbyhmYGpoYmZpYGppZmxkjivZ0FHopBAemJJanZqakFqEUwf EwenVAOT+P41L+S6Jhg/7b44pXbOrBwPv7Kunmd856cuaz+X8PhRoVm/pfhTh+s6tS8iXif0 3yhtC3vkOMdd7KXEN6bYI44XfIuZK1but7x3chffVQ6WwM/pXGtX/SxPWt5fUmguPs3TZfGP la+MGHc22c3c1PzT2m59zczwTdsmKEVX6z9meHvwgnDrntpLDRcXCsWaciht2uC4ltvJW7Ze YuGcQE1+9v47W79InqucNs9NLtFa0oPj3Psp/9wvBP/k2s6lnrvg+ZmdPxfsWFnp8lv5ho72 qhCNpwy5s2avDYm/XhjAMY9537urKyQbLNbK6vK+XpDjpuc/XUZj88NJuVbqLHeYr757yrBc 6SKzsLWbEktxRqKhFnNRcSIACnOWkVUDAAA= X-CMS-MailID: 20220516165430eucas1p214cca8eaba1db2c98d947444cad4f18f X-Msg-Generator: CA X-RootMTR: 20220516165430eucas1p214cca8eaba1db2c98d947444cad4f18f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165430eucas1p214cca8eaba1db2c98d947444cad4f18f References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Checks were in place to return error when a non power-of-2 zoned devices is detected. Remove those checks as non power-of-2 zoned devices are now supported. Relax the zone size constraint to align with a sane default of 1MB. This 1M default has been chosen as the minimum alignment requirement for zone sizes to make sure zones align with sectorsize in different architectures. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 805aeaa76..4f3687c54 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -54,6 +54,13 @@ */ #define BTRFS_MAX_ZONE_SIZE SZ_8G +/* + * A minimum alignment of 1MB is chosen for zoned devices as their zone sizes + * can be non power of 2. This is to make sure the zones correctly align to the + * sectorsize. + */ +#define BTRFS_ZONED_MIN_ALIGN_SECTORS ((u64)SZ_1M >> SECTOR_SHIFT) + #define SUPER_INFO_SECTORS ((u64)BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT) static inline bool sb_zone_is_full(const struct blk_zone *zone) @@ -394,8 +401,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) zone_sectors = bdev_zone_sectors(bdev); } - /* Check if it's power of 2 (see is_power_of_2) */ - ASSERT(zone_sectors != 0 && (zone_sectors & (zone_sectors - 1)) == 0); + ASSERT(zone_sectors != 0 && + IS_ALIGNED(zone_sectors, BTRFS_ZONED_MIN_ALIGN_SECTORS)); zone_info->zone_size = zone_sectors << SECTOR_SHIFT; /* We reject devices with a zone size larger than 8GB */ @@ -892,9 +899,11 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, ASSERT(rw == READ || rw == WRITE); - if (!is_power_of_2(bdev_zone_sectors(bdev))) - return -EINVAL; nr_sectors = bdev_nr_sectors(bdev); + + if (!IS_ALIGNED(nr_sectors, BTRFS_ZONED_MIN_ALIGN_SECTORS)) + return -EINVAL; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); From patchwork Mon May 16 16:54:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9D19C4332F for ; Mon, 16 May 2022 16:55:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343946AbiEPQzF (ORCPT ); Mon, 16 May 2022 12:55:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343957AbiEPQyg (ORCPT ); Mon, 16 May 2022 12:54:36 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9533833A08 for ; Mon, 16 May 2022 09:54:35 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165434euoutp0210a28f8851b37562c465793d342d93dc~vpCa1Ala42798227982euoutp02O for ; Mon, 16 May 2022 16:54:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220516165434euoutp0210a28f8851b37562c465793d342d93dc~vpCa1Ala42798227982euoutp02O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720074; bh=5TXl26FaMqHEmVpoCDcYHu+PuV1m41LmMinlDGGQ4l4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=amSXskJ08T0po78lLobDG/9GeM4Mjy4BvuB11ClYKzVzKKDHCPu4tLSPbcwgZHKkd CCKvqp6EvOROkxy3gmSGlBqTN4nzMO9TM5uWbhEU1kRMkvN7rWWLQHFchW49jEvBW8 0fh3yBjpmaDL9qk5aycOQmr23bkW/cPHtmp7DsVU= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165432eucas1p28fa728357342aadebf5be26269ea5b40~vpCZc4W501887918879eucas1p2n; Mon, 16 May 2022 16:54:32 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A2.4A.09887.8C182826; Mon, 16 May 2022 17:54:32 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220516165432eucas1p2e1ea74d44738e44745f49e37b6b9e503~vpCYwJZGZ0200602006eucas1p2R; Mon, 16 May 2022 16:54:32 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165432eusmtrp1057bb593a1a030e8e478dd59b33a54e3~vpCYvYe2E2961829618eusmtrp1Q; Mon, 16 May 2022 16:54:32 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-43-628281c8fad5 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 02.99.09522.8C182826; Mon, 16 May 2022 17:54:32 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220516165431eusmtip2bac363d67d5edcb5d23957c2ace71c86~vpCYcv3fi0272502725eusmtip2v; Mon, 16 May 2022 16:54:31 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain Subject: [PATCH v4 10/13] zonefs: allow non power of 2 zoned devices Date: Mon, 16 May 2022 18:54:13 +0200 Message-Id: <20220516165416.171196-11-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAKsWRmVeSWpSXmKPExsWy7djP87onGpuSDNY+MbZYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBYrVx9lsug58IHFYu8tbYtLj1ewW+zZe5LF4vKuOWwW85c9Zbe4 MeEpo8XnpS3sFmtuPmVx4Pf4d2INm8fOWXfZPS6fLfXYtKqTzWPzknqP3TcbgMKt91k93u+7 yubRt2UVo8f6LVdZPD5vkgvgjuKySUnNySxLLdK3S+DKOPvgCFPBdoGK6ZtOMDcwnuXtYuTk kBAwkbg2/QhbFyMXh5DACkaJNVP72SGcL4wSHR9nQTmfGSV+TtzMDtPS/fcgE0RiOaPE5m3L mEESQgLPGSV+vZToYuTgYBPQkmjsBKsXEciSmHbiISNIPbPAYiaJlXsms4AkhAVcJF5sPcsG YrMIqEoc+riICaSXV8Ba4tl0O4hd8hIzL31nBwlzAoVXd3GDhHkFBCVOznwCNoUZqKR562xm kPESAvM5Jeb8aWKG6HWR2HFvPyOELSzx6vgWqPtlJE5P7mGBsKslnt74DdXcwijRv3M9G8gy CaBlfWdyQExmAU2J9bv0IcodJb6fvsUEUcEnceOtIMQJfBKTtk1nhgjzSnS0CUFUK0ns/PkE aqmExOWmOSwQJR4SE78oTmBUnIXkl1lIfpmFsHYBI/MqRvHU0uLc9NRio7zUcr3ixNzi0rx0 veT83E2MwER3+t/xLzsYl7/6qHeIkYmD8RCjBAezkgivQUVDkhBvSmJlVWpRfnxRaU5q8SFG aQ4WJXHe5MwNiUIC6YklqdmpqQWpRTBZJg5OqQYm78zlAn+e6wUbhnYXpJxsbGOen3uwIXjh 3NkHRRQnR3FW1S3YZ7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aspCrxJeaZzVzlFm6Fh7e6Puu9qWQTs+Hg/OqjH46mCpnut9I+HXC5H/apc// t+9RvtR6Iadwe/DxZl32YDmZm49OTBHayb52r+ihZTdu2e1KPqCtzmuo8v5CaOBehYTomA0P T3Qezz/lN/fi7dLVmysCUrL/GlYUTpc9saBwx4cD2xrq0ws+R3XNCPSqi/Mp0PY6G8Z3J6BU euoR51se3Wzxe9JE6qYVl+s0vbNrZBD0sjDRXfaPYZp6pnpYRdfD2gV15/8cVTbQ93p31mmr /umFHLNd/st+eXChVsnI/R9X762/h9sWH3X0VDvzOP+s+iHOmbckJJ6rmGqmZmf4uu9e5hO5 UO1dkESNEktxRqKhFnNRcSIAA7FWCVQDAAA= X-CMS-MailID: 20220516165432eucas1p2e1ea74d44738e44745f49e37b6b9e503 X-Msg-Generator: CA X-RootMTR: 20220516165432eucas1p2e1ea74d44738e44745f49e37b6b9e503 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165432eucas1p2e1ea74d44738e44745f49e37b6b9e503 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The zone size shift variable is useful only if the zone sizes are known to be power of 2. Remove that variable and use generic helpers from block layer to calculate zone index in zonefs. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/zonefs/super.c | 6 ++---- fs/zonefs/zonefs.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index 57ca775f5..e302c889a 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -451,10 +451,9 @@ static void __zonefs_io_error(struct inode *inode, bool write) { struct zonefs_inode_info *zi = ZONEFS_I(inode); struct super_block *sb = inode->i_sb; - struct zonefs_sb_info *sbi = ZONEFS_SB(sb); unsigned int noio_flag; unsigned int nr_zones = - zi->i_zone_size >> (sbi->s_zone_sectors_shift + SECTOR_SHIFT); + bdev_zone_no(sb->s_bdev, zi->i_zone_size >> SECTOR_SHIFT); struct zonefs_ioerr_data err = { .inode = inode, .write = write, @@ -1375,7 +1374,7 @@ static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone, struct zonefs_inode_info *zi = ZONEFS_I(inode); int ret; - inode->i_ino = zone->start >> sbi->s_zone_sectors_shift; + inode->i_ino = bdev_zone_no(sb->s_bdev, zone->start); inode->i_mode = S_IFREG | sbi->s_perm; zi->i_ztype = type; @@ -1752,7 +1751,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) * interface constraints. */ sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev)); - sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev)); sbi->s_uid = GLOBAL_ROOT_UID; sbi->s_gid = GLOBAL_ROOT_GID; sbi->s_perm = 0640; diff --git a/fs/zonefs/zonefs.h b/fs/zonefs/zonefs.h index 4b3de66c3..39895195c 100644 --- a/fs/zonefs/zonefs.h +++ b/fs/zonefs/zonefs.h @@ -177,7 +177,6 @@ struct zonefs_sb_info { kgid_t s_gid; umode_t s_perm; uuid_t s_uuid; - unsigned int s_zone_sectors_shift; unsigned int s_nr_files[ZONEFS_ZTYPE_MAX]; From patchwork Mon May 16 16:54:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 053EEC433EF for ; Mon, 16 May 2022 16:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236705AbiEPQzH (ORCPT ); Mon, 16 May 2022 12:55:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343969AbiEPQyj (ORCPT ); Mon, 16 May 2022 12:54:39 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FD313C716 for ; Mon, 16 May 2022 09:54:38 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165436euoutp01849a5bd6efaa5a078d03b2748141d798~vpCdB8JUg2836428364euoutp01P for ; Mon, 16 May 2022 16:54:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165436euoutp01849a5bd6efaa5a078d03b2748141d798~vpCdB8JUg2836428364euoutp01P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720076; bh=8MOzPxdRNLcObOcfdHsKDSsDiJAEHid0X7DZChiwQRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZdFZKGYyJhhAXEYPGudaV/LR/WSC1UaKEBQgDN9H3Z1xv4F/+Y/dHL3dkvPKWFek 9AbPPwMW1ZGXywk1ykQ1tJN7s+UyGB0B1bing9vbgbO71ZIoCny0insPl3b+p8sgvC 0/dsHgY0WPk3oxeABE7PQcTFENwobsBGRsmkdoLY= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165435eucas1p25e4514aea76156f58bbd4b55393fe2a2~vpCbr4a7r0930109301eucas1p2z; Mon, 16 May 2022 16:54:35 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 14.4A.09887.BC182826; Mon, 16 May 2022 17:54:35 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165434eucas1p12b178fb83cc93470933e3d72c40e9004~vpCahQk6u0957909579eucas1p1t; Mon, 16 May 2022 16:54:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220516165434eusmtrp221b0a508a330117089d1382091d5eaa5~vpCagXzN41030710307eusmtrp23; Mon, 16 May 2022 16:54:34 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-49-628281cb2e59 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 91.10.09404.9C182826; Mon, 16 May 2022 17:54:33 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165433eusmtip1f24d790faf28b78ebae9f4ad2376538f~vpCaBwBE00975309753eusmtip1g; Mon, 16 May 2022 16:54:33 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain , Hannes Reinecke Subject: [PATCH v4 11/13] null_blk: allow non power of 2 zoned devices Date: Mon, 16 May 2022 18:54:14 +0200 Message-Id: <20220516165416.171196-12-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBKsWRmVeSWpSXmKPExsWy7djPc7qnG5uSDP6dEbRYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBZ7Fk1isli5+iiTRc+BDywWe29pW1x6vILdYs/ekywWl3fNYbOY v+wpu8WNCU8ZLT4vbWG3WHPz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zcIHJ0Z67P0jeNqJZbijERDLeai4kQAX7lHJV0DAAA= X-CMS-MailID: 20220516165434eucas1p12b178fb83cc93470933e3d72c40e9004 X-Msg-Generator: CA X-RootMTR: 20220516165434eucas1p12b178fb83cc93470933e3d72c40e9004 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165434eucas1p12b178fb83cc93470933e3d72c40e9004 References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert the power of 2 based calculation with zone size to be generic in null_zone_no with optimization for power of 2 based zone sizes. The nr_zones calculation in null_init_zoned_dev has been replaced with a division without special handling for power of 2 based zone sizes as this function is called only during the initialization and will not invoked in the hot path. Performance Measurement: Device: zone size = 128M, blocksize=4k FIO cmd: fio --name=zbc --filename=/dev/nullb0 --direct=1 --zonemode=zbd --size=23G --io_size= --ioengine=io_uring --iodepth= --rw= --bs=4k --loops=4 The following results are an average of 4 runs on AMD Ryzen 5 5600X with 32GB of RAM: Sequential Write: x-----------------x---------------------------------x---------------------------------x | IOdepth | 8 | 16 | x-----------------x---------------------------------x---------------------------------x | | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) | x-----------------x---------------------------------x---------------------------------x | Without patch | 578 | 2257 | 12.80 | 576 | 2248 | 25.78 | x-----------------x---------------------------------x---------------------------------x | With patch | 581 | 2268 | 12.74 | 576 | 2248 | 25.85 | x-----------------x---------------------------------x---------------------------------x Sequential read: x-----------------x---------------------------------x---------------------------------x | IOdepth | 8 | 16 | x-----------------x---------------------------------x---------------------------------x | | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) | x-----------------x---------------------------------x---------------------------------x | Without patch | 667 | 2605 | 11.79 | 675 | 2637 | 23.49 | x-----------------x---------------------------------x---------------------------------x | With patch | 667 | 2605 | 11.79 | 675 | 2638 | 23.48 | x-----------------x---------------------------------x---------------------------------x Random read: x-----------------x---------------------------------x---------------------------------x | IOdepth | 8 | 16 | x-----------------x---------------------------------x---------------------------------x | | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) | x-----------------x---------------------------------x---------------------------------x | Without patch | 522 | 2038 | 15.05 | 514 | 2006 | 30.87 | x-----------------x---------------------------------x---------------------------------x | With patch | 522 | 2039 | 15.04 | 523 | 2042 | 30.33 | x-----------------x---------------------------------x---------------------------------x Minor variations are noticed in Sequential write with io depth 8 and in random read with io depth 16. But overall no noticeable differences were noticed Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav Reported-by: kernel test robot --- drivers/block/null_blk/main.c | 5 ++--- drivers/block/null_blk/zoned.c | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 5cb4c92cd..53557e014 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1929,9 +1929,8 @@ static int null_validate_conf(struct nullb_device *dev) if (dev->queue_mode == NULL_Q_BIO) dev->mbps = 0; - if (dev->zoned && - (!dev->zone_size || !is_power_of_2(dev->zone_size))) { - pr_err("zone_size must be power-of-two\n"); + if (dev->zoned && !dev->zone_size) { + pr_err("Invalid zero zone size\n"); return -EINVAL; } diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index dae54dd1a..00c34e65e 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -13,7 +13,10 @@ static inline sector_t mb_to_sects(unsigned long mb) static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) { - return sect >> ilog2(dev->zone_size_sects); + if (is_power_of_2(dev->zone_size_sects)) + return sect >> ilog2(dev->zone_size_sects); + + return div64_u64(sect, dev->zone_size_sects); } static inline void null_lock_zone_res(struct nullb_device *dev) @@ -62,10 +65,6 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) sector_t sector = 0; unsigned int i; - if (!is_power_of_2(dev->zone_size)) { - pr_err("zone_size must be power-of-two\n"); - return -EINVAL; - } if (dev->zone_size > dev->size) { pr_err("Zone size larger than device capacity\n"); return -EINVAL; @@ -83,8 +82,9 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) zone_capacity_sects = mb_to_sects(dev->zone_capacity); dev_capacity_sects = mb_to_sects(dev->size); dev->zone_size_sects = mb_to_sects(dev->zone_size); - dev->nr_zones = round_up(dev_capacity_sects, dev->zone_size_sects) - >> ilog2(dev->zone_size_sects); + dev->nr_zones = + div64_u64(roundup(dev_capacity_sects, dev->zone_size_sects), + dev->zone_size_sects); dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone), GFP_KERNEL | __GFP_ZERO); From patchwork Mon May 16 16:54:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9165FC433FE for ; Mon, 16 May 2022 16:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344061AbiEPQzS (ORCPT ); Mon, 16 May 2022 12:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343894AbiEPQyz (ORCPT ); Mon, 16 May 2022 12:54:55 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34E83C729 for ; Mon, 16 May 2022 09:54:38 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165437euoutp021d56a44561384367e61c679c6e310170~vpCd8pl1V2798927989euoutp02V for ; Mon, 16 May 2022 16:54:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220516165437euoutp021d56a44561384367e61c679c6e310170~vpCd8pl1V2798927989euoutp02V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720077; bh=sIFPzJwmw91La4IivNRzQIhJyFo2l0eG5WseB5ln2h4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=USBwESHi0aC1sCVpZw2ZQJMFpt0F4X+44QhGlBf2ZM+PLxZ3HE4N3M+Stshhfph7b ALKrzUXd9Qnp2vTsK1CqkOieIfChJ3BhIVWgp93vcWheSzQ5IepAj9zGEXV0HJ493Q gD9VC3JGw5ZydM8ZPDMnTVv4XNv8FtLx/tQb5lMA= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220516165436eucas1p2b02b2f7c641bc1bbfa9bef655babcbd5~vpCclYJ7J2458224582eucas1p2f; Mon, 16 May 2022 16:54:36 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 09.40.10009.CC182826; Mon, 16 May 2022 17:54:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165435eucas1p1dff8d9d039a76278ef1c09dba4b4e1fe~vpCb6_gGK2301423014eucas1p1g; Mon, 16 May 2022 16:54:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165435eusmtrp141329befc30bbab3ee03ebbe79411840~vpCb6N5eD2961829618eusmtrp1S; Mon, 16 May 2022 16:54:35 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-5e-628281ccad79 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 23.99.09522.BC182826; Mon, 16 May 2022 17:54:35 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165434eusmtip100c87a23ecdeb7aa39972989a236a63d~vpCbUU0uF0975309753eusmtip1h; Mon, 16 May 2022 16:54:34 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Damien Le Moal Subject: [PATCH v4 12/13] null_blk: use zone_size_sects_shift for power of 2 zoned devices Date: Mon, 16 May 2022 18:54:15 +0200 Message-Id: <20220516165416.171196-13-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEKsWRmVeSWpSXmKPExsWy7djPc7pnGpuSDFae5rFYfbefzeL32fPM Fq3t35gs9r6bzWpx4Ucjk8XNAzuZLFauPspk0XPgA4vF3lvaFpcer2C32LP3JIvF5V1z2Czm L3vKbvF5aQu7xZqbT1kc+D3+nVjD5rFz1l12j8tnSz02L6n32H2zASjSep/V4/2+q2wefVtW MXqs33KVxePzJjmP9gPdTAHcUVw2Kak5mWWpRfp2CVwZeyZuZy1YLFhx6MN2xgbG03xdjJwc EgImEnunz2HvYuTiEBJYwSix+Nx5NgjnC6PEqkNHoDKfGSUu3nrDBtOyYd4GqKrljBKXP51g AkkICTxnlNjVxdXFyMHBJqAl0djJDhIWE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k5xH+4FupgDuKD2bovzSklSFjPziElulaEMLIz1DSws9IxNLPUNj81grI1Ml fTublNSczLLUIn27BL2MPRO3sxYsFqw49GE7YwPjab4uRk4OCQETiQ3zNrB1MXJxCAksZZRY sew9I0RCQuL2wiYoW1jiz7UuqKKnjBIff68Acjg42AS0JBo72UFqRAQKJOb0b2EBqWEWWM8k sWPbZCaQhLBAlMT60xNZQWwWAVWJrQfesoHYvALWEl0TulghFshLzLz0nR1kJidQfHUXN0hY SMBK4uuTW+wQ5YISJ2c+YQGxmYHKm7fOZp7AKDALSWoWktQCRqZVjCKppcW56bnFhnrFibnF pXnpesn5uZsYgZG57djPzTsY5736qHeIkYmD8RCjBAezkgivQUVDkhBvSmJlVWpRfnxRaU5q 8SFGU6CzJzJLiSbnA1NDXkm8oZmBqaGJmaWBqaWZsZI4r2dBR6KQQHpiSWp2ampBahFMHxMH p1QDk+XOE8YZDzfvvxB7kTGk8vLRQ8obJlemrM9zvBTjs/w+e9K6LXLqHK03V06tWf/+/pE9 LxIWJDy9/XWdz8SrPXs7Amfq8B8Q/uUVHqx7xcHlEstJgaXTZYuvsx/aLnVSXt3uYsN7yWnc qT+7V59bNo9p724xQwmJQO8r/2efZFm/STJWJ+5RNL95yoK56ZL79S4X3ta/8lPY7YByS/jh rg8x+UFJL0pbhCaHbpEPb9t70nsjW0RHgpWy4gc2QbE1vKIWzprXXq2S2/i9Yodxzi0PqX+H NJ5Z27jK+xj+bUnds6Pp+k1Gxoh8tui0zIlcD8wtD/xWqwndO3mqatbnE3dS6g4ZnblTub7k MK84uxJLcUaioRZzUXEiAK3MTqZVAwAA X-CMS-MailID: 20220516165435eucas1p1dff8d9d039a76278ef1c09dba4b4e1fe X-Msg-Generator: CA X-RootMTR: 20220516165435eucas1p1dff8d9d039a76278ef1c09dba4b4e1fe X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165435eucas1p1dff8d9d039a76278ef1c09dba4b4e1fe References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of doing is_power_of_2 and ilog2 operation for every IO, cache the zone_size_sects_shift variable and use it for power of 2 zoned devices. This variable will be set to zero for non power of 2 zoned devices. Suggested-by: Damien Le Moal Signed-off-by: Pankaj Raghav --- drivers/block/null_blk/null_blk.h | 6 ++++++ drivers/block/null_blk/zoned.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 4525a65e1..3bbae8be4 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -76,6 +76,12 @@ struct nullb_device { unsigned int imp_close_zone_no; struct nullb_zone *zones; sector_t zone_size_sects; + /* + * zone_size_sects_shift is only useful when the zone size is + * power of 2. This variable is set to zero when zone size is non + * power of 2. + */ + unsigned int zone_size_sects_shift; bool need_zone_res_mgmt; spinlock_t zone_res_lock; diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 00c34e65e..806bef98a 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -13,8 +13,8 @@ static inline sector_t mb_to_sects(unsigned long mb) static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) { - if (is_power_of_2(dev->zone_size_sects)) - return sect >> ilog2(dev->zone_size_sects); + if (dev->zone_size_sects_shift) + return sect >> dev->zone_size_sects_shift; return div64_u64(sect, dev->zone_size_sects); } @@ -82,6 +82,12 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) zone_capacity_sects = mb_to_sects(dev->zone_capacity); dev_capacity_sects = mb_to_sects(dev->size); dev->zone_size_sects = mb_to_sects(dev->zone_size); + + if (is_power_of_2(dev->zone_size_sects)) + dev->zone_size_sects_shift = ilog2(dev->zone_size_sects); + else + dev->zone_size_sects_shift = 0; + dev->nr_zones = div64_u64(roundup(dev_capacity_sects, dev->zone_size_sects), dev->zone_size_sects); From patchwork Mon May 16 16:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12851220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBD42C43217 for ; Mon, 16 May 2022 16:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343990AbiEPQzV (ORCPT ); Mon, 16 May 2022 12:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343992AbiEPQy4 (ORCPT ); Mon, 16 May 2022 12:54:56 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6ACA3CA4B for ; Mon, 16 May 2022 09:54:39 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165438euoutp01380eaa2e5ac4238fca46d29ebc120a4d~vpCewbTwr2240822408euoutp01P for ; Mon, 16 May 2022 16:54:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165438euoutp01380eaa2e5ac4238fca46d29ebc120a4d~vpCewbTwr2240822408euoutp01P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720078; bh=6O6R+aWzFD0tH6pBlgRqy5ygmaD7SLpLHM9qftmpwuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fh6lUpOxEz1L5R0lDXKJogWDFAtYMYr19gWlbSAHU966Zw8+vMGblv2wuPQAu7a5U RPyQtPr0FqsXu3HlSnG97HoIFCkN3dhmm2J3ok64Z/gmmFkIebT+VLWVGYrIW4wgRg wCETrHorIbHw+GZ7QiTP96Jl1l5jjipFf9NzVwYk= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165437eucas1p15eb77c4c9a68927fe7695a2e5830dcb7~vpCdkUKeT1545715457eucas1p1f; Mon, 16 May 2022 16:54:37 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 66.E6.10260.DC182826; Mon, 16 May 2022 17:54:37 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165436eucas1p178d079302dae3a9fca696b13b0390deb~vpCdOIri62560525605eucas1p1b; Mon, 16 May 2022 16:54:36 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220516165436eusmtrp28837a89a06654af7c04d36f8d5949f97~vpCdNanu61030710307eusmtrp26; Mon, 16 May 2022 16:54:36 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-5f-628281cdd3f8 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 23.10.09404.CC182826; Mon, 16 May 2022 17:54:36 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220516165436eusmtip27c52763e39356a08b7d9cbb75f4140dd~vpCc05sQp3184631846eusmtip2E; Mon, 16 May 2022 16:54:36 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain , Hannes Reinecke Subject: [PATCH v4 13/13] dm-zoned: ensure only power of 2 zone sizes are allowed Date: Mon, 16 May 2022 18:54:16 +0200 Message-Id: <20220516165416.171196-14-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNKsWRmVeSWpSXmKPExsWy7djP87pnG5uSDLb9FbJYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBZ7Fk1isli5+iiTRc+BDywWe29pW1x6vILdYs/ekywWl3fNYbOY v+wpu8WNCU8ZLT4vbWG3WHPzKYuDgMe/E2vYPHbOusvucflsqcemVZ1sHpuX1HvsvtkAFG69 z+rxft9VNo++LasYPdZvucrisfl0tcfnTXIBPFFcNimpOZllqUX6dglcGT277jEVzOCquHX2 AGsD4yqOLkZODgkBE4npK7YydzFycQgJrGCUOPphLRuE84VR4tflmUwQzmdGiVNPTrDAtOyZ fBkqsZxRonXqK3YI5zmjRMOWaYxdjBwcbAJaEo2d7CANIgJZEtNOPGQEqWEWOMwk8fzofFaQ hLBAsMSqZ7fYQGwWAVWJztfPwOK8AtYSr1a8ZoXYJi8x89J3dpCZnEDx1V3cECWCEidnPgE7 iBmopHnrbLAfJASWc0q0Hj4KVi8h4CLRedYHYoywxKvjW9ghbBmJ/zvnM0HY1RJPb/yG6m1h lOjfuZ4Notdaou9MDojJLKApsX6XPkS5o8TWLytZISr4JG68FYS4gE9i0rbpzBBhXomONiGI aiWJnT+fQC2VkLjcNAcagh4S99d/YJ/AqDgLyS+zkPwyC2HvAkbmVYziqaXFuempxcZ5qeV6 xYm5xaV56XrJ+bmbGIHp7/S/4193MK549VHvECMTB+MhRgkOZiURXoOKhiQh3pTEyqrUovz4 otKc1OJDjNIcLErivMmZGxKFB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eyCwlmpwPTBV5JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6Yklqdmp qQWpRTB9TBycUg1Mk6fvdjfa5ON/83dYHLet8aHDRgZJm/7YMf6cwtBzuV9CcP2hI984F6z/ seXGjM/F12TvZ65qnTA74+361NWKzd1vUmt975ZEH01/uWZJ6bX7DEdaLcJcd29JOizBtSrp /ZxYBjkRM9OMFQYs7780Rlw1CcpKK14we0//w40XXTsfr6lyDPmRmXv+6+q8JsuPd7iq890/ NKztO32j2k/8xM/V/+43BTOsWGIi95gla1/szVtnXB6FxSsd47z/WPRCpMyzahaujsfW23oZ FLZ0GJYLeLIIOs7s2Z5f0ST/oPfmzT8XwhN95j1bnOKeecU2YY39l+OzpF49miMRb77ok5qX ycEXx+bd+KtxtLG5XYmlOCPRUIu5qDgRAFdHucBdAwAA X-CMS-MailID: 20220516165436eucas1p178d079302dae3a9fca696b13b0390deb X-Msg-Generator: CA X-RootMTR: 20220516165436eucas1p178d079302dae3a9fca696b13b0390deb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165436eucas1p178d079302dae3a9fca696b13b0390deb References: <20220516165416.171196-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Luis Chamberlain Today dm-zoned relies on the assumption that you have a zone size with a power of 2. Even though the block layer today enforces this requirement, these devices do exist and so provide a stop-gap measure to ensure these devices cannot be used by mistake Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- drivers/md/dm-zone.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index 3e7b1fe15..f0c588c02 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -231,6 +231,18 @@ static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t) struct request_queue *q = md->queue; unsigned int noio_flag; int ret; + struct block_device *bdev = md->disk->part0; + sector_t zone_sectors; + char bname[BDEVNAME_SIZE]; + + zone_sectors = bdev_zone_sectors(bdev); + + if (!is_power_of_2(zone_sectors)) { + DMWARN("%s: %s only power of two zone size supported", + dm_device_name(md), + bdevname(bdev, bname)); + return -EINVAL; + } /* * Check if something changed. If yes, cleanup the current resources