From patchwork Tue Jun 14 09:09:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12880788 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 52064C43334 for ; Tue, 14 Jun 2022 09:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352916AbiFNJJ5 (ORCPT ); Tue, 14 Jun 2022 05:09:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351222AbiFNJJr (ORCPT ); Tue, 14 Jun 2022 05:09:47 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF3140A16 for ; Tue, 14 Jun 2022 02:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=VftBlw+J8XHGFIkvNwP8l9M1/vCc+WKDE/iuHGrQuQ0=; b=hBDkYP19ChP9eFYczwXoRW7hLf tPSCzeS8uChKCeghEknFU2HmTulBrE/iKt36M9kMDSvDzIgS459RjjpuYWecixvZtC54iYh2s11mq E1R2j49hP1MHGzUOE4eu4LBj0b772x0YsXIuX/cA3P5Y8E27fi//8mOBjlcb7gl2QLAA24kA4CQFc y2wYHM4+z06f8YrHAnJ1sLDpPTu6ZN7vkShONZHtjL8RY3Wfk1lbB+pQ6sHgcN6/ItTKYVb7AfJt4 7VXZDmB8OA/BXMwLIhF1/DjkxqClMd2xBlH7vBiU7FeLpiBE6jOR5o+zecYtMpRLtt9ojKYUOLDP5 YPnDpBfg==; Received: from [2001:4bb8:180:36f6:1fed:6d48:cf16:d13c] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o12YP-008ZdX-Tp; Tue, 14 Jun 2022 09:09:42 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 1/6] block: factor out a chunk_size_left helper Date: Tue, 14 Jun 2022 11:09:29 +0200 Message-Id: <20220614090934.570632-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090934.570632-1-hch@lst.de> References: <20220614090934.570632-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Factor out a helper from blk_max_size_offset so that it can be reused independently. Signed-off-by: Christoph Hellwig Reviewed-by: Bart Van Assche Reviewed-by: Pankaj Raghav --- include/linux/blkdev.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 914c613d81da7..e66ad451274ec 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -933,6 +933,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, return q->limits.max_sectors; } +/* + * Return how much of the chunk is left to be used for I/O at a given offset. + */ +static inline unsigned int blk_chunk_sectors_left(sector_t offset, + unsigned int chunk_sectors) +{ + if (unlikely(!is_power_of_2(chunk_sectors))) + return chunk_sectors - sector_div(offset, chunk_sectors); + return chunk_sectors - (offset & (chunk_sectors - 1)); +} + /* * Return maximum size of a request at given offset. Only valid for * file system requests. @@ -948,12 +959,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q, return q->limits.max_sectors; } - if (likely(is_power_of_2(chunk_sectors))) - chunk_sectors -= offset & (chunk_sectors - 1); - else - chunk_sectors -= sector_div(offset, chunk_sectors); - - return min(q->limits.max_sectors, chunk_sectors); + return min(q->limits.max_sectors, + blk_chunk_sectors_left(offset, chunk_sectors)); } /* From patchwork Tue Jun 14 09:09:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12880791 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 A4B52CCA47A for ; Tue, 14 Jun 2022 09:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242932AbiFNJJ6 (ORCPT ); Tue, 14 Jun 2022 05:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242858AbiFNJJv (ORCPT ); Tue, 14 Jun 2022 05:09:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A12174131E for ; Tue, 14 Jun 2022 02:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=i1KmEgZjd7O4n2CLA071LE1/HSTT0i2IDw5Sobh6pao=; b=DD3kNhr7zAp1AXn3LMRh/S74dh nkZtXHWJr6ntnbc5SxfdEIxL4DnzpCHtjbO1H8xa8MXxih0Xx/Z81bXRWY17DNE4htlM6KMVqwTgH Keljj9PjpXe+rKBCecjqQBcjiB5+gzAqPtvdj4y9sSFilIcJtteq9cXKMRpBrfyTDFfT5I/hvlD/C i1lZQ1pgdfJ490NEVU88mk+amNzIiBLV633MfIyVnFQVxzmighD2t49mHoeLTQrKOpyXUPTiGtqfY FxKPbqX9LvxrlHrrJE1JBZuI4N7R1yjP+UJTyK4LJNz92ylimQ8VyIH1MpMusYW9JZpLEuNXwzr12 FkJLB+2g==; Received: from [2001:4bb8:180:36f6:1fed:6d48:cf16:d13c] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o12YS-008Zea-QX; Tue, 14 Jun 2022 09:09:45 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 2/6] dm: open code blk_max_size_offset in max_io_len Date: Tue, 14 Jun 2022 11:09:30 +0200 Message-Id: <20220614090934.570632-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090934.570632-1-hch@lst.de> References: <20220614090934.570632-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org max_io_len always passes an explicitly non-zero chunk_sectors into blk_max_size_offset. That means much of blk_max_size_offset is not needed and can be open coded to simplify the code. Signed-off-by: Christoph Hellwig Reviewed-by: Mike Snitzer --- drivers/md/dm.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index d8f16183bf27c..0514358a1f8e5 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1079,23 +1079,18 @@ static sector_t max_io_len(struct dm_target *ti, sector_t sector) { sector_t target_offset = dm_target_offset(ti, sector); sector_t len = max_io_len_target_boundary(ti, target_offset); - sector_t max_len; /* * Does the target need to split IO even further? * - varied (per target) IO splitting is a tenet of DM; this * explains why stacked chunk_sectors based splitting via - * blk_max_size_offset() isn't possible here. So pass in - * ti->max_io_len to override stacked chunk_sectors. + * blk_queue_split() isn't possible here. */ - if (ti->max_io_len) { - max_len = blk_max_size_offset(ti->table->md->queue, - target_offset, ti->max_io_len); - if (len > max_len) - len = max_len; - } - - return len; + if (!ti->max_io_len) + return len; + return min_t(sector_t, len, + min(queue_max_sectors(ti->table->md->queue), + blk_chunk_sectors_left(target_offset, ti->max_io_len))); } int dm_set_target_max_io_len(struct dm_target *ti, sector_t len) From patchwork Tue Jun 14 09:09:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12880789 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 341A4C433EF for ; Tue, 14 Jun 2022 09:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353204AbiFNJJ5 (ORCPT ); Tue, 14 Jun 2022 05:09:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242932AbiFNJJv (ORCPT ); Tue, 14 Jun 2022 05:09:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 312A540E6F for ; Tue, 14 Jun 2022 02:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=R+654CqqyrFlc/qleabG9TKavNiNkiaEV85B/4QZwTU=; b=RWLPRHk06h7gBPiR/REwy8wyet zYF4IWWcvbHP2x64gxrkov+wIKJTyITn/NhUNmm+S9LTwkwzilD42WG0xp5Sx0dF3bGceXFWcQJya SHP5dL8yPTbIVksK+meg9QS4ksMMKogrWLWnwVSv2RcWTbzUmhRU+YpOI9X/+sNq9WORGHKGpx3g4 ZTZXkYSyrjIg10dHi2ktS9B8BtnVF8L7hspjTmTpmLOkz6qN3SQ3rGyJGqeB2nNo2v0DlTASyucvM OSY1gW0FMdJyZ2uMc83NsSehlfThtGKsBMdOchBi214N/q67xyU2eTW3jTN+VZdbNs/T2TjbiHkOj /mRoRH4g==; Received: from [2001:4bb8:180:36f6:1fed:6d48:cf16:d13c] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o12YV-008Zfj-IU; Tue, 14 Jun 2022 09:09:47 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 3/6] block: open code blk_max_size_offset in blk_rq_get_max_sectors Date: Tue, 14 Jun 2022 11:09:31 +0200 Message-Id: <20220614090934.570632-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090934.570632-1-hch@lst.de> References: <20220614090934.570632-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org blk_rq_get_max_sectors always uses q->limits.chunk_sectors as the chunk_sectors argument, and already checks for max_sectors through the call to blk_queue_get_max_sectors. That means much of blk_max_size_offset is not needed and open coding it simplifies the code. Signed-off-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- block/blk-merge.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index db2e03c8af7f4..df003ecfbd474 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -566,17 +566,18 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, sector_t offset) { struct request_queue *q = rq->q; + unsigned int max_sectors; if (blk_rq_is_passthrough(rq)) return q->limits.max_hw_sectors; + max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); if (!q->limits.chunk_sectors || req_op(rq) == REQ_OP_DISCARD || req_op(rq) == REQ_OP_SECURE_ERASE) - return blk_queue_get_max_sectors(q, req_op(rq)); - - return min(blk_max_size_offset(q, offset, 0), - blk_queue_get_max_sectors(q, req_op(rq))); + return max_sectors; + return min(max_sectors, + blk_chunk_sectors_left(offset, q->limits.chunk_sectors)); } static inline int ll_new_hw_segment(struct request *req, struct bio *bio, From patchwork Tue Jun 14 09:09:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12880790 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 CF94BCCA47F for ; Tue, 14 Jun 2022 09:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350773AbiFNJJ6 (ORCPT ); Tue, 14 Jun 2022 05:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352435AbiFNJJ5 (ORCPT ); Tue, 14 Jun 2022 05:09:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E2041634 for ; Tue, 14 Jun 2022 02:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=bRDG3OpzxUtRd6qdhwMYYetySjE4uBzMs6kJjEayCEM=; b=fVypyQmSxqQNaxtnADD/b+qujm wkam6jpKXOrd9FRPCzysAvQTb8bE+A4fsz/29WaAwGcqNWZclZBI5cJ8i0tmZq716D3tZTDM4QQRR DDPXZ/mr8ylTfVBkDYlFFlJLnW7ja06KMGNxr2YjlnDlFJqQ44eBh2BhQ6HKaBJRBf0SzPxDMZ+O+ b3GGKTMcgroQKoWWiDz7zVPg1kLW7nPQKFNSlVaa/yPUdvnjeDiwv/gRV9+7NXEA0nXfXOW2Xjon/ cvIkka8I+a/oEUkNjcy2z9ZsqSL0bbXcFb8EAz+toKFQeZWTG31Un9hOweJF5yDT/gUh9wvG/ApiA aw9ZZiyg==; Received: from [2001:4bb8:180:36f6:1fed:6d48:cf16:d13c] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o12YY-008Zh3-7F; Tue, 14 Jun 2022 09:09:50 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 4/6] block: cleanup variable naming in get_max_io_size Date: Tue, 14 Jun 2022 11:09:32 +0200 Message-Id: <20220614090934.570632-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090934.570632-1-hch@lst.de> References: <20220614090934.570632-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org get_max_io_size has a very odd choice of variables names and initialization patterns. Switch to more descriptive names and more clear initialization of them. Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index df003ecfbd474..4da981efddeed 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -164,18 +164,16 @@ static struct bio *blk_bio_write_zeroes_split(struct request_queue *q, static inline unsigned get_max_io_size(struct request_queue *q, struct bio *bio) { - unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0); - unsigned max_sectors = sectors; unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT; - unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1); - - max_sectors += start_offset; - max_sectors &= ~(pbs - 1); - if (max_sectors > start_offset) - return max_sectors - start_offset; - - return sectors & ~(lbs - 1); + unsigned max_sectors, start, end; + + max_sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0); + start = bio->bi_iter.bi_sector & (pbs - 1); + end = (start + max_sectors) & ~(pbs - 1); + if (end > start) + return end - start; + return max_sectors & ~(lbs - 1); } static inline unsigned get_max_segment_size(const struct request_queue *q, From patchwork Tue Jun 14 09:09:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12880792 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 2C405C433EF for ; Tue, 14 Jun 2022 09:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353038AbiFNJKA (ORCPT ); Tue, 14 Jun 2022 05:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351222AbiFNJJ5 (ORCPT ); Tue, 14 Jun 2022 05:09:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE523F300 for ; Tue, 14 Jun 2022 02:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=cPXKljoKRMe0CQB/zcaUxOrheWmQqCmqWStWsCIRHuE=; b=aWiI+nEi8Hmmh9n8MW0K98vxeE JhNVeKpD5j1I1H1gOnPS5IA53xaOMlEBeUpUNDiDSGDwyf5+r8ssD9gatptABgHrVbeboi4eB6n0B qO/64jvoDYr4AjrRY8O1Xx9T99gsHf672g0NYqrPRXVPxWf9HxLIo433PhdJvet5XNmpwcm5D5hc9 ATkYwCkWaecAkQc4p2cHPJDgUK0Wzs4UOYzH9wyu+LVjqCvBIqAGcmvOJLPW+XJ9Q4Kz33HTIo8n6 KPE3MnU2ts7jF8um1fVdad/JkinujZe/vSAKdhfSYSr7rsnNv8OZKzO1rPQq0iGPJTd2IkpGMPsVR ce0P+P/A==; Received: from [2001:4bb8:180:36f6:1fed:6d48:cf16:d13c] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o12Ya-008Ziu-T7; Tue, 14 Jun 2022 09:09:53 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 5/6] block: fold blk_max_size_offset into get_max_io_size Date: Tue, 14 Jun 2022 11:09:33 +0200 Message-Id: <20220614090934.570632-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090934.570632-1-hch@lst.de> References: <20220614090934.570632-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Now that blk_max_size_offset has a single caller left, fold it into that and clean up the naming convention for the local variables there. Signed-off-by: Christoph Hellwig Reviewed-by: Bart Van Assche Reviewed-by: Pankaj Raghav --- block/blk-merge.c | 9 +++++++-- include/linux/blkdev.h | 19 ------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 4da981efddeed..0f5f42ebd0bb0 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -166,9 +166,14 @@ static inline unsigned get_max_io_size(struct request_queue *q, { unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT; - unsigned max_sectors, start, end; + unsigned max_sectors = queue_max_sectors(q), start, end; + + if (q->limits.chunk_sectors) { + max_sectors = min(max_sectors, + blk_chunk_sectors_left(bio->bi_iter.bi_sector, + q->limits.chunk_sectors)); + } - max_sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0); start = bio->bi_iter.bi_sector & (pbs - 1); end = (start + max_sectors) & ~(pbs - 1); if (end > start) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e66ad451274ec..05e60ee269d91 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -944,25 +944,6 @@ static inline unsigned int blk_chunk_sectors_left(sector_t offset, return chunk_sectors - (offset & (chunk_sectors - 1)); } -/* - * Return maximum size of a request at given offset. Only valid for - * file system requests. - */ -static inline unsigned int blk_max_size_offset(struct request_queue *q, - sector_t offset, - unsigned int chunk_sectors) -{ - if (!chunk_sectors) { - if (q->limits.chunk_sectors) - chunk_sectors = q->limits.chunk_sectors; - else - return q->limits.max_sectors; - } - - return min(q->limits.max_sectors, - blk_chunk_sectors_left(offset, chunk_sectors)); -} - /* * Access functions for manipulating queue properties */ From patchwork Tue Jun 14 09:09:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12880793 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 777C9CCA480 for ; Tue, 14 Jun 2022 09:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242985AbiFNJKA (ORCPT ); Tue, 14 Jun 2022 05:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351197AbiFNJJ6 (ORCPT ); Tue, 14 Jun 2022 05:09:58 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4060A40A16 for ; Tue, 14 Jun 2022 02:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6sMaAlVsc/iZlKKSIsbFVmTUCNZbHnyP1/iODlYDZbQ=; b=dqDymwYlznGKKk53A6BCDplbqt NaJTWuykH5Pwi6ouG9591Z9td2pwSsgzmApXtBAKQyIQSCaYbeSiEe8R7iB5WkUmxoYuQMPTdMqA5 3qOZo/KMBMziBIR8HNyE3EUrPf+I4DjynbfAKnQCJKWLabU0mbgp4IZ1q8WlTpx+9FBQNT0GH/9vO Pt6pZiwiag/6re6IZarIVgUwjQjjwre8bgLDcxrVLg64g0eO8doKMiJhOr1il8U5F6qMOF+1t9RzF rWn68NiCqB0EqKWK8y7ixBY2qzapG6rxltd/qcRI/AgquGoVUkNj1F0mSKXvxZbP9bwPjtLvyJX+a 71/w/QyQ==; Received: from [2001:4bb8:180:36f6:1fed:6d48:cf16:d13c] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o12Yd-008Zl3-In; Tue, 14 Jun 2022 09:09:56 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 6/6] block: move blk_queue_get_max_sectors to blk.h Date: Tue, 14 Jun 2022 11:09:34 +0200 Message-Id: <20220614090934.570632-7-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090934.570632-1-hch@lst.de> References: <20220614090934.570632-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org blk_queue_get_max_sectors is private to the block layer, so move it out of blkdev.h. Signed-off-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- block/blk.h | 13 +++++++++++++ include/linux/blkdev.h | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/block/blk.h b/block/blk.h index 434017701403f..8e79296ee97a2 100644 --- a/block/blk.h +++ b/block/blk.h @@ -159,6 +159,19 @@ static inline bool blk_discard_mergable(struct request *req) return false; } +static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, + int op) +{ + if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) + return min(q->limits.max_discard_sectors, + UINT_MAX >> SECTOR_SHIFT); + + if (unlikely(op == REQ_OP_WRITE_ZEROES)) + return q->limits.max_write_zeroes_sectors; + + return q->limits.max_sectors; +} + #ifdef CONFIG_BLK_DEV_INTEGRITY void blk_flush_integrity(void); bool __bio_integrity_endio(struct bio *); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 05e60ee269d91..5ef2f061feb08 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -920,19 +920,6 @@ static inline unsigned int bio_zone_is_seq(struct bio *bio) } #endif /* CONFIG_BLK_DEV_ZONED */ -static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, - int op) -{ - if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) - return min(q->limits.max_discard_sectors, - UINT_MAX >> SECTOR_SHIFT); - - if (unlikely(op == REQ_OP_WRITE_ZEROES)) - return q->limits.max_write_zeroes_sectors; - - return q->limits.max_sectors; -} - /* * Return how much of the chunk is left to be used for I/O at a given offset. */