From patchwork Tue Oct 29 15:19:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13855080 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 3B506194A68 for ; Tue, 29 Oct 2024 15:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215200; cv=none; b=jgyoPzVwBHicSl+vRWLH468zCVIrWPAq5vN1XwrNTRqbC4fFlXSDisQlaT4QgmDP7XfqfuqPjA8iAlnBD7jkPiFB4xtXE/YMMfzWpGSyIgMJmYBJx42FTHTMIQZfCE2BL9RFztiJILgOrICLhMpYNBfikseuhzVrCUJCaGfS8VA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215200; c=relaxed/simple; bh=RTkTfNmlAK9/4u2bWiR0BiAR3mMG6QfKEBlAYe5AaEU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GmjBHg7gQjXhI3uZ0jdZabYpaQiFbMtFKk3ogLruyTGrXHN2DOXG84okQ4/KXq0mnLWQtUx3CmfvqaMABUdpYEAWFTyywhg+4+WPV9GPBFr8nPv9OQlZ6joZmXomMP0tQfNdSqAe3y6195bL338tv5pYaxOp9/PoQuyUO2z9lP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=GiVZVm5W; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="GiVZVm5W" Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49T72Trl012612 for ; Tue, 29 Oct 2024 08:19:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=KkMsdiy6+G613EM2iVNE1sWpzDf7A70uir1Q/qyFKn0=; b=GiVZVm5W+RXT zyP06X7gCJqRTFYdNORXxwmh6xw7VUUpi0VQfY3gwYgE/BB4Vzw5jFbrIiirlIAr +4VC7U26lB3w9WiUzypItJv0eIIUdYrwEhObziPttAgbNRDgVFXqR3xnWpNt4KZL Xq1U3pXWtcvZJX9ekGOEFXC+0w3Vz5cY2j7Y0I7eNk7gMXcci8Z6guhm9L1S+dUE Z8KwcmGKbQ6lIvKhEbc2IDrIgeCpY1PZTwIHNuqZNz6W2M+J+CDzvHG5U9vKsk01 edMipsrm4IT1qZzh56uphZTAEqfmTqaLLFvus43Czjkt/AzdjokeAby1x5BnGFNk XSrm5Dan/A== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42jty7asby-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 29 Oct 2024 08:19:57 -0700 (PDT) Received: from twshared23455.15.frc2.facebook.com (2620:10d:c085:108::150d) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 29 Oct 2024 15:19:52 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id DFE2C14920E9C; Tue, 29 Oct 2024 08:19:43 -0700 (PDT) From: Keith Busch To: , , , CC: , , , , , Keith Busch Subject: [PATCHv10 1/9] block: use generic u16 for write hints Date: Tue, 29 Oct 2024 08:19:14 -0700 Message-ID: <20241029151922.459139-2-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029151922.459139-1-kbusch@meta.com> References: <20241029151922.459139-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: ZD99Q-A_B1dOSFobkrBvPTuxk5sUmAA6 X-Proofpoint-GUID: ZD99Q-A_B1dOSFobkrBvPTuxk5sUmAA6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_01 From: Keith Busch This is still backwards compatible with lifetime hints. It just doesn't constrain the hints to that definition. Using this type doesn't change the size of either bio or request. Signed-off-by: Keith Busch Reviewed-by: Bart Van Assche --- include/linux/blk-mq.h | 3 +-- include/linux/blk_types.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 2035fad3131fb..08ed7b5c4dbbf 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -8,7 +8,6 @@ #include #include #include -#include struct blk_mq_tags; struct blk_flush_queue; @@ -156,7 +155,7 @@ struct request { struct blk_crypto_keyslot *crypt_keyslot; #endif - enum rw_hint write_hint; + unsigned short write_hint; unsigned short ioprio; enum mq_rq_state state; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index dce7615c35e7e..6737795220e18 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -10,7 +10,6 @@ #include #include #include -#include struct bio_set; struct bio; @@ -219,7 +218,7 @@ struct bio { */ unsigned short bi_flags; /* BIO_* below */ unsigned short bi_ioprio; - enum rw_hint bi_write_hint; + unsigned short bi_write_hint; blk_status_t bi_status; atomic_t __bi_remaining; From patchwork Tue Oct 29 15:19:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13855082 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 5905B19341F for ; Tue, 29 Oct 2024 15:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215202; cv=none; b=ZD7zMABPryH2HhKYTVXxf1OIZuxR33XfZDhD098NjI7ndh6D7qGHI/ilbQWUVn/MoEB1MLazrK67abHir3Wcg6smSkepj8jWTmHJ5/ym5CO4ym6VQ6JEuARstRyxYY14RIy7lKgpRZPiwOhxjCNnTjXKQWUu/8gp2w+0yi//e10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215202; c=relaxed/simple; bh=u823h6nUpL2mhd/bMO+hteVG/iDcIFJwd0H9jEPB4bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fVfPkrdU4w8NYwRggE3ENraEI9Fk3Lqiupm3LbASVkFwtAYbIIvCASGVj2uVKquB1kDXJfg0PikJczlE9fgWEEe1ay/I22Z3uFPAUey+XpjPXxCimaEjcsAtGRqcFKcjz56f7c4ztUot8BnApFrot/yQ+UGm6y1McfYPDp/RHuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=hc2pQwqq; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="hc2pQwqq" Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49T71GKI000853 for ; Tue, 29 Oct 2024 08:19:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=YQ+ll8EUN2qkPqvUcVib+PjturAFUp8AJc6rGfz+mJI=; b=hc2pQwqqgkaQ kJ8rI8tnoC80TP32qJjK4Gm9bvcOv/zJxfAbKVwVArxg8Rc4rlUQeUFoVntNai57 VDl7c6eiMPPZ6yn9TVSrKaGkX08v/8z5wqxYLf7mSCbGJZL6jgnZSlwkIxpJ65XQ CKqKVVQU4QIokSPaJFKDsHL4KsT6UwT69ZC/db34NZnTaLp/+Wddw2lE/cjr2uS9 tE7udOCyfhb/7sUEdWedslIOaazN75oxTl/ZlyYZDVlM0+rMiWBfZzpzrrC+0/b0 147wP8zK5AsQ1zGkaghL+6SSh8LsCkMc+0nGzq9iK1vNwLP0KlY8AVtFYph3zwLJ EmKBVHCP2Q== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42jtxwauub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 29 Oct 2024 08:19:59 -0700 (PDT) Received: from twshared19620.08.ash8.facebook.com (2620:10d:c0a8:1b::8e35) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 29 Oct 2024 15:19:47 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id F015C14920E9E; Tue, 29 Oct 2024 08:19:43 -0700 (PDT) From: Keith Busch To: , , , CC: , , , , , Keith Busch Subject: [PATCHv10 2/9] block: introduce max_write_hints queue limit Date: Tue, 29 Oct 2024 08:19:15 -0700 Message-ID: <20241029151922.459139-3-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029151922.459139-1-kbusch@meta.com> References: <20241029151922.459139-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: -cOQAsqE4bfmSQRr1orjtFaog8kkP7Lf X-Proofpoint-ORIG-GUID: -cOQAsqE4bfmSQRr1orjtFaog8kkP7Lf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_01 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. Signed-off-by: Keith Busch --- Documentation/ABI/stable/sysfs-block | 7 +++++++ block/blk-settings.c | 3 +++ block/blk-sysfs.c | 3 +++ include/linux/blkdev.h | 12 ++++++++++++ 4 files changed, 25 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 8353611107154..f2db2cabb8e75 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_hints +Date: October 2024 +Contact: linux-block@vger.kernel.org +Description: + [RO] Maximum number of write hints supported, 0 if not + supported. If supported, valid values are 1 through + max_write_hints, inclusive. What: /sys/block//queue/max_segments Date: March 2010 diff --git a/block/blk-settings.c b/block/blk-settings.c index a446654ddee5e..921fb4d334fa4 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -43,6 +43,7 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK; /* Inherit limits from component devices */ + lim->max_write_hints = USHRT_MAX; lim->max_segments = USHRT_MAX; lim->max_discard_segments = USHRT_MAX; lim->max_hw_sectors = UINT_MAX; @@ -544,6 +545,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->max_segment_size = min_not_zero(t->max_segment_size, b->max_segment_size); + t->max_write_hints = min(t->max_write_hints, b->max_write_hints); + alignment = queue_limit_alignment_offset(b, start); /* Bottom device has different alignment. Check that it is diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 741b95dfdbf6f..85f48ca461049 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_hints) QUEUE_SYSFS_LIMIT_SHOW(logical_block_size) QUEUE_SYSFS_LIMIT_SHOW(physical_block_size) QUEUE_SYSFS_LIMIT_SHOW(chunk_sectors) @@ -457,6 +458,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_hints, "max_write_hints"); QUEUE_RW_LOAD_MODULE_ENTRY(elv_iosched, "scheduler"); QUEUE_RO_ENTRY(queue_logical_block_size, "logical_block_size"); @@ -591,6 +593,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_hints_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 d0a52ed05e60c..90a19ea889276 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -394,6 +394,8 @@ struct queue_limits { unsigned short max_integrity_segments; unsigned short max_discard_segments; + unsigned short max_write_hints; + unsigned int max_open_zones; unsigned int max_active_zones; @@ -1189,6 +1191,11 @@ static inline unsigned short queue_max_segments(const struct request_queue *q) return q->limits.max_segments; } +static inline unsigned short queue_max_write_hints(struct request_queue *q) +{ + return q->limits.max_write_hints; +} + static inline unsigned short queue_max_discard_segments(const struct request_queue *q) { return q->limits.max_discard_segments; @@ -1236,6 +1243,11 @@ 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_hints(struct block_device *bdev) +{ + return queue_max_write_hints(bdev_get_queue(bdev)); +} + static inline unsigned queue_logical_block_size(const struct request_queue *q) { return q->limits.logical_block_size; From patchwork Tue Oct 29 15:19:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13855081 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (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 AFE9E196D9A for ; Tue, 29 Oct 2024 15:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215201; cv=none; b=RL8DyUi9z1wgOkMUKeNGg4fHWkw1SFm4NNb48qcdEzgwA/sg3z61wfBSKE/0tRZ8gPDADVm3Na6DfoglsxOFESPqdHE6gdkdR4Qa9wBbyFtw706SczTAK1pjTBC50n/uGATXZxPwC/SkhtiSkstQYGLpkAwYFuXtvoqcQMg0ihI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215201; c=relaxed/simple; bh=bLVs+NUjXqkb64uW7DX9xzl2BkYI8JF3mYXsk/Fl4uY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eXLqmZd6kv0xMCWfrPbnRbotm0eS9VaeQQ+bvccPpH/SVRTIPS+Wv18akFcqtMDg+yF8Ji1Si6thICX5R0oRBroB97nSe59mH4Xapn87nSAP3pKsVyd0Vp0+GOMSRlIYruBuDcpffNk1DTNXMQ3i3xLi99qDTGYDoB+PMfvJvrM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=ay2frHnQ; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="ay2frHnQ" Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 49TD7Fwn021662 for ; Tue, 29 Oct 2024 08:19:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=YaxUJJnRZ28AJAdK6cvper+b/ynFQDqHd29QjSNk8fc=; b=ay2frHnQBoz3 7Ne1TVmq/1c7UPH78vZxWhsnfpe1X2s/gMcA22+1LPYEbFzY6tEM0X8ziK5Ir6b5 vo0stBS0x8rZkyjK+2M0jb5KR/XCSleMALdE1FMBrWD6NPlS/Ps/4kThvfUoyBxp JTKbdK3kkuvpHRTkoJv5QWmXRrMYA0CON8Xw0j3c/J1EOybmElLKPn838819Tebc xPUryeS4nxIaC0fnkDpgff6K4b1FpFS8vpnl0qfBxdgLQ55www/LU9N8RecMUsQs y7ZFPQDgmc+H6UldklgDliXIn73s6UnF39rhS+d3mXEx6ODhz3rVfkbiqgCcXZ+3 Hwq9r0shmg== Received: from mail.thefacebook.com ([163.114.134.16]) by m0001303.ppops.net (PPS) with ESMTPS id 42k0af13y2-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 29 Oct 2024 08:19:58 -0700 (PDT) Received: from twshared23455.15.frc2.facebook.com (2620:10d:c085:208::7cb7) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 29 Oct 2024 15:19:53 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 0228614920EA1; Tue, 29 Oct 2024 08:19:44 -0700 (PDT) From: Keith Busch To: , , , CC: , , , , , Keith Busch Subject: [PATCHv10 3/9] statx: add write hint information Date: Tue, 29 Oct 2024 08:19:16 -0700 Message-ID: <20241029151922.459139-4-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029151922.459139-1-kbusch@meta.com> References: <20241029151922.459139-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: zDz5AWeovGVn6s6CspS8Vi_Rh6CzqwpH X-Proofpoint-ORIG-GUID: zDz5AWeovGVn6s6CspS8Vi_Rh6CzqwpH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_01 From: Keith Busch If requested on a raw block device, report the maximum write hint the block device supports. Signed-off-by: Keith Busch --- block/bdev.c | 5 +++++ fs/stat.c | 1 + include/linux/stat.h | 1 + include/uapi/linux/stat.h | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/block/bdev.c b/block/bdev.c index 738e3c8457e7f..9a59f0c882170 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1296,6 +1296,11 @@ void bdev_statx(struct path *path, struct kstat *stat, stat->result_mask |= STATX_DIOALIGN; } + if (request_mask & STATX_WRITE_HINT) { + stat->write_hint_max = bdev_max_write_hints(bdev); + stat->result_mask |= STATX_WRITE_HINT; + } + if (request_mask & STATX_WRITE_ATOMIC && bdev_can_atomic_write(bdev)) { struct request_queue *bd_queue = bdev->bd_queue; diff --git a/fs/stat.c b/fs/stat.c index 41e598376d7e3..60bcd5c2e2a1d 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -704,6 +704,7 @@ 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_hint_max = stat->write_hint_max; return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } diff --git a/include/linux/stat.h b/include/linux/stat.h index 3d900c86981c5..48f0f64846a02 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -57,6 +57,7 @@ struct kstat { u32 atomic_write_unit_min; u32 atomic_write_unit_max; u32 atomic_write_segments_max; + u32 write_hint_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 887a252864416..10f5622c21113 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -132,7 +132,7 @@ 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_hint_max; /* 0xb8 */ __u64 __spare3[9]; /* Spare space for future expansion */ /* 0x100 */ @@ -164,6 +164,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_HINT 0x00020000U /* Want/got write_hint_max */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ From patchwork Tue Oct 29 15:19:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13855078 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (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 A5C9B1946B3 for ; Tue, 29 Oct 2024 15:19:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215194; cv=none; b=aRXlAA2KGwi3QO8jCNMpRj2gjA1nH1wCmx5rZaLA9zECu5Mfj3GOQ+jUI/bqGqnqC6X/tBM1oj8Vb+299cF68VJtvrKRCtZ2g8cev3n5FYzOxdYrKmJs86imWXf2MsJIMiVeQ4sZrhasIGHo/gIUVCF2xQL104/3r/ya2+SQZwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215194; c=relaxed/simple; bh=a0Zx2TAwQU9UnfwSEprzmsqOgGkuhE+n1rpG5e7hjv0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lzEL0DkxSQjdXx47TbLszuqZEI3BxX78XKah7zvz762RGvdLDBWhvh+tjLsC17NC2UCrwSzc2FDngsU2v5YRlRrUa4g8EOeAj24dx/CAVKZEk/cyxhawwvgTwdjbaaPvvbHYKNKIOLYZMZ3LMyE+gH5dTlOUe4W5miZI1QpGD0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=Iy4uN0Qe; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="Iy4uN0Qe" Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 49TD7AbW021211 for ; Tue, 29 Oct 2024 08:19:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=qA+NGz+6KM5521lpDTzCtjJ24sEMb14jQTfwKkFiwJc=; b=Iy4uN0QeAnJo fblju/KuxVMSg2VrDQlMo4Lu9MTYEXkSULblzcwPZ6jk8IUqfa4I8imCJXuJNs4P xhxPIT8k6ybNErCpUNyU+xus9yJPN3rxpm7rmGhdAghKzbEfYXq2HdP7hNkJLhlu IzFCkZckw8M0izhlhDxtBmhokwvTkilNq6KrCkw7oI9JgEtcTcQWuXeS3R/iJH2w jBxdLnJJCPlw9rfMQ/uHC/Uir4th1yiTqe0D9+leiYUzr+CF82znP0ds5E/DAdu7 cpJhbBUjIC7jmvyrGmzN3W9jNN+RqTVN8MZ84xfqy4htzm6x2ShT0roiyr6rOSqF gu/1cH/cmA== Received: from maileast.thefacebook.com ([163.114.135.16]) by m0001303.ppops.net (PPS) with ESMTPS id 42k0af13x0-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 29 Oct 2024 08:19:51 -0700 (PDT) Received: from twshared22321.07.ash9.facebook.com (2620:10d:c0a8:1c::1b) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 29 Oct 2024 15:19:47 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 1049714920EA3; Tue, 29 Oct 2024 08:19:44 -0700 (PDT) From: Keith Busch To: , , , CC: , , , , , Keith Busch Subject: [PATCHv10 4/9] block: allow ability to limit partition write hints Date: Tue, 29 Oct 2024 08:19:17 -0700 Message-ID: <20241029151922.459139-5-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029151922.459139-1-kbusch@meta.com> References: <20241029151922.459139-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: OezDsXasoiTz7xT8u2JJlbBS9pIJPcOz X-Proofpoint-ORIG-GUID: OezDsXasoiTz7xT8u2JJlbBS9pIJPcOz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_01 From: Keith Busch When multiple partitions are used, you may want to enforce different subsets of the available write hints for each partition. Provide a bitmap attribute of the available write hints, and allow an admin to write a different mask to set the partition's allowed write hints. Signed-off-by: Keith Busch --- Documentation/ABI/stable/sysfs-block | 6 ++++ block/bdev.c | 13 ++++++++ block/partitions/core.c | 44 ++++++++++++++++++++++++++-- include/linux/blk_types.h | 1 + 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index f2db2cabb8e75..8ab9f030e61d1 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -187,6 +187,12 @@ Description: partition is offset from the internal allocation unit's natural alignment. +What: /sys/block///write_hint_mask +Date: October 2024 +Contact: linux-block@vger.kernel.org +Description: + The mask of allowed write hints. You can limit which hints the + block layer will use by writing a new mask. What: /sys/block///stat Date: February 2008 diff --git a/block/bdev.c b/block/bdev.c index 9a59f0c882170..0c5e87b111aed 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -415,6 +415,7 @@ void __init bdev_cache_init(void) struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) { struct block_device *bdev; + unsigned short write_hint; struct inode *inode; inode = new_inode(blockdev_superblock); @@ -440,6 +441,18 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) return NULL; } bdev->bd_disk = disk; + + write_hint = bdev_max_write_hints(bdev); + if (write_hint) { + bdev->write_hint_mask = bitmap_alloc(write_hint, GFP_KERNEL); + if (!bdev->write_hint_mask) { + free_percpu(bdev->bd_stats); + iput(inode); + return NULL; + } + bitmap_set(bdev->write_hint_mask, 0, write_hint); + } + return bdev; } diff --git a/block/partitions/core.c b/block/partitions/core.c index 815ed33caa1b8..24e1a79972f75 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -203,6 +203,40 @@ static ssize_t part_discard_alignment_show(struct device *dev, return sprintf(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev))); } +static ssize_t part_write_hint_mask_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct block_device *bdev = dev_to_bdev(dev); + unsigned short max_write_hints = bdev_max_write_hints(bdev); + + if (!max_write_hints) + return sprintf(buf, "0"); + return sprintf(buf, "%*pb\n", max_write_hints, bdev->write_hint_mask); +} + +static ssize_t part_write_hint_mask_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct block_device *bdev = dev_to_bdev(dev); + unsigned short max_write_hints = bdev_max_write_hints(bdev); + unsigned long *new_mask; + + if (!max_write_hints) + return count; + + new_mask = bitmap_alloc(max_write_hints, GFP_KERNEL); + if (!new_mask) + return -ENOMEM; + + bitmap_parse(buf, count, new_mask, max_write_hints); + bitmap_copy(bdev->write_hint_mask, new_mask, max_write_hints); + bitmap_free(new_mask); + + return count; +} + static DEVICE_ATTR(partition, 0444, part_partition_show, NULL); static DEVICE_ATTR(start, 0444, part_start_show, NULL); static DEVICE_ATTR(size, 0444, part_size_show, NULL); @@ -211,6 +245,8 @@ static DEVICE_ATTR(alignment_offset, 0444, part_alignment_offset_show, NULL); static DEVICE_ATTR(discard_alignment, 0444, part_discard_alignment_show, NULL); static DEVICE_ATTR(stat, 0444, part_stat_show, NULL); static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL); +static DEVICE_ATTR(write_hint_mask, 0644, part_write_hint_mask_show, + part_write_hint_mask_store); #ifdef CONFIG_FAIL_MAKE_REQUEST static struct device_attribute dev_attr_fail = __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store); @@ -225,6 +261,7 @@ static struct attribute *part_attrs[] = { &dev_attr_discard_alignment.attr, &dev_attr_stat.attr, &dev_attr_inflight.attr, + &dev_attr_write_hint_mask.attr, #ifdef CONFIG_FAIL_MAKE_REQUEST &dev_attr_fail.attr, #endif @@ -245,8 +282,11 @@ 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); + + bitmap_free(part->write_hint_mask); + 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 6737795220e18..af430e543f7f7 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -73,6 +73,7 @@ struct block_device { #ifdef CONFIG_SECURITY void *bd_security; #endif + unsigned long *write_hint_mask; /* * keep this out-of-line as it's both big and not needed in the fast * path From patchwork Tue Oct 29 15:19:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13855079 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (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 34A001946A2 for ; Tue, 29 Oct 2024 15:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215198; cv=none; b=Q4vU5RzTmz4RCaOdeHaSHucNubiL/LxyjWp/uVEweZ53Ss9lysMjShU+uHFJ+zys+EButs+p6aWRNwIU/KmcZTFOJKrDvM0fd3TyVh7loYJiT7CTAOnuhP1qZJJF9LF0oyXcxKhzvXuUaq0kxLJv+jAtrbPcS3cfwE2EwexsXXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215198; c=relaxed/simple; bh=GD7uThjhDzyP28oGcsmN6/eNWGUs4YiXhY9KVTQmUTE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FVb0E7Vfl7ZRiCZPV6gDG15miDPPdtdP/Dsm1EOG2/YqccsEIFilnCaAISL731QFV2Lb0ab1r6qqJFfg4FktCsvtoIQ+4R2MIKME6gHLaZ2nJ3ViUJn4GeqSjANzpD2WGjg3xpRwRF9iPhqSiQhhK5kuKJrXEL1TzBPBkAyh3Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=Ho3jedvR; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="Ho3jedvR" Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 49TD7Abd021211 for ; Tue, 29 Oct 2024 08:19:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=7vuu9MU8HwzONpvRjqiHwphNE/Y6asPy43+abByRhi8=; b=Ho3jedvRtHL/ 2BIwDRamOsQyk4bI0ern4VkA0Sgxm9CGZRA7LFeFM/8Sokt+oJIFrVBgg57/ro6e 4EH2C4uv9ohV4DiI0t2VJPll7Y/ADbUIFNUXC73O4eG+kCJ+k32fnuq7yEWH6mI1 6jgMa4/ZNWPvHbifiA3s/NzfL4/pyx1jrMQ8FzfnXY4Ua8PkGZ2NGye+XnKOnDoY MunY6kSk8oQ6fE/krdLzs2hnL0SdZm26LjcVGXStmKbejOYv+Pv6jVtKQihIvBct 1JchLnv0UC4SysCD62DjH6oJuE8WGuLE79n5YhuhjiRqb2rAOado9J+P8rQCM8xY e8v7XR8gNQ== Received: from maileast.thefacebook.com ([163.114.135.16]) by m0001303.ppops.net (PPS) with ESMTPS id 42k0af13x0-14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 29 Oct 2024 08:19:54 -0700 (PDT) Received: from twshared26373.08.ash9.facebook.com (2620:10d:c0a8:fe::f072) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 29 Oct 2024 15:19:47 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 1676C14920EA5; Tue, 29 Oct 2024 08:19:44 -0700 (PDT) From: Keith Busch To: , , , CC: , , , , , Keith Busch Subject: [PATCHv10 5/9] block, fs: add write hint to kiocb Date: Tue, 29 Oct 2024 08:19:18 -0700 Message-ID: <20241029151922.459139-6-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029151922.459139-1-kbusch@meta.com> References: <20241029151922.459139-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: zGKihF5yuVSeyo9r7msC7AxDVY9VDXbp X-Proofpoint-ORIG-GUID: zGKihF5yuVSeyo9r7msC7AxDVY9VDXbp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_01 From: Keith Busch This prepares for sources other than the inode to provide a write hint. The block layer will use it for direct IO if the requested hint is within the block device's allowed hints. Signed-off-by: Keith Busch --- block/fops.c | 31 ++++++++++++++++++++++++++++--- include/linux/fs.h | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/block/fops.c b/block/fops.c index 2d01c90076813..bb3855ee044f0 100644 --- a/block/fops.c +++ b/block/fops.c @@ -71,7 +71,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, bio_init(&bio, bdev, vecs, nr_pages, dio_bio_write_op(iocb)); } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; - bio.bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; + bio.bi_write_hint = iocb->ki_write_hint; bio.bi_ioprio = iocb->ki_ioprio; if (iocb->ki_flags & IOCB_ATOMIC) bio.bi_opf |= REQ_ATOMIC; @@ -200,7 +200,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_hint = iocb->ki_write_hint; bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io; bio->bi_ioprio = iocb->ki_ioprio; @@ -316,7 +316,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, dio->flags = 0; 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_hint = iocb->ki_write_hint; bio->bi_end_io = blkdev_bio_end_io_async; bio->bi_ioprio = iocb->ki_ioprio; @@ -362,6 +362,23 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, return -EIOCBQUEUED; } +static int blkdev_write_hint(struct kiocb *iocb, struct block_device *bdev) +{ + u16 hint = iocb->ki_write_hint; + + if (!hint) + return file_inode(iocb->ki_filp)->i_write_hint; + + if (hint > bdev_max_write_hints(bdev)) + return -EINVAL; + + if (bdev_is_partition(bdev) && + !test_bit(hint - 1, bdev->write_hint_mask)) + return -EINVAL; + + return hint; +} + static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); @@ -373,6 +390,14 @@ 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) { + int hint = blkdev_write_hint(iocb, bdev); + + if (hint < 0) + return hint; + iocb->ki_write_hint = 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)) diff --git a/include/linux/fs.h b/include/linux/fs.h index 4b5cad44a1268..1a00accf412e5 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 */ + u16 ki_write_hint; union { /* * Only used for async buffered reads, where it denotes the From patchwork Tue Oct 29 15:19:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13855083 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 EF0D8196446 for ; Tue, 29 Oct 2024 15:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215203; cv=none; b=jL4+fkYJSDT6MW6LsfTOwJyMeZmZIazLAQ7iSvdXV7BRlV4i57JwnTebzCV34/B9D5fM2BS69INufjauEHHAN+N8tqA8isd+s0e27b2i8WxFysj6qdlwYydVQ4eAiLv228VX2u7FyXPISoqgvLLuBB7WW7CUkBNveCFJPD4vxW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730215203; c=relaxed/simple; bh=I8/Qo8zmSvbDl9OhqTDCEq29os3x4jVXWXNHkXfOpYg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fvrbqzl9ipPdtJIyEjZ4W5uiEq58tWWCHpj06r6RgDOanI4qU6kMquqhqmm2uARWb4PvRBkXNBCscIUnELGCsh/VUjFXWVqv5C+xwo4swdE7X2MvPTU+jxRpCo2AiUbsPgehv5Ks+qIR3llsA+o/5m714Qd3d82E6y5i5lOkCH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=CCoMFHMV; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="CCoMFHMV" Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49T71GKJ000853 for ; Tue, 29 Oct 2024 08:20:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=aps8B5vbC0snCPQCS1odsvarjIZlBhTaPnTsg871jzs=; b=CCoMFHMVFLtC 8TG79XGavrREbxROokffs4StQPUxSVy942Ee4PC6TqUWrkPjxbQSb6or157j9YYm JcN5DLuaeS3+ZJFrMrfU6cA+ApxUsUyAj4sq5YuztHEFJCc4cyYCyDx8jRckiSQc fslDE+lhnqbUYSckOl+LcV5fdIERSbHFxa72jGQGYfb6DxlQQkx5mW6dVxs/Ayo5 LfubTbWLFic9jCmlfys5Jc86q+qqi/5nl8RhakEUWAn2AMZ15wlarplWAkIYMwYJ zRtW/FhtrT37CA8LuHhRXNTltlYIzt4P35fQ3GsIvdMe1Bud38irtLmseQrSLSmO yX1xEkwfUA== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42jtxwauub-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 29 Oct 2024 08:20:00 -0700 (PDT) Received: from twshared26373.08.ash9.facebook.com (2620:10d:c0a8:fe::f072) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 29 Oct 2024 15:19:47 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 2AD5E14920EAA; Tue, 29 Oct 2024 08:19:44 -0700 (PDT) From: Keith Busch To: , , , CC: , , , , , Keith Busch Subject: [PATCHv10 7/9] block: export placement hint feature Date: Tue, 29 Oct 2024 08:19:20 -0700 Message-ID: <20241029151922.459139-8-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029151922.459139-1-kbusch@meta.com> References: <20241029151922.459139-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: z2afiJlSdMlMRKzjThAIy6vI9DmDPDEs X-Proofpoint-ORIG-GUID: z2afiJlSdMlMRKzjThAIy6vI9DmDPDEs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_01 From: Keith Busch Add a feature flag for devices that support generic placement hints in write commands. This is in contrast to data lifetime hints. Signed-off-by: Keith Busch --- block/blk-settings.c | 2 ++ block/blk-sysfs.c | 3 +++ include/linux/blkdev.h | 3 +++ 3 files changed, 8 insertions(+) diff --git a/block/blk-settings.c b/block/blk-settings.c index 921fb4d334fa4..7e3bb3cec7032 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -518,6 +518,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->features &= ~BLK_FEAT_NOWAIT; if (!(b->features & BLK_FEAT_POLL)) t->features &= ~BLK_FEAT_POLL; + if (!(b->features & BLK_FEAT_PLACEMENT_HINTS)) + t->features &= ~BLK_FEAT_PLACEMENT_HINTS; t->flags |= (b->flags & BLK_FLAG_MISALIGNED); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 85f48ca461049..51e0b99c2210a 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -260,6 +260,7 @@ static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \ QUEUE_SYSFS_FEATURE_SHOW(poll, BLK_FEAT_POLL); QUEUE_SYSFS_FEATURE_SHOW(fua, BLK_FEAT_FUA); QUEUE_SYSFS_FEATURE_SHOW(dax, BLK_FEAT_DAX); +QUEUE_SYSFS_FEATURE_SHOW(placement_hints, BLK_FEAT_PLACEMENT_HINTS); static ssize_t queue_zoned_show(struct gendisk *disk, char *page) { @@ -497,6 +498,7 @@ QUEUE_RW_ENTRY(queue_poll_delay, "io_poll_delay"); QUEUE_RW_ENTRY(queue_wc, "write_cache"); QUEUE_RO_ENTRY(queue_fua, "fua"); QUEUE_RO_ENTRY(queue_dax, "dax"); +QUEUE_RO_ENTRY(queue_placement_hints, "placement_hints"); QUEUE_RW_ENTRY(queue_io_timeout, "io_timeout"); QUEUE_RO_ENTRY(queue_virt_boundary_mask, "virt_boundary_mask"); QUEUE_RO_ENTRY(queue_dma_alignment, "dma_alignment"); @@ -626,6 +628,7 @@ static struct attribute *queue_attrs[] = { &queue_wc_entry.attr, &queue_fua_entry.attr, &queue_dax_entry.attr, + &queue_placement_hints_entry.attr, &queue_poll_delay_entry.attr, &queue_virt_boundary_mask_entry.attr, &queue_dma_alignment_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 90a19ea889276..c577a607591de 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -333,6 +333,9 @@ typedef unsigned int __bitwise blk_features_t; #define BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE \ ((__force blk_features_t)(1u << 15)) +/* supports generic write placement hints */ +#define BLK_FEAT_PLACEMENT_HINTS ((__force blk_features_t)(1u << 16)) + /* * Flags automatically inherited when stacking limits. */