From patchwork Tue Nov 19 12:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879825 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 F1F0E1CC15E; Tue, 19 Nov 2024 12:16:42 +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=1732018604; cv=none; b=k/BICN10ZADUFOPcwtVlyZ6JlUv3nM8JnQUkdR4rrGkBvs+NnNCAbrSQ7yFWSCaDQy3QET08hTOpdwMZiCKcJuO49kj/U537+BcfVTJSRVWVU5N7LmGy38KswqxsjjYeMKd9/G/hrFxt8251TO/JinZgozsIYehMg6Ab4bTqXL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018604; c=relaxed/simple; bh=JQgqvEgFqb4IVq6envaifcExBhdZxCZYD2N+g+Q5dN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mjXTyKtVvPpNxzy2MUzyvkQ4FLhkN24QkNFmS7D2orxwxJBNMYENuo9QOu/DU1AWM00u5S6vXBx7SsYWqMjHlx1dggc58LC7LtvlphFFD+bjJ82gHSJJEhi5syHkohQpOBOEsV7mEyUXC40eYS9HUXvKjmQXnMCPIlOUJm2QTb8= 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=3xt5/xff; 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="3xt5/xff" 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=ZCibf9nDXx/wBVyXnoXvLzPNlRRpMiBGQGPX4h8joGI=; b=3xt5/xffCEazLGpsgTvl0WpGPp b9MvHJMZZQffhmpzey3mme+2rlDzjLBSEc+Is8lvIVwaYMLFr+D2HvxfzyGe7fAgmaIpeI144hQ0h mtpXtJBS6d1nGdO2baaJ0WQEXT1sA/qPBs2m6vcEP5perA+/mL5lMkAeE0+yZVM1URnLmMs7jh0nK GdDUtF2n3Vej4CeRijdVuFfNVZRTkoeANqJ7QkPBkcZLnWEBMk5e+YfUGR0HRG4TT20bd5QnkMUPb 3oVdRE+v0GL6+udey5zJXMFNqS1eAv8+BMTxO1Df3A38QuSdKKLRNrmZc8X7lC2TDTDAz637fZabf 1K+jQQUw==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDN9r-0000000CIry-2H8D; Tue, 19 Nov 2024 12:16:40 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 01/15] fs: add write stream information to statx Date: Tue, 19 Nov 2024 13:16:15 +0100 Message-ID: <20241119121632.1225556-2-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 From: Keith Busch Add new statx field to report the maximum number of write streams supported and the granularity for them. Signed-off-by: Keith Busch [hch: s/write_hint/write_stream/g, add granularity] Signed-off-by: Christoph Hellwig --- fs/stat.c | 2 ++ include/linux/stat.h | 2 ++ include/uapi/linux/stat.h | 7 +++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 41e598376d7e..aa2b7fa4a877 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -704,6 +704,8 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_atomic_write_unit_min = stat->atomic_write_unit_min; tmp.stx_atomic_write_unit_max = stat->atomic_write_unit_max; tmp.stx_atomic_write_segments_max = stat->atomic_write_segments_max; + tmp.stx_write_stream_granularity = stat->write_stream_granularity; + tmp.stx_write_stream_max = stat->write_stream_max; return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } diff --git a/include/linux/stat.h b/include/linux/stat.h index 3d900c86981c..36d4dfb291ab 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -57,6 +57,8 @@ struct kstat { u32 atomic_write_unit_min; u32 atomic_write_unit_max; u32 atomic_write_segments_max; + u32 write_stream_granularity; + u16 write_stream_max; }; /* These definitions are internal to the kernel for now. Mainly used by nfsd. */ diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index 887a25286441..547c62a1a3a7 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -132,9 +132,11 @@ struct statx { __u32 stx_atomic_write_unit_max; /* Max atomic write unit in bytes */ /* 0xb0 */ __u32 stx_atomic_write_segments_max; /* Max atomic write segment count */ - __u32 __spare1[1]; + __u32 stx_write_stream_granularity; /* 0xb8 */ - __u64 __spare3[9]; /* Spare space for future expansion */ + __u16 stx_write_stream_max; + __u16 __sparse2[3]; + __u64 __spare3[8]; /* Spare space for future expansion */ /* 0x100 */ }; @@ -164,6 +166,7 @@ struct statx { #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */ #define STATX_SUBVOL 0x00008000U /* Want/got stx_subvol */ #define STATX_WRITE_ATOMIC 0x00010000U /* Want/got atomic_write_* fields */ +#define STATX_WRITE_STREAM 0x00020000U /* Want/got write_stream_* */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ From patchwork Tue Nov 19 12:16:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879826 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 8671E1CC8A9; Tue, 19 Nov 2024 12:16:46 +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=1732018607; cv=none; b=sKKvVHzDDGPxuquUVreHHPi7tcVMvASBLEF6E4oR+2IkeN6d+mMbnsnuR8Rg+0tUUaTWP9As9YOmp3CNEOeUnKDikT9ODqhm4Q84c3WweF/LTMzk8zZ5NTuUg6cT/oC3inqSAaMlV2Xd8HIgmsekdGqw2ZX0rKkt9XlmZRUnEBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018607; c=relaxed/simple; bh=ItiR6s+X18KllvRMLmnlAHOdna3YMLpNb2rSIE4I//o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CYWWkMRC6UokSf4DfUPJqD9pP7G3vswXkzM0kwKmKovyNH2BLhUw0EfpYdFfeY41yuPexAisCfHxcRHFK0b0qjenQQ71EaHNBnksop1+Wmz/kZN8cNF3bV+o6WajN/Jf8v7e9k4IqPmf0pVlBDrtgJqWujiBQ4fOf+Y2oj7zrgc= 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=ZIZ28wZf; 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="ZIZ28wZf" 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=JRKFVYldGi+Mip7kGl2nMr3ub2NZztZbmnBFCrNHiBg=; b=ZIZ28wZfARIuXO6AXci/O7w4RX DhGMKs7mln6OqKLTL2Xlfhrw3g+3DrPFXymnRkx33jsRU0bHfM7qdZWjgNu2dVrYNR8ugc06+CIxp BYBVT+dMcQkhUn1/8eP3dwAUvGrnUnFrEtyajGTkcgQlXoD7+SFf/HaeC9AyhU2pf4PdfNibNFRgr BCXovDAaehBrIKrZ2gg6yaj+BtguGw+LSaEwc7rrk2sVlS5ViGFjxIfJrTmx5K7renrIVgLf9CZcE WNapHKxDw50aq0eKADFasHnAXlA2Z++AHm40+sfd4XF0s1mofVWHxfksOhw4x8gGj/Wt/BG3qys1H eub5kN/g==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDN9v-0000000CIsh-1otv; Tue, 19 Nov 2024 12:16:44 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 02/15] fs: add a write stream field to the kiocb Date: Tue, 19 Nov 2024 13:16:16 +0100 Message-ID: <20241119121632.1225556-3-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Prepare for io_uring passthrough of write streams. The write stream field in the kiocb structure fits into an existing 2-byte hole, so its size is not changed. Based on a patch from Keith Busch Signed-off-by: Christoph Hellwig --- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 4b5cad44a126..1997be247b6c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -370,6 +370,7 @@ struct kiocb { void *private; int ki_flags; u16 ki_ioprio; /* See linux/ioprio.h */ + u8 ki_write_stream; union { /* * Only used for async buffered reads, where it denotes the From patchwork Tue Nov 19 12:16:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879827 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 868E31CCB38; Tue, 19 Nov 2024 12:16:49 +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=1732018611; cv=none; b=j0Y+q6Hq65OkJMmlY60x+tpHjpWYb4GH7cNc7TehUPUi4RkBcpv50iHdb+6aE14tutt4MLVGkoCmT/c5oOLd5jRCbHeclRqmjSmMxd+rhWvGL02PvQHDlgOU9u2AIem+z2KLEvkrUd5r0J+tv7fW6lRyRtZcXSmbKlkuVHAWLMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018611; c=relaxed/simple; bh=6pxM1bOMRFet6+JOFGsE6KmOLaBM0tWwnKAnjSKCxH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D/hr21eQuXeHlyB5NtLOhDjUgpfPbYwR/1XUmFYs76hau89p8qg5gbCLmmfky8MSNpNy0GuSJxPwhOqCunNXgfu3mk6GssZwZ4lrRniKRC/WXqEcKyY+/ODkbk1Mjm0iqqXQ+MAzWh8/+5YK454QJOzGyhM3T/TpEvJMO1Brt8A= 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=BsPDud3O; 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="BsPDud3O" 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=akv2+qO8RNiZ/MdlD08p6GimzeODp1R3NwsVs3l8fTM=; b=BsPDud3O0GUVpn/5hbXXtIzOcV VFQ0MdlEnxqRcxaA1TvSmWYDn2B90ptdB0B48mB9R0rJlg9AY8RKqWE49xUJu2g6k1+xSPc4Tz812 4VYhHufa9c8uW6bjfRLj7SOY2IEP16+r2IorJ+CWh5V/WnF481bMgeRQ+By+DyZmsqbfXVdc3XQ42 aWFEuPQrfBokLajvky9HFN/wSMrpE+ZrYXrRD3r1LXcWFVBubFtDrNSSjpw2J0RmWVQcoT1nLveQ9 0l+zI5gbg6WilgIzD61DQxs+Y7f+ZGB2H0VBE2iC9xJrla3Wh9DIqdToHT9f3Ucuf1Azn00fVRbcr Pg5iKbmQ==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDN9y-0000000CItq-1hWL; Tue, 19 Nov 2024 12:16:46 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 03/15] io_uring: enable passing a per-io write stream Date: Tue, 19 Nov 2024 13:16:17 +0100 Message-ID: <20241119121632.1225556-4-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 From: Kanchan Joshi Allow userspace to pass a per-I/O write stream in the SQE: __u16 write_stream; Application can query the supported values from the statx max_write_streams field. Unsupported values are ignored by file operations that do not support write streams or rejected with an error by those that support them. Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty Signed-off-by: Keith Busch [hch: s/write_hints/write_streams/g] Signed-off-by: Christoph Hellwig --- include/uapi/linux/io_uring.h | 4 ++++ io_uring/io_uring.c | 2 ++ io_uring/rw.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index aac9a4f8fa9a..7a6a1b3726d3 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -98,6 +98,10 @@ struct io_uring_sqe { __u64 addr3; __u64 __pad2[1]; }; + struct { + __u64 __pad4[1]; + __u16 write_stream; + }; __u64 optval; /* * If the ring is initialized with IORING_SETUP_SQE128, then diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index da8fd460977b..a54da2dd83a1 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3868,6 +3868,8 @@ static int __init io_uring_init(void) BUILD_BUG_SQE_ELEM(46, __u16, __pad3[0]); BUILD_BUG_SQE_ELEM(48, __u64, addr3); BUILD_BUG_SQE_ELEM_SIZE(48, 0, cmd); + BUILD_BUG_SQE_ELEM(48, __u64, __pad4); + BUILD_BUG_SQE_ELEM(56, __u16, write_stream); BUILD_BUG_SQE_ELEM(56, __u64, __pad2); BUILD_BUG_ON(sizeof(struct io_uring_files_update) != diff --git a/io_uring/rw.c b/io_uring/rw.c index cce8bc2ecd3f..88a5b5f65a9b 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -279,7 +279,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe, rw->kiocb.ki_ioprio = get_current_ioprio(); } rw->kiocb.dio_complete = NULL; - + rw->kiocb.ki_write_stream = READ_ONCE(sqe->write_stream); rw->addr = READ_ONCE(sqe->addr); rw->len = READ_ONCE(sqe->len); rw->flags = READ_ONCE(sqe->rw_flags); From patchwork Tue Nov 19 12:16:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879828 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 C1ED71CCEC2; Tue, 19 Nov 2024 12:16:51 +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=1732018613; cv=none; b=jY+2ifJCdgYgjbkVvKtNKj6vs/NG6HmQaYJwOjKqCx7K4BP7x4Dy5knu2YnzB2KjfpZBNwdOX/ug+g9em5XIMEQ7WuMSfWzV1K0UX+Vm/F4D5WBzMXXoUH0bLkV0tuUyLMvSg7juaFIJ9qAnx9Vbzfu78iiqEgo5GX6vt7Wrjn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018613; c=relaxed/simple; bh=vh3ZDsX1PAGo8R4dyemIuOJQPsP5FnOgULIbkZHlY14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AoPdndxW71Iev4ieOvLC3P3n9Z82nbEnYcDx8HySgkK/Jj/vJXPLshY4X2gNFgCX5j9NcGWFg8eck7puQQyaiV7kn8NgWI5iOkWT7b4proRfGvy6oNGe4mEb1B07No6fqKjX3gp4hX5CLbjw65EXqMChirdKDOcefeBIzDMV1qA= 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=HAb0b4GE; 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="HAb0b4GE" 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=QST484Rjm0qjanP7JHElr8kCM2HEOEq9yFeGtbndeP0=; b=HAb0b4GELjvYnlYTmThOOY94MH MVfGgThXUIOnJE6p1YPSrR1hZibMLHhedliUtfvesUvs7SQFgH3R2cu2KPm2pQo+oEXhzB6hgypnl db9ieeHMVdBCahGChdJLmK6pMohbjwYTjD+qa3iZAu/i09+RxjrDwKDNpDHzgQqF+vjO+7KEkTJ+H lSm7eQTBjhk2iwhJiCNC9EHioEuYP7RIDtXNIpcPHSP8mHaetvVvd/t2zNNxuhttFCMg8r3jj1wFo s7yKS6HYYsK2khBRovKXX1GBlN3kSjcvfMW+fKADnosjoav3wffSuQLPUrqla7/PPWD3Fzyr3Nm9E sfEu1yTA==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNA0-0000000CIv8-3seG; Tue, 19 Nov 2024 12:16:49 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 04/15] block: don't bother checking the data direction for merges Date: Tue, 19 Nov 2024 13:16:18 +0100 Message-ID: <20241119121632.1225556-5-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Because it already is encoded in the opcode. Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index e0b28e9298c9..64860cbd5e27 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -864,9 +864,6 @@ static struct request *attempt_merge(struct request_queue *q, if (req_op(req) != req_op(next)) return NULL; - if (rq_data_dir(req) != rq_data_dir(next)) - return NULL; - if (req->bio && next->bio) { /* Don't merge requests with different write hints. */ if (req->bio->bi_write_hint != next->bio->bi_write_hint) @@ -986,10 +983,6 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (req_op(rq) != bio_op(bio)) return false; - /* different data direction or already started, don't merge */ - if (bio_data_dir(bio) != rq_data_dir(rq)) - return false; - /* don't merge across cgroup boundaries */ if (!blk_cgroup_mergeable(rq, bio)) return false; From patchwork Tue Nov 19 12:16:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879829 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 D636F1CCEFE; Tue, 19 Nov 2024 12:16: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=1732018615; cv=none; b=ohkWzUFK/4iijbsYJjH6lOMRmo1vhAHt7joZ3cLe4A2LixXvLcrHB2TiJ7pGEL8CTDTq43JKLu+WN7n9RaRtv7btauIDrZ3TIiNCLEpV5pk33lkKenJVeYliFpIdwPNG3SMJQTuqnW1TCrsig450gdA0ZJSjXOHTb5wSKioGuDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018615; c=relaxed/simple; bh=dLdNBF4zfIru8AAjimD/fY61DLdpN6M7CqjtOUNFGUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YyRx6s+giHdzXRGHYvAYKFeb3W/qFiWEbj5UZVv0B00RgGiNYrZgXsKzNOT2ZkoDd9jUN6KQ+ZsAdZ3iHLAeY9pUJWMO2HcDnbAY0xp4VxU4YNOLf3gh0hlr91GfM9y9kZMbTfxuEu7vwVjNUvlC7mcybsb6CY5EgS28MM5Zj4o= 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=KNLOE6Xn; 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="KNLOE6Xn" 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=UMJbKREIuMD5uCy3FOcLgHhasA9Umujy7x7rg1JjQ9g=; b=KNLOE6XnZ6ADV10pQg6d7nWP2r wino3rNcbnJm9lOCM8+aySOrFKN5yHudGsSKOsPX3sKtJqZSowYs4KtuvtwLGycIbVUc8SeT8gwIW gneceFxUaIgzSWpJOaexV6AMA+/nbADjVJ2a9pWDi8AP/HqJCC0FfQQEVtGAn/7yUS4LgMARSzM5E icjQPrMN69BCXX5sLkOMMW0z+8q6iguaqVd8DtLeWqa9AWNSNmbswHP9Iu40ZlUlIcvC050CR6pfz EE7TXZWy0vaAJZMagWfUZYon37HtGNJAvnlcFrzPIU5FxBcT1jMhTaDqbrx9R1O6AHRvU1sFZCmk0 gWJEbCeA==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNA3-0000000CIwW-20Ae; Tue, 19 Nov 2024 12:16:52 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dan Carpenter Subject: [PATCH 05/15] block: req->bio is always set in the merge code Date: Tue, 19 Nov 2024 13:16:19 +0100 Message-ID: <20241119121632.1225556-6-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 As smatch, which is a lot smarter than me noticed. So remove the checks for it, and condense these checks a bit including the comments stating the obvious. Reported-by: Dan Carpenter Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 64860cbd5e27..e01383c6e534 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -864,14 +864,10 @@ static struct request *attempt_merge(struct request_queue *q, if (req_op(req) != req_op(next)) return NULL; - if (req->bio && next->bio) { - /* Don't merge requests with different write hints. */ - if (req->bio->bi_write_hint != next->bio->bi_write_hint) - return NULL; - if (req->bio->bi_ioprio != next->bio->bi_ioprio) - return NULL; - } - + if (req->bio->bi_write_hint != next->bio->bi_write_hint) + return NULL; + if (req->bio->bi_ioprio != next->bio->bi_ioprio) + return NULL; if (!blk_atomic_write_mergeable_rqs(req, next)) return NULL; @@ -983,26 +979,16 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (req_op(rq) != bio_op(bio)) return false; - /* don't merge across cgroup boundaries */ if (!blk_cgroup_mergeable(rq, bio)) return false; - - /* only merge integrity protected bio into ditto rq */ if (blk_integrity_merge_bio(rq->q, rq, bio) == false) return false; - - /* Only merge if the crypt contexts are compatible */ if (!bio_crypt_rq_ctx_compatible(rq, bio)) return false; - - if (rq->bio) { - /* Don't merge requests with different write hints. */ - if (rq->bio->bi_write_hint != bio->bi_write_hint) - return false; - if (rq->bio->bi_ioprio != bio->bi_ioprio) - return false; - } - + if (rq->bio->bi_write_hint != bio->bi_write_hint) + return false; + if (rq->bio->bi_ioprio != bio->bi_ioprio) + return false; if (blk_atomic_write_mergeable_rq_bio(rq, bio) == false) return false; From patchwork Tue Nov 19 12:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879830 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 E08941CDFC3; Tue, 19 Nov 2024 12:16: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=1732018618; cv=none; b=bNATVQOjy2kcniCGaoYCtnQfNg2OsgN8UKFL8+1T9GHxLAgdo3PnEyGRScNpvI1jqY019ujI9FKQ8GAYp6Fh6wE6FzM4FMJkOwY4BCsc+r9q7vSINOQxu7akYsdVVrFECyOGV+b0wrIT+tXCx29Ka96bYuYujhjN61igDM/ZZA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018618; c=relaxed/simple; bh=ZVGxzpQZSkqWvDD3TpC2hrlv8GOQG7h+efF32UTMDAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZzKULCZlJIHAf0PKWKBe/jjSLrN9ndx2nojLaNeKutavGucH8YYUfi5+trZ4myJDP8Es78W7eVryeW9x9YkCMQltBxvyqFjRjE8IPV9d/R960eJ/r660boAaYeJTyPrHqlcTz6g+ROUHE3eClUJ/kpI9/cbiL2t6AWoekrgFKpg= 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=kFgnoIc/; 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="kFgnoIc/" 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=IuHLWbXl17oUwGr2uJNRZmdZTGTpCXDRWm/qYEw8Z8A=; b=kFgnoIc/cdWeaAdXuvsdfYiWfC U9VSgKLWJU8EJEXwZLXDZ0clTG4T5FXg2IEtvvehXKCil+BEJgFL0CnBdJg20blVlo5f5B2qlt9le qsIsbnbIdoEPzKylF8lKP1ZSbCeusXmqVXsr95hdQJUtgUdt+OSpsCWEPSTSE/JuROXFomBtnlfHj TDAcAGAdfWNakEfPkDDsZ5l6ZH6oZA6t7AJ2bwLPQGPLIjapAFsMJ848T3kNKD3WlO48iUb0eYGSR KDl6+Ac+gLrd1WiM9mamEnJIcBVzlKsC9vuFJCQmpMHRTgRFjvB99VZ80enxfxP37v6+iyGsk1uZ/ vSMDy8iw==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNA6-0000000CIyz-02Zh; Tue, 19 Nov 2024 12:16:54 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 06/15] block: add a bi_write_stream field Date: Tue, 19 Nov 2024 13:16:20 +0100 Message-ID: <20241119121632.1225556-7-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Add the ability to pass a write stream for placement control in the bio. Signed-off-by: Christoph Hellwig --- block/bio.c | 2 ++ block/blk-crypto-fallback.c | 1 + block/blk-merge.c | 4 ++++ block/bounce.c | 1 + include/linux/blk_types.h | 1 + 5 files changed, 9 insertions(+) diff --git a/block/bio.c b/block/bio.c index 699a78c85c75..2aa86edc7cd6 100644 --- a/block/bio.c +++ b/block/bio.c @@ -251,6 +251,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table, bio->bi_flags = 0; bio->bi_ioprio = 0; bio->bi_write_hint = 0; + bio->bi_write_stream = 0; bio->bi_status = 0; bio->bi_iter.bi_sector = 0; bio->bi_iter.bi_size = 0; @@ -827,6 +828,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp) bio_set_flag(bio, BIO_CLONED); bio->bi_ioprio = bio_src->bi_ioprio; bio->bi_write_hint = bio_src->bi_write_hint; + bio->bi_write_stream = bio_src->bi_write_stream; bio->bi_iter = bio_src->bi_iter; if (bio->bi_bdev) { diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index 29a205482617..66762243a886 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -173,6 +173,7 @@ static struct bio *blk_crypto_fallback_clone_bio(struct bio *bio_src) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; bio->bi_write_hint = bio_src->bi_write_hint; + bio->bi_write_stream = bio_src->bi_write_stream; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/block/blk-merge.c b/block/blk-merge.c index e01383c6e534..1e5327fb6c45 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -866,6 +866,8 @@ static struct request *attempt_merge(struct request_queue *q, if (req->bio->bi_write_hint != next->bio->bi_write_hint) return NULL; + if (req->bio->bi_write_stream != next->bio->bi_write_stream) + return NULL; if (req->bio->bi_ioprio != next->bio->bi_ioprio) return NULL; if (!blk_atomic_write_mergeable_rqs(req, next)) @@ -987,6 +989,8 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) return false; if (rq->bio->bi_write_hint != bio->bi_write_hint) return false; + if (rq->bio->bi_write_stream != bio->bi_write_stream) + return false; if (rq->bio->bi_ioprio != bio->bi_ioprio) return false; if (blk_atomic_write_mergeable_rq_bio(rq, bio) == false) diff --git a/block/bounce.c b/block/bounce.c index 0d898cd5ec49..fb8f60f114d7 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -170,6 +170,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; bio->bi_write_hint = bio_src->bi_write_hint; + bio->bi_write_stream = bio_src->bi_write_stream; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index dce7615c35e7..4ca3449ce9c9 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -220,6 +220,7 @@ struct bio { unsigned short bi_flags; /* BIO_* below */ unsigned short bi_ioprio; enum rw_hint bi_write_hint; + u8 bi_write_stream; blk_status_t bi_status; atomic_t __bi_remaining; From patchwork Tue Nov 19 12:16:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879831 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 09B461CDFD1; Tue, 19 Nov 2024 12:16:59 +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=1732018621; cv=none; b=X/9A66aE5V8Fihqs6y41bXzDs5/R+AaW5Xn88XK5gT5oNoRrTUHFONiaTK2MFuczw6XNOF0sstUh/96pKurq1kxOy3KeteaNOfTUrSjRA7rgU793RdczEZLYWzThpKiqeuWdgH+BaYhjKyWwRAFZshOJ0x2QFNuS0Y/9ZiA0+ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018621; c=relaxed/simple; bh=G3OhZoNPeqafjhWSjs/wFTomnt0V6qUyGYnXonXgjF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=idhAnEwlMX88NrBgRhQlXziFdLbhgznyF3lVKAhQWfj+DqxEp+h1KP3KODWpJYevCAbXQsxl2hoZhTDmwxskfm5UOGlFiQCwCsF05I+GGK+OlZK7F0HtdGtnFApBUo/aHxoKDfHbYbjzEPVyL/G/aloUk/dCajEr4WmIKweDRxg= 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=qeePtjZX; 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="qeePtjZX" 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=CvqY3cPqB1wQ6o4YF0pmFYAwVVeww6iPefJx83TZ+DM=; b=qeePtjZXJciAZogkGML+6X6j1J VP5OVB4FsyidKET985y65wtU1NvevhlZNnuszPb/fA3WIHZu2RGUsb72571v2/fozYlLmnce82EKZ evTNAXCco9pSljXXqHadRKhQKvdpiFSI5kSwQFBTiy0XNqWPlHl0Lb1Q+vrYevLIulVyp78VoeSfs YGkNJa1XiDgaJLjOXUJJXY2L0OIJ/DBAsM4W6hUO+zcCsc+2lnC+khHj5bWGMe6yENldCzr/kptTt W5nRq/7yZMUzdOW/WNIcSkzcrt/gwZTnNNzTL8zPZU0VX25bhq52ym9J/oHdqRyTr8Roo4fChJgX8 nGQikq+A==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNA8-0000000CJ1e-3iPv; Tue, 19 Nov 2024 12:16:57 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 07/15] block: introduce max_write_streams queue limit Date: Tue, 19 Nov 2024 13:16:21 +0100 Message-ID: <20241119121632.1225556-8-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 From: Keith Busch Drivers with hardware that support write streams need a way to export how many are available so applications can generically query this. Note: compared to Keith's origina version this does not automatically stack the limit. There is no good way to generically stack them. For mirroring or striping just mirroring the write streams will work, but for everything more complex the stacking drive actually needs to manage them. Signed-off-by: Keith Busch [hch: renamed from max_write_hints to max_write_streams] Signed-off-by: Christoph Hellwig --- Documentation/ABI/stable/sysfs-block | 7 +++++++ block/blk-sysfs.c | 3 +++ include/linux/blkdev.h | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 835361110715..ae8644726422 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -506,6 +506,13 @@ Description: [RO] Maximum size in bytes of a single element in a DMA scatter/gather list. +What: /sys/block//queue/max_write_streams +Date: November 2024 +Contact: linux-block@vger.kernel.org +Description: + [RO] Maximum number of write streams supported, 0 if not + supported. If supported, valid values are 1 through + max_write_streams, inclusive. What: /sys/block//queue/max_segments Date: March 2010 diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 4241aea84161..c514c0cb5e93 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -104,6 +104,7 @@ QUEUE_SYSFS_LIMIT_SHOW(max_segments) QUEUE_SYSFS_LIMIT_SHOW(max_discard_segments) QUEUE_SYSFS_LIMIT_SHOW(max_integrity_segments) QUEUE_SYSFS_LIMIT_SHOW(max_segment_size) +QUEUE_SYSFS_LIMIT_SHOW(max_write_streams) QUEUE_SYSFS_LIMIT_SHOW(logical_block_size) QUEUE_SYSFS_LIMIT_SHOW(physical_block_size) QUEUE_SYSFS_LIMIT_SHOW(chunk_sectors) @@ -446,6 +447,7 @@ QUEUE_RO_ENTRY(queue_max_hw_sectors, "max_hw_sectors_kb"); QUEUE_RO_ENTRY(queue_max_segments, "max_segments"); QUEUE_RO_ENTRY(queue_max_integrity_segments, "max_integrity_segments"); QUEUE_RO_ENTRY(queue_max_segment_size, "max_segment_size"); +QUEUE_RO_ENTRY(queue_max_write_streams, "max_write_streams"); QUEUE_RW_LOAD_MODULE_ENTRY(elv_iosched, "scheduler"); QUEUE_RO_ENTRY(queue_logical_block_size, "logical_block_size"); @@ -580,6 +582,7 @@ static struct attribute *queue_attrs[] = { &queue_max_discard_segments_entry.attr, &queue_max_integrity_segments_entry.attr, &queue_max_segment_size_entry.attr, + &queue_max_write_streams_entry.attr, &queue_hw_sector_size_entry.attr, &queue_logical_block_size_entry.attr, &queue_physical_block_size_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index a1fd0ddce5cf..202e1becd410 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -395,6 +395,8 @@ struct queue_limits { unsigned short max_integrity_segments; unsigned short max_discard_segments; + unsigned short max_write_streams; + unsigned int max_open_zones; unsigned int max_active_zones; @@ -1236,6 +1238,13 @@ static inline unsigned int bdev_max_segments(struct block_device *bdev) return queue_max_segments(bdev_get_queue(bdev)); } +static inline unsigned short bdev_max_write_streams(struct block_device *bdev) +{ + if (bdev_is_partition(bdev)) + return 0; + return bdev_limits(bdev)->max_write_streams; +} + static inline unsigned queue_logical_block_size(const struct request_queue *q) { return q->limits.logical_block_size; From patchwork Tue Nov 19 12:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879832 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 51F1D1CF289; Tue, 19 Nov 2024 12:17: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=1732018623; cv=none; b=tAo9l60cppDUwzamMlJ8FCG6AldPq7zTPD59TIoO1jpTH+ApM5Mihc7z+7uFD0AzgnY0YDPuwTub7BtJwU8IPDOOjd1fs9aqlLW/j+EhkWHaaOvHt48iN44n6N/6mo13QmLEbxZWNJ9FTBx/YhE58dEt13/rYAL5Yulqyl2m2n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018623; c=relaxed/simple; bh=tK1FNVzdgHIIBvw83RVPT/pLcRnmnwTOFgu64lamD28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gPjE22eP7BkcO8WY4yPToV8g2r10aLm7daG9dGPyZ2QJINPF+Sr2lj9lywtOwWUSbAghpb4NBXC1nuwqTL2EVW4ZBWx9aaig3QUeVCnxPiOhbF+9b5Bg1j334rHt2HNvLDquCX38hNOwQG/7le8ebP+Y/oMiECDZwE9CDKWMbS0= 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=Hi+i98Ze; 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="Hi+i98Ze" 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=fiaGOzS1KSxfi38Yqhc2LV5s9eWPffbt+V/ZrP6bNEQ=; b=Hi+i98ZeFrxGdbvrRMqXUysCNQ jxnLn0pWimfexW7NQxQbRmZYyhui+Q8AM+FWggZv87mukrtYTzXvfqO34T5Q4/jrqRR78TgeC167j C+nN/HnL3aW08pkVyVT7Ye+j9EKAw+fYM6Z6IgBHvaeUPJdFM2Ns2q4eTpnQlvLI/S9oWY5Zm2VgP /ZJk+Qhf21mf3oBAQ8Bx7RQ5lcBsZ7rK4YzDs121Q99eku2WZm6g3O9znE/HaKNF/46Dtg+MhfcoZ fflkVZYQKHa82Vme8uFzKoINjv0XX+nw571c+JjOCTiUi3aj1L6AFTpfJ3R7k3qDTO+G94jawhRNH 1tMYJ+ng==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAB-0000000CJ5P-3p2F; Tue, 19 Nov 2024 12:17:00 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 08/15] block: introduce a write_stream_granularity queue limit Date: Tue, 19 Nov 2024 13:16:22 +0100 Message-ID: <20241119121632.1225556-9-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Export the granularity that write streams should be discarded with, as it is essential for making good use of them. Signed-off-by: Christoph Hellwig --- Documentation/ABI/stable/sysfs-block | 8 ++++++++ block/blk-sysfs.c | 3 +++ include/linux/blkdev.h | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index ae8644726422..9f2a3005c41c 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -514,6 +514,14 @@ Description: supported. If supported, valid values are 1 through max_write_streams, inclusive. +What: /sys/block//queue/write_stream_granularity +Date: November 2024 +Contact: linux-block@vger.kernel.org +Description: + [RO] Granularity of a write stream in bytes. The granularity + of a write stream is the size that should be discarded or + overwritten together to avoid write amplification in the device. + What: /sys/block//queue/max_segments Date: March 2010 Contact: linux-block@vger.kernel.org diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index c514c0cb5e93..525f4fa132cd 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -105,6 +105,7 @@ QUEUE_SYSFS_LIMIT_SHOW(max_discard_segments) QUEUE_SYSFS_LIMIT_SHOW(max_integrity_segments) QUEUE_SYSFS_LIMIT_SHOW(max_segment_size) QUEUE_SYSFS_LIMIT_SHOW(max_write_streams) +QUEUE_SYSFS_LIMIT_SHOW(write_stream_granularity) QUEUE_SYSFS_LIMIT_SHOW(logical_block_size) QUEUE_SYSFS_LIMIT_SHOW(physical_block_size) QUEUE_SYSFS_LIMIT_SHOW(chunk_sectors) @@ -448,6 +449,7 @@ QUEUE_RO_ENTRY(queue_max_segments, "max_segments"); QUEUE_RO_ENTRY(queue_max_integrity_segments, "max_integrity_segments"); QUEUE_RO_ENTRY(queue_max_segment_size, "max_segment_size"); QUEUE_RO_ENTRY(queue_max_write_streams, "max_write_streams"); +QUEUE_RO_ENTRY(queue_write_stream_granularity, "write_stream_granularity"); QUEUE_RW_LOAD_MODULE_ENTRY(elv_iosched, "scheduler"); QUEUE_RO_ENTRY(queue_logical_block_size, "logical_block_size"); @@ -583,6 +585,7 @@ static struct attribute *queue_attrs[] = { &queue_max_integrity_segments_entry.attr, &queue_max_segment_size_entry.attr, &queue_max_write_streams_entry.attr, + &queue_write_stream_granularity_entry.attr, &queue_hw_sector_size_entry.attr, &queue_logical_block_size_entry.attr, &queue_physical_block_size_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 202e1becd410..9fda66530d9a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -396,6 +396,7 @@ struct queue_limits { unsigned short max_discard_segments; unsigned short max_write_streams; + unsigned int write_stream_granularity; unsigned int max_open_zones; unsigned int max_active_zones; @@ -1245,6 +1246,12 @@ static inline unsigned short bdev_max_write_streams(struct block_device *bdev) return bdev_limits(bdev)->max_write_streams; } +static inline unsigned int +bdev_write_stream_granularity(struct block_device *bdev) +{ + return bdev_limits(bdev)->write_stream_granularity; +} + static inline unsigned queue_logical_block_size(const struct request_queue *q) { return q->limits.logical_block_size; From patchwork Tue Nov 19 12:16:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879833 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 ADCB31CF5E9; Tue, 19 Nov 2024 12:17:04 +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=1732018626; cv=none; b=lC+tXMGilLFZdmIWEuDkIjdqaPg768WkmS0Yz1MJDpVyJAKFEcEGTsWaWkHzxNmkYna3ogyLO4ssU/T+02H7vrONcqDltbzjOWEzvjt5x093iGkXht00Bx4gjsObW3q+dVoXtRo7TrQX1LcoNx9NrXA4nOrrbiUliHP8j//w6FM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018626; c=relaxed/simple; bh=Dwzh/OpYLSodRjyM0GjZ2OwbD5NSC/lznYETElq1I6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NS/566iW6O7Me6Z6ryLpNbhHkj14QglDOGQ9+eRf/Ac6g+nnfdW7OjPIR6rk+MquyCIBth0qiTtnIK8qjWFuDWw11+DuHf0GPW1Xv9rruNfEKiE4oM1pyxiVmeWuvYMFrXcomWU1xUBUkWpVVPCGfE5MDlc+Jzo1MGfhW+PiY2E= 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=pfYpb1CI; 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="pfYpb1CI" 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=eFnAU/YKrxAyCOfUvcjuy01kOFc9uTpB/T3yj/VVbHA=; b=pfYpb1CIj8PrENBsku6UAQacBw w3a4aG7fE4mHf1ocsBB1gkmOmpeEr8nuBpFbQ+TjkHJPHDWlYhS2whFI6t1q5Fcf/upN96+LzZZB6 0M2NdX+yOKP+4s8ZGt1fP+e39m1c/6niYRonZcEVZHw4EF8g7nH6vIrfsfjZXtHBb30Bc+XEm/hYI 3GdmTZRH10Od6yN1wYAPn60Som2J22Ezz85YFlOywTfWqC4SWyVDJDAxkdsNrUWjQXPM6sAiR4B41 AVIDnBIc58XDWL7du7C61zsY/v9ningkdr+1Fphe7FM68/+qbScEWtNtR4JMaMImhG2Mt0clTIWG9 5bjjW8hg==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAE-0000000CJ83-1nRx; Tue, 19 Nov 2024 12:17:02 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 09/15] block: expose write streams for block device nodes Date: Tue, 19 Nov 2024 13:16:23 +0100 Message-ID: <20241119121632.1225556-10-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Export statx information about the number and granularity of write streams, use the per-kiocb write hint and map temperature hints to write streams (which is a bit questionable, but this shows how it is done). Signed-off-by: Christoph Hellwig --- block/bdev.c | 6 ++++++ block/fops.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index 738e3c8457e7..c23245f1fdfe 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1296,6 +1296,12 @@ void bdev_statx(struct path *path, struct kstat *stat, stat->result_mask |= STATX_DIOALIGN; } + if ((request_mask & STATX_WRITE_STREAM) && + bdev_max_write_streams(bdev)) { + stat->write_stream_max = bdev_max_write_streams(bdev); + stat->result_mask |= STATX_WRITE_STREAM; + } + if (request_mask & STATX_WRITE_ATOMIC && bdev_can_atomic_write(bdev)) { struct request_queue *bd_queue = bdev->bd_queue; diff --git a/block/fops.c b/block/fops.c index 2d01c9007681..2a860dbe5e48 100644 --- a/block/fops.c +++ b/block/fops.c @@ -72,6 +72,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; + bio.bi_write_stream = iocb->ki_write_stream; bio.bi_ioprio = iocb->ki_ioprio; if (iocb->ki_flags & IOCB_ATOMIC) bio.bi_opf |= REQ_ATOMIC; @@ -201,6 +202,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, for (;;) { bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio->bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; + bio->bi_write_stream = iocb->ki_write_stream; bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io; bio->bi_ioprio = iocb->ki_ioprio; @@ -317,6 +319,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, dio->iocb = iocb; bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio->bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; + bio->bi_write_stream = iocb->ki_write_stream; bio->bi_end_io = blkdev_bio_end_io_async; bio->bi_ioprio = iocb->ki_ioprio; @@ -373,6 +376,26 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) if (blkdev_dio_invalid(bdev, iocb, iter)) return -EINVAL; + if (iov_iter_rw(iter) == WRITE) { + u16 max_write_streams = bdev_max_write_streams(bdev); + + if (iocb->ki_write_stream) { + if (iocb->ki_write_stream > max_write_streams) + return -EINVAL; + } else if (max_write_streams) { + enum rw_hint write_hint = + file_inode(iocb->ki_filp)->i_write_hint; + + /* + * Just use the write hint as write stream for block + * device writes. This assumes no file system is + * mounted that would use the streams differently. + */ + if (write_hint <= max_write_streams) + iocb->ki_write_stream = write_hint; + } + } + nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1); if (likely(nr_pages <= BIO_MAX_VECS)) { if (is_sync_kiocb(iocb)) From patchwork Tue Nov 19 12:16:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879834 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 13EF81CFEA9; Tue, 19 Nov 2024 12:17:07 +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=1732018629; cv=none; b=K7QUQzrBHhA7HDXGEZK4re22cfAG0zkbepp8FfvMNiWCo3fi3KqgyOv+M5l+GS15665pCKw7UFMRL5BInnJWfj/ByzvtcCCiWoPe6aP6rqomb5x9kRXMIOdorb7gGP0q0gXRqzw/LahqDS5wEzhONX2e+VXtZTWy5MmA5TKC7qM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018629; c=relaxed/simple; bh=0BkYocf6nlva5SOD91SKI1D9GWHp4nOP7oE/1rBzWII=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cEhEuzwzRohKHtXk4QfdVDkN2GFnSuXjI+42K4Nm7gZcILaZgBP+uKUYAMpWZUmb8jUWM++xxabxTDd7WWD70hCYmj1n3pIaFbXSyDQ6DtSKxKB8f+J3ywWcpR/P3aLly9TcOmZvuBcu47K0U0fF/dJQOYYreyglXsScNa5t2p8= 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=yo8LSWgG; 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="yo8LSWgG" 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=QEFSXa9pfZuyC335Q9FZkYypCzaBxC18nhKs2Bn5gTU=; b=yo8LSWgGsJjg6bOWvHYI8Tz+iY /7ZYBWC0ba8f0srndQWhluBgtb093d4O/vpEp0ldGZ+W7sguDiVZJED56tWGlAP+C4DFnuTQCw0Sc uD9A4r+VjE5l8HvIGMlXKQsr7nfGzf9DUhby7VCQwiID8qVT0z1qrC9oy3DEm4QlgrDnB6UO348PU hLqmNUAZAF+fP74rDlokBx5xoRTu6LXxL99DHklGx53YbH+YUomNT36h88ri1/hs3RsGmY+5z5+dq wdgXKqO2blKYh94BYCMgRWza3KBi4TFSpjph3mFFxnlUVTe7Mc6UYySFIXq5sxrbyEA9grQ+gRzYH cEHMLsiQ==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAG-0000000CJAq-3xFC; Tue, 19 Nov 2024 12:17:05 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 10/15] nvme: store the endurance group id in struct nvme_ns_head Date: Tue, 19 Nov 2024 13:16:24 +0100 Message-ID: <20241119121632.1225556-11-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 The FDP code needs this. Signed-off-by: Christoph Hellwig --- drivers/nvme/host/core.c | 4 ++++ drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1a8d32a4a5c3..d194b36b08ac 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -38,6 +38,7 @@ struct nvme_ns_info { u32 nsid; __le32 anagrpid; u8 pi_offset; + u16 endgid; bool is_shared; bool is_readonly; bool is_ready; @@ -1600,6 +1601,7 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, } info->anagrpid = id->anagrpid; + info->endgid = le16_to_cpu(id->endgid); info->is_shared = id->nmic & NVME_NS_NMIC_SHARED; info->is_readonly = id->nsattr & NVME_NS_ATTR_RO; info->is_ready = true; @@ -1638,6 +1640,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); if (!ret) { info->anagrpid = id->anagrpid; + info->endgid = le16_to_cpu(id->endgid); info->is_shared = id->nmic & NVME_NS_NMIC_SHARED; info->is_readonly = id->nsattr & NVME_NS_ATTR_RO; info->is_ready = id->nstat & NVME_NSTAT_NRDY; @@ -3644,6 +3647,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, head->ids = info->ids; head->shared = info->is_shared; head->rotational = info->is_rotational; + head->endgid = info->endgid; ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1); ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE); kref_init(&head->ref); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 900719c4c70c..9b916a904f00 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -491,6 +491,8 @@ struct nvme_ns_head { struct device cdev_device; struct gendisk *disk; + + u16 endgid; #ifdef CONFIG_NVME_MULTIPATH struct bio_list requeue_list; spinlock_t requeue_lock; From patchwork Tue Nov 19 12:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879835 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 8F4341CFECF; Tue, 19 Nov 2024 12:17:09 +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=1732018630; cv=none; b=qEmZQuEobpRl6O55EwBOT5guZwtTz4iL6klbxexDf3uwIUDN9pNNMton3knATnJbxfW97+gOzOFuFcolBENuq/Bd3HbzDVf/Fyv/rDPb4TMrbgB1Kppwt+nXBWmk3GiIAWPYd7BhtkWhNrzWdtlp2eM2+5QVsGaFNKglIXZYJj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018630; c=relaxed/simple; bh=vnGU4okU53nYgmwOe3httUO+XccGFlcUk+FJra+UCfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HS/3yCdJvqUD0l4j8QLyPNP8FQuIywSsy7bvPB/tRv+RpsLzc1pRMip1scLK9X1Is1fo56lWCBobY26ui098PZ5/Ym0JriJ8ehaNoNrRk1Z61w51qLn99plCiwChqmjuOPEouGijwDraKcI92H7XL0y53XNk3vkusVZtA2QW2To= 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=sli5kFmY; 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="sli5kFmY" 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=gIxXCn1b8yRUHIv/Q/T8s0ufDNDjaj42bcMFpNpW0/4=; b=sli5kFmYL4O16QWe+uEScUndGZ o93i9baryKF3o2gZbKSCP8ro38uRViFjlN7Kvr0d/KnfhXI0o0p4Uca+xfZDKKVY6ewt7ntD5L2/J vuOEYMQW7YJhZuZ6oAh6vxA6wwT5aOTsC7LSoyEsFl/FcUOlh+HZxxt9RQvVvQcekZIEMWfxtMjdA zIu3O2SUkufdCLhoJtyiDND86643nhgE9Jp7XS6xO8ZwrJ7eaU2HT46BTfrCUZuFTI8goqK6XOGmU /zglOJ2G2sLQCvPjDg3M1gLE2a53aQlzhJrFMdGh4Uj1gihc2kJNKQjEs7CtCBmoBZ+dqF6hKgRJg i06CSJNg==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAJ-0000000CJDT-1zwp; Tue, 19 Nov 2024 12:17:08 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 11/15] nvme: pass a void pointer to nvme_get/set_features for the result Date: Tue, 19 Nov 2024 13:16:25 +0100 Message-ID: <20241119121632.1225556-12-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 That allows passing in structures instead of the u32 result, and thus reduce the amount of bit shifting and masking required to parse the result. Signed-off-by: Christoph Hellwig --- drivers/nvme/host/core.c | 4 ++-- drivers/nvme/host/nvme.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d194b36b08ac..0d058276845b 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1671,7 +1671,7 @@ static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid, int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid, unsigned int dword11, void *buffer, size_t buflen, - u32 *result) + void *result) { return nvme_features(dev, nvme_admin_set_features, fid, dword11, buffer, buflen, result); @@ -1680,7 +1680,7 @@ EXPORT_SYMBOL_GPL(nvme_set_features); int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid, unsigned int dword11, void *buffer, size_t buflen, - u32 *result) + void *result) { return nvme_features(dev, nvme_admin_get_features, fid, dword11, buffer, buflen, result); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 9b916a904f00..8cea8416b0d2 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -892,10 +892,10 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, int qid, nvme_submit_flags_t flags); int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid, unsigned int dword11, void *buffer, size_t buflen, - u32 *result); + void *result); int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid, unsigned int dword11, void *buffer, size_t buflen, - u32 *result); + void *result); int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count); void nvme_stop_keep_alive(struct nvme_ctrl *ctrl); int nvme_reset_ctrl(struct nvme_ctrl *ctrl); From patchwork Tue Nov 19 12:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879836 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 CC1001D07B2; Tue, 19 Nov 2024 12:17:12 +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=1732018634; cv=none; b=P0RPfDZFn0yljJx19UG63moT8zzROzJuSF9mT1N7mTe2pcvynsk1Sg4Dy3Pvm4AR3edrpTLREGnQyxKy7zrmc/L9CAbHkldF0M9uumlSZCzg2vFp8hIS3Xo+0ISIs0oPwT3s+VyYZ0F0Bwka22HBkCt+pizvj0X/6vZgWOfuCWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018634; c=relaxed/simple; bh=mM+jJIYJoUQdYmVJ3nz+C2g+egOAaPl06ivxgzm808w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=igkyM0zn0doY7jOlkljJiqSw5PqxCdTXbxpw4Qds+wWGMwsT89DayVWvGOy0gUl/s/w2BM5k2D74MJDmhpI1hmVytyPAyBMcqGz2ndAhPhksv/NCWv28Po2NOceqlsQdCA1as8PtCHnmLUlTHM2EkUWZGEqXvQEzXLSqpOmgrSE= 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=se4b/Ja2; 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="se4b/Ja2" 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=dP9K1xCe3x7QngHbD7VKt4NIpaWi7nUk7H9PVbWTde0=; b=se4b/Ja2hdUcjFBstF7JQRd3VT 9/VmqBpHjD3r5C4T1zh4kpZKEOhDo3FjHyAdbp9Qs7Vtw6yNRD6p0W9+nyQqVw8cuA35lDgZFfPtz n57SPZMbN9tk300kCv7Xe9pK0dRpMGjx0DAwklgIgwbxNFldITEL3CJRK9ozOu5m9vMfaeH8aMaVd 86MjI8r92h+HUD+6SOTPM22cDaFWGAQS8/nJspAh2knXG7N1ZKf5bEDCTJ2z5dLCV0YVm6U+ntxz8 z1W2qtW+hmlsN39ZRvP9p3QnU4IdiskMe+jqiXh9NFCvgWibX0ctzI8seBWGlmG5Qub+2323rIB8U 4c+EtKlw==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAM-0000000CJGE-0iRu; Tue, 19 Nov 2024 12:17:10 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 12/15] nvme: add a nvme_get_log_lsi helper Date: Tue, 19 Nov 2024 13:16:26 +0100 Message-ID: <20241119121632.1225556-13-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 log pages that need to pass in a LSI value, while at the same time not touching all the existing nvme_get_log callers. Signed-off-by: Christoph Hellwig --- drivers/nvme/host/core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 0d058276845b..b61225201b47 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -151,6 +151,8 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, unsigned nsid); static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, struct nvme_command *cmd); +static int nvme_get_log_lsi(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, + u8 lsp, u8 csi, void *log, size_t size, u64 offset, u16 lsi); void nvme_queue_scan(struct nvme_ctrl *ctrl) { @@ -3069,8 +3071,8 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) return ret; } -int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, - void *log, size_t size, u64 offset) +static int nvme_get_log_lsi(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, + u8 lsp, u8 csi, void *log, size_t size, u64 offset, u16 lsi) { struct nvme_command c = { }; u32 dwlen = nvme_bytes_to_numd(size); @@ -3084,10 +3086,18 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, c.get_log_page.lpol = cpu_to_le32(lower_32_bits(offset)); c.get_log_page.lpou = cpu_to_le32(upper_32_bits(offset)); c.get_log_page.csi = csi; + c.get_log_page.lsi = cpu_to_le16(lsi); return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); } +int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, + void *log, size_t size, u64 offset) +{ + return nvme_get_log_lsi(ctrl, nsid, log_page, lsp, csi, log, size, + offset, 0); +} + static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, struct nvme_effects_log **log) { From patchwork Tue Nov 19 12:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879837 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 CFB3C1CC88B; Tue, 19 Nov 2024 12:17:15 +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=1732018637; cv=none; b=Miv0QstU9wBlJ8HG02aWMfIHvc+0ONO3yA29+o1GceGZEJiF8JFIVF2MhVq8CtUF+lBEn3YHL60Doocpwy+RcfXdu1asyCN6zwWxB3Y9dHMDfS9gA83HgtX5f0u59K1OKrehRcqcJHcnJMoOJ+WdUbvtexpso6LuyITen1Jmjyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018637; c=relaxed/simple; bh=aqU70x+8JE4cK6pEiSOjRyQrfvHp/gG8+/zpYsNt59U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gdpjVCPOnM+jhWRkUYbCH86VZFxkOarOmUVCZ5Yjn10ZJeKOyXFp+Lo06h8BzMQ4tBdL3CeweNlQDPxQRx7ULu9E7viOwiD4YWUgUFtyLSA4TC24/sH9C+DKk8IWLnF98cdzFpeGdUSSMqzG4wKGDrp/uCN8PbuAkdsD0rOdZrc= 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=sZ8feOWB; 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="sZ8feOWB" 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=/D7d7RbaAdY6pT96Lch3FWUHj0+0Tnm1oMwJv1RL0mM=; b=sZ8feOWBJgRHUWno1tFS9M53vp n8Ne0smuC5Co1pbsKu/Sxz8ru8ylt9WMnskOaI8ADHHhH8i+pSgjsGBBEkSMTZKjvewKf1XOzMNXd TIIDeXkNKanZwBupnwGsm2fFB46hheCO3a0/cN+dNZyVgE9i8McMnM+Dg9zN6hudKqdGSfERFV5xC QaVZrezrNKWqKDEkRlgGw06X72NGWhPp82S5ziX1t16A1w7cTpueMIXtz8nXYgqk5S9HLHCIrwYpA fVKePr+y7rKngxqq/GkAn/ptLuWvIhMzPG3znieHHBzTNuD3qVqxX8m+9zw0RsnYx3docdAj1eDej 7yYZ0J9Q==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAO-0000000CJJV-2vTw; Tue, 19 Nov 2024 12:17:13 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 13/15] nvme.h: add FDP definitions Date: Tue, 19 Nov 2024 13:16:27 +0100 Message-ID: <20241119121632.1225556-14-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Add the config feature result, config log page, and management receive commands needed for FDP. Partially based on a patch from Kanchan Joshi . Signed-off-by: Christoph Hellwig --- include/linux/nvme.h | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 0a6e22038ce3..0c4a81bf878e 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -275,6 +275,7 @@ enum nvme_ctrl_attr { NVME_CTRL_ATTR_HID_128_BIT = (1 << 0), NVME_CTRL_ATTR_TBKAS = (1 << 6), NVME_CTRL_ATTR_ELBAS = (1 << 15), + NVME_CTRL_ATTR_FDPS = (1 << 19), }; struct nvme_id_ctrl { @@ -656,6 +657,44 @@ struct nvme_rotational_media_log { __u8 rsvd24[488]; }; +struct nvme_fdp_config { + __u8 flags; +#define FDPCFG_FDPE (1U << 0) + __u8 fdpcidx; + __le16 reserved; +}; + +struct nvme_fdp_ruh_desc { + __u8 ruht; + __u8 reserved[3]; +}; + +struct nvme_fdp_config_desc { + __le16 size; + __u8 fdpa; + __u8 vss; + __le32 nrg; + __le16 nruh; + __le16 maxpids; + __le32 nnss; + __le64 runs; + __le32 erutl; + __u8 reserved[36]; + struct nvme_fdp_ruh_desc ruhs[]; +}; + +struct nvme_fdp_config_log { + __le16 n; + __u8 version; + __u8 reserved; + __le32 size; + __u8 reserved2[8]; + /* + * This is followed by variable number of nvme_fdp_config_desc + * structures, but sparse doesn't like nested variable sized arrays. + */ +}; + struct nvme_smart_log { __u8 critical_warning; __u8 temperature[2]; @@ -882,6 +921,7 @@ enum nvme_opcode { nvme_cmd_resv_register = 0x0d, nvme_cmd_resv_report = 0x0e, nvme_cmd_resv_acquire = 0x11, + nvme_cmd_io_mgmt_recv = 0x12, nvme_cmd_resv_release = 0x15, nvme_cmd_zone_mgmt_send = 0x79, nvme_cmd_zone_mgmt_recv = 0x7a, @@ -903,6 +943,7 @@ enum nvme_opcode { nvme_opcode_name(nvme_cmd_resv_register), \ nvme_opcode_name(nvme_cmd_resv_report), \ nvme_opcode_name(nvme_cmd_resv_acquire), \ + nvme_opcode_name(nvme_cmd_io_mgmt_recv), \ nvme_opcode_name(nvme_cmd_resv_release), \ nvme_opcode_name(nvme_cmd_zone_mgmt_send), \ nvme_opcode_name(nvme_cmd_zone_mgmt_recv), \ @@ -1054,6 +1095,7 @@ enum { NVME_RW_PRINFO_PRCHK_GUARD = 1 << 12, NVME_RW_PRINFO_PRACT = 1 << 13, NVME_RW_DTYPE_STREAMS = 1 << 4, + NVME_RW_DTYPE_DPLCMT = 2 << 4, NVME_WZ_DEAC = 1 << 9, }; @@ -1141,6 +1183,38 @@ struct nvme_zone_mgmt_recv_cmd { __le32 cdw14[2]; }; +struct nvme_io_mgmt_recv_cmd { + __u8 opcode; + __u8 flags; + __u16 command_id; + __le32 nsid; + __le64 rsvd2[2]; + union nvme_data_ptr dptr; + __u8 mo; + __u8 rsvd11; + __u16 mos; + __le32 numd; + __le32 cdw12[4]; +}; + +enum { + NVME_IO_MGMT_RECV_MO_RUHS = 1, +}; + +struct nvme_fdp_ruh_status_desc { + __le16 pid; + __le16 ruhid; + __le32 earutr; + __le64 ruamw; + __u8 reserved[16]; +}; + +struct nvme_fdp_ruh_status { + __u8 rsvd0[14]; + __le16 nruhsd; + struct nvme_fdp_ruh_status_desc ruhsd[]; +}; + enum { NVME_ZRA_ZONE_REPORT = 0, NVME_ZRASF_ZONE_REPORT_ALL = 0, @@ -1276,6 +1350,7 @@ enum { NVME_FEAT_PLM_WINDOW = 0x14, NVME_FEAT_HOST_BEHAVIOR = 0x16, NVME_FEAT_SANITIZE = 0x17, + NVME_FEAT_FDP = 0x1d, NVME_FEAT_SW_PROGRESS = 0x80, NVME_FEAT_HOST_ID = 0x81, NVME_FEAT_RESV_MASK = 0x82, @@ -1296,6 +1371,7 @@ enum { NVME_LOG_ANA = 0x0c, NVME_LOG_FEATURES = 0x12, NVME_LOG_RMI = 0x16, + NVME_LOG_FDP_CONFIGS = 0x20, NVME_LOG_DISC = 0x70, NVME_LOG_RESERVATION = 0x80, NVME_FWACT_REPL = (0 << 3), @@ -1883,6 +1959,7 @@ struct nvme_command { struct nvmf_auth_receive_command auth_receive; struct nvme_dbbuf dbbuf; struct nvme_directive_cmd directive; + struct nvme_io_mgmt_recv_cmd imr; }; }; From patchwork Tue Nov 19 12:16:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13879838 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 EE5DC1D0E10; Tue, 19 Nov 2024 12:17:18 +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=1732018640; cv=none; b=ayWvZzClS4hPr1qTdKHIfv3sOnBe2Obad1YvbPlybcHOwr6wTucuZq8/ajy+7VQadJWTdRFN6VKoERWbp3IJAqOjAxc8osaQU+DEnN7GDP49eflP3aDpIe9IqqnqChRy6jNIh8V3WztVG8BNISXdEgKpOGetTfhs8Cl7hJyfe7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018640; c=relaxed/simple; bh=J/BBIHLXbfQ1xNijrjooKssM5rtn8HvBrlUm1US2obk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L7Np653T/XA4+4T9pgynrpdUXVpn3+BS3ZQsKu3/lp/Pm8FryzGdARV4mhNtFa01Il9ou6RWZX6vCwOfH6JR/specjFtnGLtfvs/u3gVqjj5c6sxuLqEH+GzitW6hKCKNVrD6gHoqO62iE5a8GI23+LI7F/Wt6qsYprpi6ebDFs= 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=iX6N5usS; 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="iX6N5usS" 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=hUzFZ+6FshEO8qDOzDKYYt7UzsaW6ENPIVFJY3i4Ksc=; b=iX6N5usSzl5VUxc9vsJlWn6NU1 EL9wo40+nmZF8v0f4dY0502RtQn+SvrFmDAPVVW5K+UWkUrYCAiir3O6Ms8mK0Uiiqr6Ap4BApEpg CCebaH+Ojm3AJRFc73fC3GP1SfW7g5oCgcn2pNahsVFHmIqw5eIPljGNXQHqF74UGMB6qNvggkwxI fzRJHHEyhcRgzikQ8TaAT0J9sRGU1LWOFnl3HnJ32T4UoO2Cev7tuZPmZY/GpakmPqGIs08X9PLue R9VtzppUNmcAWtYoGz4ZFkEqHIwuR21jhsLtLQUjDy75HnhTU2Xm07VchUGwei2VulgBxu2AxpOrZ JVVGAPuw==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAR-0000000CJMO-0zoF; Tue, 19 Nov 2024 12:17:15 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 14/15] nvme: enable FDP support Date: Tue, 19 Nov 2024 13:16:28 +0100 Message-ID: <20241119121632.1225556-15-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 Wire up the block level write streams to the NVMe Flexible Data Placement (FDP) feature as ratified in TP 4146a. Based on code from Kanchan Joshi , Hui Qi , Nitesh Shetty and Keith Busch , but a lot of it has been rewritten to fit the block layer write stream infrastructure. Signed-off-by: Christoph Hellwig --- drivers/nvme/host/core.c | 129 +++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 4 ++ 2 files changed, 133 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index b61225201b47..543bbe7de063 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -673,6 +673,7 @@ static void nvme_free_ns_head(struct kref *ref) ida_free(&head->subsys->ns_ida, head->instance); cleanup_srcu_struct(&head->srcu); nvme_put_subsystem(head->subsys); + kfree(head->plids); kfree(head); } @@ -990,6 +991,15 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + if (op == nvme_cmd_write && ns->head->nr_plids) { + u16 write_stream = req->bio->bi_write_stream; + + if (WARN_ON_ONCE(write_stream > ns->head->nr_plids)) + return BLK_STS_INVAL; + dsmgmt |= ns->head->plids[write_stream - 1] << 16; + control |= NVME_RW_DTYPE_DPLCMT; + } + if (req->cmd_flags & REQ_ATOMIC && !nvme_valid_atomic_write(req)) return BLK_STS_INVAL; @@ -2142,6 +2152,107 @@ static int nvme_update_ns_info_generic(struct nvme_ns *ns, return ret; } +static int nvme_read_fdp_config(struct nvme_ns *ns, struct nvme_ns_info *info) +{ + struct nvme_fdp_config result; + struct nvme_fdp_config_log *log; + struct nvme_fdp_config_desc *configs; + size_t log_size; + int error; + + error = nvme_get_features(ns->ctrl, NVME_FEAT_FDP, info->endgid, NULL, + 0, &result); + if (error) + return error; + + if (!(result.flags & FDPCFG_FDPE)) { + dev_warn(ns->ctrl->device, "FDP not enable in current config\n"); + return -EINVAL; + } + + log_size = sizeof(*log) + (result.fdpcidx + 1) * sizeof(*configs); + log = kmalloc(log_size, GFP_KERNEL); + if (!log) + return -ENOMEM; + + error = nvme_get_log_lsi(ns->ctrl, info->nsid, NVME_LOG_FDP_CONFIGS, + 0, 0, log, log_size, 0, info->endgid); + if (error) { + dev_warn(ns->ctrl->device, + "failed to read FDP config log: 0x%x\n", error); + goto out_free_log; + } + + if (le32_to_cpu(log->size) < log_size) { + dev_warn(ns->ctrl->device, "FDP log too small: %d vs %zd\n", + le32_to_cpu(log->size), log_size); + error = -EINVAL; + goto out_free_log; + } + + configs = (struct nvme_fdp_config_desc *)(log + 1); + if (le32_to_cpu(configs[result.fdpcidx].nrg) > 1) { + dev_warn(ns->ctrl->device, "FDP NRG > 1 not supported\n"); + return -EINVAL; + } + ns->head->runs = le64_to_cpu(configs[result.fdpcidx].runs); + +out_free_log: + kfree(log); + return error; +} + +static int nvme_fetch_fdp_plids(struct nvme_ns *ns, u32 nsid) +{ + struct nvme_ns_head *head = ns->head; + struct nvme_fdp_ruh_status *ruhs; + const unsigned int max_nr_plids = S8_MAX - 1; + size_t size = struct_size(ruhs, ruhsd, max_nr_plids); + struct nvme_command c = { + .imr.opcode = nvme_cmd_io_mgmt_recv, + .imr.nsid = cpu_to_le32(nsid), + .imr.mo = NVME_IO_MGMT_RECV_MO_RUHS, + .imr.numd = cpu_to_le32(nvme_bytes_to_numd(size)), + }; + int ret, i; + + ruhs = kzalloc(size, GFP_KERNEL); + if (!ruhs) + return -ENOMEM; + + ret = nvme_submit_sync_cmd(ns->queue, &c, ruhs, size); + if (ret) { + dev_warn(ns->ctrl->device, + "failed to read FDP reclaim unit handles: 0x%x\n", ret); + goto out; + } + + ns->head->nr_plids = le16_to_cpu(ruhs->nruhsd); + if (!ns->head->nr_plids) + goto out; + + if (ns->head->nr_plids > max_nr_plids) { + dev_info(ns->ctrl->device, + "capping max write streams from %d to %d\n", + ns->head->nr_plids, max_nr_plids); + ns->head->nr_plids = max_nr_plids; + } + + head->plids = kcalloc(ns->head->nr_plids, sizeof(head->plids), + GFP_KERNEL); + if (!head->plids) { + ret = -ENOMEM; + goto out; + } + + for (i = 0; i < ns->head->nr_plids; i++) + head->plids[i] = le16_to_cpu(ruhs->ruhsd[i].pid); + +out: + kfree(ruhs); + return ret; +} + static int nvme_update_ns_info_block(struct nvme_ns *ns, struct nvme_ns_info *info) { @@ -2178,6 +2289,18 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, goto out; } + if (!(ns->ctrl->ctratt & NVME_CTRL_ATTR_FDPS)) { + ns->head->nr_plids = 0; + kfree(ns->head->plids); + ns->head->plids = NULL; + } else if (!ns->head->plids) { + ret = nvme_read_fdp_config(ns, info); + if (!ret) + ret = nvme_fetch_fdp_plids(ns, info->nsid); + if (ret < 0) + goto out; + } + blk_mq_freeze_queue(ns->disk->queue); ns->head->lba_shift = id->lbaf[lbaf].ds; ns->head->nuse = le64_to_cpu(id->nuse); @@ -2211,6 +2334,10 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, if (!nvme_init_integrity(ns->head, &lim, info)) capacity = 0; + lim.max_write_streams = ns->head->nr_plids; + if (lim.max_write_streams) + lim.write_stream_granularity = ns->head->runs; + ret = queue_limits_commit_update(ns->disk->queue, &lim); if (ret) { blk_mq_unfreeze_queue(ns->disk->queue); @@ -2313,6 +2440,8 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) ns->head->disk->flags |= GENHD_FL_HIDDEN; else nvme_init_integrity(ns->head, &lim, info); + lim.max_write_streams = ns_lim->max_write_streams; + lim.write_stream_granularity = ns_lim->write_stream_granularity; ret = queue_limits_commit_update(ns->head->disk->queue, &lim); set_capacity_and_notify(ns->head->disk, get_capacity(ns->disk)); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 8cea8416b0d2..f10aa0cb6df5 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -493,6 +493,10 @@ struct nvme_ns_head { struct gendisk *disk; u16 endgid; + u16 nr_plids; + u16 *plids; + u64 runs; + #ifdef CONFIG_NVME_MULTIPATH struct bio_list requeue_list; spinlock_t requeue_lock; From patchwork Tue Nov 19 12:16: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: 13879839 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 064E01D0E3A; Tue, 19 Nov 2024 12:17:20 +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=1732018642; cv=none; b=maLenixWJr2KI9/8mWwp313dEQLo8dRkQWb2fwYkOEuYs1NFa5bT9v5O5P2JeMPpEFvdh0k/OoGq3iHc7wv1gH2W7uFGvCeFKVMTsyRTf61cahDTan2GuTTIdf5ukZdxwiboAxEZIKSF0p4lBPaJaMkniz86rcvrQ7V1SleZ3xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732018642; c=relaxed/simple; bh=0mruMxanft8RAOOhOn+R3dNkn6CDPrf8czsoxHAKvXs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lvic9p91K4ZYNM+s+0Vtla7RuXqvRt4W7SC2Z2ClFfe6O4y7oz4oARySN+2cijIt2WbDyWO6sHQKKZb4evS0+ZxVb7MrePkb0jqPEBYe98WOAz6fj2A0xQdE/9zXGicMoD3dRYhinKcJ/Rb9nZLyyZ/m7WoihW+OCG9PBguOsNY= 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=MGZmuUG5; 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="MGZmuUG5" 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=hi5wiGxgAmC0Cdjfsdl0g9zpBk10TijhAP5DsB115+4=; b=MGZmuUG5w97cSfwF4J9cGxZDwy aQzYCs6GoMDxhAgTIEdPCDR6J1HIu4GhTxJAg+TsGHVkk68cn8ptBmGgiYZCzLdkLJGIcLfNWZSKn X7q5icZsgLRFz1BosbfqEbsldSPfV4+7g4iZKzDrLyq5slY16l4mXKUdi2RrWb/phgNLkeNH5QEma //fyzeaQaMnHJ+d2K7tgHHVz4CKSUJqddal4HKFBZMND34ccirDLLdDAzvSKdtxXu2zQFayvqFQhT PzgpO19j/8Ew8xuL9cJW24D1IVNkQ2MH53TMv0abWK0UvDfi+ZhoPGrAA0NBQAlsPMnAzR++RjZiO tDWKDm7Q==; Received: from 2a02-8389-2341-5b80-1731-a089-d2b1-3edf.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:1731:a089:d2b1:3edf] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tDNAT-0000000CJP8-3EaH; Tue, 19 Nov 2024 12:17:18 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Christian Brauner , Keith Busch , Sagi Grimberg , Kanchan Joshi , Hui Qi , Nitesh Shetty , Jan Kara , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH 15/15] RFC: block: allow write streams on partitions Date: Tue, 19 Nov 2024 13:16:29 +0100 Message-ID: <20241119121632.1225556-16-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121632.1225556-1-hch@lst.de> References: <20241119121632.1225556-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 By default assign all write streams to partition 1, and add a hack sysfs files that distributes them all equally. This is implemented by storing the number of per-partition write streams in struct block device, as well as the offset to the global ones, and then remapping the write streams in the I/O submission path. The sysfs is hacky and undocumented, better suggestions welcome from actual users of write stream on partitions. Signed-off-by: Christoph Hellwig --- block/bdev.c | 9 +++++++ block/blk-core.c | 2 ++ block/genhd.c | 52 +++++++++++++++++++++++++++++++++++++++ block/partitions/core.c | 6 +++-- include/linux/blk_types.h | 7 ++++++ include/linux/blkdev.h | 2 +- 6 files changed, 75 insertions(+), 3 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index c23245f1fdfe..f3549a8cdb3f 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -440,6 +440,15 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) return NULL; } bdev->bd_disk = disk; + + /* + * Assign all write streams to the first partition by default. + */ + if (partno == 1) { + bdev->bd_part_write_stream_start = 0; + bdev->bd_part_write_streams = bdev_max_write_streams(bdev); + } + return bdev; } diff --git a/block/blk-core.c b/block/blk-core.c index 666efe8fa202..9654937f9b2d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -574,6 +574,8 @@ static int blk_partition_remap(struct bio *bio) return -EIO; if (bio_sectors(bio)) { bio->bi_iter.bi_sector += p->bd_start_sect; + if (bio->bi_write_stream) + bio->bi_write_stream += p->bd_part_write_stream_start; trace_block_bio_remap(bio, p->bd_dev, bio->bi_iter.bi_sector - p->bd_start_sect); diff --git a/block/genhd.c b/block/genhd.c index 79230c109fca..3156c70522b6 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1070,6 +1070,54 @@ static ssize_t partscan_show(struct device *dev, return sysfs_emit(buf, "%u\n", disk_has_partscan(dev_to_disk(dev))); } +static ssize_t disk_distribute_write_streams_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + /* Anything useful to show here like the ranges? */ + return sysfs_emit(buf, "0\n"); +} + +static ssize_t disk_distribute_write_streams_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct gendisk *disk = dev_to_disk(dev); + struct block_device *bdev = disk->part0, *part; + unsigned short total_write_streams = + disk->queue->limits.max_write_streams; + unsigned short part_write_streams, part_write_stream_start = 0; + unsigned long nr_partitions = 0, idx; + int error = 0; + + if (!total_write_streams) + return -EINVAL; + + mutex_lock(&disk->open_mutex); + if (atomic_read(&bdev->bd_openers)) { + error = -EBUSY; + goto out_unlock; + } + + xa_for_each_start(&disk->part_tbl, idx, part, 1) + nr_partitions++; + if (!nr_partitions) + goto out_unlock; + + part_write_streams = total_write_streams / nr_partitions; + xa_for_each_start(&disk->part_tbl, idx, part, 1) { + part->bd_part_write_streams = part_write_streams; + part->bd_part_write_stream_start = part_write_stream_start; + part_write_stream_start += part_write_streams; + dev_info(dev, + "assigning %u write streams at %u to partition %lu\n", + part_write_streams, part_write_stream_start, idx - 1); + } +out_unlock: + mutex_unlock(&disk->open_mutex); + if (error) + return error; + return count; +} + static DEVICE_ATTR(range, 0444, disk_range_show, NULL); static DEVICE_ATTR(ext_range, 0444, disk_ext_range_show, NULL); static DEVICE_ATTR(removable, 0444, disk_removable_show, NULL); @@ -1084,6 +1132,9 @@ static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL); static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store); static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL); static DEVICE_ATTR(partscan, 0444, partscan_show, NULL); +static DEVICE_ATTR(distribute_write_streams, 0644, + disk_distribute_write_streams_show, + disk_distribute_write_streams_store); #ifdef CONFIG_FAIL_MAKE_REQUEST ssize_t part_fail_show(struct device *dev, @@ -1135,6 +1186,7 @@ static struct attribute *disk_attrs[] = { &dev_attr_events_poll_msecs.attr, &dev_attr_diskseq.attr, &dev_attr_partscan.attr, + &dev_attr_distribute_write_streams.attr, #ifdef CONFIG_FAIL_MAKE_REQUEST &dev_attr_fail.attr, #endif diff --git a/block/partitions/core.c b/block/partitions/core.c index 815ed33caa1b..a27dbb5589ce 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -245,8 +245,10 @@ static const struct attribute_group *part_attr_groups[] = { static void part_release(struct device *dev) { - put_disk(dev_to_bdev(dev)->bd_disk); - bdev_drop(dev_to_bdev(dev)); + struct block_device *part = dev_to_bdev(dev); + + put_disk(part->bd_disk); + bdev_drop(part); } static int part_uevent(const struct device *dev, struct kobj_uevent_env *env) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 4ca3449ce9c9..02a3d58e814f 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -74,6 +74,13 @@ struct block_device { #ifdef CONFIG_SECURITY void *bd_security; #endif + + /* + * Allow assigning write streams to partitions. + */ + unsigned short bd_part_write_streams; + unsigned short bd_part_write_stream_start; + /* * keep this out-of-line as it's both big and not needed in the fast * path diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9fda66530d9a..bb0921e642fb 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1242,7 +1242,7 @@ static inline unsigned int bdev_max_segments(struct block_device *bdev) static inline unsigned short bdev_max_write_streams(struct block_device *bdev) { if (bdev_is_partition(bdev)) - return 0; + return bdev->bd_part_write_streams; return bdev_limits(bdev)->max_write_streams; }