From patchwork Mon Nov 4 06:26:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13860931 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E25EF17583; Mon, 4 Nov 2024 06:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701615; cv=none; b=K8DTJflLk8K6X8OLAGGyj+nkayPLJjJKePu64FoQUqxLOFtsBPKw6Cv0DyX/zynxK+EdFKJW/4Auh4QZ0MSPN88ug8y8AQytjwJDCAFnc/2yEr0Zv02QsyLT3xslTy6QXsH3ILYpVq/JRZXM8EiCZienrh3Whh4SCO/hK/sCQrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701615; c=relaxed/simple; bh=+BfJ+HPwVKRE95LTxnWPD1+CbCnKzc6B0thWWFK8Gl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FsgWSZHZh5TjCkUL2RxRThK1mEynhp4iopyG75OXRF3Kgjq6AzLLfnqzA6XZt+/Wee7+WW+tIvV0vG4bcPyzoL/AjS6TpwREI/2z3vkyPqYdm1M/HxMcrZXRK0joEIor8sJ1vgHTYB9IiVf3lpWpr0cgFOttGDXcIvmli//KZm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=4cws6TOh; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="4cws6TOh" 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=O1tyXiGHyIiRUZY9ORb1jpf4aW68m98TAHkBFvd/LWo=; b=4cws6TOhglIWpz0RrgCsW40pHO iMXHKFL5XJxPNIClhXkCV6ZfGSlqzKqUW0xlfLbM9N6PUer61NhWffnUdK+dz3Li/emUJX5s4kZ0w FWW8UrXtWBMYBqSkMo2BKKnBecjCiyERq3K5avaN4pfz1i+zC03i5rwayNc0W82ekTA6wLiTxof+q TNlUxqoInudE3HPj7YH9THeka7ayQsVI61vesU7ZXozSMvcuy8sP8L5MEHNiHn+IK7GO6Wl80BG7j fwRKUidx3WXv3CZsYnZs+oLqTVKcCtl/tyEQlK+cd01Wek7ZFT3OhKhiukGfJxXJtgqzF9abItlu3 MrVEtHuA==; Received: from 2a02-8389-2341-5b80-c843-e027-3367-36ce.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:c843:e027:3367:36ce] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t7qY8-0000000Cl2W-2XBl; Mon, 04 Nov 2024 06:26:52 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 1/5] block: take chunk_sectors into account in bio_split_write_zeroes Date: Mon, 4 Nov 2024 07:26:29 +0100 Message-ID: <20241104062647.91160-2-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241104062647.91160-1-hch@lst.de> References: <20241104062647.91160-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html For zoned devices, write zeroes must be split at the zone boundary which is represented as chunk_sectors. For other uses like the internally RAIDed NVMe devices it is probably at least useful. Enhance get_max_io_size to know about write zeroes and use it in bio_split_write_zeroes. Also add a comment about the seemingly nonsensical zero max_write_zeroes limit. Fixes: 885fa13f6559 ("block: implement splitting of REQ_OP_WRITE_ZEROES bios") Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index d813d799cee7..f440919b6c6f 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -166,17 +166,6 @@ struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim, return bio_submit_split(bio, split_sectors); } -struct bio *bio_split_write_zeroes(struct bio *bio, - const struct queue_limits *lim, unsigned *nsegs) -{ - *nsegs = 0; - if (!lim->max_write_zeroes_sectors) - return bio; - if (bio_sectors(bio) <= lim->max_write_zeroes_sectors) - return bio; - return bio_submit_split(bio, lim->max_write_zeroes_sectors); -} - static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim, bool is_atomic) { @@ -211,7 +200,9 @@ static inline unsigned get_max_io_size(struct bio *bio, * We ignore lim->max_sectors for atomic writes because it may less * than the actual bio size, which we cannot tolerate. */ - if (is_atomic) + if (bio_op(bio) == REQ_OP_WRITE_ZEROES) + max_sectors = lim->max_write_zeroes_sectors; + else if (is_atomic) max_sectors = lim->atomic_write_max_sectors; else max_sectors = lim->max_sectors; @@ -398,6 +389,26 @@ struct bio *bio_split_zone_append(struct bio *bio, return bio_submit_split(bio, split_sectors); } +struct bio *bio_split_write_zeroes(struct bio *bio, + const struct queue_limits *lim, unsigned *nsegs) +{ + unsigned int max_sectors = get_max_io_size(bio, lim); + + *nsegs = 0; + + /* + * An unset limit should normally not happen, as bio submission is keyed + * off having a non-zero limit. But SCSI can clear the limit in the + * I/O completion handler, and we can race and see this. Splitting to a + * zero limit obviously doesn't make sense, so band-aid it here. + */ + if (!max_sectors) + return bio; + if (bio_sectors(bio) <= max_sectors) + return bio; + return bio_submit_split(bio, max_sectors); +} + /** * bio_split_to_limits - split a bio to fit the queue limits * @bio: bio to be split From patchwork Mon Nov 4 06:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13860932 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7E5217583; Mon, 4 Nov 2024 06:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701618; cv=none; b=IOE5gwS7Ui8H84wwi5zCm/dvrmO7GxYedQcZMkeXxDYJamBHvU2UGXsvnbz5Q+nQB9kD/3WBf5Sjma1GhWDBMcbUp6pScrPQmK6NmHWlArfCUK6zgRA2HKYkcHk6XaH41cppitXhm7uAcjkOnODg0W8ltNqTDWllJH2LGQEyXX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701618; c=relaxed/simple; bh=YZuzsXtnbUOLLvjZnxC3IdczgYFmB6LLq/rW8p7spxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MzVfC3VsnC4oDtSldeOm0TYrlWiuUlhpoi1V7jDXStxye/nUI3WtM0Ta0onkWqmAxj+S9B0qmkJn6ShZycmEEI9T9S6EFuvV7jWe7EHljNpWuYAtTDLrx17gcOskIw3wVroWDws9clrWcqkA1zCq5+DcsgGX6G0x+fghutYusrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=jbTc6Shu; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jbTc6Shu" 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=wSc3axFl040BTlkVHJV3xpYsecHplStlVUfIc2n+5R8=; b=jbTc6ShuJQpPXOMh7Rg0XO8+O8 hgdXfmY6FkeDSa4L23Rp4xjFRNVACZcRVxpIORsftD3oRyg+DjATtij0VutygmqLcaSxCXDEuKilU iiaBPESyuvCZx3yQgGrlTYAeugprvNX0/wzT3hovm2Sq0nzjZ0nJNvjj9wxfUW570EiYu1kdf9yoP Nay17h0plV4URGOLAjfKg7XcZO2yHYL6rSu22taXzjwRLKJ6ts8kwI6zf+tOQ0tn9gxSU10Ofw5WS JtXQLJDkgBghm5ixqSahjGOdmqc0pj49m/soo7tYXgbW3gqNAqi+0ZVXwEILqH1Py4eb8WjZ/dwYa svmBP4NQ==; Received: from 2a02-8389-2341-5b80-c843-e027-3367-36ce.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:c843:e027:3367:36ce] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t7qYB-0000000Cl2o-1S1r; Mon, 04 Nov 2024 06:26:55 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 2/5] block: fix bio_split_rw_at to take zone_write_granularity into account Date: Mon, 4 Nov 2024 07:26:30 +0100 Message-ID: <20241104062647.91160-3-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241104062647.91160-1-hch@lst.de> References: <20241104062647.91160-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Otherwise it can create unaligned writes on zoned devices. Fixes: a805a4fa4fa3 ("block: introduce zone_write_granularity limit") Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index f440919b6c6f..4e6c0a52009c 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -287,6 +287,14 @@ static bool bvec_split_segs(const struct queue_limits *lim, return len > 0 || bv->bv_len > max_len; } +static unsigned int bio_split_alignment(struct bio *bio, + const struct queue_limits *lim) +{ + if (op_is_write(bio_op(bio)) && lim->zone_write_granularity) + return lim->zone_write_granularity; + return lim->logical_block_size; +} + /** * bio_split_rw_at - check if and where to split a read/write bio * @bio: [in] bio to be split @@ -349,7 +357,7 @@ int bio_split_rw_at(struct bio *bio, const struct queue_limits *lim, * split size so that each bio is properly block size aligned, even if * we do not use the full hardware limits. */ - bytes = ALIGN_DOWN(bytes, lim->logical_block_size); + bytes = ALIGN_DOWN(bytes, bio_split_alignment(bio, lim)); /* * Bio splitting may cause subtle trouble such as hang when doing sync From patchwork Mon Nov 4 06:26:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13860933 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5211618562F; Mon, 4 Nov 2024 06:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701622; cv=none; b=ShnpqfJHNuaYWJDwiygZjIWdOomF0u5SdbkHoUBsRI9pH3OSNcvb7iTKmoYfgTnlwDd+TmyBzhU0nLGOILMPPklEIUjvbEMMa0jlAKSTGIgj0vxksy8Buyn0mXPZJNZqIM45XDJw3LzmSvGnOvN6Ms8pVCsoQ4iD6D7Fh41ZtT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701622; c=relaxed/simple; bh=g6OYhJEpuFSZK+RD+Rcgv51mtkjmW9XYxjjcxWbViNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FreWuIpmSrD6xdvt70hPERmO53FZi2Bbf1+uilXJkeNi8Mvub0bWF3UNnBHf7PcpM3BjtDzs7j49M9x1D4n2QUw7DdaKUJyCCBJr08cN/AxT0YKP5CGtRJ6N7gDr07bJoLXDf3JQHCpKGGiQhlEFnojbX60xS3G5s2U0mYQD1zU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=n3uGDmY4; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="n3uGDmY4" 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=UQTaU5P/0JZcdZzVmIgMgjW5rz31/6LiQC/DFO7xtXw=; b=n3uGDmY4t4ineTx+aJ9cLtOLal uazOnNWgd2Lggupez2fHbcWkmwkihYnipWBv3hL98CoR5T9S6EkLba4rlpNe2C0VYbJhhGlyPq7Xj jnZxC68d7vkz6tnXx5Zb0eawWQuolDvZiSmLMiyQKgEkCrLfpKx68WMBBQNljvz5qzgGNa0zbmZ/E RkZQ3clseZjim+HYznOpSCmRUq0nopEb7n1KgbOJbZzrq9izHWRkjENflABhrW5q8B9lYtUxvQ9Nm ymccRnDy9LRsH9Xi8Ww6SmCt3fkVf34+U2FfkpWj0dzWeIaF/YCZMosYYx0rHWaTZ5wVeKn5ygKcx XQ88Pdmg==; Received: from 2a02-8389-2341-5b80-c843-e027-3367-36ce.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:c843:e027:3367:36ce] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t7qYE-0000000Cl38-1bvG; Mon, 04 Nov 2024 06:26:59 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, Damien Le Moal Subject: [PATCH 3/5] block: lift bio_is_zone_append to bio.h Date: Mon, 4 Nov 2024 07:26:31 +0100 Message-ID: <20241104062647.91160-4-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241104062647.91160-1-hch@lst.de> References: <20241104062647.91160-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Make bio_is_zone_append globally available, because file systems need to use to check for a zone append bio in their end_io handlers to deal with the block layer emulation. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- block/blk.h | 9 --------- include/linux/bio.h | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/block/blk.h b/block/blk.h index 63d5df0dc29c..6060e1e180a3 100644 --- a/block/blk.h +++ b/block/blk.h @@ -457,11 +457,6 @@ static inline bool bio_zone_write_plugging(struct bio *bio) { return bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING); } -static inline bool bio_is_zone_append(struct bio *bio) -{ - return bio_op(bio) == REQ_OP_ZONE_APPEND || - bio_flagged(bio, BIO_EMULATES_ZONE_APPEND); -} void blk_zone_write_plug_bio_merged(struct bio *bio); void blk_zone_write_plug_init_request(struct request *rq); static inline void blk_zone_update_request_bio(struct request *rq, @@ -510,10 +505,6 @@ static inline bool bio_zone_write_plugging(struct bio *bio) { return false; } -static inline bool bio_is_zone_append(struct bio *bio) -{ - return false; -} static inline void blk_zone_write_plug_bio_merged(struct bio *bio) { } diff --git a/include/linux/bio.h b/include/linux/bio.h index 4a1bf43ca53d..60830a6a5939 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -675,6 +675,23 @@ static inline void bio_clear_polled(struct bio *bio) bio->bi_opf &= ~REQ_POLLED; } +/** + * bio_is_zone_append - is this a zone append bio? + * @bio: bio to check + * + * Check if @bio is a zone append operation. Core block layer code and end_io + * handlers must use this instead of an open coded REQ_OP_ZONE_APPEND check + * because the block layer can rewrite REQ_OP_ZONE_APPEND to REQ_OP_WRITE if + * it is not natively supported. + */ +static inline bool bio_is_zone_append(struct bio *bio) +{ + if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED)) + return false; + return bio_op(bio) == REQ_OP_ZONE_APPEND || + bio_flagged(bio, BIO_EMULATES_ZONE_APPEND); +} + struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev, unsigned int nr_pages, blk_opf_t opf, gfp_t gfp); struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new); From patchwork Mon Nov 4 06:26:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13860934 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9E2A18E055; Mon, 4 Nov 2024 06:27:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701624; cv=none; b=D0q77x53DW/D1ITCFQzHiFMf+YBm+jMCLarfvvw1dTI90EgsWbdQiQVd/SOPirxcybDr7DLBfKrC1L/vM64+Zjnf8ZouscthZP2UNuuBGgVHw575S4YI7f+1PexfXfVmw/yFFC+YDS+Ylbc3qgGpvdYjUTmAuC44kytAzKX+FDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701624; c=relaxed/simple; bh=azT/nFSf6O23BcSY14Qav6wZktxauuKFYgRYZ7pxFzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S2mw9g8yzmEkdBcuWyNcwRtEljOKRVnDpxQ6cMMtDwJAEdr9vqpXn096j1Z66W611ZnHHuu9BbCzTeR/eDDiM5KMmdcdb6xbPI1ouHFw2PmX+TUrF3/vC5gioOhstFE7LCoz8Jaxua4vB6j/ghsydoPDKcN1loeLLWycYdrDoVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=feo4lkFq; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="feo4lkFq" 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=oaCuK3vkoOE1dSVOtHe46/RXy5sHzSmiC0OTM79f9S0=; b=feo4lkFqHb0iC7/NYjKy+EcfRk CBI8OZHgdt4nLXZvT0r87wDZUmIevqWGhPxNz+vpU44BRpFLTxIoyVFF4h5dCvXfgpBHAm4oNpU1i q+nZWmdPPOnE9tcDr+PUipQSaxKpdSJt2SqDh5bsLwi4ba0DV/1dB0AHc2nMuTpSmxRddpRea3KCw Jjisq4TRlOQsXwXr7Aftn2oNReeZUL7zB6AyIcaJIq0j32Uuz06FAyg4nuFhK5ka8XZBRC2oliKaq 9s3nwHhpKE1U8ga2WTZ59H9NWExaHMmRKFK/QypKvWwbkQ8m1iM5jakzDSWlg5YM8KxCNX2m5gnzx PpGSitrQ==; Received: from 2a02-8389-2341-5b80-c843-e027-3367-36ce.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:c843:e027:3367:36ce] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t7qYH-0000000Cl3c-2RTe; Mon, 04 Nov 2024 06:27:02 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, Damien Le Moal Subject: [PATCH 4/5] btrfs: use bio_is_zone_append in the completion handler Date: Mon, 4 Nov 2024 07:26:32 +0100 Message-ID: <20241104062647.91160-5-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241104062647.91160-1-hch@lst.de> References: <20241104062647.91160-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Otherwise it won't catch bios turned into regular writes by the block level zone write plugging. Fixes: 9b1ce7f0c6f8 ("block: Implement zone append emulation") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/btrfs/bio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index fec5c6cde0a7..0f096e226908 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -366,7 +366,7 @@ static void btrfs_simple_end_io(struct bio *bio) INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work); queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work); } else { - if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status) + if (bio_is_zone_append(bio) && !bio->bi_status) btrfs_record_physical_zoned(bbio); btrfs_bio_end_io(bbio, bbio->bio.bi_status); } @@ -409,7 +409,7 @@ static void btrfs_orig_write_end_io(struct bio *bio) else bio->bi_status = BLK_STS_OK; - if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status) + if (bio_is_zone_append(bio) && !bio->bi_status) stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; btrfs_bio_end_io(bbio, bbio->bio.bi_status); @@ -423,7 +423,7 @@ static void btrfs_clone_write_end_io(struct bio *bio) if (bio->bi_status) { atomic_inc(&stripe->bioc->error); btrfs_log_dev_io_error(bio, stripe->dev); - } else if (bio_op(bio) == REQ_OP_ZONE_APPEND) { + } else if (bio_is_zone_append(bio)) { stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; } From patchwork Mon Nov 4 06:26:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13860935 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8322C18E055; Mon, 4 Nov 2024 06:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701626; cv=none; b=Iyvu3uyvxrQhS52IAHlIcSh+hcj3gBnI+tCGpBqkYX6H1UKc98jg/SUpqvoZq1JFHZtCHusGoZ4fhas8vRGfVnp0h4bt85jiQfogxaijL9lHoQbEE7N2nnd8jKjfDO+ysM7tCTjhfxa6Zixew4Jb1HpI/8QUAUWR1BwOKO3lRQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730701626; c=relaxed/simple; bh=x4pZsqaJSIM08917wBINhJVChtdoCgyHeEtOK+95nO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RDYBUFppDJYS491NafFe7Ndbx4T3ZVfvzxABlHyJlT/VcJQy75GNR6Ld9/zgS8D/hB3URD6DUtseH9zKJzgbF/zAbIlJE8uU0Dcvu/VeFjWcoYV1vPVyyo6J1jyWYiOe13aCfnuBCgsYgdZJyW+q+llnjBqN8shZ/dFrLst1vhw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=JUw3j8vh; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="JUw3j8vh" 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=1FR35fBVW6o2eMLvhGFCd1yW8PBeRzvCzSaFkrJ5xdg=; b=JUw3j8vh+gCK69iISx/CnaXE6H 6KaC+OexU3v4NTnd4CMBWUMCkdMM1+X4WL9/ZYbvUXTb82n/57+kKk3Ru9pT1dmg8FkzpccsewvkS kv1vOgOSinB9kFfwcmfOJw9plMCcQWNC3gLiqTJ9/XqBZj3bh6yFjpHWW/6/wyDa+K4OJd3cIeAfb SSOU45ywlPdc6kbWHcgWRE9NbBgRX2njyKMLxTamIKThhcj0eWNT4GBYcCTD6pXwbsFTwtPgVTjB0 iG6OB0ICKqGb3B4xSqumHjRw40jXF2vrTCfRuw2xEROWZumbJuYckKkAYaaIZgX1q2ANIte+L1y98 xeh6QxyA==; Received: from 2a02-8389-2341-5b80-c843-e027-3367-36ce.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:c843:e027:3367:36ce] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t7qYK-0000000Cl3x-0jm6; Mon, 04 Nov 2024 06:27:04 +0000 From: Christoph Hellwig To: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Damien Le Moal Cc: linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, Damien Le Moal Subject: [PATCH 5/5] btrfs: split bios to the fs sector size boundary Date: Mon, 4 Nov 2024 07:26:33 +0100 Message-ID: <20241104062647.91160-6-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241104062647.91160-1-hch@lst.de> References: <20241104062647.91160-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Btrfs like other file systems can't really deal with I/O not aligned to it's internal block size (which strangely is called sector size in btrfs), but the block layer split helper doesn't even know about that. Round down the split boundary so that all I/Os are aligned. Fixes: d5e4377d5051 ("btrfs: split zone append bios in btrfs_submit_bio") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/btrfs/bio.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 0f096e226908..299b9a0ed68b 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -660,8 +660,15 @@ static u64 btrfs_append_map_length(struct btrfs_bio *bbio, u64 map_length) map_length = min(map_length, bbio->fs_info->max_zone_append_size); sector_offset = bio_split_rw_at(&bbio->bio, &bbio->fs_info->limits, &nr_segs, map_length); - if (sector_offset) - return sector_offset << SECTOR_SHIFT; + if (sector_offset) { + /* + * bio_split_rw_at could split at a size smaller than the + * file system sector size and thus cause unaligned I/Os. + * Fix that by always rounding down to the nearest boundary. + */ + return ALIGN_DOWN(sector_offset << SECTOR_SHIFT, + bbio->fs_info->sectorsize); + } return map_length; }