From patchwork Fri Oct 11 02:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13831992 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 608F71F4FA3 for ; Fri, 11 Oct 2024 02:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728614997; cv=fail; b=i+ehOHntMnzNyA53I13ksGBMyBz6VKQQcoP3RFZ+oEvU6VmzfJHG1PbNAtJnRUXG2A58701PQq2mKaJP+azXWi088DnKBxQ5nRmUwj1DRuxabIR401tHsd572Ip8IDjp8dVwuKgizTgBOtncjreh7tF7os5yLCGhC3UzFJ14Wto= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728614997; c=relaxed/simple; bh=YykUjuTbY4HSJ7EPT32TBgvp7PNwN2NRu+JmwFHfBEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=IlOjPkOB5XhQJYzR7c4cF3s0fHSCro5bx/FJKOUfJFRzpKU/HDkYHEfHh+wsRr6JpuWyCYa5ilbKWrEbEgVQD8OGvqHBOKUXIR0XpmoF8MMtJ3ftEiId7y/SWB7AoxwtZ9546xNE3dD0IM5FWru5R8sY9JV5DTy9wfC/VNgg0WY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=W3BC0J+3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=Ry0vaMrY; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="W3BC0J+3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="Ry0vaMrY" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49AJtcfA010765; Fri, 11 Oct 2024 02:49:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=Jm+RoCfhJWXuvuAVi5syuitoXwr4QEG+yLXN6IZJSjY=; b= W3BC0J+3MddAyHseLU6860j0qV7eX9M1AD7Fyz8Khc4X7GOC6MSNZ9UI+zRny1J7 PgAlQe02n5A7JmPmgcdVpyE8YgODeH9szQj+Hqtea3YO7+emKJvDzaw6hVQpfUUL 918jln/MfwBF5ybVK/uFGyQGTHWEyCyqBakqzcsr7XGr3Bg1vTri3SbbmANYqyml RZQ9XIR2C4TUXZ8gY/Cy8VWhe3Sh3DKY//ldrhBdEhWiXy34oAhEztepCazL6iwi NETfHPXA3jd0PquZVgBdPEqif6/ttN4AuE8nTvjTWBR/J+704/J+TsHAVcKfI3ps L7DqnJpk0LYdrWNGqacJvg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42303ym1m8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 02:49:44 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49AN7SfG017546; Fri, 11 Oct 2024 02:49:43 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2049.outbound.protection.outlook.com [104.47.58.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwawtnt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 02:49:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T4o+C9gWOuRPf8mXGNga84fEIgCwbHxf5RzMATDweqRYrBQrd3POodZ7zmDMBFF1cn71zkVd59OOSjF8bb3NFPb3H6619fq1+Azw15fIKbfLYjhfySnWKc03Ar1d76/zR5qFGIkdkEgllVs6d1NzD7Go9sunj3GhMhhFQEN+ZkgX/LTTuwwy8Su9jQqMhDB0lKbrkIyAr0A9gwNYKiz8dD/8+gLlJnxex2DFkWGF+bpRR7dRmHauMO11rRvNCOw0JiN/g3ijgVPnbNw6j42FHimQB1vFtiKc/jmc+dLrRUV2Yv75jdyBLCRv+NwhloC7oD5AxEdicVsn/nXGIniYIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jm+RoCfhJWXuvuAVi5syuitoXwr4QEG+yLXN6IZJSjY=; b=CJIdITgDeX9H8xZhXSAHctjWyoa8Z4Yk+4gcS+/lyRdUcqycrlW4e9y24vzfJhaAkwpgTsIzix7CI6JjW1kwarwveUb5G2KpfnNCc/O7Ko6cmlb4uvFkd6A1/I5bcZsEz6ZYX/voHVR6VD6IIsFlLTMWcDmvHHeGg+mkhbU09mrmSmFmk9FKvL9vu/mytw9dqNX8LEQd7eftdad8kZwnqgSAz15JL0qU7Jx5jrrfaHRjdCICodCORLBfmdpnCdlXOOSO7IBcjbexCEkl9u0OBrZe9L3QQ5jsZXAbEs11L2sG4mT1qyzCBLqE6jXmaK79/G9KDzVXV6LXFnzCvQlQrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jm+RoCfhJWXuvuAVi5syuitoXwr4QEG+yLXN6IZJSjY=; b=Ry0vaMrYINIUciinakcPRmBXsZOOkUG3+JmMY14jiej/MJkzT89ye8+fCVz7VQXPVwPtV8hqbknNEoOhcybsZf5ujNErRJNJvs20ToJdzhIzbmSNr+XExhgL68BHWybiLbNRLwobtGxLU9Z+LwoNttqax7o1p+lAYVdAqjevhrw= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by SA1PR10MB7815.namprd10.prod.outlook.com (2603:10b6:806:3ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Fri, 11 Oct 2024 02:49:36 +0000 Received: from PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::fea:df00:2d94:cb65]) by PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::fea:df00:2d94:cb65%5]) with mapi id 15.20.8048.013; Fri, 11 Oct 2024 02:49:36 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, wqu@suse.com, hrx@bupt.moe, waxhead@dirtcellar.net Subject: [PATCH v2 1/3] btrfs: introduce RAID1 round-robin read balancing Date: Fri, 11 Oct 2024 10:49:16 +0800 Message-ID: X-Mailer: git-send-email 2.46.1 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::21) To PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR10MB5706:EE_|SA1PR10MB7815:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b7e4821-88a7-4211-5a02-08dce99f5783 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: YzEfPN8b9hVroUk62IvO19Qnl3Rp0XmvsGdtZyLHD/jD3WvLGAqXj48SLurrqwA2XnIet3/krVSpEQG9SBKFS8s1O7+WYBEZljmkBv4n4A10wt+YbSzPEY9FlngEtQ4STAy60VQbiZ4CW56RMn7Ult0MH5fVNEE+d7ZzKrYHwlcSAkYujs6+2XLTHXYhuAtIlokv4dy6hsPWvu2I8hSoqmGIisA6AQta/0TXbFI4HH6YHL+Jv8WBDTGva1u5V/vfjNOn4nWN1VlfqWXNHrj1nYDuHHOxofdHZNLTCJlnEyj5EAJXAz6FIktcUMQXLDYDeFLkuP55ZLJK0hXpSD2AMontieNXzP0AicMeygmfj5ONrx5Fkw8xG/tcayD3O3LsThlnVYk82yyEv1c59JeBn9Gs6VO0sfaUU76GNrtvjq9NexGOuktB0xg0RmcjFhc42vjd+k5KbFfI3uvn2rcmv1iqT3gbj3GB7Huj6mDsFysGjyi5oW3RrCFQ3oDWMiTQg31Jf+5a4vjPGVtKHA8fL5WjUt1M+fzVZ7hKiqVZmukJW2epyiHlw3Ct3J4ROZsYi4eITEhky1XmHnDYfE9N/cavxlvTdf1gQ249JIaGT+iPkDsrUo9+llpx/lHBbIr0thYDUUnS/m3UV5d6LXYAyrLoAGsgST7ZbMm5nDRhfKd6xo3l44Kq7aMWcs8T+JHXyuElAMfbLrTA3abxGBVSsS+05E6zHVUK49EJSZT4T2evt57NjzfmgnN63MRthkPkniHRGbavJCLdJbp0hMtFOZI6JvcIdG9jAQd4IMIu1LeBDCkksUMtjrGzX4nKpVFsv6LxzTn/yp+pPhjrSidcq5sA88jWuHgsZB2LrN2tbk5PEfBd12zaZGISvR+lW+V/43PYovETv/aZVbJKPB+uVk/yn/Ii6+JqgwfoSjZAo6gcY2QoCF5uJFZQDN/XuWEeethLbBGFJ3AUZsc+1Pxm2ff0x28KNaiVqTGy0C1cxdeLE95MMPpGTGudvCQhgDarWdn2SpjFygMnuYHNRFGJV4shhP+/wLDFjlZanKoHC4j7JylKh6hg4fp8FtgIPXE1y9tX0XA5jdC6Ncjeq1xM1gvCN1aUiASiFP+ZNU/16K83aY/BEHJfxxXWZeWThT5w3pEG1CEeQFJw5z0CKvqeEhhwiYXIKsLhoZyg8DMb9te9xMLfb0kgT/FIkLPAJHC67lCW6B9qANcPWvmCulhgBDYr12LgB3i2V/ci3GPp1q+EilUoQdLiySguXpnl7ECIxhdSO/OQOxrHNe7XV2NQwA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR10MB5706.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /2uqLuI6wk3chKzflMEYwgYrGkZAXsNo8etCO382sAI0Q5MVXXoaZHqxSXl8MPHIJtnMPPZHpnbFNKBVBut5Cr2MxcN0+EhDmKVlqmm0RLXICM2VFB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LEoKC1l41XsAVvH5tYHHpspaLKJe3/htP1UejkK20i5XyOYzfdMrIkxNiiX4Znr7dYPs4iLQZviJkIji513v94C2EwyH5Ow18bAbnSfLEz+Ntjbf6m3FBExjGoil+FFv0UhaS0/7jjHaHxgiIzJNBBmeZ8JoEfmQy5pwZOCBQlrZEncgqZbtcXewXut1JZBL1MEZTcjU414YG8moM+3XHDGetwnkvsyreXvJlCrLpu3CQ2ZG+FhkCuRbyovXKKbfih6pg3slmQbSXqyaMr1/XZ27Kct7o+m4ujSQzrHpjUFZe9Duu8yjtvFf5AOMdNqC467+LaZYz/TFk2CthcYGfPPC7lXJAFwxeycGKk3vqizjzyUCUBdP32JYrkSEXXbtrDpVz8Wjvjgj+rCsPeAFmTbgH0KcaP X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ZJJMxm8UTcLDQGFlXxAop3sArtitLuBAqz8eahSIJyb5W+VpxE9r4QzTZC25w72W+QQ6JZkb6dB4VqF5gql//z42rvnA3jOhEjZhmp+5TPR3Gun4oQTXODbTABeF0SDNQ8GjZJ+hbphzsOmWhVPh/dbjAaB8NbbfB90+jfMjzceSv7kbc/MSJuIa8oG7l7gS/zgZTARkILwLOFtIhOJeYns0BZSmG6VHrRRe8mZwLlEdpfLqiZSgl+zhHWWGnZZYMvLaY6ldIUnH0RBszCFyS/PV7ZxkoBXgsm8K8vmtWbJ2TlIokFedU9yZVl/sF2mZK7xozJyNMPkthybXmAfJvkWowG9jPVD1AR6/RVtlhWkKJyhbJ5Y5udotrqiJajm95+sy6yv6460scYHek8tPavx3gHcahn17byzR/9cOFVi8deA4ho5/ubxRKelkljxFW3bxGff5fItmYDAV87FzG6LOL+L9/PzRNy525AfYc6BxIkxVucO+T/GUmu93tYKZQxNE7XJR0j9KQwERdbrxOSrYSE1gUHtE0B46hksZpggGMj401d90UQT2EUc3yKyj25BfdETZGHl6F0BzZjPo8yNIjdCuG/IDPbBQ0Eztm9E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b7e4821-88a7-4211-5a02-08dce99f5783 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 02:49:36.0330 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: efernfpPl40pKRNFjRZUYf2m+4+2tOAqsIQQYgljvlDiWdRQq5KBY32Qa7wqv/Tp9+ThgcEcBT8RUKwYKlhSmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB7815 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-10_19,2024-10-10_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110015 X-Proofpoint-ORIG-GUID: oWTXCEprIvGiLcYAEHTGOUfteafmryjc X-Proofpoint-GUID: oWTXCEprIvGiLcYAEHTGOUfteafmryjc This feature balances I/O across the striped devices when reading from RAID1 blocks. echo rotation:[min_contiguous_read] > /sys/fs/btrfs//read_policy Default value of min_contiguous_read is equal to the sectorsize. Signed-off-by: Anand Jain --- fs/btrfs/disk-io.c | 3 ++ fs/btrfs/sysfs.c | 88 ++++++++++++++++++++++++++++++++++++++-------- fs/btrfs/volumes.c | 53 ++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 9 +++++ 4 files changed, 138 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4ad5db619b00..5b157f407e0a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3320,6 +3320,9 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device fs_info->nodesize = nodesize; fs_info->sectorsize = sectorsize; +#ifdef CONFIG_BTRFS_EXPERIMENTAL + fs_info->fs_devices->min_contiguous_read = sectorsize; +#endif fs_info->sectorsize_bits = ilog2(sectorsize); fs_info->sectors_per_page = (PAGE_SIZE >> fs_info->sectorsize_bits); fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size; diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index b843308e2bc6..bacb2871109b 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1305,7 +1305,11 @@ static ssize_t btrfs_temp_fsid_show(struct kobject *kobj, } BTRFS_ATTR(, temp_fsid, btrfs_temp_fsid_show); +#ifdef CONFIG_BTRFS_EXPERIMENTAL +static const char * const btrfs_read_policy_name[] = { "pid", "rotation" }; +#else static const char * const btrfs_read_policy_name[] = { "pid" }; +#endif static ssize_t btrfs_read_policy_show(struct kobject *kobj, struct kobj_attribute *a, char *buf) @@ -1316,14 +1320,22 @@ static ssize_t btrfs_read_policy_show(struct kobject *kobj, int i; for (i = 0; i < BTRFS_NR_READ_POLICY; i++) { - if (policy == i) - ret += sysfs_emit_at(buf, ret, "%s[%s]", - (ret == 0 ? "" : " "), - btrfs_read_policy_name[i]); - else - ret += sysfs_emit_at(buf, ret, "%s%s", - (ret == 0 ? "" : " "), - btrfs_read_policy_name[i]); + if (ret != 0) + ret += sysfs_emit_at(buf, ret, " "); + + if (i == policy) + ret += sysfs_emit_at(buf, ret, "["); + + ret += sysfs_emit_at(buf, ret, "%s", btrfs_read_policy_name[i]); + +#ifdef CONFIG_BTRFS_EXPERIMENTAL + if (i == BTRFS_READ_POLICY_ROTATION) + ret += sysfs_emit_at(buf, ret, ":%d", + fs_devices->min_contiguous_read); +#endif + + if (i == policy) + ret += sysfs_emit_at(buf, ret, "]"); } ret += sysfs_emit_at(buf, ret, "\n"); @@ -1336,21 +1348,67 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj, const char *buf, size_t len) { struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj); + int index = -1; int i; +#ifdef CONFIG_BTRFS_EXPERIMENTAL + char *value = strchr(buf, ':'); + + /* Separate value from input in policy:value format. */ + if (value) { + *value = '\0'; + value++; + } +#endif + for (i = 0; i < BTRFS_NR_READ_POLICY; i++) { if (sysfs_streq(buf, btrfs_read_policy_name[i])) { - if (i != READ_ONCE(fs_devices->read_policy)) { - WRITE_ONCE(fs_devices->read_policy, i); - btrfs_info(fs_devices->fs_info, - "read policy set to '%s'", - btrfs_read_policy_name[i]); + index = i; + break; + } + } + + if (index == -1) + return -EINVAL; + +#ifdef CONFIG_BTRFS_EXPERIMENTAL + if (index == BTRFS_READ_POLICY_ROTATION) { + int value_rota = fs_devices->fs_info->sectorsize; + + if (value) { + if (kstrtoint(value, 10, &value_rota)) + return -EINVAL; + + if (value_rota % fs_devices->fs_info->sectorsize != 0) { + btrfs_err(fs_devices->fs_info, +"read_policy: min_contiguous_read %d should be multiples of the sectorsize %u", + value_rota, + fs_devices->fs_info->sectorsize); + return -EINVAL; } - return len; } + + if (index != READ_ONCE(fs_devices->read_policy) || + value_rota != READ_ONCE(fs_devices->min_contiguous_read)) { + WRITE_ONCE(fs_devices->read_policy, index); + WRITE_ONCE(fs_devices->min_contiguous_read, value_rota); + atomic_set(&fs_devices->total_reads, 0); + + btrfs_info(fs_devices->fs_info, "read policy set to '%s:%d'", + btrfs_read_policy_name[index], value_rota); + + } + + return len; + } +#endif + if (index != READ_ONCE(fs_devices->read_policy)) { + WRITE_ONCE(fs_devices->read_policy, index); + btrfs_info(fs_devices->fs_info, "read policy set to '%s'", + btrfs_read_policy_name[index]); } - return -EINVAL; + return len; } BTRFS_ATTR_RW(, read_policy, btrfs_read_policy_show, btrfs_read_policy_store); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index dc9f54849f39..ec5dbe69ba2c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5962,6 +5962,54 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, return len; } +#ifdef CONFIG_BTRFS_EXPERIMENTAL +struct stripe_mirror { + u64 devid; + int num; +}; + +static int btrfs_cmp_devid(const void *a, const void *b) +{ + struct stripe_mirror *s1 = (struct stripe_mirror *)a; + struct stripe_mirror *s2 = (struct stripe_mirror *)b; + + if (s1->devid < s2->devid) + return -1; + if (s1->devid > s2->devid) + return 1; + return 0; +} + +static int btrfs_read_rotation(struct btrfs_chunk_map *map, int first, + int num_stripe) +{ + struct stripe_mirror stripes[4] = {0}; //4: max possible mirrors + struct btrfs_fs_devices *fs_devices = map->stripes[first].dev->fs_devices; + int j; + int slot; + int index; + int ret_stripe; + int total_reads; + int reads_per_dev = fs_devices->min_contiguous_read/ + fs_devices->fs_info->sectorsize; + + index = 0; + for (j = first; j < first + num_stripe; j++) { + stripes[index].devid = map->stripes[j].dev->devid; + stripes[index].num = j; + index++; + } + sort(stripes, num_stripe, sizeof(struct stripe_mirror), + btrfs_cmp_devid, NULL); + + total_reads = atomic_inc_return(&fs_devices->total_reads); + slot = total_reads/reads_per_dev; + ret_stripe = stripes[slot % num_stripe].num; + + return ret_stripe; +} +#endif + static int find_live_mirror(struct btrfs_fs_info *fs_info, struct btrfs_chunk_map *map, int first, int dev_replace_is_ongoing) @@ -5991,6 +6039,11 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, case BTRFS_READ_POLICY_PID: preferred_mirror = first + (current->pid % num_stripes); break; +#ifdef CONFIG_BTRFS_EXPERIMENTAL + case BTRFS_READ_POLICY_ROTATION: + preferred_mirror = btrfs_read_rotation(map, first, num_stripes); + break; +#endif } if (dev_replace_is_ongoing && diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 3a416b1bc24c..0db754a4b13d 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -303,6 +303,10 @@ enum btrfs_chunk_allocation_policy { enum btrfs_read_policy { /* Use process PID to choose the stripe */ BTRFS_READ_POLICY_PID, +#ifdef CONFIG_BTRFS_EXPERIMENTAL + /* Balancing raid1 reads across all striped devices */ + BTRFS_READ_POLICY_ROTATION, +#endif BTRFS_NR_READ_POLICY, }; @@ -431,6 +435,11 @@ struct btrfs_fs_devices { enum btrfs_read_policy read_policy; #ifdef CONFIG_BTRFS_EXPERIMENTAL + /* IO stat, read counter. */ + atomic_t total_reads; + /* Min contiguous reads before switching to next device. */ + int min_contiguous_read; + /* Checksum mode - offload it or do it synchronously. */ enum btrfs_offload_csum_mode offload_csum_mode; #endif From patchwork Fri Oct 11 02:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13831993 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 19BB41F8F1A for ; Fri, 11 Oct 2024 02:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728614999; cv=fail; b=fqTTVZl8xd76Pm72G0TWQFGguDu8USdhYV6Jqh0pKGPecSecG/nZk8GD112dYfQuP6rp+T20Q3xcw72XzI/jgHVE0RRQ7FF8AmEnI6f+M4m9X+SU14jfHQ72rMB9ONOBtIepmqt9/Nkv7G71ftRB2/pTJ9M2ssgJgme7unrwJJc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728614999; c=relaxed/simple; bh=kG4OnVo0DyEuW3u8ZZtkBYz5re0TsqGKo1/qcOKWMKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=bmn4zJ4yxWBdBHS8W1eRhgYPTn9PlPVViW+89XEX5+PM4CZY4iT2etLMEOoeJovt52qv7sdYZ6CZMrFsdrZkSYeVpcJEZY7pyLSmajZ5xP5+aDGhs5/3EQ3Mm9KnMUzEvQpXts68Lz4YEW64fc+kDk1KxmFg2Ut8OkpyGzehiaw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=MK/7OeUR; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=vSU3g7+b; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="MK/7OeUR"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="vSU3g7+b" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49AJtdl5012157; Fri, 11 Oct 2024 02:49:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=BbLM7oq4Qly7ZOxJZJ2nNsrSMYfY+f02iyF3nrR1/Jg=; b= MK/7OeURDrPJOyY1ptJ8pSIj3w7toYHAPsPNqqGM1TCQ7UapLQSkwguMcJfMBn2P erXZez7AtzvyQnV8ongOVZP71Astv5JyU0ANUMHJlzGVivSp68n3ElGBR1tdtr1c MYvLFymuQtgdLtHTPpZErmZHNDhvrFGGqW2umev//0Kt8l9rqmVlc4Cj8h13Bx0r S09osqFrIIBVLrp3ntGTzbOaw42nQxGTihgG8TdeuyFmo7RRIwwVJXdJo7pmYJS0 nsK4vdBQsMW7UYt4EJMWFmDelPXn8RBISC43kZpJRkQIIS3BymRsz5MUo1BFDVjB x8sYyyDZ0e+316fbBIK6Vw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42302pkvh5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 02:49:45 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49AN7SfH017546; Fri, 11 Oct 2024 02:49:43 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2049.outbound.protection.outlook.com [104.47.58.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwawtnt-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 02:49:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YkB4mhS4okffKbS5lCk3g29EnGcvz+SGckT4RHgAoQdTOiVMahCeQJi4ekfLh1EAGovEGqZouqg10zmmJLPoDtvsBYZPHTEE0fVzM9Br3bdQ+Gci2V60jHW9qFDQuNva2/jhsEG3530BTyZaKE2JvHeOFd3g0G3t3Xe0sMNtItvpvSQwLe2GmLuUmO9DV89pB+Of3PfIzGzFLOjlLSXGc3zlMhs7YTh7dhA+XoZLkFACbW2rUIplUiNv35r3za1nt0NYa/L4jaJy5IzVEF0gW4ia5zg8MhfDlEO78ve/E4QcCUgtSCBDHRp1hTG8XSZ7C4YPboN0lf9HsS6IoHxuCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BbLM7oq4Qly7ZOxJZJ2nNsrSMYfY+f02iyF3nrR1/Jg=; b=D0nTYCiGss9pcsizhKZ+9THoG56Z1ZPzKiru0DEl9EhgMF5A8ZXraP+187FBIavAXK06A3Y/E1gk2biH2kAvYy5me9ZOkxsj6p9Bk8kNvg9v8bgdEQEDxjz9pDehW4w4UmWm4jRMCqfAQ3hKyeHDbGGmPpaEK5KNhbJRWxHjVmpzXWt/q3Mq4BM6Xz+QdYIP36L16E7ByT6FoKCYRilO9Z6A677TeDbgwYgmSOzNRT02AEKflffl6aAgTybwyhaH5YuYYIchL0EM3ORrtjCeeZ5RSm8FdcuEzSERmtDrNJ2+rkFI66LtwhU9H9Ff1E7zBHtILarbiTwFj/7QDmWOlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BbLM7oq4Qly7ZOxJZJ2nNsrSMYfY+f02iyF3nrR1/Jg=; b=vSU3g7+bOayoYMJDFl2XgyktFuYCUHXs/XyzienYUa9xnF87AlmDecxGtofEr7HXMaDlhOseD5g4p1hwnlkhrMVvZ1WJzXe3buAhhGrNft0JppqWYk/trYgxA/tT3GIwOu4DW6WhDUyMh2JMJQFp7YZrWFNL1M1ATQMWQ+F3rdk= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by SA1PR10MB7815.namprd10.prod.outlook.com (2603:10b6:806:3ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Fri, 11 Oct 2024 02:49:39 +0000 Received: from PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::fea:df00:2d94:cb65]) by PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::fea:df00:2d94:cb65%5]) with mapi id 15.20.8048.013; Fri, 11 Oct 2024 02:49:39 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, wqu@suse.com, hrx@bupt.moe, waxhead@dirtcellar.net Subject: [PATCH v2 2/3] btrfs: use the path with the lowest latency for RAID1 reads Date: Fri, 11 Oct 2024 10:49:17 +0800 Message-ID: <5dc93c29ea3b5c8f6049d38bd968c8caf143ca7c.1728608421.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: X-ClientProxiedBy: SI2PR02CA0029.apcprd02.prod.outlook.com (2603:1096:4:195::6) To PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR10MB5706:EE_|SA1PR10MB7815:EE_ X-MS-Office365-Filtering-Correlation-Id: ea31fb1b-d7c4-46e4-71fb-08dce99f59ec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Ant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XVhq//qKrYiXLcMkOxGbn3ff0hux8hDzt+q2FAzRArZ54brZ6CvBz6qGzcmkFr9LALI7wJ+S81TkXDAQ3mybjk3yXRHA7FUBzY5GS2UdjF9a5uRoslSTDJcKwqrElOimaDDS2f1JmzVsnVQGBh9Wsr+p107VDRai9RDt9P7ZnNfDw5sejyMq6J4Hk/KeBTYiq2uWwD+K5+6EfNFum+pIpZYn6IUT+xr X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR10MB5706.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3OQO1QiL6SwiSb7zNKX1cEBUxlEp4b2SF5THqkWOEPa/4da5s6h2cqKvrLJ7RQPMIfNAh3oyuihw4LdQ6Wqnw/cJzVJDd2Eqzc16Kjg2kxnO8OtDz6ssxg9NRjn2PMWfdvoHXSkxPvQsIh096TT7gUSgtbRNG4Y/TKhz9/K91ieNQIh2HrbmyEdyuRmVap2PTMf4f6fUoO1hnAF0IAVj+he1XIiKMNef7rYsuKYKN952+uMORmKnSr5Tqv4HAFPdnfjKjImGCKFCTTyYnxJAWRAEZ5yjWYXuncEzuv8yoD1930YfAnwKJFowiv7kIP7rq5LxyaXwZtivYTESZ3Zuy42RvTIzbuGDfvya5pkgJrk/hYEpupY9q/DQw0Kk8iqSd5D5KLL24pjDiO4B2ZNaiIfUjuSg6gno2vZEjC1FC8Zg+Mu4Yr8ShYsY1FRmXWcWmrYUFaCcm3MSgzHzxpuWT2wwsgKrbBLxgEyfg4qSxI0o119cQiStTlOFYafndUJolMf3y+wQu9Q4tCHFx4X6Z2Yb2NJP8uhaxhmMAmrt3KvLay7k1rk+Esg46wjC9jqiIG/bKBrhlysK00VcMVkcAH4UCCz0gzamEbEhoEuYpc25LY5i1ue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CtfrICUEOBMt3++/s1FTSX3WVghU1cqiVKWmbeL3y15XMzr7WxWmF7izeYoWFvq19NJjlrs6L5wDfO/63kn9xkPCnEjGdzVnevrXFz6K5Hw9LVOcqZ1YaQ6Fc4Iwhz7A21do1KFm6CGiMPvNJzt3bFXBomlEBiDnOI31pfC6lCPH6QPcqweZkEqFxNBN0ulJyT1IEukVrrUCiQ/o+qHTzkEjd5JqQGDFKIte9DPbeDqY2ll0C/oEgW1Gv0h+MNEiIohFUPnC0RRYk1jzxRXAchQ0EZ7QLux8QCdAMtkJQr3jOQujxJKqBd803p9PlCKIv6I1QX4nPZzc9Qm3YqzWNaVcc1qLgysJYWb8hS5UFclpVCwkB5KNKh1rJjyvaCpupr9Cr0cPQS8uIatMsyiZ3j6WA6FmT1+mMWmtyUFvZ1kDF3copQk0gQ/KHF/TUTbCUprleJrUt/IgU+ocYERWKllhyp5TQXeE5Pw3C1uC07I53G7cnh3m8ZYFELHyHs3HHl4z+ZaCvRc/AAtaGuNm6Zqy/mNuahPb3BwxLozLJs1Cq/NhyQ3e8XhsZmCYckkRJCRYTOnJsaf+6FroXo4RePREw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea31fb1b-d7c4-46e4-71fb-08dce99f59ec X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 02:49:39.8339 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sR/mJQ8NWXmgDEPamSI5zggiktRcMNR8W7gkN96t0L2deoCbUqfeq6ESnf8mvplde3eo+KyTIMBf8gXtivLzcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB7815 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-10_19,2024-10-10_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110015 X-Proofpoint-ORIG-GUID: FRPdFSHA3kKuJItkIWyhB-pqRc69Wvhf X-Proofpoint-GUID: FRPdFSHA3kKuJItkIWyhB-pqRc69Wvhf This feature aims to direct the read I/O to the device with the lowest known latency for reading RAID1 blocks. echo "latency" > /sys/fs/btrfs//read_policy Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 2 +- fs/btrfs/volumes.c | 36 ++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index bacb2871109b..9f506d46a94c 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1306,7 +1306,7 @@ static ssize_t btrfs_temp_fsid_show(struct kobject *kobj, BTRFS_ATTR(, temp_fsid, btrfs_temp_fsid_show); #ifdef CONFIG_BTRFS_EXPERIMENTAL -static const char * const btrfs_read_policy_name[] = { "pid", "rotation" }; +static const char * const btrfs_read_policy_name[] = { "pid", "rotation", "latency" }; #else static const char * const btrfs_read_policy_name[] = { "pid" }; #endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ec5dbe69ba2c..8912ee1d8b54 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -12,6 +12,9 @@ #include #include #include +#ifdef CONFIG_BTRFS_EXPERIMENTAL +#include +#endif #include "misc.h" #include "ctree.h" #include "disk-io.h" @@ -5963,6 +5966,35 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, } #ifdef CONFIG_BTRFS_EXPERIMENTAL +static int btrfs_best_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, int first, + int num_stripe) +{ + u64 best_wait = U64_MAX; + int best_stripe = 0; + int index; + + for (index = first; index < first + num_stripe; index++) { + u64 read_wait; + u64 avg_wait = 0; + unsigned long read_ios; + struct btrfs_device *device = map->stripes[index].dev; + + read_wait = part_stat_read(device->bdev, nsecs[READ]); + read_ios = part_stat_read(device->bdev, ios[READ]); + + if (read_wait && read_ios && read_wait >= read_ios) + avg_wait = div_u64(read_wait, read_ios); + + if (best_wait > avg_wait) { + best_wait = avg_wait; + best_stripe = index; + } + } + + return best_stripe; +} + struct stripe_mirror { u64 devid; int num; @@ -6043,6 +6075,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, case BTRFS_READ_POLICY_ROTATION: preferred_mirror = btrfs_read_rotation(map, first, num_stripes); break; + case BTRFS_READ_POLICY_LATENCY: + preferred_mirror = btrfs_best_stripe(fs_info, map, first, + num_stripes); + break; #endif } diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 0db754a4b13d..f9c744b87b61 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -306,6 +306,8 @@ enum btrfs_read_policy { #ifdef CONFIG_BTRFS_EXPERIMENTAL /* Balancing raid1 reads across all striped devices */ BTRFS_READ_POLICY_ROTATION, + /* Use the lowest-latency device dynamically */ + BTRFS_READ_POLICY_LATENCY, #endif BTRFS_NR_READ_POLICY, }; From patchwork Fri Oct 11 02:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13831994 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 1AD6D1F8F1A for ; Fri, 11 Oct 2024 02:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728615002; cv=fail; b=CML0mTex1g35mX9yH+b7cxjuhosK2seqb4LGG/f4Srbooyiyy6eFYgdBL9GL5sPbMJ30GusYW3D+7FZCjt7BfUuw5o1j7nS89nYByYxhsFCWKUoXHH9btlVRyTcAhrB8Mi21KU5BTgjH65XBe5G5Im0g/idxZR+W0HPDRYQbh8o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728615002; c=relaxed/simple; bh=TY9hOvKIwNu5+ajylBS5FShEOkdBlfS/qoToplKJQhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=uyI8nWracAqSaLWTMIbeqVXkQ2JmB3s0OuCwrZExhpCzaKHcmehxkhhHlKOHsJLB9mYrs+VaB1AamAx79HF9B1DeRbhkp13plp11aQJvYDX9S9s+jDV70vlQrBNNTrQ5yzlcW7fD+RyJnzI//Tpmm8rsFrFBr75X7UqY1tCP28E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Cs5+Yko/; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=BWI5hxgH; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Cs5+Yko/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="BWI5hxgH" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49AJtc76009430; Fri, 11 Oct 2024 02:49:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=3Csd5xkYD6/LTkMznQoTXWhWX0BOD5yqTfb0Rti2K38=; b= Cs5+Yko/UmcJe+wZfruZZPaMZDvJVFEr5qIyscbrH+FBLECEI5kTairqH+SME+c7 olNXUH7ju6GIhsD6d29a1hRxdPd99w8TuCkWy3LrA5v/Ph9iZmDCHLt9mK1+R9y+ 680LXh6UzIy/TeXEBfpZKtxxVOiAlPTH8h0jXdIukmRxXOoZS7Pzcn5uOl5oKhpu 1AbWsxcdWw5AEJNu78NIs+88VtO9hNaLpo417iivA28dIgr74juNL0Yl7MbP3ox7 zGtH8MI/7Mu78KHTKHvvTwYO5L8pbF80vknaS+0DIFH9Bf8buBAUpQOODNM8Hj63 0dvkrujN7r2Lma/eCAms5Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42306em328-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 02:49:49 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49ANUPiU017122; Fri, 11 Oct 2024 02:49:48 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwh5y81-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 02:49:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cPnz5s+7WKsOXwGzhiF2iWVdCq1+9UpRqfaX3wsE8DRYAfBWKYxf512kuQrveDu5fscJz5QeJQ3T8cSm6xSMcdHJ9flw/rWNPj6nRVGHWNN4YrtVFxdgDx8RyC+156Ac93+66M3WXuVU00c9+XROQnE26f0tfzPRnyDm1Ir7cRi9k1Hj3J6E1GPsN9f0l0pCbHjFsVEqBSKR78PUMhzii4mwp0jfyZpcRirIKuRdWtswtvXa6n9rELxrIbOrCu60yPAhhuMjh2W6PamzQwGv02118hDTouKjfwcDo1v43sWTlpIofOwL5PYW9YoYmzXZbYgFhm2Al/qd4vcT9bpSgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3Csd5xkYD6/LTkMznQoTXWhWX0BOD5yqTfb0Rti2K38=; b=HO8o62L6Ic5bkPJ+bxUZfSncMgt63fS4YqVc5o0vwG+eaC9lWkfmzk5RWW7ZlvH+dk55rD8019qEO5We0fzSqRUYz2aI4dhtp/jv1uq2Hon9uI3NIc1pH2sGaudi1gt+aXm8fB/wJPfPQRQ7XY098yMNn4ZyhgiqR0ceNi214dhyMm7+7YMRv6VMs9RbOkRqbcFbhjUl63F7MqVh+bWO88xR8y682n9zBqjYPALdllao7YwoVbebCiUHQUfFTZgzP/GT/cY+dOpem3mS6mLbuArhkURjcE8sTQS118Fe7OwIOD525EvAAIfffHgy2BvNAaTbHbg4QQC7i02Sg0Ihew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3Csd5xkYD6/LTkMznQoTXWhWX0BOD5yqTfb0Rti2K38=; b=BWI5hxgHsnEzok3vlrw7GW+6k+JXicgsy4OkqP1qd20MPefkNZ89aQY5cb+dpdJBx4wVLXoWccUMYRaiWXVcdekysBvPyPYBijgNxXJl/fvIr/kUYd17XY771d8eiclhcF3AgILHFsOTL9EZJeg/F//j7f6qlfG2fupqtWLaVns= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by DS0PR10MB6870.namprd10.prod.outlook.com (2603:10b6:8:135::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Fri, 11 Oct 2024 02:49:43 +0000 Received: from PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::fea:df00:2d94:cb65]) by PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::fea:df00:2d94:cb65%5]) with mapi id 15.20.8048.013; Fri, 11 Oct 2024 02:49:43 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, wqu@suse.com, hrx@bupt.moe, waxhead@dirtcellar.net Subject: [PATCH v2 3/3] btrfs: add RAID1 preferred read device Date: Fri, 11 Oct 2024 10:49:18 +0800 Message-ID: <8152126f6388d65a4a01f785caddefb796d671c2.1728608421.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: X-ClientProxiedBy: SI2PR04CA0011.apcprd04.prod.outlook.com (2603:1096:4:197::10) To PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR10MB5706:EE_|DS0PR10MB6870:EE_ X-MS-Office365-Filtering-Correlation-Id: 1451ccee-6e39-4c65-0b44-08dce99f5bcf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: pL0mWZHKa+vB1YuPLTIN74Exw4T58+82Bgt/4gv4z9hXgHlfWziDmKKofyVj8am7GH35K45ocpzZUZZOUfkutaDdE/8JCUpaN00mKvYf8S/DfBNzyY8+2VpoUhVcK9dhnZHuIQRpJ+MwrgkQ/D+q/qjsflNWdi6nz4KbQdASVbp5BorHMhFzfgBgrXJNm8z+EMbM30Y+8N8wBf0RsnS9SRZ/jeIGaZSj4BPMwTSY8taiPeczkMJ/vPOFfkl06hs+KEoV0zhtw9B/G3iqI1HR3/QQjVxbyZrzWY9PU43P6dNcycc8ZlX2NRRFb/8Cif5LznwvUxLfqJwUyNi9uZDfVUqEhYliHqt52YH/6nwC5b6Y6xVYtFl2ca46rH+MmFv3N0nTy6I88SUqfiCmuNqySD/GSCEWN1j9E+s19zpqXu9VU+ahg5DJSOYNKyKGzhuZaTZnhsvexYckJq6V0mKlIvjZb7FN6QFUkP1q/m3goSf/bOouHsIWpWZYVsojOFgs1UnvFWP054yP1pjHVNRUusaZLIzqBDuxUAwItOdcgzJcpXIkA7Fs3OJvMC4sM9LzEhoe2MsR4CWPAvHJzidKl34G9Wvgb5LFf0WQvddDUcWEl+yiajZuXn5Z++HNmqMSLKjhdM2eTaDm4kX6BseMvKUeFvB61UjeYS6fYEDP4Rd37CNcRlHRd4EFFXHwDZFdJuLPM3Ef4TPbnn0ru3QtIeDmBvUSunEnk390xK1nUqj4oNlOoPzdkwaD1ZJq4R7Z7JKIIE1ytR8xJ+ElJCIpDc8XF8CVokj3iznyQd77WKh9wT6LYIwaipOH9tAMrDFXPyGpYEqXASpLUarCIYXoszH/qbSNF9BxOkD3GfJP6RfSA/Ls8s9+D+nFIZBZsXAdix/3ZoheOWtyVAM6OYox9WBY/jN/TOC+0V0Nai/JTYkXkSl/7y7iQd0TcSJIllJfux+jGexM2zfLRqRTjMfC3ozeWyrinGSWRaX3xEIHSXmnoEX17A93/SzVYvOL9xRNh8rbRm3DRs+YPlsvOILvWK2T0HUxbwMYUbukKY0bcOGtqutFQ2ookWEnK1tDfCG0mdakjV5LNvMIhBEayGbuXybZzWJWhXcRtR1Oj1yoqs0jk1kmS4Tdyw2uaVoZW0sg917pHLtQfdNseClwiKN/sMDPRcHhW0HPBv6+WXDFhqFQgrFFlynC7+ocMmCtJNAHzUd19wd/kYMX0KKtP/oU/LYk5zxOAGAjXUFLsWCyQgFb+LZ3O9VY6XnM7DY1UKAUxC49Od27bwtnpvpfM7HEdg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR10MB5706.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HTHnt7wFCIY22lwq8+diAlPcTujGnTTBw2fGRVppMEOYDADS7IU0WAGa3pIUH6wZ3IRa2HMoYj0kYqyxLe0NOaCvxzo03dNtpwPcb/yioPKbsKikrLT89sYSWP2oXxYNtZyZ0Ap5E59+kidXNWeufBj/Ztg5RVc8U6+ZzshP8GOOZE3eEFBluIHsWJaBoIKW14oiaSXRvGALtSX3fuVmXDkKucJ8/Ecc24BOzP7thSz9mBy/od/JJidN/Fbk8wWUGm4o5U63B2HZuUTedmCM+HcagqrsajxDCWGvlDRz4GCwwaUx1t7j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WHqB0DWwUkecSe/q7Jdctxsv5UOFhC1C0XTxkBHGatJK8kORs711m8Y9ZKUp3PGSLcO+SNsU1y3gUc+V42Q3krmtj1qcHI49Q2p5tnPPer8LOW7/os0LAXD9Q1EjleI8qrgk/VC8aFvQbWu3OZ0Y9y7zUIj/8Ee9w0C1DWFJGM5+b/KgPXb/Op2jdb4kU5YBNqqATE3ss7tLir1NBoZn X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: mKeNifYkWvyJpdIprbl/PQWlrGMAHZeVq/ZAj0D5p5ZVEbn+GzP3GiF1uXwrlj0e84FkXzgzx/gjB225cLNf0kQ1o34nWY1Z+wcCyY2AhZObIr3h+GTYk8g3KaiBXOcvUCuyCys5sHxdAJIVv/Qqv9/0bfadgGcPrWEtt6fHQE6E6BXzZOR3xNuChZBRdEqf2m/Pgt5RAbzqOgCihfo0RVw3EvyR2IGwDM16SRJWfYnUR5MpDyse/rj57Sbr5vYIXdYXXRAbCzrk0PgTfsfmsHxFkA98pjUhRLWjolbnnztN5fKuJwNp+ye9wSjy1xUi6cNLWU1U8+8EDEYJomgTat/FmW6JeK7FUJIvkbDH5p4dSwyqRJma5Fb5FEAg+p3DcJA7xs2421ab0xYWLAWvx6OK/AwPljnis+BjwaxUeNvXTKsuY+ZAydodP+6sG191RHLe0+ORmLrZf1gxcVpI5+TgTXzCcoiasU68FeRdrcVVzfTW9/W1NMAJ+LHKNf1r6t7Mdjug+On3j34fuBa96mBg2VM7z6kv3araFeqZm8LXx9ia/oGUWeakLf6cEVfMbHCGCqghzM5pu6433Okkbd1gHM0TIqNS4udqqQKzPcI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1451ccee-6e39-4c65-0b44-08dce99f5bcf X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 02:49:43.1622 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dWGooqZuYLDlUcF8u4c8P9X8Xpt0iVbLrcrv0XDyO3vxRePiqrvOS1Mf0FkQyizZFt06G+AKioExqPlmR6tcFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6870 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-10_19,2024-10-10_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 spamscore=0 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110015 X-Proofpoint-GUID: egOULLLRdkkev-3pwfce8vyzjYGBKXxX X-Proofpoint-ORIG-GUID: egOULLLRdkkev-3pwfce8vyzjYGBKXxX When there's stale data on a mirrored device, this feature lets you choose which device to read from. Mainly used for testing. echo "devid:2" > /sys/fs/btrfs//read_policy Signed-off-by: Anand Jain --- fs/btrfs/disk-io.c | 1 + fs/btrfs/sysfs.c | 32 ++++++++++++++++++++++++++++++-- fs/btrfs/volumes.c | 20 ++++++++++++++++++++ fs/btrfs/volumes.h | 5 +++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 5b157f407e0a..0e7b29282136 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3322,6 +3322,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device fs_info->sectorsize = sectorsize; #ifdef CONFIG_BTRFS_EXPERIMENTAL fs_info->fs_devices->min_contiguous_read = sectorsize; + fs_info->fs_devices->read_devid = fs_info->fs_devices->latest_dev->devid; #endif fs_info->sectorsize_bits = ilog2(sectorsize); fs_info->sectors_per_page = (PAGE_SIZE >> fs_info->sectorsize_bits); diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 9f506d46a94c..aa4c9cbaa61f 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1306,7 +1306,7 @@ static ssize_t btrfs_temp_fsid_show(struct kobject *kobj, BTRFS_ATTR(, temp_fsid, btrfs_temp_fsid_show); #ifdef CONFIG_BTRFS_EXPERIMENTAL -static const char * const btrfs_read_policy_name[] = { "pid", "rotation", "latency" }; +static const char * const btrfs_read_policy_name[] = { "pid", "rotation", "latency", "devid" }; #else static const char * const btrfs_read_policy_name[] = { "pid" }; #endif @@ -1332,8 +1332,11 @@ static ssize_t btrfs_read_policy_show(struct kobject *kobj, if (i == BTRFS_READ_POLICY_ROTATION) ret += sysfs_emit_at(buf, ret, ":%d", fs_devices->min_contiguous_read); -#endif + if (i == BTRFS_READ_POLICY_DEVID) + ret += sysfs_emit_at(buf, ret, ":%llu", + fs_devices->read_devid); +#endif if (i == policy) ret += sysfs_emit_at(buf, ret, "]"); } @@ -1401,7 +1404,32 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj, return len; } + + if (index == BTRFS_READ_POLICY_DEVID) { + u64 value_devid; + BTRFS_DEV_LOOKUP_ARGS(args); + + if (value == NULL || kstrtou64(value, 10, &value_devid)) + return -EINVAL; + + args.devid = value_devid; + if (btrfs_find_device(fs_devices, &args) == NULL) + return -EINVAL; + + if (index != READ_ONCE(fs_devices->read_policy) || + (value_devid != READ_ONCE(fs_devices->read_devid))) { + WRITE_ONCE(fs_devices->read_policy, index); + WRITE_ONCE(fs_devices->read_devid, value_devid); + + btrfs_info(fs_devices->fs_info, "read policy set to '%s:%llu'", + btrfs_read_policy_name[index], value_devid); + + } + + return len; + } #endif + if (index != READ_ONCE(fs_devices->read_policy)) { WRITE_ONCE(fs_devices->read_policy, index); btrfs_info(fs_devices->fs_info, "read policy set to '%s'", diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 8912ee1d8b54..87a072fa9be4 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5966,6 +5966,23 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, } #ifdef CONFIG_BTRFS_EXPERIMENTAL +static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, + int num_stripe) +{ + int last = first + num_stripe; + int stripe_index; + + for (stripe_index = first; stripe_index < last; stripe_index++) { + struct btrfs_device *device = map->stripes[stripe_index].dev; + + if (device->devid == READ_ONCE(device->fs_devices->read_devid)) + return stripe_index; + } + + /* If no read-preferred device, use first stripe */ + return first; +} + static int btrfs_best_stripe(struct btrfs_fs_info *fs_info, struct btrfs_chunk_map *map, int first, int num_stripe) @@ -6079,6 +6096,9 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, preferred_mirror = btrfs_best_stripe(fs_info, map, first, num_stripes); break; + case BTRFS_READ_POLICY_DEVID: + preferred_mirror = btrfs_read_preferred(map, first, num_stripes); + break; #endif } diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index f9c744b87b61..b5ade9d41fe7 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -308,6 +308,8 @@ enum btrfs_read_policy { BTRFS_READ_POLICY_ROTATION, /* Use the lowest-latency device dynamically */ BTRFS_READ_POLICY_LATENCY, + /* Read from the specific device */ + BTRFS_READ_POLICY_DEVID, #endif BTRFS_NR_READ_POLICY, }; @@ -442,6 +444,9 @@ struct btrfs_fs_devices { /* Min contiguous reads before switching to next device. */ int min_contiguous_read; + /* Device to be used for reading in case of RAID1. */ + u64 read_devid; + /* Checksum mode - offload it or do it synchronously. */ enum btrfs_offload_csum_mode offload_csum_mode; #endif