From patchwork Fri Sep 27 09:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13814080 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 87DFB1BA886 for ; Fri, 27 Sep 2024 09:56:02 +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=1727430964; cv=fail; b=KN1tsC7UUio98F8Bk4b7HsV2Nxx8ryUAsDJWD/PRUSjOX6YScTtH7mkhxiuy44d/e3ckRot/nFb8mbYofdrY0c0MGXjV0LOIMc+sMEFqHkZrBK+3HS7OLhKgP/5oc/ynuEhRibrCSewuhpEO6D8ktg7POAiZdwIgTPcFyO9evtQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727430964; c=relaxed/simple; bh=92xKHMDt6WPvJNqzSsVj9NxTydf5iCoGYqJytJJSjbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=L24YFll1TXjYsxVjRE30T617ygcS1DndtMDcleEO3dWqlmdE9iztWZm9UeV4R3iVxpcoWkhxRMZ79NgWsS6xehEb0+d9wzcAF3p/CuF1BFggNKC4TwpBzpkwb1xGips0xPlWEQUrpjFsLnPUI5v4vsRIvRWGySudLjru3PUwavI= 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=TrY+WmDw; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=LVwuSdP+; 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="TrY+WmDw"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="LVwuSdP+" 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 48R5gdMn020797; Fri, 27 Sep 2024 09:55:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=VTJbyif4LS3g8SnNRgyssGWkd4St3/wt/cbZVkt008A=; b= TrY+WmDwI3YC35QgiAUWPuBs32+admEdpgAQ+BfqFmtl+aBMgx7hQWa6qZOQyayJ 15m7QNXb2OjWUbRPsFW9MWlQ1gSZglEB57xr8U4Q9e9bVcy1Mwd4liqV7hMv2Avh EsXG+1z125FzSIdkwUIe96kPEaDkkHyf7UkxuehCSMmjtQnyA2iu/T0F+pRtMLjh XGe4pvMryBJXYCyOtUGmPZYvDHdXDYYMukpuXBpnNYCNTY0eiuFTPraeC3m5kaHI rtI4pvs57s3f4myCj/FJ6/qFshhj5Qi6F1vvKjUw2cKwfQiVPBrvaL1NZcJCHvSM rMUJ0AHaWtavXtGSCAAnkw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41sppuf980-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 09:55:55 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48R7U8Qx026125; Fri, 27 Sep 2024 09:55:54 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41smkd8vdn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 09:55:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t8//0y79oFYpYfMfC9RyS5LPHrbk6OCrlBriKT3y27xsPZ9NgAcxmVPY/4p+cg8ZqmbfCwFG/kyvRq2r4JZCzFObmQ3LLdw6JsqOvBZi2T0zPowNTVun7Z+hMGsuTOfrlJhUr29J0bUC8leO6QngIG6+ro5W2jwvKoiNMoYNL19SiYdb1GC7x5ZrtHKfTN5xeQp0ohW/zl64q/cMxzTJX7VxTFQjpV+cNsQ7GgETJlMAnxXtXQ8x3h5KwpMe+gRGM5+tBS4KhifqsEKfkPs8+czOrURs26BQ/UU7JAkNihlsN9kK8g0jiX3X6AUeYxSAI+GbHY5mXiv0PyDjqcQNLw== 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=VTJbyif4LS3g8SnNRgyssGWkd4St3/wt/cbZVkt008A=; b=XryluxlU6rNY0u7D4RV99YuxcClVM+13bBFN0J+v1pndRB1oaf7kYMN2+GdSBQKoRX8px9Oc1w4KNSyCOifzPIyvxTxe9QSDs8z1xmV/jIaZH+ldYOQ7FpAe2uY5T6ZGismhNl/9CmNFyQXqtna1l5+3zP2oPfPwSH1e4V4J4AIq7LjclzOaVhoZxgNpB4IeKUkMygiEYL7BcBRt3sr8hxpXB56Sc2XQ87VoHZ6zp0dztnfdHDqizIIHMWzExZsJ3y8MEpcUKOgicYo2gG6f7uFVRcoptws0HAN+URDEvzywgaOnq7eQ6XPqsE37Dr6WF6fc0kjemg5bIai0PIaAMQ== 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=VTJbyif4LS3g8SnNRgyssGWkd4St3/wt/cbZVkt008A=; b=LVwuSdP+8hWuSF2nlMGErMuqWXp5FKlfP2NfKc2VemFSmMT0/+BZPGB8B3Fch4m9bHC5qfh/eUFEq5ShUi5Cql2i07H/H+SfzAw37jYdK7vfkMtdHb8BjbjuIdDa2ofF78qrY0530FKxqdLSet+6mTnvoHQcorAF+YulfQuFhVY= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by IA1PR10MB6735.namprd10.prod.outlook.com (2603:10b6:208:42d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.9; Fri, 27 Sep 2024 09:55:52 +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.8005.010; Fri, 27 Sep 2024 09:55:52 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, waxhead@dirtcellar.net Subject: [PATCH 1/3] btrfs: introduce RAID1 round-robin read balancing Date: Fri, 27 Sep 2024 17:55:20 +0800 Message-ID: <63676f15fe9b1ca6c10eb9021829b4666db6d021.1727368214.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: X-ClientProxiedBy: PN2PR01CA0143.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:6::28) 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_|IA1PR10MB6735:EE_ X-MS-Office365-Filtering-Correlation-Id: bc8c6c6c-0748-4d1b-48cc-08dcdeda924c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: edS2krot5JkMkmpWuGECZqhNBKK57RoWGSctEU8Syn0v1gaS7FA1dZoIkbe6Ut6F+2Q6+USPqQz2YrLF11WkHdpdSibqnSBiX/dh3aWXATZidBWgN1dxSecuLXDtKFc49WUVO0srq2XZaKze9rDAVmn2Jl3IfkMXB1fgr3GnJNseDgHufJm5D8ffUnIKmZwsNhXRgzoMRgfQVa/VxzBMwlDYQPQQn7qjeZbrhzMBF0ZVsZHt++zXzjL5zD3aDVvDI1XwblAJTPg9zHhDHt4s3ltVAxGF46Um2Y0yACg3713htE+vXgyKvXZS+er/jCb2jVX86pRBUUVMjwF0FhjUVmE0vE7W/HT8di9lGBMrmUWgwexGc7edxkmgXgjANigWCXObHCglCLF3eAd8FrrxCWJ611A5JHGdX6oWEPp4fzejMOB283FQCiA2qgsIZt/jTs0xggs33qKVwZErgEXCPEOVqYZ2xwkGs3Hike0cR+N2wDt/653IBvl23ZD2AtjcFIPgxKQJd4UuMcgsQauMNNpXxIu2EQLA54jRdsT9cU3CJ7mdyjFaDDMg0+3agg4jcp82Qat6A3XxKx+CtaOagOQwMLxpCa75+J1SdiM4ATV3u5idpmmIZxhmVtxWBZ0Mjx8dF0UL/cYTSanK5P7pH0io0bbB7jziwhxdlgxq8cCtGJSxLpQbuMLXYwHshVJjrrbBdAJT72Tb2j6nFGCnfUhdF09vr0K9Rz+XL5LSG+hIAzT0flAlB65U9ete1bNrEbIXamW6OVt3kA1EWBBOQu8wgY6vjOwDztE0+bD6XdjDkL1Z1nRudFMBrhdfRJxzLaU5/vfRftC984LXthgTu1uXjgxNamPfZAEccvPouw3ycdgogUCkw+9/RCpCveO/DdGEzSQtYVaOaGm9wrFv8Ek+JQTT3spJ5TSBL8kIVqkgbWByZMN67FSaoXHVTqNDmwCDyCnqGwYaniTpN0Y61b5WwsYNUaku/sBb3LnIvPBGUiKeInKTdA1hVLBTf69eXGhSLVAI8ceMc2RmTmwRXyIjCEoGivWIBQUAtUNAY9BVoMA2WbgfiP//JLftotMFizEY2WKRiqGdBgmOPpnK2Lxuu+fqcH6YaKayk73SI/MZ3U3+y95hqvRU+Lr2Qsdcob09qgRlk33bGpyGpKwGuOe3D2Iwa++IQtNtQG9Eab3TjNBtjm9PEOlSmfEcFjhrK2Q9teF2jZLP9OVHVRxbuYMO7FwcymZ0lp3EvcCzFgWNvAC4+9rbznEhOoNe5zIyC5W8vwxTXHePELb0IACI4qxOgNSppTOGnhX77HAT8Rl39APe97TaN0hovb3JPhARTfbVhixgnEmr2+FGGiZiXQ== 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)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e/LMpGIOy9BGqwu1SkaHsWyNrE6zhwleW53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dIKwDBpneVf0b6qmELqfcwrUUNHb8M0zuGf/PZ8mNX0N7TC/Mu3OCGOrXLFE0RY20JzZwBBHCox1EgVTK6XMGBBKkJo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc8c6c6c-0748-4d1b-48cc-08dcdeda924c X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2024 09:55:52.1845 (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: VqnMHMr84JBzVNJWyGHT8dZBdRrmelYHyQMWND1z3rT9BEMM8AzLgVWhuTG4wBYQa5o7IPNH+neHQD8ggtJWwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6735 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-27_04,2024-09-27_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409270069 X-Proofpoint-GUID: We-7LOwJzhVDWenPEJ-suDk42G-7HTaI X-Proofpoint-ORIG-GUID: We-7LOwJzhVDWenPEJ-suDk42G-7HTaI This feature balances I/O across the striped devices when reading from RAID1 blocks. Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 4 ++++ fs/btrfs/volumes.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 7 ++++++ 3 files changed, 64 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 03926ad467c9..18fb35a887c6 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_DEBUG +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) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 995b0647f538..c130a27386a7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5859,6 +5859,54 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len) return ret; } +#ifdef CONFIG_BTRFS_DEBUG +struct stripe_mirror { + u64 devid; + int map; +}; + +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: for testing, works for now. + struct btrfs_fs_devices *fs_devices; + u64 devid; + int index, j, cnt; + int next_stripe; + + index = 0; + for (j = first; j < first + num_stripe; j++) { + devid = map->stripes[j].dev->devid; + + stripes[index].devid = devid; + stripes[index].map = j; + + index++; + } + + sort(stripes, num_stripe, sizeof(struct stripe_mirror), + btrfs_cmp_devid, NULL); + + fs_devices = map->stripes[first].dev->fs_devices; + cnt = atomic_inc_return(&fs_devices->total_reads); + next_stripe = stripes[cnt % num_stripe].map; + + return next_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) @@ -5888,6 +5936,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_DEBUG + 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 4481575dd70f..81701217dbb9 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_DEBUG + /* Balancing raid1 reads across all striped devices */ + BTRFS_READ_POLICY_ROTATION, +#endif BTRFS_NR_READ_POLICY, }; @@ -431,6 +435,9 @@ struct btrfs_fs_devices { enum btrfs_read_policy read_policy; #ifdef CONFIG_BTRFS_DEBUG + /* read counter for the filesystem */ + atomic_t total_reads; + /* Checksum mode - offload it or do it synchronously. */ enum btrfs_offload_csum_mode offload_csum_mode; #endif From patchwork Fri Sep 27 09:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13814081 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 5337B15F3FB for ; Fri, 27 Sep 2024 09:56:08 +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=1727430970; cv=fail; b=eb+hGBK/2vWxB+l2noVQlNFbL9t1fsxpeeXcElKtL+lVIBhE8A4DYbUWB/zP0vmqQgfrQFEsOt7yGJvzmYh13739ihePibzWq8nHX48YR7hTJVh1OXN5WuDykxAqk89wOFNeijQHfuOVOnY9kR+MV15ONnCnO0UW95r/sb2Zoh4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727430970; c=relaxed/simple; bh=DGXGzKRmV9OkakR2hl8Maa5Vd1BbfUrHMW6fVXr5/l0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=SRYucTYgfvf1dqhXdvmNdoaL7U0e88q5L2gbPqR048T+OLky/ZouIE4rOHmM8u3wlPl3QDbme0QNqEx5Ox9+LZikwdqVCeaD8DAxNeN75w711jxb2p3d9EVXqAjBgZ3In0glMcHhPFU/jgXgXvqxwkUsu4sfuaR0NNtBYhuMMvg= 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=Bb1GMI90; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=uP2Va1rz; 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="Bb1GMI90"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="uP2Va1rz" 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 48R5gpDB016237; Fri, 27 Sep 2024 09:56:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=I2nWAhPnDAzFXZ38kUp+mbGwP85xmEyhxf67nD1Lbqk=; b= Bb1GMI90XxCYoON0wxqC+eMNzQ7iZQiXZFyXOHNmB4WqB23GqpcAAa7gafp+ylpS rHyBCOaK/9voNZf5sFnTfOzhH7w1fSP3Kf1sMjjAN//CAo2LvRl4uhLF8YtbLCk1 Ixcrot6BCxQNQ1G3jfzFLWS5SlgVg1KWxYsciqjry/PLVL3T0m6Z+TxWVNczOMqR MbcLKWrpJvRWiNdyINrHWtK/df9PHENw9SMts/4fIKUhtbao3y6BfuPeF/KQHIqT IvzJMXEFdc7gqfW5Lp6KFsMFdy+QmJsau371zg0K24LV1RBNYXGpukTnfZagw9IR Iy/SO2iTGK4Vo4cjP0bJJg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41sp1aq4rh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 09:56:01 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48R9V3BG032943; Fri, 27 Sep 2024 09:56:00 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2176.outbound.protection.outlook.com [104.47.57.176]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkkmste-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 09:56:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=opHNVQte/LEWHgElPs9IFZ8b+oW6JHsxjF9N6eFXrHJ6EH+WGtKM46dQQHLSl2zQwcsRho4+wXFidDGqhgLod9qUL5ntozW5jGNIMkmo1ivnMu5+KhAZgSgHLua9nar0gBEIhdDKoxv+cxEhs+/ZM1ga+DVth8y0cNQ0SvSiCAJaI/ubh27Q+jWVDyzVx4EJzhW8PdYL6DbermabnOmyvHdnSd5gaX3asACIHaXGthun8tXmN8TIu5GcYSGME8SeJW+XdLvhRHbSQQwE+3gQWMuSsBqfGhF+EJRsAC86iSM+U9QoJA5Svs/4Ae67fywmmFYBnYaNKmgkvmw+E4ab+A== 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=I2nWAhPnDAzFXZ38kUp+mbGwP85xmEyhxf67nD1Lbqk=; b=l5pZk9mm1FuZxVzcL967TwBTPVgy3vz0+SaJr92Bg2pESu+F7I3iSIwANFIBIhTo4tKSgrXGw2iC37NHCodsX5LCrlItVn8or27TyZWQUONgdPar6AJgQzdQScAJj7t7KhYayEmeSNFpLnkwQvXxsTCpRGVFB6WTg9/tDKb/XYzKiSrAcJXIj0W0w+1soCvdbXLCOIVnD4dIIcco66Ix6ArZgdwHYuSZqI3p8G3iiknkugboEjE1LjN4A7ZMf+KH6OZQqkk248A+OV7RGvXirs4Ozo7d9LezTxkGjtC0IWxYwDJ4HhHH33A2oMgF4g2X54DajwboOsvWJxl9+fmPUw== 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=I2nWAhPnDAzFXZ38kUp+mbGwP85xmEyhxf67nD1Lbqk=; b=uP2Va1rzaubEmWQWjLhTdRd/wE0n1CDw7N7sALwZZ4Q1UAVQKYsjTEiwkSg3mVjKdOQik1PDGQWKR/2oiVDKW+kDFd49S+gtR1gW7YLw6rIn8fjg15/a9oKsSx3hC6DifPN8g6MOo/duvaq0vRa30F4zOrLcMNSVdqfwP3/XGiM= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by IA1PR10MB6735.namprd10.prod.outlook.com (2603:10b6:208:42d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.9; Fri, 27 Sep 2024 09:55:57 +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.8005.010; Fri, 27 Sep 2024 09:55:57 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, waxhead@dirtcellar.net Subject: [PATCH 2/3] btrfs: use the path with the lowest latency for RAID1 reads Date: Fri, 27 Sep 2024 17:55:21 +0800 Message-ID: X-Mailer: git-send-email 2.46.1 In-Reply-To: References: X-ClientProxiedBy: PN2PR01CA0191.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:e8::18) 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_|IA1PR10MB6735:EE_ X-MS-Office365-Filtering-Correlation-Id: 90c2ae5b-db0a-423d-9083-08dcdeda9596 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: cywEeAGLBN4IbH3F6UBl+sYuodnpEp9/bLsIygIamCsD7QCItNKGN3TMi/924wqArsfx8UMVUt+/XKNQMD0ThTgvSobtJMsZkAShV7EaLUrbrABUAFU33C0x+O9k0VK1LV9Iqjr+80cS27rzHPGmElJWNhaUI1xviefjq308/aBPmejqVpMwSSXK2NIfww553Bz5posPE8QXe3LWx1QdF/aZdXvq8BRALBbnM0T6emODdNOK3UcFG/U71jppe//7DigGEDc0TCq5EnJa5uGtPTIpPQbVhvPfsMM9xrcUgMnQjzuUHxZwe8OV0zQjxKX/gpn7TXIb9LPSCL3+PCB9Bnq4S8FOvP7SvkXLPkA7nCHSxgVQVXcp760+It6IPYOc2sf0NP7U0uYq3juc4iKS+AwnNcAaxlK/lqxtdwFHrmORU+rmoiorXAOQzT6xaSeOalbAtTIsNKkbn04puTa7XtWlimCOsH0D2v85vyx8/yqgkzyiNFHIHa+NIvKzIya6vfN94wOJJ0hLofMYgrAQZ405mCABLO8wEl9EDeSRiRKYPVvRdrWXC0jg/veBDJ+QyF08u7vM7dcMTDnjakw93AnhL4TmdXxGNrZ/MMR5K0xNPcJiaLtdGnWK75eyIhHLgc+a9YzOMUTv66FZPdEvInEou0i949nkFK4uBiyJ1m+tAXupIjtkDghHZlCIh0Zf+olfJTSJE/DKFe3uw6tU/rp52pvFyDJ9ZH/r1isna8aJPSc9Z8mgu3WPiQPTuy7bBFgJmv4VndJ1VR9QxrEiaoKFBbSZVGtrTGzMgVEjzxBrp9iYqwvZdzsiI1XN2wRQJo4vhQRlqjHYr2Mo2os6avY07pZeNKuYU8DnYHG/kDE43RZAYJQnYJliffCm/L/NXf/ezT/Rtmf+97ydxbDIX8GM5LetoT3h7tkHCaX59tFJQClKUKnWgrmCAnxvULQk4N4fnGw86Ga+3YIkFjNLCUKSndXt4E9/+bilz2XauYYNW62y/EtsF02sOgwMYYoqx1zXxpUC1jFkeecKrCTkLQ5jbRf0VBhYbleliOQqTNgHSjOeVd3JowjkQtHbUI6XK1/AzCkgaJow7rkb7NNnTURbk6VXqeM61cc3QyTxY+CMqs25gmg2yMxQEw44vmNhBOIg2T/TsHr7PFmJROO3PrU7OtPvoWNL8np0+b2j+SmwV8X1TsvLRyLhWzc/1j0pRmGNv0+Z7OxAnUhcRenoA6SlgNybHxnjNUHpeE1Y3qDTla+EDIlPgghzkubpNCIzIhKEEUYfub/dEvQUuqyGq9C7EBONDwgp3YbuZhB3AH0qgYqzXyoFleLF4GH3Skui2Ojd7Gm/94deB9NEhiDi7Q== 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)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PLwlDXxaOlrwPyOHOTr1naCgQ3Hb51Nmm3Z58+2fWaTNRG/13jCN11zKlMm7E2ryen2XdrOAZIJGvtdrNbM/6CrCWzW/915T4pWhD1Ofpy860MijcFi803dCkgK/kzMq1YTqN+xWcENjdkaeJBUVrR+Y0aozDmv2yVk9ZGOSHhD+Nrh9KHNes8qcjVnWeuWTLcTkXEr627QNDbZ3+vOFC46RevpIatv5gJE55WxAHWoA2RCsVGxdgU+XdNC145UUxeApBnxCjQJ0qsfIOC9jCcz29uVV2Zt4QE2GRmsgmjzigFocbz1Jlj0Zq1/69ryiijy0VglkpcfoTRbA2tPNpb//QznChoMtdw0dv/DslAadyssRnGGvy8/zNUapn41QBdTEuVVVZs6qq56kDdUUk6a9TzUgTGDPRIfBXviXSJFnBbmwUySdIfkfE22UfN0A9Mhw6NGXus/+CPQ2fbuRIQ9VMs0+xvURif/+amTAjE7JOx8oTquT3IArC1mdspC0b9Aqv+joNaGR1D/xr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-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: WA7K+GaHrIhQs0RK3ejsjSU1sYKKTtDuEYcsI2kvL18jMgbZYyjm081g1s1a5hFH7B0qR7y3PoA70H+ttkGAPDLx6oJrnewsQuimr1A4JCf3xWCXMucagPpOtx16dDphFXxYKk+q+GKRoqyB3fKkjFyJT4OENgQEBoRuKI6PCwRmE8VqgNpiDlmQ5Z3rHp+myjNO7DaMKoxbNGp15v1f9+D/1ObugXb8FhpXOd2sXsr+i9kAX94lrP1m7p1QaiKQd9uIiSyvEu5KyvGrUjSNY4sxGp3QwLb/ezrYq7MpauvSa+buPm7YwKNDOfJRfcT+8LX8cxoBmHpWvRRpKWsvrWAPBIGxfcEZdsnsnOhvBqFpsxw6B4278mFjaGUf+xBHH8THXT9NjtK5iuiEjufK0EHSD1BEEvsIQsvqLFMSPEm0ObqPcD/fZiHj3bdqTd2YWqUA4k3sC2u2pRE0qKxgBgpNglCGqeXDdgeyL+nPQj0pfCqfMkE04HYLLREPBo2DDeaemjaKu+lIKuhvDimlX4VfJj2h/wxAmoJUd+t5ahXAS2c+V6eWr/eFYsO49jzutYCUm8FMeEby5UI6wFvoyB+Ncss4IhSXnQ7BYiJz1Lg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90c2ae5b-db0a-423d-9083-08dcdeda9596 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2024 09:55:57.6871 (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: 1tTW+i2vRoEP3dCgzWgVm8Fj2l7ZcxFzFgmTTgAyPS1mZ9BHeJKWMMrc7WCd+uiCrt4onVox8CjaTRXE58Xqbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6735 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-27_04,2024-09-27_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409270069 X-Proofpoint-ORIG-GUID: DiJItAlQg1L9zlBhOw2acenGFrkfpQkU X-Proofpoint-GUID: DiJItAlQg1L9zlBhOw2acenGFrkfpQkU 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 | 40 ++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 18fb35a887c6..15abf931726c 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_DEBUG -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 c130a27386a7..20bc62d85b3b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -12,6 +12,9 @@ #include #include #include +#ifdef CONFIG_BTRFS_DEBUG +#include +#endif #include "misc.h" #include "ctree.h" #include "disk-io.h" @@ -5860,6 +5863,39 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len) } #ifdef CONFIG_BTRFS_DEBUG +static int btrfs_best_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, int first, + int num_stripe) +{ + u64 est_wait = 0; + 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); + else + btrfs_debug_rl(fs_info, + "devid: %llu avg_wait ZERO read_wait %llu read_ios %lu", + device->devid, read_wait, read_ios); + + if (est_wait == 0 || est_wait > avg_wait) { + est_wait = avg_wait; + best_stripe = index; + } + } + + return best_stripe; +} + struct stripe_mirror { u64 devid; int map; @@ -5940,6 +5976,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 81701217dbb9..09920ef76a9b 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -306,6 +306,8 @@ enum btrfs_read_policy { #ifdef CONFIG_BTRFS_DEBUG /* 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 Sep 27 09:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13814082 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 337F915F3FB for ; Fri, 27 Sep 2024 09:56:15 +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=1727430977; cv=fail; b=oxxLuPMn7bNlGvWRnNu9OcQZFZbz9nhhQOQpKwGRLhhnaenY0DAdyW03w38DBhoEpf1Uxm816y+T6IVU2srxR8ew3NExs++NwjHxv9ZGj6avcs5qJ4JOpRjDXCPdeNyna1AQOFaJBECuQhuCzAsWAbCkIlWDWxTH++rMqr2bNfI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727430977; c=relaxed/simple; bh=SidbuV+9Fysyvbd0dxRTrVjsmMde1LeQLy9QmL+lBdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=qF0fhQNGBI0Wwdbm+H3eEnnCfMR0hYCjpR0ufsMAcewx5X+SWJo9rY0xjmofrRLD4ifWgVy+KcsJ2vg7ZkH0/R8o57sPIw/hZnEk9luEAYNBAMP9ZNNxFDlsPGVS//2Mv6plYBs1gAY+1QiYYaqvsIpDMgwV8ZTNZ2h8ESm9xgw= 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=DxqaM06E; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=dNx+ZS5H; 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="DxqaM06E"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="dNx+ZS5H" 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 48R5ge7Z016199; Fri, 27 Sep 2024 09:56:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=Y3eiUWTHDk0llyofKQ6R3XClNBsHBe85hIM0kYFhds8=; b= DxqaM06EPRR6VneE3Q9jYwDwHNjfaeO3g+Rqr1UYCZUfdUO+rmVUYb88GaAxlLr/ rUB4WFl5XLP9bDC3Rent8YujCucOfKWM4/p9/V/ET9Q0ghOX8E6OqZyv7uBa1Wnx 5EmnR0AfPgBZUzhfA0UDyjqI7jH8OUYMB5LFYWGeL8n4MkKJhYPo8NH5sDcj+GoT mvJh5MstOGCe82bLK8u9NFh8Us9dnjRJU/+iK/sPROL3IioV5KOyk+EFfiofxgG9 zrtPRSN07RdQgrPOge1qlxOHMGE5SUKFqVJcYn9V4HGqiCn9yRoO6zbFprqImguE SKm9F3KYe+SU068wXrUZxQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41sp1aq4ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 09:56:06 +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 48R9DXEg025240; Fri, 27 Sep 2024 09:56:05 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkdc5ss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 09:56:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LKOu3Sa+8YRAbwffz4nlnX2AIoA87mSKN59hSI1LppfX7gCJi8aD9pwpxmm8IVo457c54JIcLddKn2mXYo2rPIRuu5eYZpVG8+3TSKaoMMw3ZXwI7J1vYb5IH1JIT5AV9C+cf6tWbKGvDS9Xo/ac/dfiBH0aFMNf17O/VQ1dcDJJGvOo06uf+cIgvAn6TCmEVTiEGNtkkLBdSTqQ3G8qd3qW2lCJE8ymjhN/vdSQhQaKnRVoGvjkiNzWb+on+OdQ1dNa0W7SZsqXrbKS3LObLjY8imgwh7Dt96838qJHRXU7Y4wpLa+TSXbR7yKbkSSnbdF8Y1a1a1QwBBJjGgFKZg== 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=Y3eiUWTHDk0llyofKQ6R3XClNBsHBe85hIM0kYFhds8=; b=BHFWQPWhww8Hlb+lpWmlB1sybaTlKpOpF9G9hGTMQ3YYiC/LFOdItCArUYuifFU9xrzo+lvudXI6VOo3oDyTpC1pSQNg/TJPSGLuAzQlK8EX62zX1W6sbmwlzOWx0f/3pTP+fXNbBsMQvPKkiZbYiS9/+a9h1OncSnxtJSSPcHlOrT0nSJ9xSfw5XwnbofASzEpzZuAhTnpUZ/BZ2zLaog0zh4+KHe3YWRRWG89qwtCKx7dS/sJT/uEV3d+VhM9kjwdKV42pMVwM42mEoUnKJF2d0QMyRwBT0CtoLeOVmby/eS99x+LFOEOv0NekxhXcApRxPwE95SKKZDdgy912RA== 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=Y3eiUWTHDk0llyofKQ6R3XClNBsHBe85hIM0kYFhds8=; b=dNx+ZS5HhAk8Feez6dJyl+jsmsRKIxOKTbb52OsBW3ZhGoXYZl9VWMFigrZIa5NYLTP98ctuen9/IT7d9PQoj77tKPKRC/HtxkGx4NesciPVwex/tN+YJg6SLLnsgBY0RjVyZYUVMC1h/PJiVzsVlnIz2y4uGP0jsSg+6WrE3Bs= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by IA1PR10MB6735.namprd10.prod.outlook.com (2603:10b6:208:42d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.9; Fri, 27 Sep 2024 09:56:03 +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.8005.010; Fri, 27 Sep 2024 09:56:03 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, waxhead@dirtcellar.net Subject: [PATCH 3/3] btrfs: add RAID1 preferred read device feature Date: Fri, 27 Sep 2024 17:55:22 +0800 Message-ID: <6c2ae62fbae41873ebc52f89c4e506b897ebed82.1727368214.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: X-ClientProxiedBy: PN3PR01CA0075.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:9a::15) 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_|IA1PR10MB6735:EE_ X-MS-Office365-Filtering-Correlation-Id: b40df12b-7a00-407c-5f7a-08dcdeda98c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: 5FZIDbsgcXFjqGsvHNrT4JiMycfYvcYr5IwR6H1i2nN8uZTETSolmhsGLc/fJ4DeBjt/23AQFA/89wmirP1C86BTwTvG/FdGyQVXA7QFB553lSmHPYL6EyRdNSDAfQtLTL/x/iZUUEcx/qMTIp/abPLI7AhiBfjnadmVPkq95ZbF6XVklwr6MnnBHtLX36Fjf+Q3Ox6d3tiWHpsDjTurr8jTpLX9fdBqRfLk+Ey9LOpL5DjgM0fl2w4P6O0kZHzGva7lY+NP86brdtxSPbYVAcoUreDOTJpXbVlxKqdZdFzw0BpGhtoDpzM5zyqB5DOzcMQm2T5EH4dqdteqXaDdcoq39GmBB4JNEPoVZPRCAsZAwTodz8pMsxtvagNs1ZQBN6/3K8LqukPPlV4qyXc9rptfIvsqi6sZyPJgrvvxf4jA3wBP2IQkYSn00SMCHLQRn5+icO7fHgZwXpdCgh8jjXrKCAO6pQ++AuH0lxvGzzEEOu7vi6gPBaYDFwqi7IreipgeUkRoRdMLvUSgF0DK0ISAnjuwhxO4u7tmCY5HU1/ZAG0C828oCbMzKitumAOyF0FT80hoi/xM8bgmbogFJAfWkcG7oOoPy7FjDQPS5PCswNdIfMaryjs3dEwdfTYICSGL+4kF9lPZWlbqGEY6gq0yFjIEUt7qMRTFUTWANzbVtkbxjkECqA3boc4enwlovEdCQ767upFlTISaS0RSr1SbSs/uFZZ2STgs/VIm8uqgJsb2Nb7isJe0sy+bducf99VEaLFY550GQRRbU9/wgXfotzh+NkeXmQvVHh1kkfyoIbMnL25ifL2NhRCLlYlnbsLU/plgfAoxOUzfxWDNangAhejKN6/8dzpBwWAnzDENcf1NkjSLxCKE7GyZXj0JxGEVHdv3igns9pDIf9o8llwLwacSq04k8fgHjoqY+GYBCT1bzaGRQbXZ7nVBxWSWi9EIkPYqqCDIFgi0ebDLdTqcOFZelr4I7kH0T/w2S9Au4w6+itQerANEJYLnUpQPTnqBLGJg29vLCx/2DdWrvjwbosUeTRqG9XhXPS9W66Ts9/lGCEJH6qYLylIie+t39BWE0k+pjQ4Yuy8+lgFCN52CCsEE3Ng5nQSA0GsGgXiYDhJBRiCgWX/A1ynkeAjrjZGUdvQcQgsZa8usydTPDvIxkcXtRb/He6KLfOyKlnWVoJQRUH3O6jsmr//u1rp5es9PupLIfDhImOc4CGx3aqkB3jDg+ufKog59H1aa5SSnHJx/pLj4VwdFcOM+fQez7vW61ZZYGRgvFLm5BzH12lRN12K3AtVw7jZmIvTc6QF6/gMCjsAZAW2JPAT0Lix6wAEHiZws5uFQ1pv4Kx+hKA== 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)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lp7jLwQWtmxMmwSIxCbFhrlHghq2D+oZKIqq2/LASnn9Gq5fc0FrmOGdRuPuP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eEhSdnmZS7P7IOjeUSXfbhgwefNYDbhgQt3gHiHUXZ79jenCb5suEW633D9jdv+RgBKTgRPvudVRLP6LTycwQEqP3Cm0B9wMQgu8kk5iqLDwu0akNPrvJzpUcNOMy+O0bT/W5igD8xj1vKwIGsNe+KSQpqtPMpcns/s54jYd4e28tUVuEmA+qXZzK9qDg+d1XwCTMOFuzg9H5X6E9IynzNyn30BEDHnhUfmzUwuOok5XjaMGDg/QhvRSZRQI2dQ5qKreWfuW2av6b/6qVKTEOj197kSz/sDVLClIGsk4jq9fktbxoGmfJbojAiRdkzRy1KfCYxRsI9lp9kKf+5k88Zah+yBy56nY4HSByitx1M1+IBXomONZ/E7CgVN5fZabqg13eZRl2SLn2GUQAuVKz7rsJ1dBsXte4FIoKAB98uZVgyp0w1XweLKYE34OpIi2tsJYZCbA6ExQrj5sZMr7y X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: dJ135WDZs4+N/9id4GnXIUfrekBSMhHW0maioav7rVuO4GUHTGjzhpD26+YGldBKaD/T6DS2VPSeqEJmTntc/WOCE4X59iabIe3rXHti5hkkx5Yyh/n1CW0kghSuw76lOmbndrctbU/djZ3IQdsfNabm2032R+XFCITdrWZKeEQz7azL1Cr4Uluw+cLF5c+fsIPTOE/0vWjHEr7c3U3TBeXYM6OZxNBQT1hh9ljThsFdYDSPaolzPazIPrRZNxpAdXong5Rg1unmrYpIDNnk+KyDsm0/f2/uXIeGkhcqCTKfDvC9Dw7GZXyQwxsaAH1BpEIKSZcPtokyC42Q0WqeshxNhnwv+cN8CgoLzO49jnkg0+FybBTIzAErHsU7dPLIGjIeHISkqNyFTC03jQk1ltzoFUJfKqM71RKDexH0RHsasEQSHMa7nB1FpgKXNatfqvbfN+hxkHVhV/Xa95+9cWuuOfRczFQexlujs+VZPJZQETDrUZBgNn+/TmSs49R/GL/vERYSF84AChdSYyzpp0ZD6FpTkwjlT8ytDsM1svyi1ySa6LNhTOwM/ytnszmtthG3U2td14bwA791dEFz6Iv7TnOQMARElSsYVMTW1eg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b40df12b-7a00-407c-5f7a-08dcdeda98c5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2024 09:56:03.0262 (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: gLnGnEf9ElEKB0WWR0OgG6LmK/jb/QqIZDWAm+BZdEL/p/KdLTv1InlWPwKIEbc0tTya9dryf97J0RXE6mixOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6735 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-27_04,2024-09-27_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409270069 X-Proofpoint-ORIG-GUID: LYHtf9ZMDinYXzt8qYUCw8rUlXUuscKK X-Proofpoint-GUID: LYHtf9ZMDinYXzt8qYUCw8rUlXUuscKK 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/sysfs.c | 92 +++++++++++++++++++++++++++++++++++++--------- fs/btrfs/volumes.c | 20 ++++++++++ fs/btrfs/volumes.h | 5 +++ 3 files changed, 100 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 15abf931726c..e32999ea761d 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_DEBUG -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 @@ -1320,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_DEBUG + 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, "]"); } ret += sysfs_emit_at(buf, ret, "\n"); @@ -1340,21 +1348,71 @@ 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); + char *value; +#ifdef CONFIG_BTRFS_DEBUG + u64 devid = 0; +#endif + int index = -1; int i; + bool changed = false; + + value = strchr(buf, ':'); + if (value) { + *value = '\0'; + value = value + 1; + } 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]); - } - return len; + index = i; + break; + } + } + + if (index == -1) + return -EINVAL; + +#ifdef CONFIG_BTRFS_DEBUG + /* Extract values from input in devid:value format */ + if (index == BTRFS_READ_POLICY_DEVID) { + BTRFS_DEV_LOOKUP_ARGS(args); + + if (value == NULL || kstrtou64(value, 10, &devid)) + return -EINVAL; + + args.devid = devid; + if (btrfs_find_device(fs_devices, &args) == NULL) + return -EINVAL; + + if (READ_ONCE(fs_devices->read_devid) != devid) { + WRITE_ONCE(fs_devices->read_devid, devid); + changed = true; } } +#endif + + if (index != READ_ONCE(fs_devices->read_policy)) { + WRITE_ONCE(fs_devices->read_policy, index); + changed = true; + } + + if (changed) { +#ifdef CONFIG_BTRFS_DEBUG + if (devid) + btrfs_info(fs_devices->fs_info, + "read policy set to '%s:%llu'", + btrfs_read_policy_name[index], devid); + else + btrfs_info(fs_devices->fs_info, + "read policy set to '%s'", + btrfs_read_policy_name[index]); +#else + btrfs_info(fs_devices->fs_info, "read policy set to '%s'", + btrfs_read_policy_name[index]); +#endif + } - 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 20bc62d85b3b..c49ca48e7b2e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5863,6 +5863,23 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len) } #ifdef CONFIG_BTRFS_DEBUG +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) @@ -5980,6 +5997,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 09920ef76a9b..9850edaafe8c 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, }; @@ -440,6 +442,9 @@ struct btrfs_fs_devices { /* read counter for the filesystem */ atomic_t total_reads; + /* 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