From patchwork Tue Apr 15 12:14:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052112 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 93EE12957C7; Tue, 15 Apr 2025 12:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719298; cv=fail; b=MrfeLP3Aw7kiSfbqzLEMfgLYDcDhAsCm3vv1gG23DNSZ/TZ75JGO24Ad8GpmE8Thbw63qo49AAVxv6xRLaJWoXTpbrP52gSHdQ6hIbgUzvQ/x9BdcMbEE2oiGRLmPAQpY5UlTXPkWS4zue1Mov4GZO0ZlxSb9mm9y3yHXxe9lAk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719298; c=relaxed/simple; bh=96Eu+VEEpNJdkpq44h41WMUR6c4BaA910XJ75KMdX5c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=lj/wc+MKsmI7Ql9qT2w++eyEfGdAB8B/Vv7g9VlkHFP2O2RIhTYmLH09tGn5ZAEKFbP+lLw8/fs3N/2+3sE7Tqcf/57yfadlAYc2t7YjAUWEH7rQnPTQR247q94nhEOOroBGwUauv1fi2cu/IZVOEy11ZpRrZvjUPhbRN5XpZJo= 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=ZrLSMDDw; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=AFWBRbWF; arc=fail smtp.client-ip=205.220.177.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="ZrLSMDDw"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="AFWBRbWF" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6foGr032429; Tue, 15 Apr 2025 12:14:43 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=d3zAPOwQn3c6nTul65QgxHNFMc2vGRcTpjyC6oDEm9g=; b= ZrLSMDDwOc9mRY/5a/O8GKJ7UZKzY9heORNhH+NQO8DgcYlpqsRfQPYYstvgnnYJ ZXPO+Hyr0J05ssdyg+HDRL2/LcdlH0zeP/Fhp/MRLBX1gmldYyp0Uu2yf5rWby8d 3bDGlTQBZskfnz9Z3L5YrXU09KOSZjVWQCzi8y/pLPM2jnHLnON6+UeMpYl3VdkF JMlYP6M25FNIn8l28/tajXRadROl/2hFbMrWk2v6F4UjzxhP5Nk3zEeOeSN9CCSq b9Af0puAhcY/UIkoaZj7QjNgYxpNkA+hLahi0iJQQkfnCH7SH+P5zpfQTLLDhlVi yg+hKkU+qMaIrFTz8/ki9A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4617ju9k2t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:43 +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 53FB4m7K038808; Tue, 15 Apr 2025 12:14:43 GMT Received: from bn1pr04cu002.outbound.protection.outlook.com (mail-eastus2azlp17010023.outbound.protection.outlook.com [40.93.12.23]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4r76ny-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ks/aGc7YJz9/BSRpb6CQyv9UyUjTbvb+YCdfc8cdCWHjmXAIuJQGCNkcNhjv010QyaArRG4sLlelyoTjym5Y0J4Q6Xc8sSoM4A7gJF8lqy0EhlyzEW+r7d6KycYx8iAthuSoURM0LeiVRFdCJbLnIpARoOsTPTG5Uvc/iVfDGRt7u7V7lrFKDE/ov04OEE8GkdXR/fxf6SWVN/jKXHGHrSkAl3nbvVNqG4BvzjQn7tJGuNJ+R3NwdaNGDSU054VovjFmsJzInOthtnPnt31c/smHxmcw17imVaKMZvrQ5JRpXU/UC+Z1b9eNxahHW5EYf4YYN58qCPV5DaKJU0Sc0A== 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=d3zAPOwQn3c6nTul65QgxHNFMc2vGRcTpjyC6oDEm9g=; b=TKIYPOKolRtNqnIHvd1GYgcDZcX4Ryc06EoSTsB8MnrC2tNlvGNeUYan+b54PmhaYHKQWO0jYDKwmetBQhn6kC4WJ6cB4pZ1PlTq/y+Zyw463hOKcE0Cm6x9zGE+rRnpo4Cyrg1sijyoElu4ghaqhZRo39d2jsRJLzk3D52tchm2gm+IQIP5wVLG2CZ/dINnPIrMeyd7STG/xuXTvz67CLH9BI5p9HROpo9R+Qco9cEUWVh7LxVzkqBWXYlmxviDLFQlz3tJLybeKxguw64tKVVswX67blQUapkOOD3yx6ZNMdoj+6Wp4Y4e/dJ3IOKv2WiYbJQSiP34ZCJKrZkVAQ== 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=d3zAPOwQn3c6nTul65QgxHNFMc2vGRcTpjyC6oDEm9g=; b=AFWBRbWFk2Lzkz4UDT9Wd0/Y/8Q++1fonehl9gMKAZq+ffkBRQr3PzChNRFnvlCk0GqrtJF87gp9nnFgQHijrL/LlILnuEgPbOOwpZVxuqgXPPBvQrAUSzvJUauuaVQ045pg4KZo7Txoa4weErL8Ep/EOND3LfPu3mSCJG8/xfw= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:41 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:41 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 01/14] fs: add atomic write unit max opt to statx Date: Tue, 15 Apr 2025 12:14:12 +0000 Message-Id: <20250415121425.4146847-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0126.namprd03.prod.outlook.com (2603:10b6:208:32e::11) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fbd6347-85f8-48a6-b708-08dd7c171981 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: q2Dxko5xLPs19AGMr2R12AUufefhqodCl9IecF5Y7NBLiyZ2yuiKQgJg3McZwjtJrf3tUDCcl7DbzEklWwurL6OGxE0BWF7YFNxeMQCwSwL+K8wvTRZbR55FdMTM39J9KAGWGbyveLU3/zUm/6073LfF/EjMgagaGtHBOOeeGTKmbyKpWnZzmXCaXkTPHVL2S36JnNmc47qLUY/77lQ27DUIi5KUoDFJ21KMAqraCmiMkmm+rgf/IPLIwTUC9PVGSsGpsF+q0aIN7b2cSu/lVH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FoXQpMehoVG6RB8L1XxLzIiGcR1/epp08hotUDULVl9dAt0ciRL+fJsze3MliYIX4mtyU5WmOVQPlrIfr3jgddpw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gGPxKKGVTLp56hixKRhnm6kGnGvEU4wrxloCFxucskXxRzDN1RwD6NCro8KoJsVnh71Q6AvFMGBf2rHdyHs30fkvORbajHq33qdzQRyKSqBy6+YLV4W/8anwQ3smvU5G0E86dJtOUKWQdBCBONcj/kFGCW8OP7VrAOl2kTMiCq69oIyKDYdTCI81q4iaLJ8EOC4dBMlBjJQfI4gn1+9KPFeM9LIMZgP4kgSGJNUu+WCKV64eLdeZiwZ8kNX4tCApexOJZHu3J9ivKD/M9li++I1WVwVyMK7ULrurKSwhqLZn0wgkfNlGj84wiWJhpIHai2FpwWXyVT7MeJabhz253vNTBWHn30tfVu1cSyG7RsNPPZa6w3p94jg3RYTJkbv9hmYGWT2xWGnX25fNix7OpudxY76+PQedbF7ypa3kXBDVNwI8pSorRS02THb3TPO8INQ2pwvWmdoQlL000nSCHaSEHKQY/jAiPA+PJEW2tnbLhxzd39o4nt4P5sL51JE/hID/c37aQy/vfm47q9uIjdPptL72Eqx4txf3Tp1/JdQj6FknPxSwO2JimlOUiFyyPhJs5cwKxHVatHsbSgNPHc8uJFoP469sdIy+LOAhmLbg27bMyWv0cfqf9zCxWZiAWZxexPPQIZvBLK83GdihCFailvp/0sLIQ94nPLHTaAjmAxKKPUFQbAK1wVpP6/mDWz3fZ78CauFviDzq59J0b5R5OzRSdgc6blic8Cb66c2LmdbQmnPJtAzbEIChNB0u5+8MZlAkI5BOTIACTJaLjv24xb2CXpl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KTka90KsZNf+BPggou+dpN+jwxUBxK4ncNL0NUznDfzzBvSBZmABayUYq6y11E1ax4T8UWfBZ6eImhwcGa7wyFW1/+xxHZS22L30o8tLoeklaOklAq6QsRy6HqWX5ZmGhZKaIYHDVMxsOFYy+ZM2vCLwDFB6AYQynxKMSrlixXkJscMDipup3l8XvTgGa93X9JpEUgQ76ndz2dtjaO9fEfafD645ExG9TyKLWRSOFPx4PPD/ic3U6e+d1rIj8kbMmXLflwPdUyiIxU4Gwrt8GPIIgu5qcR+AE/IAAScNQtymkGJ7nlvK3i/R61dq31njVZV9uipjOuoh8AY2whPDzqaGsgAYsG9mzbgW6/+k820vu+EhLcR5nj5Oo0gPYhhYIfeZ/pZU5So2i8rD1tPSffM69PtHLfVduovFc8vwv8R/N7hC55w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0fbd6347-85f8-48a6-b708-08dd7c171981 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:41.2401 (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: LUefVs5cl9nuoDYIuulvt9NPvWUNFcHCVcFKTKqWtHUxf/U6OLf609rCZxG7JYGA1Pk5j741hqsacjes8+R1cQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-GUID: x39Hlyw8sVOGcMsWACdbuFCh7nxBokYC X-Proofpoint-ORIG-GUID: x39Hlyw8sVOGcMsWACdbuFCh7nxBokYC XFS will be able to support large atomic writes (atomic write > 1x block) in future. This will be achieved by using different operating methods, depending on the size of the write. Specifically a new method of operation based in FS atomic extent remapping will be supported in addition to the current HW offload-based method. The FS method will generally be appreciably slower performing than the HW-offload method. However the FS method will be typically able to contribute to achieving a larger atomic write unit max limit. XFS will support a hybrid mode, where HW offload method will be used when possible, i.e. HW offload is used when the length of the write is supported, and for other times FS-based atomic writes will be used. As such, there is an atomic write length at which the user may experience appreciably slower performance. Advertise this limit in a new statx field, stx_atomic_write_unit_max_opt. When zero, it means that there is no such performance boundary. Masks STATX{_ATTR}_WRITE_ATOMIC can be used to get this new field. This is ok for older kernels which don't support this new field, as they would report 0 in this field (from zeroing in cp_statx()) already. Furthermore those older kernels don't support large atomic writes - apart from block fops, but there would be consistent performance there for atomic writes in range [unit min, unit max]. Signed-off-by: John Garry Reviewed-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- block/bdev.c | 3 ++- fs/ext4/inode.c | 2 +- fs/stat.c | 6 +++++- fs/xfs/xfs_iops.c | 2 +- include/linux/fs.h | 3 ++- include/linux/stat.h | 1 + include/uapi/linux/stat.h | 8 ++++++-- 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 4844d1e27b6f..b4afc1763e8e 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1301,7 +1301,8 @@ void bdev_statx(struct path *path, struct kstat *stat, generic_fill_statx_atomic_writes(stat, queue_atomic_write_unit_min_bytes(bd_queue), - queue_atomic_write_unit_max_bytes(bd_queue)); + queue_atomic_write_unit_max_bytes(bd_queue), + 0); } stat->blksize = bdev_io_min(bdev); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 94c7d2d828a6..cdf01e60fa6d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5692,7 +5692,7 @@ int ext4_getattr(struct mnt_idmap *idmap, const struct path *path, awu_max = sbi->s_awu_max; } - generic_fill_statx_atomic_writes(stat, awu_min, awu_max); + generic_fill_statx_atomic_writes(stat, awu_min, awu_max, 0); } flags = ei->i_flags & EXT4_FL_USER_VISIBLE; diff --git a/fs/stat.c b/fs/stat.c index f13308bfdc98..c41855f62d22 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -136,13 +136,15 @@ EXPORT_SYMBOL(generic_fill_statx_attr); * @stat: Where to fill in the attribute flags * @unit_min: Minimum supported atomic write length in bytes * @unit_max: Maximum supported atomic write length in bytes + * @unit_max_opt: Optimised maximum supported atomic write length in bytes * * Fill in the STATX{_ATTR}_WRITE_ATOMIC flags in the kstat structure from * atomic write unit_min and unit_max values. */ void generic_fill_statx_atomic_writes(struct kstat *stat, unsigned int unit_min, - unsigned int unit_max) + unsigned int unit_max, + unsigned int unit_max_opt) { /* Confirm that the request type is known */ stat->result_mask |= STATX_WRITE_ATOMIC; @@ -153,6 +155,7 @@ void generic_fill_statx_atomic_writes(struct kstat *stat, if (unit_min) { stat->atomic_write_unit_min = unit_min; stat->atomic_write_unit_max = unit_max; + stat->atomic_write_unit_max_opt = unit_max_opt; /* Initially only allow 1x segment */ stat->atomic_write_segments_max = 1; @@ -732,6 +735,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_atomic_write_unit_max_opt = stat->atomic_write_unit_max_opt; return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 756bd3ca8e00..f0e5d83195df 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -610,7 +610,7 @@ xfs_report_atomic_write( if (xfs_inode_can_atomicwrite(ip)) unit_min = unit_max = ip->i_mount->m_sb.sb_blocksize; - generic_fill_statx_atomic_writes(stat, unit_min, unit_max); + generic_fill_statx_atomic_writes(stat, unit_min, unit_max, 0); } STATIC int diff --git a/include/linux/fs.h b/include/linux/fs.h index 016b0fe1536e..7b19d8f99aff 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3475,7 +3475,8 @@ void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); void generic_fill_statx_atomic_writes(struct kstat *stat, unsigned int unit_min, - unsigned int unit_max); + unsigned int unit_max, + unsigned int unit_max_opt); extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int); void __inode_add_bytes(struct inode *inode, loff_t bytes); diff --git a/include/linux/stat.h b/include/linux/stat.h index be7496a6a0dd..e3d00e7bb26d 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -57,6 +57,7 @@ struct kstat { u32 dio_read_offset_align; u32 atomic_write_unit_min; u32 atomic_write_unit_max; + u32 atomic_write_unit_max_opt; u32 atomic_write_segments_max; }; diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index f78ee3670dd5..1686861aae20 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -182,8 +182,12 @@ struct statx { /* File offset alignment for direct I/O reads */ __u32 stx_dio_read_offset_align; - /* 0xb8 */ - __u64 __spare3[9]; /* Spare space for future expansion */ + /* Optimised max atomic write unit in bytes */ + __u32 stx_atomic_write_unit_max_opt; + __u32 __spare2[1]; + + /* 0xc0 */ + __u64 __spare3[8]; /* Spare space for future expansion */ /* 0x100 */ }; From patchwork Tue Apr 15 12:14:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052114 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 673D5294A1D; Tue, 15 Apr 2025 12:15:00 +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=1744719302; cv=fail; b=XvkIxoLG9kX6b+m7nJIdpAP9hXtE9bgN9oJpJBjXFbB9H6bijJLeU1UmBhHpRLjyvR1AukEpHJSEw7PSUV+cYQGXvE6Fmw7kfjgt2eGBpNRaBdbthwP3SZQKRQVnsq6YIPEZYkRcDLrB5nX5ExGEp1+qPcOk3u9LYMqndE1OrY0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719302; c=relaxed/simple; bh=/Gc9YxwkEPXlQwpTWBqIaTS+N0I2IhLUfDnljXWFgSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=tsY5TYhk3xiC9DaiMy/VV8x3hwfrOM8qR6F/3vRUmdnfVRu19/JyVfswbgUrBdpAOtNFBb2JkmE2zo4eFpMjt3kdXXihMkBmnQdz0JPC08JYFQIcT/VCc9IwNwaQsDiVvLk+n8hx5xWvoFYakUfu7gtPr4+Y+U8eJc6jwy819NA= 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=j/h4EvVI; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=TghJFtc0; 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="j/h4EvVI"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="TghJFtc0" 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 53F6fpK8021579; Tue, 15 Apr 2025 12:14:46 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=1DLzKEzxZWroZS79L7ym5z5u37TJWbokIXzfpxvotNA=; b= j/h4EvVI5C1OCk88pp79qtZGi+4URPZKhKL5BDZATQ5sytjx14CsPycYCfJDNfLN 68kyMLjH+8k8MwRMxu10Rrx1fsDlbLaSd0Bty+ELyqiH+npL+zy1e73/jVA+bQED smoIlMX1Guzl8XBYz2Rc66zV7m57lXq0xOQOXcPzt/VS9eFixhHr0tLjDSHNVRM8 hiuZfob9KCHlL8a5iYemSnYqB20UOJeA4ZYQkWhE1yoj43bWzHrdfQF8YzSfoYkE DwYc+nDlRqgfHh0NvjB2p6Q35YK7zj1yfkaNVT40r7f9+5ACJiVWK6PxHo7tsmcW Uc0WhlMjwIxjoYhiiscJFg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4618rd1ds5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:46 +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 53FBb4CV031005; Tue, 15 Apr 2025 12:14:45 GMT Received: from bn1pr04cu002.outbound.protection.outlook.com (mail-eastus2azlp17010022.outbound.protection.outlook.com [40.93.12.22]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460dbaewrq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gCOXt5DFsv/H46QX9sjGNRd1cHZzWW+eiN8yIJ/7j/UL05nf0tiS14jd/UNDfKArWOTVfPyX6+CcQkQHAU15aSvO3s9hbTDXRew3Kb7oKW+bkBW43HM6KFds276ZdH1+LNccNyEMj85RaeL2S2nPRBlMkilLbClrU1N1EE7E7CWwoiQU8yrcqOnhLjuLB691fQbMxflm7f5RqySJsjvzyj7TgYbQHr/WvqGA9oiKte28F3/VWJVsUt0Eh2MaxJjcfE3TFxHVPpO7OCbA/DMqElUiDHd0ygNQ69hKd+/ASPbb7SRXBF7zCntVyEdG4vIU+nUzpVyHRpzWqfPT53/daw== 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=1DLzKEzxZWroZS79L7ym5z5u37TJWbokIXzfpxvotNA=; b=HHbcD/jmyfsvejXrv8f2Pg4YXoHnlvt0DhA/RXshbT8Z8CczDvSPaazUzkZy4sk+th9F93VX1biq0sUBLZpgFSHUaUc2TMbl8YMGS5q2DdqcAIfGDkC6PXCSekvDY9QmFrINu8fI05ymPCsHBkMtoxd/GUJB6nDmGa80QyTdX7clB1DWnzU2ibK7JQuXpDscVEvYpapOnV0aesLb8FIT6EYhqHuM/FNcQSnyeeNPwJq7OvKQ+yTxEMtDXq979NTvMUFWDB8l6xqNkDG5vo4DN6TLutsPG0o2o5LA7ABvBwv2vmtQdSmOURnflxHz5ZF2FRO2KvnBL9XTXloZ71Ib4g== 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=1DLzKEzxZWroZS79L7ym5z5u37TJWbokIXzfpxvotNA=; b=TghJFtc0iIr/PUOJ4l3yP0LEMtoCOnVguXeDafftwoCqdllwEwZw4weEQtOgvz2vsQUPvdqyV1ENzubeekEXvIzisG/Y7yX/dzN/9aiMNyFimd5F/lOcb3B3OVo+j7xDAQLo5muIGkW4iW/Hg5vRJmkS+MGAAYCpPXul+Vnwvzs= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:42 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:42 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 02/14] xfs: add helpers to compute log item overhead Date: Tue, 15 Apr 2025 12:14:13 +0000 Message-Id: <20250415121425.4146847-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P222CA0029.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::34) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bcdbbd5-d1c6-45cf-db98-08dd7c171a62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: rEa3gi4oQQ1+vOhEpn883EQGI/OfQaAKnqAhhFv/SUKKFz9iOEUGviD/MN2dTHit7lEd8lXHTJY+GxcxLU3CTgcX+7eW6Bq0he7RuLHdLPtUp/Gj8eyfHI9cwT5NNNQO45/i8w0qlDOXib2RS71QYJqoySAfi0Kw9rWeR3e5nAkpwGelxLRmb+ENBuf5CnaUjfCbz0csxRVo0tTusFQ5QCP+TIlKbBX/roc1e73KigYgyP+U4/uZG25mSczIvMOyZIWnCLCISa6WVpJbXmuQWDBZ2PbXL5wsKZvfhlUQ1sj5xsLwdA7LGdYC767HGGaPh1T6LGuoHY114v/EO5OuMU8o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lK4dZUhLyPb0GqltVyrcyvDlSN9R0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QvR6XTGGFr1a8X8ttMj3C82ibHg/aU59YQoTVvb7R9UFI6IiR+7QSZU+b4yvvbPGksJxgEtgYM/273Xs8Klay2/vcP9SYiqNNYiJaXl4a7ctebFu/nqxyd3TWnBxjNfnKuzDhYMbWerVS+9Yx730bUW2blFgdNrVso+cEgTBcElSYLt8c4SsFVgojzB3aftb0nCRSxQnEJXD9wVrcrK/oO3u6prKReamH7+vkRUIO1lED9YNEmjYKRTPVgj84CgXFyOV1yu0cGrSc63lx3kMmqc+HRyZA/IeDpn5znihsbke+x3IGAPNNcna9lAy5YCEyJ/ttb1cqsCzx2xFbLco7Ojky7e9FlVIuzYqelUNdTCERhg21dCZ3o7Ra6yMnbKxB0eRr+cl/m2WelKdb+bO1ZnPhoCCAr61fhbtkk1cQJgHb91DVFo0gNkV9p835Mx4kC9nfp7HoQdMnhFgxyH7TnKMKMWnNZmlk7d9oJ+hTk3EHEZhdX3DKreErZEfTRP8uJcdOwV6LK15WDRvIbT78XXoESZUZoW/M8G7Rd7c73sWOwiZTJSvK3JBWWBawBYhN+qZPg1THMdGhPX1QzQjil4S4xTgg8H0ZpzQBjFoWxr6NUwaOpN4V1m8EDnIqpdbFYL/pkcULpOGFYTIQYKqr+4i6m8Dh2wDSy4qyj77QU95bxIb2tnZnbj5FXZaauS1Vmz6cKlFOduK5Gr4vLE1X3biXC9XuULsgGiWLjDsf+VwbmGxA1uUJegoHfxJ4GOhI73H3/q8GvfQiMmjfdkoAWsK9rsaaUzG9fCDrZTo5MbZqmhVZ7gTwgLXs4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BudfHWcaR+HUrkA51OF/ie5FK9Ksqs10JNuuzCK9OCfgcX1461mpd9povRsO41P3Le6K/36vBf+EUIw0D81vglTZiVak2dU+VeavxX4+lu7y8pCBr3zkFQ+HpDUQ60DSixMsDJK4WPQH8TCxDn/ep4FjM8/ysgTM4zEk/ddSMcUYdx6PyYjIPmmWnzMZOFq8skbL5dV/78rNFX4W/GiD51HqcHLcxJn4tNtyOWfMsVfMngizbfQfen4GGrl1dQMEx14wlUTCzHYKgI2BYGK82Ftd/K+C/CF3hF7eGGRMTUyJhMGGvvxZA1nkT+7qJJKp2FNXjCN9mtJWhw627jWOoD7bTQz6rFhynSgvMFGaKV7XAJ7eunnOUu+4anUlZ8bhrEMgLgiZQAvO2MDyrY8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4bcdbbd5-d1c6-45cf-db98-08dd7c171a62 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:42.6715 (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: 5BiduD+lZidQHBEKek2bJbDCdWmJ50DTGnj46ayx/z4xOcYm12KLhDUcQe7ByUtN4ZFjxDGKBIwgnMx5vGE3HQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: FNKRpx625l1CN8W6llj4QzIrTSWs3SfI X-Proofpoint-GUID: FNKRpx625l1CN8W6llj4QzIrTSWs3SfI From: "Darrick J. Wong" Add selected helpers to estimate the transaction reservation required to write various log intent and buffer items to the log. These helpers will be used by the online repair code for more precise estimations of how much work can be done in a single transaction. Signed-off-by: "Darrick J. Wong" Signed-off-by: John Garry --- fs/xfs/xfs_bmap_item.c | 10 ++++++++++ fs/xfs/xfs_bmap_item.h | 3 +++ fs/xfs/xfs_buf_item.c | 19 +++++++++++++++++++ fs/xfs/xfs_buf_item.h | 3 +++ fs/xfs/xfs_extfree_item.c | 10 ++++++++++ fs/xfs/xfs_extfree_item.h | 3 +++ fs/xfs/xfs_log_cil.c | 4 +--- fs/xfs/xfs_log_priv.h | 13 +++++++++++++ fs/xfs/xfs_refcount_item.c | 10 ++++++++++ fs/xfs/xfs_refcount_item.h | 3 +++ fs/xfs/xfs_rmap_item.c | 10 ++++++++++ fs/xfs/xfs_rmap_item.h | 3 +++ 12 files changed, 88 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 3d52e9d7ad57..646c515ee355 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -77,6 +77,11 @@ xfs_bui_item_size( *nbytes += xfs_bui_log_format_sizeof(buip->bui_format.bui_nextents); } +unsigned int xfs_bui_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_bui_log_format_sizeof(nr)); +} + /* * This is called to fill in the vector of log iovecs for the * given bui log item. We use only 1 iovec, and we point that @@ -168,6 +173,11 @@ xfs_bud_item_size( *nbytes += sizeof(struct xfs_bud_log_format); } +unsigned int xfs_bud_log_space(void) +{ + return xlog_item_space(1, sizeof(struct xfs_bud_log_format)); +} + /* * This is called to fill in the vector of log iovecs for the * given bud log item. We use only 1 iovec, and we point that diff --git a/fs/xfs/xfs_bmap_item.h b/fs/xfs/xfs_bmap_item.h index 6fee6a508343..b42fee06899d 100644 --- a/fs/xfs/xfs_bmap_item.h +++ b/fs/xfs/xfs_bmap_item.h @@ -72,4 +72,7 @@ struct xfs_bmap_intent; void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi); +unsigned int xfs_bui_log_space(unsigned int nr); +unsigned int xfs_bud_log_space(void); + #endif /* __XFS_BMAP_ITEM_H__ */ diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c index 19eb0b7a3e58..90139e0f3271 100644 --- a/fs/xfs/xfs_buf_item.c +++ b/fs/xfs/xfs_buf_item.c @@ -103,6 +103,25 @@ xfs_buf_item_size_segment( return; } +/* + * Compute the worst case log item overhead for an invalidated buffer with the + * given map count and block size. + */ +unsigned int +xfs_buf_inval_log_space( + unsigned int map_count, + unsigned int blocksize) +{ + unsigned int chunks = DIV_ROUND_UP(blocksize, XFS_BLF_CHUNK); + unsigned int bitmap_size = DIV_ROUND_UP(chunks, NBWORD); + unsigned int ret = + offsetof(struct xfs_buf_log_format, blf_data_map) + + (bitmap_size * sizeof_field(struct xfs_buf_log_format, + blf_data_map[0])); + + return ret * map_count; +} + /* * Return the number of log iovecs and space needed to log the given buf log * item. diff --git a/fs/xfs/xfs_buf_item.h b/fs/xfs/xfs_buf_item.h index 8cde85259a58..e10e324cd245 100644 --- a/fs/xfs/xfs_buf_item.h +++ b/fs/xfs/xfs_buf_item.h @@ -64,6 +64,9 @@ static inline void xfs_buf_dquot_iodone(struct xfs_buf *bp) void xfs_buf_iodone(struct xfs_buf *); bool xfs_buf_log_check_iovec(struct xfs_log_iovec *iovec); +unsigned int xfs_buf_inval_log_space(unsigned int map_count, + unsigned int blocksize); + extern struct kmem_cache *xfs_buf_item_cache; #endif /* __XFS_BUF_ITEM_H__ */ diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index 777438b853da..d574f5f639fa 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c @@ -83,6 +83,11 @@ xfs_efi_item_size( *nbytes += xfs_efi_log_format_sizeof(efip->efi_format.efi_nextents); } +unsigned int xfs_efi_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_efi_log_format_sizeof(nr)); +} + /* * This is called to fill in the vector of log iovecs for the * given efi log item. We use only 1 iovec, and we point that @@ -254,6 +259,11 @@ xfs_efd_item_size( *nbytes += xfs_efd_log_format_sizeof(efdp->efd_format.efd_nextents); } +unsigned int xfs_efd_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_efd_log_format_sizeof(nr)); +} + /* * This is called to fill in the vector of log iovecs for the * given efd log item. We use only 1 iovec, and we point that diff --git a/fs/xfs/xfs_extfree_item.h b/fs/xfs/xfs_extfree_item.h index 41b7c4306079..c8402040410b 100644 --- a/fs/xfs/xfs_extfree_item.h +++ b/fs/xfs/xfs_extfree_item.h @@ -94,4 +94,7 @@ void xfs_extent_free_defer_add(struct xfs_trans *tp, struct xfs_extent_free_item *xefi, struct xfs_defer_pending **dfpp); +unsigned int xfs_efi_log_space(unsigned int nr); +unsigned int xfs_efd_log_space(unsigned int nr); + #endif /* __XFS_EXTFREE_ITEM_H__ */ diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c index 1ca406ec1b40..f66d2d430e4f 100644 --- a/fs/xfs/xfs_log_cil.c +++ b/fs/xfs/xfs_log_cil.c @@ -309,9 +309,7 @@ xlog_cil_alloc_shadow_bufs( * Then round nbytes up to 64-bit alignment so that the initial * buffer alignment is easy to calculate and verify. */ - nbytes += niovecs * - (sizeof(uint64_t) + sizeof(struct xlog_op_header)); - nbytes = round_up(nbytes, sizeof(uint64_t)); + nbytes = xlog_item_space(niovecs, nbytes); /* * The data buffer needs to start 64-bit aligned, so round up diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h index f3d78869e5e5..39a102cc1b43 100644 --- a/fs/xfs/xfs_log_priv.h +++ b/fs/xfs/xfs_log_priv.h @@ -698,4 +698,17 @@ xlog_kvmalloc( return p; } +/* + * Given a count of iovecs and space for a log item, compute the space we need + * in the log to store that data plus the log headers. + */ +static inline unsigned int +xlog_item_space( + unsigned int niovecs, + unsigned int nbytes) +{ + nbytes += niovecs * (sizeof(uint64_t) + sizeof(struct xlog_op_header)); + return round_up(nbytes, sizeof(uint64_t)); +} + #endif /* __XFS_LOG_PRIV_H__ */ diff --git a/fs/xfs/xfs_refcount_item.c b/fs/xfs/xfs_refcount_item.c index fe2d7aab8554..076501123d89 100644 --- a/fs/xfs/xfs_refcount_item.c +++ b/fs/xfs/xfs_refcount_item.c @@ -78,6 +78,11 @@ xfs_cui_item_size( *nbytes += xfs_cui_log_format_sizeof(cuip->cui_format.cui_nextents); } +unsigned int xfs_cui_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_cui_log_format_sizeof(nr)); +} + /* * This is called to fill in the vector of log iovecs for the * given cui log item. We use only 1 iovec, and we point that @@ -179,6 +184,11 @@ xfs_cud_item_size( *nbytes += sizeof(struct xfs_cud_log_format); } +unsigned int xfs_cud_log_space(void) +{ + return xlog_item_space(1, sizeof(struct xfs_cud_log_format)); +} + /* * This is called to fill in the vector of log iovecs for the * given cud log item. We use only 1 iovec, and we point that diff --git a/fs/xfs/xfs_refcount_item.h b/fs/xfs/xfs_refcount_item.h index bfee8f30c63c..0fc3f493342b 100644 --- a/fs/xfs/xfs_refcount_item.h +++ b/fs/xfs/xfs_refcount_item.h @@ -76,4 +76,7 @@ struct xfs_refcount_intent; void xfs_refcount_defer_add(struct xfs_trans *tp, struct xfs_refcount_intent *ri); +unsigned int xfs_cui_log_space(unsigned int nr); +unsigned int xfs_cud_log_space(void); + #endif /* __XFS_REFCOUNT_ITEM_H__ */ diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c index 89decffe76c8..c99700318ec2 100644 --- a/fs/xfs/xfs_rmap_item.c +++ b/fs/xfs/xfs_rmap_item.c @@ -77,6 +77,11 @@ xfs_rui_item_size( *nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents); } +unsigned int xfs_rui_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_rui_log_format_sizeof(nr)); +} + /* * This is called to fill in the vector of log iovecs for the * given rui log item. We use only 1 iovec, and we point that @@ -180,6 +185,11 @@ xfs_rud_item_size( *nbytes += sizeof(struct xfs_rud_log_format); } +unsigned int xfs_rud_log_space(void) +{ + return xlog_item_space(1, sizeof(struct xfs_rud_log_format)); +} + /* * This is called to fill in the vector of log iovecs for the * given rud log item. We use only 1 iovec, and we point that diff --git a/fs/xfs/xfs_rmap_item.h b/fs/xfs/xfs_rmap_item.h index 40d331555675..3a99f0117f2d 100644 --- a/fs/xfs/xfs_rmap_item.h +++ b/fs/xfs/xfs_rmap_item.h @@ -75,4 +75,7 @@ struct xfs_rmap_intent; void xfs_rmap_defer_add(struct xfs_trans *tp, struct xfs_rmap_intent *ri); +unsigned int xfs_rui_log_space(unsigned int nr); +unsigned int xfs_rud_log_space(void); + #endif /* __XFS_RMAP_ITEM_H__ */ From patchwork Tue Apr 15 12:14:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052119 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 4C18528E3F; Tue, 15 Apr 2025 12:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719424; cv=fail; b=gTqyDhHyn8W0nS+FYO+4WNIPCdDHp3FTf6tJ6ZxBkAEqyVyxsbri3QtJn8Gf2r2ts30Rm0X8UuF7Ur+vGJrtCtoqq1IDmogKT4yI+ljRUXNIMKYmJ+VT/GcV9c56Piywacn8MFtPxPRV24obtlVAa/yp42un3HAhObi623hLm9g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719424; c=relaxed/simple; bh=aBbCgTE+0p+dUqM5/IOXqx+WKdyzVIPaWCYBrY++5Rc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=WtBEr0KitFPwtfP88T7VsWFFtH+N7kaE84F1Xphus4NgEHgTnA1LZXQMAszsywHGDqi/QNyf1DJqJ/etFB+ZsihTI239ELB7D25jvzJT4x42Z6sslIVCwcWOPw6AJlfIyCMdbC+4MFC0P8n98MOwx1jlbdCyJo8PwrNS5W8eCs4= 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=Ppw1/77F; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=nG4HuOls; arc=fail smtp.client-ip=205.220.177.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="Ppw1/77F"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="nG4HuOls" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6gRc9006222; Tue, 15 Apr 2025 12:14:47 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=SKB77eQW3EJ+VRK6VE2kRFRgX+2VOScnIommq5SSPBk=; b= Ppw1/77Fugrms8yBpsswBVGCXOxfnQhrZEocN8zSJnC81yyEX38ItCz9dE5mbDvt EJTSbW3KqHAj2fLa60ewBzsUI1UgJSn8qRq0UutHmcLdTknIgyp6gTIGiiWXlBh4 o+RoFlwMdaVwPYJiaUOHmsmkOYfa1Z/wXjwOO3hPc/HgA4JSL81UOjwuZJFkVNqS RzNCXc0tiKCDla0DWYwi8wA7yqonebevPbs9ndg/BngQKtxwR/0RUzzf3o8VXaz6 v47VQdDtEvI0+xzTkLtL07r/EXSXRnw3SMBAaecA0K2wiXnNvQr++6EbzQzArKoI e39Osl0GTTcSITngmTLrOQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46180w9j48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:46 +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 53FB6Hqa038842; Tue, 15 Apr 2025 12:14:46 GMT Received: from bn1pr04cu002.outbound.protection.outlook.com (mail-eastus2azlp17010019.outbound.protection.outlook.com [40.93.12.19]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4r76rv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=n8xjf4JwZNLj7JeVWjC+NYC290snMDgdd0Dg5b1Dfw1pg4Ojz/PM37Eo8NHDIc7sKf2w47Pp0onGDC6BxGgyX2i2pLutXL4DssYyX57d8aDD/d9LybOiKObhMoxs0w3ABWKvZ2YBWDHj93SAc1MYz3leGbsE0GC/9ctRaPrdnwe9iEHkiBsGqGNIBv5ADrb1ZzTNSbuiryetQbCEMoSSp7WrgfIdqXecGmJZ+JKHZZOXOlb/nyhtuFf9NyOv0sGoaw78NPE7dRpW1vNKNCRkXbcM+fX3ke66k5I6Zys9yiD/mj8PL4y2pSmtsZm1qQXvhlyL57NA5E0g2oTsUYrSrA== 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=SKB77eQW3EJ+VRK6VE2kRFRgX+2VOScnIommq5SSPBk=; b=csPi6F5w9rYigdY3vltRWVQY99F7OHByblk/xQ5TXFQ8p/5JT1q6nQU/5METmZNE/HXiO2JnikV4mCGo5UPZzMTBGLZOW8gxvI0xkXxjxRzT4E2rUq4KU1DPyzxjp0qyKxN6pRZRg7HxqRwbLsP0UQLScx2U9oevmOTGgopcRhPFL/7KzbZeVaUvbOJE6gCARlfamb1oXxvniiMODiyJd0QVSWYjKAqxZdthv//9jWyEyowQawDkWpaU0UT60gOrVMD92DVY+VS6bVH/zAN0AxzyQqyoJbSomMvYTnmR5cUTnjnDLyPsBl0t3V9zc9Df4q64sCnN6Uhp2GFfTr9tNg== 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=SKB77eQW3EJ+VRK6VE2kRFRgX+2VOScnIommq5SSPBk=; b=nG4HuOls+R2wsAreaBuuWi/ra+kpLdMwxvgcsWrnAp8SjtBYxM3UA2CJ5iNT9ua2MnYW939VsOmIBNOZsCUDXzGYBet3qogBRu2Mg1BX4K7l87X9RxVOnAhiJI49QKGKsIyjGe7SB+/qkOrSR/gnfjCqtVpmcT3SsaW1CT1BjXQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:44 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:43 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 03/14] xfs: add helpers to compute transaction reservation for finishing intent items Date: Tue, 15 Apr 2025 12:14:14 +0000 Message-Id: <20250415121425.4146847-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: LV3P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:234::33) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: 415c68b9-655a-4d29-b600-08dd7c171b23 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: WTxoBW/jcRcY3ERD5he7eToIR6QJYPDxoQSYUanlaDnYX/0E0FwxY+rH/+vgzMSZmJ+hqGbZzkbOhu3NtZWXMlfYQYrELX760c9Jq/yBd9JOAaJ+/Fvoc8DOCnEMr2LYherMc6WIfdvt1HUUnsAL45qs47NlolNEu6Jfy2Dg/FzH2/CfXn5BqMG9IRVsItxZP9YlhfhIj1i5YkY6nwxFUF07WqPUdw9hZQU088dm04lvz3kXKjoh12+rdQkCxsN5Fh//X1sN+NO7Nc9pCdfrB/ZWF28dAmOgz9eWHhswPuiBZSDYxcjA1PNPWdfMB0PUCbXom3ZLwJQVmJDwJ2Zp8/LQqUrSZrDpzPk9ok5u0To8d4RMLiZodw6jwzJNMafAmx2qpeVM69oW0oFkxLL7Cz3hHwGP9uwT44SJEA+6O190mP6t3Q6Zi269mQwhGHj177emxhJ4IA+KwWRTHQ9slcDiKgc4c9q4y6zLaHSmb3qXGj4vgmmsIrQwET8eVUCT4TwRD5UbmHOwCJsVb23eF4c4vPKugicpSm/ibUvqA+X6EificRD/LzfL1Q+S4r4TuH1ua38V5C+sYW7SPXpBHOw6E2TVYGpzQxFtD2ePjf5h34HOTx6HJshvki61M3gdCtx84jvZYUFmjNFKOIr+mR47XjKdwx+otmXms6x0+q5+iVm3OM0FeLQjptOb4wktOVCyVtruNUIkMi/Rl3Mv/2yc+WCU8DVAd+yi4e/qRRDN7Y8ptTctynd4ZsrDRFSHAqk5Pqs3klCXDH+D3sbj/AU9Jkvgxq7dzNcVbBmWJF1dd+XUBK1A1m1ducPrmburA+s1mMkRYp/4mPZy08z56hkiN6gbycg/wLrvHWoHhFYKCuviDJv+RIMKK/iExXSQVRN3aJ3GNeykosA9qWJdMJaoOvpXZCKjkWzS4ZJZJIaaeUeRGxn84aMNES7enDW1YaLSol52GabgewUki7yyrU0d8wh7zbFIxFq7bvXjxuVyrY1jCuvrrdBmIZqQnBG64/fvh3l2c5+XtEKaTDEQAabT2dreM1SoUvaWFC7fKzv95Njhr/fR7V53Hd0xCnfHudds8eaG78rw4mPCQIf0AHJCDU1dC6249B0C2w1ldj0xyoLkv8nN5fswSd0n4S4pxjnkpks0bXQkTB2kDcjfvmEJ13pL12e/BU3ZRddOZX/I0ml+rnQ2oQksAGh09Agfojy9/TO5rx9hQOGeYlon4grt8zNvnpG8mUQ5JTdC4Q/CbJ/GtStO4e6Bvf4+ryPjdHGqx9LI8uRUMk9r3/vzrg4d/Bhcjgk8RNig5Q6BqDYFQ/cnfVFUHlwhqv/XRpviomcLAGIju1umVbxK51mOd1IIQ/QpT/l+GbteyFPoCS+ona3KaB942dmJdLMmteVUagNZW/GE0Y4Wr5+zY3u0tJgp2Or3kZ22Z9F4KubJQAQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SIMCpu0rqCccbocpwugl3RCe1TRi/P1UL4k4mUPOdwpshguLcnql4ck0sP4ZfUmAPvsBxCUCH3fGt7NtfGN94QVrwVUR+9qmJYe2DcaNFItzrfcg+mgYrW03CRM2rj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3c3Zzzv1Qjtjc921Cc6Av5jpbk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 415c68b9-655a-4d29-b600-08dd7c171b23 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:43.9326 (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: eHNz+T6G26KwXy4cD96bEk5ZmEvLQP8QiIUKxJyQGbycAjPco72wIx3jAOrCtSlPMfRyzCyD2zHuZ/iDQMiamQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: T1bgrOwxnZDGz5yIEpxxd4EWJROTh1bH X-Proofpoint-GUID: T1bgrOwxnZDGz5yIEpxxd4EWJROTh1bH From: "Darrick J. Wong" In the transaction reservation code, hoist the logic that computes the reservation needed to finish one log intent item into separate helper functions. These will be used in subsequent patches to estimate the number of blocks that an online repair can commit to reaping in the same transaction as the change committing the new data structure. Signed-off-by: "Darrick J. Wong" Signed-off-by: John Garry --- fs/xfs/libxfs/xfs_trans_resv.c | 165 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_trans_resv.h | 18 ++++ 2 files changed, 152 insertions(+), 31 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index 13d00c7166e1..580d00ae2857 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -263,6 +263,42 @@ xfs_rtalloc_block_count( * register overflow from temporaries in the calculations. */ +/* + * Finishing a data device refcount updates (t1): + * the agfs of the ags containing the blocks: nr_ops * sector size + * the refcount btrees: nr_ops * 1 trees * (2 * max depth - 1) * block size + */ +inline unsigned int +xfs_calc_finish_cui_reservation( + struct xfs_mount *mp, + unsigned int nr_ops) +{ + if (!xfs_has_reflink(mp)) + return 0; + + return xfs_calc_buf_res(nr_ops, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_refcountbt_block_count(mp, nr_ops), + mp->m_sb.sb_blocksize); +} + +/* + * Realtime refcount updates (t2); + * the rt refcount inode + * the rtrefcount btrees: nr_ops * 1 trees * (2 * max depth - 1) * block size + */ +inline unsigned int +xfs_calc_finish_rt_cui_reservation( + struct xfs_mount *mp, + unsigned int nr_ops) +{ + if (!xfs_has_rtreflink(mp)) + return 0; + + return xfs_calc_inode_res(mp, 1) + + xfs_calc_buf_res(xfs_rtrefcountbt_block_count(mp, nr_ops), + mp->m_sb.sb_blocksize); +} + /* * Compute the log reservation required to handle the refcount update * transaction. Refcount updates are always done via deferred log items. @@ -280,19 +316,10 @@ xfs_calc_refcountbt_reservation( struct xfs_mount *mp, unsigned int nr_ops) { - unsigned int blksz = XFS_FSB_TO_B(mp, 1); - unsigned int t1, t2 = 0; + unsigned int t1, t2; - if (!xfs_has_reflink(mp)) - return 0; - - t1 = xfs_calc_buf_res(nr_ops, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_refcountbt_block_count(mp, nr_ops), blksz); - - if (xfs_has_realtime(mp)) - t2 = xfs_calc_inode_res(mp, 1) + - xfs_calc_buf_res(xfs_rtrefcountbt_block_count(mp, nr_ops), - blksz); + t1 = xfs_calc_finish_cui_reservation(mp, nr_ops); + t2 = xfs_calc_finish_rt_cui_reservation(mp, nr_ops); return max(t1, t2); } @@ -379,6 +406,96 @@ xfs_calc_write_reservation_minlogsize( return xfs_calc_write_reservation(mp, true); } +/* + * Finishing an EFI can free the blocks and bmap blocks (t2): + * the agf for each of the ags: nr * sector size + * the agfl for each of the ags: nr * sector size + * the super block to reflect the freed blocks: sector size + * worst case split in allocation btrees per extent assuming nr extents: + * nr exts * 2 trees * (2 * max depth - 1) * block size + */ +inline unsigned int +xfs_calc_finish_efi_reservation( + struct xfs_mount *mp, + unsigned int nr) +{ + return xfs_calc_buf_res((2 * nr) + 1, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, nr), + mp->m_sb.sb_blocksize); +} + +/* + * Or, if it's a realtime file (t3): + * the agf for each of the ags: 2 * sector size + * the agfl for each of the ags: 2 * sector size + * the super block to reflect the freed blocks: sector size + * the realtime bitmap: + * 2 exts * ((XFS_BMBT_MAX_EXTLEN / rtextsize) / NBBY) bytes + * the realtime summary: 2 exts * 1 block + * worst case split in allocation btrees per extent assuming 2 extents: + * 2 exts * 2 trees * (2 * max depth - 1) * block size + */ +inline unsigned int +xfs_calc_finish_rt_efi_reservation( + struct xfs_mount *mp, + unsigned int nr) +{ + if (!xfs_has_realtime(mp)) + return 0; + + return xfs_calc_buf_res((2 * nr) + 1, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_rtalloc_block_count(mp, nr), + mp->m_sb.sb_blocksize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, nr), + mp->m_sb.sb_blocksize); +} + +/* + * Finishing an RUI is the same as an EFI. We can split the rmap btree twice + * on each end of the record, and that can cause the AGFL to be refilled or + * emptied out. + */ +inline unsigned int +xfs_calc_finish_rui_reservation( + struct xfs_mount *mp, + unsigned int nr) +{ + if (!xfs_has_rmapbt(mp)) + return 0; + return xfs_calc_finish_efi_reservation(mp, nr); +} + +/* + * Finishing an RUI is the same as an EFI. We can split the rmap btree twice + * on each end of the record, and that can cause the AGFL to be refilled or + * emptied out. + */ +inline unsigned int +xfs_calc_finish_rt_rui_reservation( + struct xfs_mount *mp, + unsigned int nr) +{ + if (!xfs_has_rtrmapbt(mp)) + return 0; + return xfs_calc_finish_rt_efi_reservation(mp, nr); +} + +/* + * In finishing a BUI, we can modify: + * the inode being truncated: inode size + * dquots + * the inode's bmap btree: (max depth + 1) * block size + */ +inline unsigned int +xfs_calc_finish_bui_reservation( + struct xfs_mount *mp, + unsigned int nr) +{ + return xfs_calc_inode_res(mp, 1) + XFS_DQUOT_LOGRES + + xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, + mp->m_sb.sb_blocksize); +} + /* * In truncating a file we free up to two extents at once. We can modify (t1): * the inode being truncated: inode size @@ -411,16 +528,8 @@ xfs_calc_itruncate_reservation( t1 = xfs_calc_inode_res(mp, 1) + xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, blksz); - t2 = xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 4), blksz); - - if (xfs_has_realtime(mp)) { - t3 = xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_rtalloc_block_count(mp, 2), blksz) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 2), blksz); - } else { - t3 = 0; - } + t2 = xfs_calc_finish_efi_reservation(mp, 4); + t3 = xfs_calc_finish_rt_efi_reservation(mp, 2); /* * In the early days of reflink, we included enough reservation to log @@ -501,9 +610,7 @@ xfs_calc_rename_reservation( xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); - t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3), - XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_finish_efi_reservation(mp, 3); if (xfs_has_parent(mp)) { unsigned int rename_overhead, exchange_overhead; @@ -611,9 +718,7 @@ xfs_calc_link_reservation( overhead += xfs_calc_iunlink_remove_reservation(mp); t1 = xfs_calc_inode_res(mp, 2) + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); - t2 = xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 1), - XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_finish_efi_reservation(mp, 1); if (xfs_has_parent(mp)) { t3 = resp->tr_attrsetm.tr_logres; @@ -676,9 +781,7 @@ xfs_calc_remove_reservation( t1 = xfs_calc_inode_res(mp, 2) + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); - t2 = xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 2), - XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_finish_efi_reservation(mp, 2); if (xfs_has_parent(mp)) { t3 = resp->tr_attrrm.tr_logres; diff --git a/fs/xfs/libxfs/xfs_trans_resv.h b/fs/xfs/libxfs/xfs_trans_resv.h index 0554b9d775d2..d9d0032cbbc5 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.h +++ b/fs/xfs/libxfs/xfs_trans_resv.h @@ -98,6 +98,24 @@ struct xfs_trans_resv { void xfs_trans_resv_calc(struct xfs_mount *mp, struct xfs_trans_resv *resp); uint xfs_allocfree_block_count(struct xfs_mount *mp, uint num_ops); +unsigned int xfs_calc_finish_bui_reservation(struct xfs_mount *mp, + unsigned int nr_ops); + +unsigned int xfs_calc_finish_efi_reservation(struct xfs_mount *mp, + unsigned int nr_ops); +unsigned int xfs_calc_finish_rt_efi_reservation(struct xfs_mount *mp, + unsigned int nr_ops); + +unsigned int xfs_calc_finish_rui_reservation(struct xfs_mount *mp, + unsigned int nr_ops); +unsigned int xfs_calc_finish_rt_rui_reservation(struct xfs_mount *mp, + unsigned int nr_ops); + +unsigned int xfs_calc_finish_cui_reservation(struct xfs_mount *mp, + unsigned int nr_ops); +unsigned int xfs_calc_finish_rt_cui_reservation(struct xfs_mount *mp, + unsigned int nr_ops); + unsigned int xfs_calc_itruncate_reservation_minlogsize(struct xfs_mount *mp); unsigned int xfs_calc_write_reservation_minlogsize(struct xfs_mount *mp); unsigned int xfs_calc_qm_dqalloc_reservation_minlogsize(struct xfs_mount *mp); From patchwork Tue Apr 15 12:14:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052113 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 79BC2296D32; Tue, 15 Apr 2025 12:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719301; cv=fail; b=OWqtpUsbISjmUUFsmYANDGQtuoEtuBJig2g9MzTh89trhBiajyxlWOIvxmmCObo6qveapL2BvucfCuO6Rv8Lg25391YGc9RvYE2lfEAwMl01H7PuL7wLDesswepHqoj48wGh4ISZO44CmvtY5XtP1WmnMgTiSir/3R7lgR3jajU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719301; c=relaxed/simple; bh=MYS3ImCwkABPW5OQEXi1s9uudYw1zWMQnI5ViTAHVPk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=tfpyB6bqPob6a/3tqrAaSIS0JtJUFhY14M1wkCN6iQngKN1SBnlKsP/iXhZbOer6V/Whd/z2rgdgPr0TijYKwDCoTvYFQujm71p/LZFi1mF8CwtkjIZG5U7OKsriID+NJk8uO1yvY5i9P0dGagJCz9YBZ8bRLXO3reaXmebfdWA= 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=clVtkVsY; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=yYSGqiFb; arc=fail smtp.client-ip=205.220.177.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="clVtkVsY"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="yYSGqiFb" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6fnn3032426; Tue, 15 Apr 2025 12:14:48 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=xjTvL3RPR141S5zgrWRMIkIh6Nft0D9VJwf6Vp/fnCg=; b= clVtkVsYRyVqUhcDgTtQ2RysyToK49ZGB3sV98Xh8cjHI8EJ7KR1QG0/McF2oJ9P dnR6mxfBOlD1YI5AB/VUju/k9/F7Wh6Dzj9PiPWRjBCab/gwYyhxcRane+iP9QJ3 ty7XMls2VDYS3WerTRZhSjMVsGeKazQXAALBWyPxXyIIwdNg6Hbutvoxyw6jhZel sMubpKZQQDrjbQZHGs87HvGg/dCQRDkBvKoVqQTT3WEyDP/PsOkYye0hQ0HKXk3D Im8xx5Hn5EaN1qnI97sGMY03el3it6M67eQy9qV17nZZXUAL1DOJgEZbPgTxUL1L ia/DBMQO4lSIHfZcIQ2Q5Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4617ju9k2x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:48 +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 53FBStwk031119; Tue, 15 Apr 2025 12:14:47 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010005.outbound.protection.outlook.com [40.93.13.5]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460dbaewty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cLP3+oIEwIW9stkOzdA7bayHgziA/hncsr1kVHVTgjrYvfH/oaVgra2FEg1xxIFClEwkjE6f7v98W/17FKGLkQirVzwMIFObQCqfy/ZEAB0AQ5mvWWH39kskizhXyHPCIyO1QEfaFeenuQ6Vas/PjHAlvbDmqZTEtXG2CEUDQI8yPNzC9EuHv6EdrQRys9IbrtlAo1remRcDJVyhQ+xYot724wk4G/TGMyrOGQqTvDhFEuUJKC/gx7VNcJmp5qn9RHkxtHM8fWneclUDbGo0J0KO+pfrpNmULOH+Sczu03oLWxQkE9rg1ZbHigzRdkGonaw5tTdB5oWd5m3fssws7g== 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=xjTvL3RPR141S5zgrWRMIkIh6Nft0D9VJwf6Vp/fnCg=; b=SoC2v7xEsfRV2lc+9jt6QOKG070UTy/vqO9cr3/U7WTGpMI5WTwT8E4buwcohNHKNFRe46iTiUDSLLqaFOpl+y2tjvZ0RZk3Uvoj7GeFB4BrXocy4p8UDYJKHGnyTaqujAqxzTPqHwG66xILT2rY2CjNR7bcFQQiFdqbI9UNHbqEgqcBdwYNhmd/qNXW5JnQiuQkNgzJsQqp0UmaEHlt8NHpzwl4OLo15t+YhBfevAJnqHZhr24Aj8oZH40ZkCnRWQpfe4pyKeFNTvyvkiPY+KpjiIXOlXiGb7qvvT4Eu9X8VG82oaKa9QGPPQ/xeUnxGWoPzoijVDHp/iM+Hp25Ig== 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=xjTvL3RPR141S5zgrWRMIkIh6Nft0D9VJwf6Vp/fnCg=; b=yYSGqiFb8MSbxFg3zj70CY6FYRB3QkP64+MJQ66Dn5EKhMQQoPIR7j5SkTAZzyf4qnBmTd6EeDxVve1uQK1pW45S6CYW+b2SoLi5C3p/QAMGAYnbirRIv7REbiDQT1Rh+cUaTQJAmzzmH6IkF8iKBSSzAq//eYC0vU1/lpw/NyY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:45 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:45 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 04/14] xfs: rename xfs_inode_can_atomicwrite() -> xfs_inode_can_hw_atomicwrite() Date: Tue, 15 Apr 2025 12:14:15 +0000 Message-Id: <20250415121425.4146847-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::12) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: eba17243-89ac-4c7c-cfee-08dd7c171bf4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014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LCiYzPyc7n0O0LekzfyOFKyXHwBKuKu0HgGBqQYc88qPhFQAxPxICB3niMoYzY88foRMZaxjeBwT5xpv4HDmUekAn0vlLVQdWAAR9MnRDHKzRR2/KlTLSCJUIaO5odZNR2IjUY0anNAgYD5j0g4c7Jio/TamBEjU8UR4Wyzro3fO8gPwMtQFSKwBiE9YGus8lKFMZ7Nbd38AQ5LFa0ztna7wh4YkdCuogR7aQSnoVpM3forTJGcXFTGZdLHI5XmKxX1ynthw6lav1VXvSOoTIMCOt2NTjNTmTyAQi/3tHTDqcpLeYG9jYJARiLjCHpttPPFJ2ikvz4EdkJdnImVKXPudTpEkqoBRV3rB7we8nJqGS0homacJ4Vy7Mwmbw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GQYdF7zn3geokpipaLZJFOHVwgTlqzw2BGlbblj7JkDC1F2WI/0c0hLDvBJi9mEPTDnJb9gamYN9K/Ckgy179tXCCW8v3rNJVSQLmlSubs9AikAZZhnAwp2TOZ/69aTcon91P5XzAF+AVq6r0opWal0l9CLI91S5mneK6h5feI2Fcg7FbD+yT0xSvjlzrCG5GTsPuc5TW9dqvECnXjTjhIntLv3QluQ2SwGIEiEnQfDqFKSCRyg+8HXTFJH7tcDsJZUX6krlQgQsqRwQkmg6x2MJBGnR/nzk1y2h/YFB8WkqbRsTRiNMf//tM/wamGUsrWBJ9vXdmbyo81ZXOGVCZ7WiD2KIqLGslbIrIlGMb/evO5oWnfvBvlQBY7fR4ZdvSyyJ6lGfLYb3h8ZOiblWQp9QlzQbHW4EsyLk+Lxmz799tsINvRqT23ssVL2cbHUjQZt4EAb8AMgnIlCEXWFdKZvxIYw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MVj62PwGhjS5x7M2WxNcnLEnvxKLSMJBB0kRR8weFyweLAYTqYla5zYRYNbqmNQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: FD0eQKhhh6fM+7aZWbLfPs1L3Ux745W9d+3rZru3rFhgp0cwchLz5NM+Q9Por9oJDIkup8Wt0XIAkyH/abC/LAtsXBsC82N/s6NONPjo0bgPaQ5VJ2ume4VjwBJOtubz+TBdDoiGYYGjXjHbNPXjrClR7Hr4LTexqmTIlIane+wcvdeD/yEH5aklsDPWItDnlq8Zh/IDYWaLGgr0dfHPv077I1MD7TUT3d5+5VCQB16B5CyISHZWqlxpvJ09Wlwdg0TKcry4PBs0vNgx+Sx4X/7E/RlRYZt/GqnAkyMC2dL/FtnqB3KC/Vw6mIBtjZvxNheHMyo8Y21vdO+aLaxlywixElxEImPt/cPr47vpYU3nIs9vglT1g52aheF9n2C7Qcd1ZR8JCWuD2PzDZC4niF2AAJ8GKUAGNVgx+P03oBonrRZuvMlyfAnmoXO2d8rAqSgSxXCraBqI2qtl+mLd7WU+ia7bWxHAY++27sZT2yl9QoJb466oc4KYe9Oyok1pJH/mBcrYxiEeezvs8xg7GHOP4pfpRZ2i547pbFRIODnWKPb5nFuGKnIG/DQAbXFrj0x2WeUM1991rufF2D6Eh/plFDqI5/LL6vVvv1xtGz4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eba17243-89ac-4c7c-cfee-08dd7c171bf4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:45.3015 (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: W7eoVSuKY1WD80boDezeaf4TXpFRg1FcoEkA5v4LRZuiCjObWbLd754Kipb/N4BDt9xYUzQG60M0Fp0iTSo+TQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-GUID: 1F-NxBQhMg1LnaPCGMkukhdtoPmXoz2K X-Proofpoint-ORIG-GUID: 1F-NxBQhMg1LnaPCGMkukhdtoPmXoz2K In future we will want to be able to check if specifically HW offload-based atomic writes are possible, so rename xfs_inode_can_atomicwrite() -> xfs_inode_can_hw_atomicwrite(). Signed-off-by: John Garry Reviewed-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 2 +- fs/xfs/xfs_inode.h | 2 +- fs/xfs/xfs_iops.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 84f08c976ac4..653e42ccc0c3 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1488,7 +1488,7 @@ xfs_file_open( if (xfs_is_shutdown(XFS_M(inode->i_sb))) return -EIO; file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; - if (xfs_inode_can_atomicwrite(XFS_I(inode))) + if (xfs_inode_can_hw_atomicwrite(XFS_I(inode))) file->f_mode |= FMODE_CAN_ATOMIC_WRITE; return generic_file_open(inode, file); } diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index eae0159983ca..cff643cd03fc 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -357,7 +357,7 @@ static inline bool xfs_inode_has_bigrtalloc(const struct xfs_inode *ip) (ip)->i_mount->m_rtdev_targp : (ip)->i_mount->m_ddev_targp) static inline bool -xfs_inode_can_atomicwrite( +xfs_inode_can_hw_atomicwrite( struct xfs_inode *ip) { struct xfs_mount *mp = ip->i_mount; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index f0e5d83195df..d324044a2225 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -608,7 +608,7 @@ xfs_report_atomic_write( { unsigned int unit_min = 0, unit_max = 0; - if (xfs_inode_can_atomicwrite(ip)) + if (xfs_inode_can_hw_atomicwrite(ip)) unit_min = unit_max = ip->i_mount->m_sb.sb_blocksize; generic_fill_statx_atomic_writes(stat, unit_min, unit_max, 0); } From patchwork Tue Apr 15 12:14:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052115 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 ACDFC292915; Tue, 15 Apr 2025 12:15: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=1744719304; cv=fail; b=tV6eAlMBv0VULH66VSiFE4IG7wPV8veRYl+Yx4FoKpPc4SRr0HgVndSNBsRBkJGeoLxWjG86aq8c0CEqy5c9vKgDDkp0siFSsVzkNMdUmr8MuPI8clg6Zf5s1Dra4V2gnflDml2UNHTe7D4gAEhbWt15QjjdwRGnB9ImHFh0Sg4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719304; c=relaxed/simple; bh=pra161ou/h8chlA9yXUQcjoXcHRvfZfy4MOaTpjse98=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=uGcsiPgyNCd4NduEzvIu0AwZ39mH4MRQA1ixw17529JS1TVSxW5sA1AIdJpKv9PT6/c2lpGhAUJFxsFQGILnUQA5Rd+4qKwh1LzIhQGKiSZCieeBdH6jZ0BAK6s0tmZLCJbiJxY15NfRYNdlpL4xePsrXaE1/sQMtSnicn1Eqqo= 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=OhhFfnXW; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=v3npITCz; 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="OhhFfnXW"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="v3npITCz" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6gCgc010289; Tue, 15 Apr 2025 12:14:51 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=4MVFHj2jeR3CYDsF+FSYfPKETrPlcvNbqSeNIdTwSqM=; b= OhhFfnXWB2SdfPuNqYz4MEChdp/dfx586GM1ODLYSR7rhFf1K6pbsB/9j7iNoaIN /ulRTpB6O/oGKY/1Se4weeW/5yP8tuYdusi/4GEEwEAJJqGjkUMlALlPHDKxZ3Qw GKydD+4St4WCx5FkuMpETGQ5YiZta8eYfmH7K7ecFZVmOu8kjVLdfBGwsXGy2v0b FxAY0iF237skV9jmRrHiGcCNdXaMsLWOgxZABh/srWWU3kw4Hh7OZeHgvN/NqPp8 1h0OFjBxRGHOtQa/oaLiLT9LN+e6thpPj8moVtKtb7396DzNglNb15pPX+RjM4pM EFzBi2gbXVFiy/5Y76HpAw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4619441brd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:50 +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 53FBFQaa030960; Tue, 15 Apr 2025 12:14:49 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010007.outbound.protection.outlook.com [40.93.13.7]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460dbaewv9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mwk4isMa7kiDhFb3Z0wVOds63M0A/ctGuKfsfiIW+9Z7GzQ0/GMUX5haxiEm+Xycv8zdLXhFkjQHrJ5/+RIJuOwGlhyUi2JvMSpsouf7OKqT5V5dc7/zMuLezJz3rKUycYtoqfHkQQOQLMI4uqz2ewV3dAOcIVffbVjSuYQuWqHWUG9nNL2ur1FQ5w4Awis4+SppX95nuUtYmiIu+IHLgxM+dcddlZfxukDHiIpuiWuS20STbv2FLXdJ2QkGWly6szswZRJh1quPWKFUBlUbkQg0oAZNsix3NQ4k8oRAOLwT/s6qdZkZjDEq5z7yXoR1JIs59sCB5HxR58eoQRpmqQ== 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=4MVFHj2jeR3CYDsF+FSYfPKETrPlcvNbqSeNIdTwSqM=; b=x70xAbnBHe7wK0UOQX/teIz5cBsKhxFLGcFrzsybQl00CVNxUhfu/3D2bd9Axc5P1MM3aTWZuqz53nqb9zX/JY5m0WHlkXnh54rmOjgP3YFQJPLrJg2QQZHDGj7xDso6ah4Px4MAQpxVq16/RvC9NcLdkf38p4iBOk+fJ+KlDCRibQlCFL7y7YbBeQertrkUaLoSigyqiQ+Z5o9m0wGZA0u/UmgJZz6WKCn4vnsYZ+1IM6BUoOorHYGB628wsAjVCZbAehlbA0MbzxODbhHJvdbMCzY8y/xTgguADw5zddg23HUjY1cQW61RmKZSgCmnfe1ggE4qHBU2AVZVddyW6g== 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=4MVFHj2jeR3CYDsF+FSYfPKETrPlcvNbqSeNIdTwSqM=; b=v3npITCzfMsj/fFH7OQfN8ivwmiROm2wArajGg1mjfN8ve2H4pcK9KnyIJYAE4SPPoHWCutHuw7bLctgUw6OZjkuVkooineDtgKIkeED7Ml8zZQG/Kdo+2RHcHk0X5/1N9xJkNz8uwRrpdYnf6wkk1rSCS925+0v/Y3CXXUb8NU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:47 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:46 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 05/14] xfs: allow block allocator to take an alignment hint Date: Tue, 15 Apr 2025 12:14:16 +0000 Message-Id: <20250415121425.4146847-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P222CA0030.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::35) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: b6fe9d43-6b95-4287-d4ec-08dd7c171ccd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: OxEqlfUDjH1QZs04M2d3h/KdSL0tgkAXqz4FJ9haGNoJeVL9X2jwHzJO28Bz9hj51Cu8Pck1D/d7sEKczYW+r9oqH3yGAtga0/adTwY8zdzlXxkAxHRhLH4qGy3QhdL+PReP42pysOWvie1TqBl7qATTCEUp22iyAiC7rXZh9EkoSNlCSQ5psJM5v84fWRArPF2LKQI0tuYi/ZzuOnyBIQtU0KvpBWcPlBwngqPXUgqtac2SQFgwwlihCFs/74X9a5P53D9vanv1TV1/ENm0yWB1/TlNpWGMecRUT7PG6t8gXekZ2YJlRoBX3CU/Q2cr0Qz7Jf8Ay5ffxA9h7aHPFjn0Mvx2RYDmwnO8JBJRycRvsi6+bftrAcJAyQg4r8m+SLYmT0pnV2qkMzxlJdiRys3rhqZ1nwxbgWAgEZzGSmfCi53qV4FZa0tgm/vGlX398JttYZZY9srY3w6cInBSNg5z0E7BxCO7xgXBQ21fGDflhpqjMrFY8udAnPLti3T2gJ9QwLNGIUV4/ryrcmiSQRVWvziUAPvC1xWeb1Mmjp4VpIJYEyHn5U6UfkPywBAc1P2Pqwt1nP9shUKHmCSPx70S1q1smt8CYLHXjKXsVQP6UuiqTjW923DnJN2BELcRD5fpHYXsD5gKYyVi726A/JCy0y2ZPPT6aWI0qftg1SOE1KdkhFlB/O+xm/IQE7+dlf51xa5L8/W2ZViDn6BRcj34RvVHiDJ9i9DucdQduyS92CgTS561YEAjZHYVMCstuXWxWoi5fgHXEkL+U1mgGDU5Sb8/cVmyw2cC8x+E8v2k5/q7fAmgHQLNKU9yG/4/Z9NwDXVaEBZ3QRY3E5L7RbkegfgVupjch5Ab8FvIMKik8vFuxqm5JA16Dmg1MylFfqe6vTkoeaZmrGwhgIE6AG0Ej5c0vvpcvacKmDIbApNvf9OT2uFRva1L6BIscjjrQ5hnvfVLBXLOkjmHHMzCMmCTkkeKDewNK5L1OO1lwT+qfi6arCw9wd5sTjNLdxsIC20nQMudwJWOS/PoORx46Go9QNrzNzdsX8cAZEYYboxf02A5LvAsBYFZ+uJl6G1GN8+C+DuHwnSWiMgzky4f7y8LTWN3WKp2pXKRPrjQceEnWve0PtLz7bqMYS4Z3FQJqGhGBENhJ8Cof129jvhAGI4M4qYf6rPVCJMSdSPZ6UozyMw4U4H+czY3Dik/Hye2iYT+kOHdM8DZNXwSbEog1QidHTAH4qvPHrvnwqWY2e94bqUSyIvyZX8Sy7PFVwWQXZOTkKwl0LEhJ8EXb6LgqE/7SOE6xqa1YA9pvYFGkpy6z1nlTwywYEK9VrXGrU2hjWl72AF0bgh4Yhpd9M4W62I3aLmrzHW2FhzAnCGrE6xymXnvPH9k6n9gEDUZAZo5hJHxOtlVSiZFHQ7ty/CqhlQkGcU7kH1CoxJlRRMzdGQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8igpuZ679oVpU82IzsHGoEHP2eJjL4e6flCgOPouX54+oebIBUGldWoMuEvMWGbTXk3WK7QO9BgXxAD2LWOGpQ4MK7HeSZ6kR6HJpD7XtdieMfUdmo3GKnWaSnFtk6Nd4lYd92RY49SC9+Pd+QGaa1oZIm7rVp2UZqphdMhEVFAO4KknHMFqbpXo87zCknbo5aN4DCbKjQyeyP6sX9UvB+RlcuajySNcD+0GeNFIdBwt4GeJ5JsMMmZa4unxbuRl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19HvbcssOBvPEt13psm8M6u9VJEix42Z2N9T/w3h0YHk0rd9A4WzkCQqLh4fxNpQQjOHmfC/DPXM3nYCUeMPQ26cAzZyKH6O0RSMJB6u33asOkXHfiG6sec97dhvbCyKKk9uvU8h1Uv/g2tCoqkMIFPOKafSAhq1snPbYPTnhSqzCqVBHM/RyR1rO+pZYizZRsPR3QFMfYWcmzQStHn77vSVuu67HtRzBcxOjscTKTGl5vksgn9H5BySXZYqfd7MTUMbp7LcP2vrWiUIEZq7h7mjar5gJaqOQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tP0xuVmyKEBIS7VmzJ978DIiyrVlU1Xga8E4wG9Ghk0KLT7YKOFwrWSGliFSmxy1K/B7Wup9zZmzJOCQCzQ1+SJSzATU/NKpzVnf1SHRTRmneLT9/+0y+jziFjs92T618qZH/onDgrYH1cUdQGcQizsKUBtPv6+GkqyXvmxdXIMpXiLeNqqxxZFuhPPoLI1uwtJryvw2PbxHeeN//D2q9uqynvSRFm7mkcDY9LraHV4sJCNURgSaLEMkY19my8zKK96HiawHa2ngaz43SdsmQuenp6n7wjscm3eY8GPYVJeF87g/oOfzDdJYNv+ZOaH5017nVJpAf4h/Buv/dGVRPdHHlVi7POzuo/MvcncxHobLdcXKbb9xPyi8/UygFZU8M5AUfKnXz8AMRJP/X5PNblxPTZWbgZEbCP8MxBCtRicH19AU5PtrU9XQsRQSeCLKl7aLON0wLzaWwfq1kfBAGnVeMKrB2lVOSrCOcwhGFBJ+f9QzNtBsxdrGHy4hnupt+enfiwkOQhLwq8ujIxxWWWD2DtwMRNSEf3mT4vyoSB2r7unLK847gJED4y986OWO8zC3VDq08vFYaOZj14bR7R3fVniMBDdGlHuNuXhBG60= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6fe9d43-6b95-4287-d4ec-08dd7c171ccd X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:46.7189 (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: wa5j3S27bCCr5zKQNgyfBELD+/eUx/2JjSA5yKjo8cfxK7o8vL6eejW3EKQQvRS1Tk3odDswS+spAZJdUz7kbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-GUID: 0GewARQvDMleKejCH0qVLZx3FOJHecXq X-Proofpoint-ORIG-GUID: 0GewARQvDMleKejCH0qVLZx3FOJHecXq Add a BMAPI flag to provide a hint to the block allocator to align extents according to the extszhint. This will be useful for atomic writes to ensure that we are not being allocated extents which are not suitable (for atomic writes). Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: John Garry --- fs/xfs/libxfs/xfs_bmap.c | 5 +++++ fs/xfs/libxfs/xfs_bmap.h | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 63255820b58a..d954f9b8071f 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3312,6 +3312,11 @@ xfs_bmap_compute_alignments( align = xfs_get_cowextsz_hint(ap->ip); else if (ap->datatype & XFS_ALLOC_USERDATA) align = xfs_get_extsz_hint(ap->ip); + + /* Try to align start block to any minimum allocation alignment */ + if (align > 1 && (ap->flags & XFS_BMAPI_EXTSZALIGN)) + args->alignment = align; + if (align) { if (xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, align, 0, ap->eof, 0, ap->conv, &ap->offset, diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index b4d9c6e0f3f9..d5f2729305fa 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -87,6 +87,9 @@ struct xfs_bmalloca { /* Do not update the rmap btree. Used for reconstructing bmbt from rmapbt. */ #define XFS_BMAPI_NORMAP (1u << 10) +/* Try to align allocations to the extent size hint */ +#define XFS_BMAPI_EXTSZALIGN (1u << 11) + #define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \ @@ -98,7 +101,8 @@ struct xfs_bmalloca { { XFS_BMAPI_REMAP, "REMAP" }, \ { XFS_BMAPI_COWFORK, "COWFORK" }, \ { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ - { XFS_BMAPI_NORMAP, "NORMAP" } + { XFS_BMAPI_NORMAP, "NORMAP" },\ + { XFS_BMAPI_EXTSZALIGN, "EXTSZALIGN" } static inline int xfs_bmapi_aflag(int w) From patchwork Tue Apr 15 12:14:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052116 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 719AD27B4F5; Tue, 15 Apr 2025 12:15:03 +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=1744719305; cv=fail; b=QzfRtXVEWVONxmlIxzcwmFHMqlLxuXDO2fh0L2Gru513ABsaAbCnol4yWNiBZWNt4BNZtbDz3BJKc5NFNqdaXU96E7eYNlabh0BujMk4xAKihaUnuMjOAwEY8Yabtir7AOxoMKBTmkYuxXNp/aK298qSwXLhM3cdPpt8CwgtvJY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719305; c=relaxed/simple; bh=8AkaQr8WYXfEC2U/gfJs1iCWyLKb9tVvnjdo5dvbCYo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=cK/6YI1WyiINl+KKt6W5hAKZD+EfeA1Ig/2AYXJBmgTUQ8vwMBnmAhJDAU3GuSUbtOzfx8p2ZImQMc4KE/QlmmmGQxbFMZuRCiiW+TamSd9eELufdg1TbgioaditjyILUByRYbXGp52g+pFoCj24SPrs6GcNp6oYaS9TfUfVzQA= 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=dp7CJ+Cv; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=N7LYxO/x; 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="dp7CJ+Cv"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="N7LYxO/x" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6fwFC009864; Tue, 15 Apr 2025 12:14:51 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=QpUdZIa1cGL+CRVflFJyljcjY09NJGGTBUE6oGA3NFk=; b= dp7CJ+CvbsM5eywjTp562LQI1ErIpCj27cvlDr1Amg2tQRw7RhqcS7imQTq9PqBJ s9DYcjrXINR7D3WoSYyMKwk8UBqy7lUdGwWPy2uOGzmP/N0OOJgZxyxi9akXBr4x ZqI4wBDVJ+T135UHntHCaM7v+OLoaCdCm0oPQ279wTXV8ACRwStMwPFwXiUNThrS r7/0U/mTSCef+U2LnzbFA13c4hzjZnJsppRWjY0sILViqbNGIi6a7TTq9SiXRWfd +HrUDBk05DgLlr/VCHo+Wv5Zhp6rkp0P6OA5x99VQ8drE3V9BI8agpWKkydZ1iEq iTFIwOp3ABKTOpCwEB81lQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4619441bre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:51 +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 53FBFQab030960; Tue, 15 Apr 2025 12:14:49 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010007.outbound.protection.outlook.com [40.93.13.7]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460dbaewv9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eVmM2g97SWiCxAq7KgkjKodvwOKWuS6D9O5EnPuxKAaqIKPpk+srFBvHE1vrffP1ZAyF137Mx1aAa0cJG4+8dFy6pGcVV9AuRR7NcwyMaTNXa+u7d+Mg7UXH0JTv7ggwXl69QWhqcuXixHWNCibJxH2BwrnminqASV67oQO3fBccq9tUpDne6MBYNHCrDn5EpmDwy6GV4ZDoSIBlrcbzwcqlOdcJvSajgJuV7I/+lNsd0ugs9jvWauiF3W9hIS9XlHJt4wAtbGH3yTTF2ZMx+o6OBS5++AobDVNAo6qI6Cd5jeOm4Y3IVfY1U9whbCzft77HVVYX6CnOWMZ2KURatA== 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=QpUdZIa1cGL+CRVflFJyljcjY09NJGGTBUE6oGA3NFk=; b=SSxtkW+kKTLHk2akKMqDzD3xfgVVO+8nKaMYXf7OUaT3EmeMXfKkG4SNFsLhwMRwRdgiro5rPWMQHEF+aNZd1efEGJ0p8L7lutRaKrj2pgyi7C1iV4KvuLuNwlf3VYNEh7LpKzBdHKQExmkDfRl0XB5Pn11gcgI/FJA12pNVJTkrgou2gph7gnWOKToN2h8vEm6h/P5VlDMMjq96A/cC88MPWJhKB9XKoIpMg/TLiGihbj2Uqa9vab/9A/nrwcVWSK/w4jYNWOQJiLr21zFUsC6PhpA/r8C8lb7wbXFauPaOoVmuONyFI/7bPE9wHEmtVV2XTMm0lj1D44lBHzaTQg== 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=QpUdZIa1cGL+CRVflFJyljcjY09NJGGTBUE6oGA3NFk=; b=N7LYxO/xTDNHp5a47V7cDVq6uTjkepFtmVfGH3TpdH2VGEjd5q+7rxdnqHLvh7ZXqolRG6oyGHPPCUKJ+fLLV6NtvVhLL4CE69Lp0rkLHk1YOLl3Imqjk94DPUmLURMHEWtMsRn9n4a+QL6+bQY0U41ii4a0ZjYzNvYPd6uV2j8= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:48 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:48 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 06/14] xfs: refactor xfs_reflink_end_cow_extent() Date: Tue, 15 Apr 2025 12:14:17 +0000 Message-Id: <20250415121425.4146847-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BN9PR03CA0854.namprd03.prod.outlook.com (2603:10b6:408:13d::19) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: d6c746d5-04c5-4a77-a501-08dd7c171d8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: dpggx6htTuRfsG27xgDpbKsIC2Ez6uBZuleLyIlLD4/bvlSHJZg2SRGy2ddUGkpmvEa6xrLnR8sEvc/VKr09WP/30lcid6XrQZCNVJwbiLm6G8NFe3CmH7gSU/kBJLdsp8WuwS+pm8Jqr6OIjtTIbLz02M9Nh/BXdf0Jw9v+hGb35cE7QhMQKSczci8UILy0YIoCVLUCujDvpOFFS9Dhx1TiRM7SquYxQT2RN3IFllJkwE0k6j89Do2yPQsdKk8P5k63o4fjhYJPfEyakfhYg7B85N6GKDiOFbcVzkfn5Kk3fhCOkSyjQHTwKVi2/oftPpUhaTV+6Y+zA5eybFj+PWFrP+X+tbQLu4JR7peoE713SnNfabP0ZgYWnh7UbVk8LzL6ympZ1XtwmS62zJG3DbUV2hu2w1jRNk3SbWYE4ZJsIBSGCoCzfOgttQgkMigDq3drLWfAdXGIlGwfTdvmHSWUX6t/bYnHwKAyHdaIMydyApHx0X5vDdV8K81fI+EOYn6rhru1jMJ9tye/AuTvg7LLnheumybyGph6i7zfxV30m59XQAxXX69aj+T7/KJICqygdjsFtDz7Q3xOncy6YsBxmJU9M3X7n24k5/Xk17Uvqi1uvd37tBjrYH2nHla3ClpFrICfNej2spmoNXK5mmTGBsDIaj9JPzh4hnoW2ja18ppDqcmPkGbFO9ntudDr8cVEmWSv0XXRhPCpr4oifhEe1W7tUlsdwv669y+5MP6YdDmf4lBqJKow1tD/vDcqwQAsCPl+4hA3taGiBUVHL+KY4ddwuNoFwYCavehA/Ewq25tBfNKtpCycdNRnKbcNk8D7IrDAH64GF7GN9I5PIwlBzukn/GWeIbcY8YtYdkLsWLy/uO7m8Rmb0usqQwWNhORm4Msec/TpIFKO70Ib1n8MPg3eXFYCP5t6HDwPRXcM+2k85XGGOlny/Qxu95lQGLmSV6XejzWBgF8KgJtCarTXGUaInebtst87BaxrIrURlrNrmuXXoELaaPxoRB2BNTZgJ5GBwrDoo6BkJ1OmtsL0WzdFnBLK/uzz3S0KXUnGSlIdF8SAyHSlOZikIurOwGnQ719+s7xkvz01gIh9rwbGuD7x3+xUobG2eZsSIm9gMhUKKHjFY6HSJGpbPltGnkLYBxVQTKHZNCywsh1FYeOqpd2Pen234UQBebecFiF2xG/mp03lWol/FaWf1IvWvWz+Up9Xp0Et7f8UCKvexlXckym4Ub+96247Qh9QYFRiLTAXJVxTZFGtbHkskktkSwoBddH8pRmfPv2QZClCty/0MooQ530ziuFweUHurU02tQO1hcCpIKXNapVJDL067GA8pNHfcjgxkUwl+pA59PGG+wo6P05pjT9dHspAhIP+GqozTQUw2iI1pIEnM7e3cq9ps+8DNqW6+2NeozNWdbF6tj0WcXfdw/dn2Cpi7Fg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Ex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IbAsKWxV/PvlZ1XM8q+G+ZKiMaiIELhhVB7/+O6W5kX6AjNkr0V5Wc4iKr2mFyg09ZAZ25HLpV0VCaabr59UrTBKk0nrP9VyJpD6/r3YHY9nM4NDZ7rcD65HBheFEjUTQLTlrQXQuvHlHHjae7a1q77YErUBbaJkbo6DJQIfqn/nK1o31H1v34QRo1HTIiVgSySl71SKaDZjszNa3pl/Y8kW33fUGKyUszBLhWGYA5t/nehIEE2DS6KNi8+2QT24VSQvvgk6VH8A0zZIVdKLuwDuFtz6oAJbnHnoua+g42CfmyJkFn8qoSYitxiqhny4a3ZtHS+At7z/kRdEjGQgU39efnc7hr2mruDREuuec4O+S1BZjCMbqPoXBeTkrKsnQCtE5+HNbE4SveF0Kv3OnDOc5KZkkgUDfOQK+sTcLu6SHOReA5qknPB7O1jl+T/ry7aDNhtoF9nVOqRqzeySoMhcprNFGYChevulMlkB077c1IpuBf4NCGCcsrSwP1bMQK76A/kn1fduA76WHYG0Y6gosfhUqpKs/Jy8OLmMr6m1i0OTkNYmjW1epg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: i3paqKJ8l3cBn9ElPHSbCXJs/mIKa+u/Ig00Zg+tPgqSPf1grS0766jQAQ2pFymfb7GbLBYYzz3YufN2uuVdnaqjyQON67p1MvNYZhYiOR2v/QGEBF6veMuTN47HAYLTsi5NlZV71YsP5lKhe4Y1b5NYNLOJiddvQbSM4LGNceET/u/bLmsa4ImKBVBnRr3f8RL+4V30X3aR5IM9uxUh2mqV9mQLKE3grqDj6zp1g53i1oDP5vhR2517l08NvB2s9f8e70obq25ZE13bq+n+p0t0+IoqpgvuFTJvqvbpzCRsEV/SQIT/F4BflIM9PIHarh0kouUbyVW+D+NR6x84iT2WK4zuGzt9V8YTucfMhNby/f9/rH39Oprk7LGOWgQrf4AFJ42cF86x1PrQt+pe69V6MHDyx05PQN6gIg6jTnoIvqO1tCqYDoCBAy9fuBMBSLeGGNpRGWutZsUNu+X7tmQzPuNmuI+VhGVNmvafEJf7oTT4yZNo9TaVsFVxWsZ2r8RZqTufXWbcaP9MqllJ+hvHllru1KHpi3IrkRZZwLQqonlldiCMvv5VZN8f6oqCgwJjQk1CTqHsbv75inb8Zf9xfdVMRNy4wHkBE2xzR+4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6c746d5-04c5-4a77-a501-08dd7c171d8a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:48.0031 (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: 4Tbg7WWFzd9oq+eygNiEmVc8YLF3QwCPxu1rAvdPYTtG3UdtF6oyQ+X0lsI4Qawrjr/6omZLHozLjCVHzBotAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-GUID: dL43aWgR2Gy8aic6ERu7At9_UXWF_z-A X-Proofpoint-ORIG-GUID: dL43aWgR2Gy8aic6ERu7At9_UXWF_z-A Refactor xfs_reflink_end_cow_extent() into separate parts which process the CoW range and commit the transaction. This refactoring will be used in future for when it is required to commit a range of extents as a single transaction, similar to how it was done pre-commit d6f215f359637. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: John Garry --- fs/xfs/xfs_reflink.c | 72 ++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index cc3b4df88110..bd711c5bb6bb 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -786,35 +786,19 @@ xfs_reflink_update_quota( * requirements as low as possible. */ STATIC int -xfs_reflink_end_cow_extent( +xfs_reflink_end_cow_extent_locked( + struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t *offset_fsb, xfs_fileoff_t end_fsb) { struct xfs_iext_cursor icur; struct xfs_bmbt_irec got, del, data; - struct xfs_mount *mp = ip->i_mount; - struct xfs_trans *tp; struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); - unsigned int resblks; int nmaps; bool isrt = XFS_IS_REALTIME_INODE(ip); int error; - resblks = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, - XFS_TRANS_RESERVE, &tp); - if (error) - return error; - - /* - * Lock the inode. We have to ijoin without automatic unlock because - * the lead transaction is the refcountbt record deletion; the data - * fork update follows as a deferred log item. - */ - xfs_ilock(ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, 0); - /* * In case of racing, overlapping AIO writes no COW extents might be * left by the time I/O completes for the loser of the race. In that @@ -823,7 +807,7 @@ xfs_reflink_end_cow_extent( if (!xfs_iext_lookup_extent(ip, ifp, *offset_fsb, &icur, &got) || got.br_startoff >= end_fsb) { *offset_fsb = end_fsb; - goto out_cancel; + return 0; } /* @@ -837,7 +821,7 @@ xfs_reflink_end_cow_extent( if (!xfs_iext_next_extent(ifp, &icur, &got) || got.br_startoff >= end_fsb) { *offset_fsb = end_fsb; - goto out_cancel; + return 0; } } del = got; @@ -846,14 +830,14 @@ xfs_reflink_end_cow_extent( error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, XFS_IEXT_REFLINK_END_COW_CNT); if (error) - goto out_cancel; + return error; /* Grab the corresponding mapping in the data fork. */ nmaps = 1; error = xfs_bmapi_read(ip, del.br_startoff, del.br_blockcount, &data, &nmaps, 0); if (error) - goto out_cancel; + return error; /* We can only remap the smaller of the two extent sizes. */ data.br_blockcount = min(data.br_blockcount, del.br_blockcount); @@ -882,7 +866,7 @@ xfs_reflink_end_cow_extent( error = xfs_bunmapi(NULL, ip, data.br_startoff, data.br_blockcount, 0, 1, &done); if (error) - goto out_cancel; + return error; ASSERT(done); } @@ -899,17 +883,45 @@ xfs_reflink_end_cow_extent( /* Remove the mapping from the CoW fork. */ xfs_bmap_del_extent_cow(ip, &icur, &got, &del); - error = xfs_trans_commit(tp); - xfs_iunlock(ip, XFS_ILOCK_EXCL); - if (error) - return error; - /* Update the caller about how much progress we made. */ *offset_fsb = del.br_startoff + del.br_blockcount; return 0; +} -out_cancel: - xfs_trans_cancel(tp); +/* + * Remap part of the CoW fork into the data fork. + * + * We aim to remap the range starting at @offset_fsb and ending at @end_fsb + * into the data fork; this function will remap what it can (at the end of the + * range) and update @end_fsb appropriately. Each remap gets its own + * transaction because we can end up merging and splitting bmbt blocks for + * every remap operation and we'd like to keep the block reservation + * requirements as low as possible. + */ +STATIC int +xfs_reflink_end_cow_extent( + struct xfs_inode *ip, + xfs_fileoff_t *offset_fsb, + xfs_fileoff_t end_fsb) +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_trans *tp; + unsigned int resblks; + int error; + + resblks = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, + XFS_TRANS_RESERVE, &tp); + if (error) + return error; + xfs_ilock(ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, ip, 0); + + error = xfs_reflink_end_cow_extent_locked(tp, ip, offset_fsb, end_fsb); + if (error) + xfs_trans_cancel(tp); + else + error = xfs_trans_commit(tp); xfs_iunlock(ip, XFS_ILOCK_EXCL); return error; } From patchwork Tue Apr 15 12:14:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052117 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 E866B29B76D; Tue, 15 Apr 2025 12:15:06 +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=1744719308; cv=fail; b=VcBubyqWdiAGbKlLg03Kg52qqd2GiOz8s4KxRJp87ygwzXZCxfrkuie4rocuvyXk0PPNTkZw+mP680I7GfIqdqm6hSPYiLlWwjZQ/Aao6htdzC5vJKnMeTlsYOdvSjIetDw0fd8+Z7pYzGY71onHW27oOV3ThTsIAbxR8kwvD8Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719308; c=relaxed/simple; bh=ZV/j3R1d4BHfD9BhkfVmzGXRF7EHcc+uLbR9PAi+240=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=FvJeMrz1+U+x8WDu+1qIaCoguxgnWYq+uyIYIMuD5+uNzwxdSOUcxi4dyr8c+5wbQA1mrYe2lG5kpcoQ55AzuRRgtTf5ZftqqQYRRgDFIQ96oYJUeioN8rELzUkUUeO9tttKRdbOc7NBEYSfV9SiQryKLVBsstZ00U1jhPN4/i0= 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=YO0FcbCa; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=boGFqFEF; 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="YO0FcbCa"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="boGFqFEF" 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 53F6fplD021585; Tue, 15 Apr 2025 12:14:54 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=r+wLD7Nb0mVa+1yO+BQsTbXIxRs143At6oP00Kda+D0=; b= YO0FcbCacbWl7W/KWJcp22YbV7HKKH89HZdZX2k+ojiHTpg+ii3W/5aD1+h3q0Sv O3sUCXZojB9OgOA0TqH2+yDWnTK6mLugioOVuP14Gl3rMdYBcrMPYu82VAMgEppf QiQWCwHS3Nw7eP9LEwRa1QOmh0W7lbLKe1B614t6HD8zEPQLS4LXv1D6x/jqbRAh Nr25QF0TP/wybkUKnT1w8sg7/m10V1+6hc9azRW1K6ug6LmgSyeO1tnPDoJzqSdC OWoFk1RMgq//7rGzopg6eu/eg/YPqnmMuJTC+KRV9dnVblzBL8fNxr5yM2hXcGZh vQZm8JZuAOEhnXev1mKDxg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4618rd1dsc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:54 +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 53FAu9hg038859; Tue, 15 Apr 2025 12:14:52 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010000.outbound.protection.outlook.com [40.93.13.0]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4r76wk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BcCGkPifDmCA4KdOEET1r37Y7W7rp9atNhQ4G7kdob5jQmOne52291Pmp8Aa3d1tE04f2IpV2A1Wczk7KTD7ZWU43Gk6gxeAgvCf2k4E7lrK02mvmdsu5hU6Z8XuSs30KJsMOJHHfIqPLmS1tFJnqw6+5Ezp/78lAErQuS3aJ5zNzxkM24eJ6BdS21uf7RIodmSgzaiqFe9Igkk7imibs9lw6cRp2LIalJq3PyFCUuIMyk8u66leuyvbpur/a4hK1QdsQSODLmggZVqoRfi/p/fQItuMr4bMDYXnfPWl7L27Ilk2BKARbwWteMmGAb8loYEd4NjlI7gLYF9vYi/Q/Q== 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=r+wLD7Nb0mVa+1yO+BQsTbXIxRs143At6oP00Kda+D0=; b=BuoPf6v0FIMu197ThtNScgogwRJFhiFKYDht+bNbkJpPfH1WEk4+hPIivI2/Jp4BKA6rHqaDnVwHVC7GTUnzRJiGR44Wfab84rYZMo2vnMq5Bg84T7Sg57cAnCVGEEgnJDkpdK+YCL9pCFa9+Dc6H8vO2bNvKxrOL0byUvyfOcp5eDgEUgvB0fvdUWSxxcuWOJGIgYX4lgncvcRQKLCXDtIAxm0RmbsqeekkBAsfi7Rg27oF1iw9KhdFr9QWWfFoHhvgmQdSLRf83gZ8pr+FBwgm9yCqZYiNeMA3klrxcUS/+vO4dOOIfz/QEqTIBgGWIhFnxUHHWIgax2kExFZANQ== 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=r+wLD7Nb0mVa+1yO+BQsTbXIxRs143At6oP00Kda+D0=; b=boGFqFEFeKPTdVILfAO1ihogdZ5poJs0AfaUhnj7hSsNnhXNPlnCj0SsZwD0jq4GG/zYmwIktSHLu7TyWROy33z8TpbuwnLyKoYMTkLFDbmrfCmauu5cAgmbIF8whgRawCMq9J8B5+k26jr81ym1IErn2DbW57pcGJW0xd0L9FA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:49 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:49 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 07/14] xfs: refine atomic write size check in xfs_file_write_iter() Date: Tue, 15 Apr 2025 12:14:18 +0000 Message-Id: <20250415121425.4146847-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P222CA0026.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::31) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: aec1db15-d493-432f-7085-08dd7c171e51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: 5AorzA52uDRj+Vq1tDjgwa5fh/2PkYO7+2MM9G2tEWIUBxXVcxiL/SpsBrKL2iKz1FsIAIgQQewY6jq/g8LZt8k3X7m7luvytBFQsqeMJtUbY0gZr9fDrYYMlzDuCo3R5vI2BQJ37bSyfbJPOphzk8bNfTiTCM9HTy3WqQbuONjcTSZmrIUS63Jr+CJchlRYPKSfy6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hALQHOUgxyRqoQjhZ5ftkyx0BpOZ5ZfsjUWZvB0BNwsQu0cd2CmPpUFkuptYM8WFbB3WAOBFJZTEAEwZ3tg3Q1uEQH76o7UrMiW2Wdbm6xXHT4OzSahkXqTkkApLomkUjJ9gdryBa3khUWuDjHZLFcoRqLHjA+TTI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZhZFUF0ea2itIs54R/uJzd4iplIZrAiNXAHOD+lB0CcHfTUCTS74Ll1wRsLX38XgxOmeglXo5OZ9Z1qvFJDPTBBy3jnA/tde/lAr6YXK6+NBHpYB4mYNf6zIYv3XSlgySCTeTaFwuMmXev2XU4rTt659spz9QTU5Q4wcGukzSVkw1JTAhGL4iGgEM7fEg8EOkL+VJAMv0bfGBroZfuPQ1b98wXCAgDxdlQUS/rvJfkaTk8ieLaNn/dzB1ncsguY9xfTjs3Qi7Mcs3ygD/ThCJaT1LRrmkEEhE1CXFnGWwvWnCMfGiba7JgBWTimPWjtJR3mjbPY58X8Iz8I7RJu9sv6nnRDpW8+sAb/08mvu2uHbv8we1L+1LkVJhIz6O+aNTVEy0FqCaM+/ZVoX0s2toGQ9oXTEwDBXbekNHslEjnNTIcpaw7qv6aA/zx2LswKC9NfzoPCZkzLz5D3puaqvHDi35uAL+e5TOtAmJRpRFEvLyiHQ/+zXgmMLh68DDwImjBmVeNojo5Eea9rMTjjlNJLxN2A0XdMSoz2RHt4VhLpTCqDtPF8ucQ+IldUWUQaRyglu9lHytHxCOUwZJY8mkH70p6JRYZjE7VBEOuudIBH/tz9bar3hSvaQW4NnNNjxN6lxXO6RAK88KYvLHlKmDhMNaMIaYNoY0vFYeNxv1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dSUfRGLQ21tfjaCjoplgQj5emkISgCMiVPg5jtS6VmuJhe6hcE0+GjhZ3cWKcfRRKPYWOExfB+N6YpHEz1ZZOOvVcfVmtMrfMCoQQ0y0Rh8I8kevWodp+M+8UQxatOR1Ow0riJ6wvMtuBH4hhT0n4f8XHMEJJqAb/ID0z7ZYh97B+qB7EcLJrZ0yKAwAdykrJSGc1V+lgziqzneuv5jNOhFZsyM1y0uq3GGrf+mdYsSKTQ9VCLDg89iAlELnYkD1BykjLJk5+nZ6OvOtoWb1EYyI2FKMzOnK5HqPdfO8Gb5lnqQwMMSOG248kKdHDf0pbqBlhhAIFlNLyAqJYkIfUYxmksTkqy7N6cb/31PibzTeKysi/kx6uCaanOb0h2HqDNCWgZFQPDsE1aJJrA3CRxBqnM3HzIS6OclGTXabDWey7Z1tENox+eDojsLKbFRsc7pqzuupa8Z4RW1mx/E4/rc5pY28ofoERuMs8hOLoS1eq7KySyazpK6PJQBc1mPC/EaptWcphvmJHSyssCinf6WuGk/O6G5sGksOag+0DKclxEzyeBM3RaSgQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: aec1db15-d493-432f-7085-08dd7c171e51 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:49.2511 (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: UTsuiycBJYZkE5RAoqVRa2/pxW1aW91TKZRcnBXg/y055v/AwIaacHkGAJj0Y+ZFv6YTE0yVSGXZwnDMkB4AYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: KVZ9CFEAwgbjOFolq65vKcF-q08dHjsk X-Proofpoint-GUID: KVZ9CFEAwgbjOFolq65vKcF-q08dHjsk Currently the size of atomic write allowed is fixed at the blocksize. To start to lift this restriction, partly refactor xfs_report_atomic_write() to into helpers - xfs_get_atomic_write_{min, max}() - and use those helpers to find the per-inode atomic write limits and check according to that. Also add xfs_get_atomic_write_max_opt() to return the optimal limit, and just return 0 since large atomics aren't supported yet. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: John Garry --- fs/xfs/xfs_file.c | 12 +++++------- fs/xfs/xfs_iops.c | 36 +++++++++++++++++++++++++++++++----- fs/xfs/xfs_iops.h | 3 +++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 653e42ccc0c3..1302783a7157 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1032,14 +1032,12 @@ xfs_file_write_iter( return xfs_file_dax_write(iocb, from); if (iocb->ki_flags & IOCB_ATOMIC) { - /* - * Currently only atomic writing of a single FS block is - * supported. It would be possible to atomic write smaller than - * a FS block, but there is no requirement to support this. - * Note that iomap also does not support this yet. - */ - if (ocount != ip->i_mount->m_sb.sb_blocksize) + if (ocount < xfs_get_atomic_write_min(ip)) return -EINVAL; + + if (ocount > xfs_get_atomic_write_max(ip)) + return -EINVAL; + ret = generic_atomic_write_valid(iocb, from); if (ret) return ret; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index d324044a2225..3b5aa39dbfe9 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -601,16 +601,42 @@ xfs_report_dioalign( stat->dio_offset_align = stat->dio_read_offset_align; } +unsigned int +xfs_get_atomic_write_min( + struct xfs_inode *ip) +{ + if (!xfs_inode_can_hw_atomicwrite(ip)) + return 0; + + return ip->i_mount->m_sb.sb_blocksize; +} + +unsigned int +xfs_get_atomic_write_max( + struct xfs_inode *ip) +{ + if (!xfs_inode_can_hw_atomicwrite(ip)) + return 0; + + return ip->i_mount->m_sb.sb_blocksize; +} + +unsigned int +xfs_get_atomic_write_max_opt( + struct xfs_inode *ip) +{ + return 0; +} + static void xfs_report_atomic_write( struct xfs_inode *ip, struct kstat *stat) { - unsigned int unit_min = 0, unit_max = 0; - - if (xfs_inode_can_hw_atomicwrite(ip)) - unit_min = unit_max = ip->i_mount->m_sb.sb_blocksize; - generic_fill_statx_atomic_writes(stat, unit_min, unit_max, 0); + generic_fill_statx_atomic_writes(stat, + xfs_get_atomic_write_min(ip), + xfs_get_atomic_write_max(ip), + xfs_get_atomic_write_max_opt(ip)); } STATIC int diff --git a/fs/xfs/xfs_iops.h b/fs/xfs/xfs_iops.h index 3c1a2605ffd2..0896f6b8b3b8 100644 --- a/fs/xfs/xfs_iops.h +++ b/fs/xfs/xfs_iops.h @@ -19,5 +19,8 @@ int xfs_inode_init_security(struct inode *inode, struct inode *dir, extern void xfs_setup_inode(struct xfs_inode *ip); extern void xfs_setup_iops(struct xfs_inode *ip); extern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init); +unsigned int xfs_get_atomic_write_min(struct xfs_inode *ip); +unsigned int xfs_get_atomic_write_max(struct xfs_inode *ip); +unsigned int xfs_get_atomic_write_max_opt(struct xfs_inode *ip); #endif /* __XFS_IOPS_H__ */ From patchwork Tue Apr 15 12:14:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052120 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 8534B1C6FF5; Tue, 15 Apr 2025 12:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719426; cv=fail; b=eHhttLTa+uGkYKWy5iboIWCicqApcDOdUNB6QM0uWNzSck2eKZJpswmNA9TFHEiKDE/eeZCqj1uGAl8q92MbOi/6DmnE4Expft/DjYmiOPUNN5sD/d+jfddVKPvFVc0k0AUX55OVtBZT7Iu0Pi65xS+AAczyecWHWTo6EiguAvA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719426; c=relaxed/simple; bh=lKy25y1FtnrX3rj/uj9DMcYTl9X4VoFxjVMfiILkRuU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=nw93B1tGr6KyykXVq8Y40MB7xXaA11n2Sp3pTn8FuOy8AGho284DThuBrCEa+B3ipRXhz0kdSbBXD1qwzkomfIxJ76uUPFc/YsMiCC0ScTPslEXmlBMDa53wPuJ6PNTVKFn+XRAdhpH2VELFyOVl7Pqyz+4c7Rh1WZ2NgiqP56c= 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=CGR0sDay; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=SwRxtEAC; arc=fail smtp.client-ip=205.220.177.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="CGR0sDay"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="SwRxtEAC" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6g2Wi022165; Tue, 15 Apr 2025 12:14:54 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=+IuTevoQxU2ikSIf4UJ+XPa/rufQNrDOLkN5FfxZY1A=; b= CGR0sDaymHrwQ3Xpkqgr1i/tP9PNHfWlwZPsbHyWgB5trMhoZmt86JTx/XOEuE/7 NXTVILEtNA+UNte2GvnNrsvqExNSkRstluuZ1WjjCkU6dsVuFXpge+mzbID8qGax vNFcx0W4iODLIs07E8y1K0x3kd3g//0Jn15sf0UqfLvx8uGfYsjdCwSE/NPVaKQD K6q9CXCiWeUw747WVyLlUajWiBXSrMiG/E5NVIjr6eEgW3Warq0iij8KD4g5GIXa fvBzil0NdwhMTCXzDOopeKeq+bXASA8xoauuvhi2BQjZMwmzkV2yWaVit+qiwAJb E2DZd+/5ylGPQ4wgzSQKag== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46185msf8g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:53 +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 53FAu9hh038859; Tue, 15 Apr 2025 12:14:53 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010000.outbound.protection.outlook.com [40.93.13.0]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4r76wk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=csKHcNYFiLc6mKAELZ6oQxrhfYR57MzDTAnmyZuL8liu8dG/NxhKdy07X1eI2n4zJYyd6Am/22L34CyBtkMFdqqztx2OUVvbXg4nEIpjlODJajbZEdoeHQdi6L7obbL6/oEw5trCm7OYgCnNNvnFxZ+7aeWBQiQzQR1eajxKF0agaMjuXaXCHt0rl0EKR/NKjeYcpC3iTP42q1mE4zD1aC4b41BKqwfD/ySJCDzO/axaRHAH4xCzezVShZ1Z3kn8NyllWk8zAatk02mjQupBsjsPijry77Y/yJk3a52wQwlbuugNNReNciywdW9DEwoCq3+A+rSbQqhP+PdG+aruDQ== 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=+IuTevoQxU2ikSIf4UJ+XPa/rufQNrDOLkN5FfxZY1A=; b=opQwJMW2di6wx/FLml7Lgy8IbabWtKNbZa8lNMfg6/QrgVmB5mL8t0ArI/pgS7Jyf8dZhQ2XxNVwXqpZXVx7r6m2Ra5oae3dmJF8GFsU+5a/hiMeuY/HCEwJaT3DEPiIqmUQKTGi0JJe5l2yRvZxsjdFE9m+ExTr0b1ar0e4xXsc7n3NSczKca9wmfKJ2D+sa0Cw9eTrwm/dL/9N53iTW8kwduShCkjt+2/z4VzMKr94GO5y+uuR1v2UKwaBj/MpBMAbPtmAhQ5ScGEbyf7+nyMyBLKFpceaowr1qAKHzZpIt2JYLk/rnsBE8TY0R/9H6BGfYjIGgKzmDPpAtrY+hw== 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=+IuTevoQxU2ikSIf4UJ+XPa/rufQNrDOLkN5FfxZY1A=; b=SwRxtEACcsApQTYXiiwmGPzWjHWnhy+Y2d/w5nrAV2mC1R0ERXe82Q3xJw8JNbbtzYOEY9ljulqHuW7/KeBJvOcppquWCTK6DULsxQ6fjcGiDl+vSW0RRhVpuOovODSH8Lafmsdo/TqMlGTMigtmlyARy6/iGp3hmYlhP9BMpPY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:51 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:50 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 08/14] xfs: add xfs_atomic_write_cow_iomap_begin() Date: Tue, 15 Apr 2025 12:14:19 +0000 Message-Id: <20250415121425.4146847-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BN8PR03CA0022.namprd03.prod.outlook.com (2603:10b6:408:94::35) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: c77aceb7-539c-44d0-ff39-08dd7c171f10 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: AvJhT3Xqho6v7eihrx6ncM5+ZB/3o8cO3llzpytX8AOBobtgIUHq1TaakCyJGiwXVs4PXEJPZ2nC2AfI5uzL89eGf3egTujjIM8FdK+ak92JqMszcZneNNtuIsnhFi4IYS3ncW7Fuq5a/X880oOvqHmbFkaY25Lw3xHW+WZ50DPS1NHelZ9HJff7peKA5OEZYDugigsl/+fMxIPDhnlzSgijIh/1YWl8CxaFT1iQWPbLL2Gp0jAkWvx6bi6udg0i/UmOWUcPM6MPml2xDDCQJ0BLRcJl8FeyfLbJwoD1Fn1MICH6PRY+dqBDChDZNqkkvqECU2HFW8adlcZac+mR8nKEX5t3Bkq9b3+/LO4Xlx62d9R5aSJ5TnJEkittHvaFeVZV+9K2y8wQd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255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kkdtIEThPlVjD5+oEIiYCra1oxRtyOL4JEFgiHX92Wz2A+TzlxjusGufzw4NxCgPWXq/ad2OntvGsEyeQcswILGT7/7D+BpdNJT6T9mjNQcTR7Xzaz9xbL3ggvwZ1MbUxiF5ar7kFGREyBxCICHqkw9+Q+rCcfKJMVEcwGE7RLXh4mW0Bayw6RQS05RUBg5m5jdZdh8fwCMTDOmnTrH7Zj/FnfLGVhQ620IfE3jvVaEW7jUpQS2698gxai1CCWItDZjzhWL6fop9JP+eAHenCFkQwGPhkKVrMkaxV+n7esrJTUc+q44e0e8q3y2r6ZEtWVMw4Lxp2Hmuv/M+5Bip6iGFJCbCiPiQjNNwNj8wgUhwrCmqnGGbp6JZ4x2jtQ8kj7YqTpn+MX6agcCwqC+ChsPA6kP2JCfEm71KF+zgx+bR0MLKLiNUo0jahSp6G/gcmJPfHXtLm4PPG3yStwcdYhe/IlpM9UnMF521sTmZ74tB/T4aOo7AO8RNx0o04vyrNViDvvH4s6WwdtBjz9Ix0Y8HV4e6WhOAJzL4nwK9tcbmyTc8YkwAF3SPipgDj6WjjGkOnSJnr20Qk8osThKOpiYN3251Nf9iAlkqaWyf8TNVenToCwrlkb2swrV5IUggHU8wIbuwkofBgZYG8K3B8DfqCnzPBWnuzvFhTCo4LnZcN+ZqMph01haeE6oi5XKz8usdDlPB66Fu2BhdmI5lsRe/Wo9CkHIqsFRgE8ZD2rhbkZh1Pcm2T1dlvqSzfRpXEGXRzyyAWNs5g4tTcWf7Dou75jjjhgCvLmvh0fj+vf6zbNP7dRVlk2AzfF2r6vJkyvaVBmzk+b+ng32F9M/0IK0Ha8kLq2G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bw/Efwc7LJ+EVJWR5RplXYMgXsqXiDWp9rLs6WUPTPcAZJ0ICM/KbaecNd5tAbHgPxIy+ue6cUSLQ7zOEhINQuWRae/wqRIJ/6VbYUL/2Waqlo2cFxBPYC6lgzZk/rSXomgSADv6p8kugeN8DGY4qmIXO66lM2Qr4fbmMqDic6IACA7iYeYDb2hcJu3JiB6GyJeIWC8DFRW3KPKRi6eADGTklWr6JsTQi23jJq2nfoFZPxnunkLo+Uhm3F99IFzRtc5ubAEFOY/hsAPiM3p7MBfRl3PrlVa4YukvnxBQsb295/ZxJPkyBLs8lgDF3IMvWQbArUHptHVzkRsKLDHzHlttN89jkTKT8dHjXNg3A4lvXFfXSjVvKk6Jvbd/UeANoKqrrUPFOOPpQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c77aceb7-539c-44d0-ff39-08dd7c171f10 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:50.5204 (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: T4HNdG4IPCKB+uyD9twnNRJb1UO3G2IOyzUj2U90gHP+PXZMGYZEORIyhSM7u9oOAERvu5hCrrusPx8uvS7m+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: JK0_Xs7GM79-VPGx0KwXHipouGLeXIbk X-Proofpoint-GUID: JK0_Xs7GM79-VPGx0KwXHipouGLeXIbk For CoW-based atomic writes, reuse the infrastructure for reflink CoW fork support. Add ->iomap_begin() callback xfs_atomic_write_cow_iomap_begin() to create staging mappings in the CoW fork for atomic write updates. The general steps in the function are as follows: - find extent mapping in the CoW fork for the FS block range being written - if part or full extent is found, proceed to process found extent - if no extent found, map in new blocks to the CoW fork - convert unwritten blocks in extent if required - update iomap extent mapping and return The bulk of this function is quite similar to the processing in xfs_reflink_allocate_cow(), where we try to find an extent mapping; if none exists, then allocate a new extent in the CoW fork, convert unwritten blocks, and return a mapping. Performance testing has shown the XFS_ILOCK_EXCL locking to be quite a bottleneck, so this is an area which could be optimised in future. Christoph Hellwig contributed almost all of the code in xfs_atomic_write_cow_iomap_begin(). Signed-off-by: John Garry Reviewed-by: "Darrick J. Wong" --- fs/xfs/xfs_iomap.c | 126 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_iomap.h | 1 + fs/xfs/xfs_reflink.c | 2 +- fs/xfs/xfs_reflink.h | 2 + fs/xfs/xfs_trace.h | 22 ++++++++ 5 files changed, 152 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index cb23c8871f81..049655ebc3f7 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1022,6 +1022,132 @@ const struct iomap_ops xfs_zoned_direct_write_iomap_ops = { }; #endif /* CONFIG_XFS_RT */ +static int +xfs_atomic_write_cow_iomap_begin( + struct inode *inode, + loff_t offset, + loff_t length, + unsigned flags, + struct iomap *iomap, + struct iomap *srcmap) +{ + struct xfs_inode *ip = XFS_I(inode); + struct xfs_mount *mp = ip->i_mount; + const xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset); + xfs_fileoff_t end_fsb = xfs_iomap_end_fsb(mp, offset, length); + xfs_filblks_t count_fsb = end_fsb - offset_fsb; + int nmaps = 1; + xfs_filblks_t resaligned; + struct xfs_bmbt_irec cmap; + struct xfs_iext_cursor icur; + struct xfs_trans *tp; + unsigned int dblocks = 0, rblocks = 0; + int error; + u64 seq; + + ASSERT(flags & IOMAP_WRITE); + ASSERT(flags & IOMAP_DIRECT); + + if (xfs_is_shutdown(mp)) + return -EIO; + + if (WARN_ON_ONCE(!xfs_has_reflink(mp))) + return -EINVAL; + + /* blocks are always allocated in this path */ + if (flags & IOMAP_NOWAIT) + return -EAGAIN; + + trace_xfs_iomap_atomic_write_cow(ip, offset, length); + + xfs_ilock(ip, XFS_ILOCK_EXCL); + + if (!ip->i_cowfp) { + ASSERT(!xfs_is_reflink_inode(ip)); + xfs_ifork_init_cow(ip); + } + + if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &cmap)) + cmap.br_startoff = end_fsb; + if (cmap.br_startoff <= offset_fsb) { + xfs_trim_extent(&cmap, offset_fsb, count_fsb); + goto found; + } + + end_fsb = cmap.br_startoff; + count_fsb = end_fsb - offset_fsb; + + resaligned = xfs_aligned_fsb_count(offset_fsb, count_fsb, + xfs_get_cowextsz_hint(ip)); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + + if (XFS_IS_REALTIME_INODE(ip)) { + dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0); + rblocks = resaligned; + } else { + dblocks = XFS_DIOSTRAT_SPACE_RES(mp, resaligned); + rblocks = 0; + } + + error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, dblocks, + rblocks, false, &tp); + if (error) + return error; + + /* extent layout could have changed since the unlock, so check again */ + if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &cmap)) + cmap.br_startoff = end_fsb; + if (cmap.br_startoff <= offset_fsb) { + xfs_trim_extent(&cmap, offset_fsb, count_fsb); + xfs_trans_cancel(tp); + goto found; + } + + /* + * Allocate the entire reservation as unwritten blocks. + * + * Use XFS_BMAPI_EXTSZALIGN to hint at aligning new extents according to + * extszhint, such that there will be a greater chance that future + * atomic writes to that same range will be aligned (and don't require + * this COW-based method). + */ + error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb, + XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC | + XFS_BMAPI_EXTSZALIGN, 0, &cmap, &nmaps); + if (error) { + xfs_trans_cancel(tp); + goto out_unlock; + } + + xfs_inode_set_cowblocks_tag(ip); + error = xfs_trans_commit(tp); + if (error) + goto out_unlock; + +found: + if (cmap.br_state != XFS_EXT_NORM) { + error = xfs_reflink_convert_cow_locked(ip, offset_fsb, + count_fsb); + if (error) + goto out_unlock; + cmap.br_state = XFS_EXT_NORM; + } + + length = XFS_FSB_TO_B(mp, cmap.br_startoff + cmap.br_blockcount); + trace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, &cmap); + seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, IOMAP_F_SHARED, seq); + +out_unlock: + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; +} + +const struct iomap_ops xfs_atomic_write_cow_iomap_ops = { + .iomap_begin = xfs_atomic_write_cow_iomap_begin, +}; + static int xfs_dax_write_iomap_end( struct inode *inode, diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h index d330c4a581b1..674f8ac1b9bd 100644 --- a/fs/xfs/xfs_iomap.h +++ b/fs/xfs/xfs_iomap.h @@ -56,5 +56,6 @@ extern const struct iomap_ops xfs_read_iomap_ops; extern const struct iomap_ops xfs_seek_iomap_ops; extern const struct iomap_ops xfs_xattr_iomap_ops; extern const struct iomap_ops xfs_dax_write_iomap_ops; +extern const struct iomap_ops xfs_atomic_write_cow_iomap_ops; #endif /* __XFS_IOMAP_H__*/ diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index bd711c5bb6bb..f5d338916098 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -293,7 +293,7 @@ xfs_bmap_trim_cow( return xfs_reflink_trim_around_shared(ip, imap, shared); } -static int +int xfs_reflink_convert_cow_locked( struct xfs_inode *ip, xfs_fileoff_t offset_fsb, diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index cc4e92278279..379619f24247 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -35,6 +35,8 @@ int xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap, bool convert_now); extern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); +int xfs_reflink_convert_cow_locked(struct xfs_inode *ip, + xfs_fileoff_t offset_fsb, xfs_filblks_t count_fsb); extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip, struct xfs_trans **tpp, xfs_fileoff_t offset_fsb, diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index e56ba1963160..9554578c6da4 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -1657,6 +1657,28 @@ DEFINE_RW_EVENT(xfs_file_direct_write); DEFINE_RW_EVENT(xfs_file_dax_write); DEFINE_RW_EVENT(xfs_reflink_bounce_dio_write); +TRACE_EVENT(xfs_iomap_atomic_write_cow, + TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count), + TP_ARGS(ip, offset, count), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(xfs_ino_t, ino) + __field(xfs_off_t, offset) + __field(ssize_t, count) + ), + TP_fast_assign( + __entry->dev = VFS_I(ip)->i_sb->s_dev; + __entry->ino = ip->i_ino; + __entry->offset = offset; + __entry->count = count; + ), + TP_printk("dev %d:%d ino 0x%llx pos 0x%llx bytecount 0x%zx", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->ino, + __entry->offset, + __entry->count) +) + DECLARE_EVENT_CLASS(xfs_imap_class, TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count, int whichfork, struct xfs_bmbt_irec *irec), From patchwork Tue Apr 15 12:14:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052118 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 E86F929B77A; Tue, 15 Apr 2025 12:15:06 +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=1744719308; cv=fail; b=I+3tHJwAzz2LyUSalDqGsjFx/KATjop2sMwRi5JP9/VnTOqvXHqzS9vA2365HgvkwrxRTBAy0l0zq2Z8gOFWXJkJS4VXkEmF+egfsTR4urlnsRLdOi1F69FWtfVkCQqdnXAKGSUCiChmCB9+V89hCiSVjU1EgK/K9dRu8ZmTnxE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719308; c=relaxed/simple; bh=UyMwuJ+lIB08dRfG/SSOantSxU/2xoypUKU+azLlxhQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=nAUYmZlf20Q9X44l3XvwqUPaVThxwoh/wOBrBW3VC5FUhF2smJuDV1JYg5K0RincduZpct50NzQ6C1ezSbCpKJtrF4kIo2bSFu9QyUS56K/1yA75pF3Ojni7zEhUDhD7krNymaRXhGZBaOoFNjpI1x6utXLs9nyhsVn+33RSyvA= 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=LDXhW3dL; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=K2ucWayF; 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="LDXhW3dL"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="K2ucWayF" 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 53F6frDv021703; Tue, 15 Apr 2025 12:14:55 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=16dIHWGqysP6D2Br2j5PueHAxkCdgXuedFYgBTCRSN0=; b= LDXhW3dLv1TNxFskZ+KRHvExRdVyVu3mkrc+RWmuq38kRFiBdFoPf3yrbhVcyaCe NYLebQxwU2mheOBOmSJxeRvfaLUK1nMlP2hax0FlBRXG3IAR6irxqRRdtPPkna7E gjwrcsXxraHyiIwSK54SuoBRsa2LBOBxJCK5s0w3rrKnumu302IUrtmSz47wQH2/ PdCVaKxwooCsB5wCLsA587u46gbFaKURzYi6NgrxGErec246XRy8trrlqlHTKg8x iz2/xr5Bv5l4gQv8layqTpdphysHV4HXIeCYhX3uuG+VF3F1byqUhfx1e8GXWfxI YgVB7VkpYjnLqCiYWxBhzA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4616uf1q70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:55 +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 53FAu9hi038859; Tue, 15 Apr 2025 12:14:53 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010000.outbound.protection.outlook.com [40.93.13.0]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4r76wk-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aklXPnhw5ZMYxYLCNos0oiYvJJJU7EunD5Ghy//yC3cxt0lqHaGdq31segU3AL505zIUOTIGNpl42j4JkumC7Jx+FatSiZocaagCOyz4Ma7T7thTYwAdLpwLVVamG8/eYv+IuqV22qCExrnSJ61k2kcf2NYK5/dqtu5BHt34noadOdSN/vNT6HbuCl5Hzj8ORV32nL0ZNeDUolG9saWLDZwicmgOa2qBDf4Emq01UbhoWirqUs3NYeHXUuOc/N+ntr+HBttcv3giwhYCo7M8L5Y60h1/2y15GtX/uD1fP/vxCM8/g1m8EMCsiqJpGXiEGm7+wJpCOSA+OfrlXwhFWA== 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=16dIHWGqysP6D2Br2j5PueHAxkCdgXuedFYgBTCRSN0=; b=C431Hvg3oYk1qvNw+Mp9yHSFSPjfwnIQnXmWNlx8PygZQ/RNowFt/KLoq3CXnXNBnXQ6Tr41S6S4LvY6C3jjER3ju4T+J7guBII/UoDKzOoS1bxLBlcgrbQPusZsAhZIiiONCisVj9X5xqjDjWl/4qFwmkcXzBNERPDlb1icmVBRy0k5NvzZ4l2LjHhWi8PaYmOILkgmwiDQSTby+aEByf0+CEJTYllddRGiShEqCAbFbvDRt1/2HV6z6nRQuc1rG4EWBtR00L5JbhLGTEjzDMdxWEOulSCzSln0DITnLQWe/ZNlKa9gO1gZbUorrZAkqszOWEKi9gwITaiwBiqS9w== 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=16dIHWGqysP6D2Br2j5PueHAxkCdgXuedFYgBTCRSN0=; b=K2ucWayF+xnHMwG3Y7VKOdLdvV66wYj0pNtlFIONcXHkfu+/b/ppIY0pro5rzWPGELmAf/Awfe/q6uroSF0mn8b6e39nWf3SMQu9ELCjS7X/a7CIkrXM4D3JiQwrGKPP9R113wk5Fj2LjtQkY1GqP5OXMUBywt+yd+wDL+HGa2M= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:52 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:51 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 09/14] xfs: add large atomic writes checks in xfs_direct_write_iomap_begin() Date: Tue, 15 Apr 2025 12:14:20 +0000 Message-Id: <20250415121425.4146847-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BN7PR02CA0010.namprd02.prod.outlook.com (2603:10b6:408:20::23) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c0f5880-6f86-4bd3-0f5d-08dd7c171fe1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: Oieoi2JxV2ui8Z1uRrcnBVGl5wfkQI8/Mu4XwfREJWljmIDawbZJqWmJ5nXWybGvIE1UFO8+1itXujUFy/izHQwuk095UoOdeBNb7/H3mfH2NWCB7xOpMf91PFvLu7Y29YjAisav+mKTyl0cT3XLbaXA3OmY1ynxZo79QGtb57iZ/005MPMcjlNDy7W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61bQt6LYuAjFEzyCSq5V95/DKo9lTZWRe2epZ6odiolSrGxWgopDPMRPbF1fGA5kKUazDNWeo+DbtSRN9T6ArqyrjusK+JunOhIoGG/WnlD6bzoIX0PvyqtS8oMHfd5auqxnHv3Ln3MQ1qIeMqhSMTFasmCbHo8tZFirYyk5R2mLC4pmzRM4LP8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7CZR4s0ZAGrqdLhbgCmhj7tSpXFLmz6HV19a5zuoQDt3rPrvhizhwoMozmD0br29YNekbdWjn10If/NnlyJ3dtXZSMMOHzma10OrH+r64feBu2CaCKt4e55MXjWqIqRyGwELXB/2DLPlBj9cpEVzOwvcS1xAqS+AUM5SLXfy3YrA4V8jhozKshn91cTZUJ50LJiSOFNviduw8eOoT4tMH1zStxO9dcrbzK8aOQ4l0+GFa0YxVMLAzsFzkI17xqBQRFhpyS2A7HZCP3V51GacVih9TAzD7JjmZbdcykG9epQyZM/9b2iYoiZLjfmPiuvdX2XO6zR335pX/SoHgvsA0U38RIILf5Ohooaejszr/LTTCQmh2cR437YtJv9npXFNyMGdtNnvT7vmdMYXzwrUeRn2qCaePqTGSDhiDUf1a7PgzR4nyAtw4h6dzuCmWjJHdi+T6qBs3LO4yrUvHTsCXHZxfJO/7NbgMKarBhQ/qcHRwqwfVYDDFY9OlYsuE5TclwD26RGMvaIYHjHI+0wG0Aii9XQEAj96/vZmSQYKgkbb2O4Kb6PQpwedncCT7WzpOHp6Uv4kuFhFLqhTYVNHlhcmtP0jHStqpMHMvVFVGOG7IHGwY+yo4+x9o1YUEZMk2wk8Qv+p6oeVsrlq8hD25+bQsvFVx6n6lXtusK3B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bHyOxKUviDFSFcPiJGIXr+VlEjKpgHCuB7BT6t/Z9oIW/umICFg4vwzuXBNJpHQPDl0ZxoeNL81BbXyabDRAwR35qTiWqA62naI8+IqnNc1Qcc3taNs6lpzC54VTNkSzbCkUCxWfel//3jrUFOE3sgBSuVU4REmgJvEzvvC9sgZHL9K9AA9ONr6w7ctAa90O094SvUzrnIUt7Itp8VMGbSswnRB9dwTI/D7I54KTfnrwld+/pKCBrj/xBJRmzXEKNdWG5Clx8b6smOjsmbXESVyyI+kFqkgAg9XOtqY8kWzXosyOka0/fC/fOmDYkpmvTyTEnVDSFdcC0h0Q4Es17CBS/gJZYlvweh2h/FOx1X1NwxEYZ5kvjVlpMVKmguzcWJVqHuu7XE3D7s0O+DPbdVHIMoNJYaHgBUmzQlW3SVkh8BvGXysu+kEiE/jLJLorXA69unlbShBICyYW/2Rt8j3Uma7II8hnhHqRMXLhV1GlxxYbFa7tgub8IvTz23HH+SEr35ir2Ch7Gt5PD3AtKsEG0XZCXp9fH0TBbARI3Ss4houj4vg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c0f5880-6f86-4bd3-0f5d-08dd7c171fe1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:51.8401 (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: 9w03O2nBzW1tz6S0QtwNFDS7VyxLJ+/O/nM00t7vST2l2sKIs9xpw+W9doG9V+yi9e5FMJ+27QnG1ovVVVjYng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-GUID: AGhLKuuAPuBk2babJhlvTTDW3BZAW3Lv X-Proofpoint-ORIG-GUID: AGhLKuuAPuBk2babJhlvTTDW3BZAW3Lv For when large atomic writes (> 1x FS block) are supported, there will be various occasions when HW offload may not be possible. Such instances include: - unaligned extent mapping wrt write length - extent mappings which do not cover the full write, e.g. the write spans sparse or mixed-mapping extents - the write length is greater than HW offload can support In those cases, we need to fallback to the CoW-based atomic write mode. For this, report special code -ENOPROTOOPT to inform the caller that HW offload-based method is not possible. In addition to the occasions mentioned, if the write covers an unallocated range, we again judge that we need to rely on the CoW-based method when we would need to allocate anything more than 1x block. This is because if we allocate less blocks that is required for the write, then again HW offload-based method would not be possible. So we are taking a pessimistic approach to writes covering unallocated space. Signed-off-by: John Garry Reviewed-by: "Darrick J. Wong" --- fs/xfs/xfs_iomap.c | 65 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 049655ebc3f7..02bb8257ea24 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -798,6 +798,41 @@ imap_spans_range( return true; } +static bool +xfs_bmap_hw_atomic_write_possible( + struct xfs_inode *ip, + struct xfs_bmbt_irec *imap, + xfs_fileoff_t offset_fsb, + xfs_fileoff_t end_fsb) +{ + struct xfs_mount *mp = ip->i_mount; + xfs_fsize_t len = XFS_FSB_TO_B(mp, end_fsb - offset_fsb); + + /* + * atomic writes are required to be naturally aligned for disk blocks, + * which ensures that we adhere to block layer rules that we won't + * straddle any boundary or violate write alignment requirement. + */ + if (!IS_ALIGNED(imap->br_startblock, imap->br_blockcount)) + return false; + + /* + * Spanning multiple extents would mean that multiple BIOs would be + * issued, and so would lose atomicity required for REQ_ATOMIC-based + * atomics. + */ + if (!imap_spans_range(imap, offset_fsb, end_fsb)) + return false; + + /* + * The ->iomap_begin caller should ensure this, but check anyway. + */ + if (len > xfs_inode_buftarg(ip)->bt_bdev_awu_max) + return false; + + return true; +} + static int xfs_direct_write_iomap_begin( struct inode *inode, @@ -812,9 +847,11 @@ xfs_direct_write_iomap_begin( struct xfs_bmbt_irec imap, cmap; xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset); xfs_fileoff_t end_fsb = xfs_iomap_end_fsb(mp, offset, length); + xfs_fileoff_t orig_end_fsb = end_fsb; int nimaps = 1, error = 0; bool shared = false; u16 iomap_flags = 0; + bool needs_alloc; unsigned int lockmode; u64 seq; @@ -875,13 +912,37 @@ xfs_direct_write_iomap_begin( (flags & IOMAP_DIRECT) || IS_DAX(inode)); if (error) goto out_unlock; - if (shared) + if (shared) { + if ((flags & IOMAP_ATOMIC) && + !xfs_bmap_hw_atomic_write_possible(ip, &cmap, + offset_fsb, end_fsb)) { + error = -ENOPROTOOPT; + goto out_unlock; + } goto out_found_cow; + } end_fsb = imap.br_startoff + imap.br_blockcount; length = XFS_FSB_TO_B(mp, end_fsb) - offset; } - if (imap_needs_alloc(inode, flags, &imap, nimaps)) + needs_alloc = imap_needs_alloc(inode, flags, &imap, nimaps); + + if (flags & IOMAP_ATOMIC) { + error = -ENOPROTOOPT; + /* + * If we allocate less than what is required for the write + * then we may end up with multiple extents, which means that + * REQ_ATOMIC-based cannot be used, so avoid this possibility. + */ + if (needs_alloc && orig_end_fsb - offset_fsb > 1) + goto out_unlock; + + if (!xfs_bmap_hw_atomic_write_possible(ip, &imap, offset_fsb, + orig_end_fsb)) + goto out_unlock; + } + + if (needs_alloc) goto allocate_blocks; /* From patchwork Tue Apr 15 12:14:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052122 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 B2848297A43; Tue, 15 Apr 2025 12:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719429; cv=fail; b=IDxmw6p7JmDW6mLxmOazDkZ7SlosrA52KLKmR6VSQ8QuFdid6YCeCq8D7xNuldVbdML7Ex5c1GWSINLiMhXRfNlhCqBY4iVN587qSs95EG5tH3r6IyMWyusnVCf1hIMsEOdcWfl4ROf0WGWm2HYkh+dtgRbgaDyQV+bsgkw8XCo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719429; c=relaxed/simple; bh=aXaR4tZ79do1Fy4OuLBPodUSkzCOuY+03cJewoNP5kI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=l4J5XakkjAVMWgu409VCHMS31auPm+UB9nAsLUSc2YgIE1Wu1kkkLTTy9aw7dDdhQCC/f8Xfh98GwTY74CGAqayvSzF/HJs07JckuaVmnLXBRiosgBiAQ6bGqtzh/3LNjmepIrCF+cvSe7dOAJH3nobpDwSlBqzTljeeyTPzljQ= 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=e5opsWmz; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=H6CFW1r7; arc=fail smtp.client-ip=205.220.177.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="e5opsWmz"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="H6CFW1r7" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6g0GH021298; Tue, 15 Apr 2025 12:14:57 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=JIURtKTTU8cVWjYG5kShsUH5v7SuxBX/D0/28SLHG68=; b= e5opsWmzJNy6YnLTF+cbFhE5e0R6TfKd9Sv/36Qb3p4x5c3XLahrB3HEJChB47ob aelrGepCJzX5abVZDtaN5adSQw4LCTvwcJXTuB+k2gtUIqzR+z5CioS6a8XewnjU HWJe1mSQDzn+rfYOF9Xf2UhhHlPi3F5hgqjicYTD/5cVnKwnLy/0chnCJiulre5m VXvessemT4FC0DRus5RIy2jmTYQsCa63nTo1A8FFGLkvSOOngaI5gZBuflDAZ1XS F4RBFF9QsmlH52GbgsquirxHCW1f/TVebvfsDYFRhRv+HoZ9s/nrIsznEIkxPAyv unDv5SweJKK+StzLDHr9FA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46185msf8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:57 +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 53FBpWCD005917; Tue, 15 Apr 2025 12:14:56 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010003.outbound.protection.outlook.com [40.93.13.3]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 460d5v5nwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q2nP/xZJY79Abnpd7BC/CiPJOwtpuURcKRQH2aN56gGbNb3Pxa4Cbvx7r+UvmBCuz9wLdpBBICZbome4aHKMhIbnpV0+cuZ4QMHy7lGqyhfp0gDjCAwUqnzxRLPAbtD2yKDmGK6Zby4Pta+XQTs+CRJv+9e0WB0mrCa7l23QeVnCDYopkRaBVWsqXZNzSKBXqskyBqTs277EZBgSu1BY9C5ttQYuC/q0F9suqCVEkK77vLmADZiTS8Us8I06vcPgocSvIF4ogdYu3hG5vyoG/je5k69uHOXRlIWMiZ0L9iPogx+UYMrmUqnOdPJMK/SN7tbz8Sfb9UJZV+9w2d4RFQ== 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=JIURtKTTU8cVWjYG5kShsUH5v7SuxBX/D0/28SLHG68=; b=QVKYdoQ8UVxEHMO7pQdMi8arXxwV6dqjOX1Vs+1djcZsUig8FgffjPCQvfZzNvCRUowciLoymRC/hthvekHHamlm/reIuHpevg7+fHeH3gUduxlQcbdgBYypfn/Ho5m0dpkdB5L++MC59TPdK5Qsmu4EO1pa8mMuTtMwkq0yANunNFwp/RLGdDqnHpIxJ9qzhkJGi9O8YASZ6+uhfvGcbDFGY7vQT41iRr3nkSKqb4QLPIh3HItR9JapaNZyJ8hBbAq2xWsOhS7vbi/ateK005a8qDIeU2XEqWN2+NdOSaWc+dy6kecXiu3xn8JgzgTUrdROlOfkIU9FHg1iv/JC0w== 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=JIURtKTTU8cVWjYG5kShsUH5v7SuxBX/D0/28SLHG68=; b=H6CFW1r7oGoKwrHKeCFAYXbxCzOPrP92U3GV6QvN3zdJcGZaeEU2MCE8KXWYTou2MUP2OEgEMSjOLwz4Gr4ompuCJwZUavHaKanM1u4eliaEzlBYLQgsbLA5sB8nNVpzSr6ecXpHiTSPhXIi1XYzsNZGWC6cKbGc1zEYQL+Oz1c= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:53 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:53 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 10/14] xfs: commit CoW-based atomic writes atomically Date: Tue, 15 Apr 2025 12:14:21 +0000 Message-Id: <20250415121425.4146847-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0160.namprd13.prod.outlook.com (2603:10b6:208:2bd::15) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: 64d94d16-4bf9-43ba-6e87-08dd7c1720be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: +ZqoFp0z4BurAWLc1D4i7O1NjyC4XozflLS7QyTrZ3nJGQE5+iwtbYSfL9igBt4c+vbDGOih0dx0JYTs0QkZ8LSUf/Z1cHxTTSPQR7MFjX/sgBIT46k9ZQCgG58weE0wcv0wiL41hDz4ESMtypWrEqXJ5ihGlXmaPMyMTgeOyrG/AoAxZHMRk/NwVuQ2ZJnlyUnSP9ZP9pZEau+OzIulRW/bGavs/qgHXOJjBx6D/Frrpi8HZnvfUWt1Pv9A7YaV45tz5jo5XiTMRnX2+jlnvTCmt2PA9+5/ihjAn66NASySxHvwD/qhUqgIhhoyFR5cnd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N4EOQIcqiWPMMIqbj+vF1y8jtLdPV4i48a+cboCpSDJY8uxjSx1GSNOs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4CUt8Nw0BiB0qB16THAFG6D3Mob2ifkWy44Rx37p7sE1bWiukaK1UerbslCyr167JciO9L/JpxYkMjpx/2oLg/0gpfVfoMIQbO6sMNh0halzZtHsr1cH4ZhifxBkF1EOC3X8ZqaOcAWTixzcG1bk/3QpeF/YLZEziFb+r8x3C0UiIW5KgpuhhJ1qOUSytpITAf7EXIlzLTBJiGkvdxY2ztGdtImP0F8zVSNe+oexhQc9FhdLCzf8/xhv+KKATOS77Xl9akSdE1NftwLOP0bRo57dv3Gtc5Pki5sMEX5KJKM9fQr6dVxy2SIRVukhtxAlnho5s5klHhTWv/j88dxNKGFxR90OMlSqkEy8SlPlxaWIIk0dOPKffnc+3R20w/MlqHzKkt7Adja5zxnRtMdirFxpCq8CRyH3us170osJ+gVpLDxO7eMFhykR9CcX27XefnifyZP8LcmfCBQ3KfEWOg0FbiIzx+NqDBd5hKfIdKpy7rKiEVXV2UbafpcQX9IgjdNxIOLsuHUUTobwJt/quWJMMtKtBai5lQX4Vi+ajE6UtNHNG1DBPvRQYGbd8QqLW8cwq7K8knAsw/5vb6bnv2HqSulyA6uf/8GWjvUP2+dI1BLcRLzqPOz17LBMLGK6mnRnjvrPhWjYkcrH5Xghht5xpIY5iSqbbeUvxYto0X/h7MJgAovDFJP8Ml45kVTwEK9/IFQHsJp5kuj/+c/Bzkc2DM9KoAmzGeMEOIHaO+dwIwrdHMXjkcTqstXRTgmDjJCTM5JJMAwJs6xtk/MZIydqJZ5ymHWkRcyl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D+FkVnnpXg7Rsz5498xOaUmbEHYL/crfP1sIy0clWZO/DRFx2akMsijd0rzrx6vmGS0231LwZA3V+RNU5/pt41uZIdr/WldIeILt4W/JUrQpk0j1ZkUshQ6UpPd4UYVvFRx5Jhjx12vVpjqN7MLM9+7NrzVQLeLEBdXqiCtBvDBJQF/3Vx9DaTdnCVf3fkclhHNMmmDUyc0jDz04rwUfJs1EkzkfDCCwfCE+JPNfp0yydDFIP3Rx59M3NbRNLR7+fUiLGQmetLZx9bBVYLusFBxZ2obKnVBN2MtvpYH3ONNULH5nYxbXLhfWUOtAbv8XjF2w6zixKWewCxdt7ywd7Hx35MLgpbke9u+AzRV3BV7jyIUFRpLBtpKlUMHZx3o+xPtN8fmNA3Xpm/9agzPCoqWlxDM0HfEuzL4j1pxulS7I= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64d94d16-4bf9-43ba-6e87-08dd7c1720be X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:53.3692 (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: wV2BMlTo6i+4RWGoXsOCLGoqzBLJHQhhgyQ0h0KRvFAxqNOujAzX4hJ58OyNSS17UOdmpbC9uMXLd+7tF5OKBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: aPB0ltmz8QRMWIyzD4hGSDpMQmG3Ay4R X-Proofpoint-GUID: aPB0ltmz8QRMWIyzD4hGSDpMQmG3Ay4R When completing a CoW-based write, each extent range mapping update is covered by a separate transaction. For a CoW-based atomic write, all mappings must be changed at once, so change to use a single transaction. Note that there is a limit on the amount of log intent items which can be fit into a single transaction, but this is being ignored for now since the count of items for a typical atomic write would be much less than is typically supported. A typical atomic write would be expected to be 64KB or less, which means only 16 possible extents unmaps, which is quite small. Reviewed-by: Darrick J. Wong [djwong: add tr_atomic_ioend] Signed-off-by: John Garry --- fs/xfs/libxfs/xfs_trans_resv.c | 6 ++++ fs/xfs/libxfs/xfs_trans_resv.h | 1 + fs/xfs/xfs_file.c | 5 ++- fs/xfs/xfs_reflink.c | 56 ++++++++++++++++++++++++++++++++++ fs/xfs/xfs_reflink.h | 2 ++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index 580d00ae2857..797eb6a41e9b 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -1378,4 +1378,10 @@ xfs_trans_resv_calc( resp->tr_itruncate.tr_logcount += logcount_adj; resp->tr_write.tr_logcount += logcount_adj; resp->tr_qm_dqalloc.tr_logcount += logcount_adj; + + /* + * Now that we've finished computing tr_itruncate, use it as the + * default for atomic write ioends. + */ + resp->tr_atomic_ioend = resp->tr_itruncate; } diff --git a/fs/xfs/libxfs/xfs_trans_resv.h b/fs/xfs/libxfs/xfs_trans_resv.h index d9d0032cbbc5..670045d417a6 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.h +++ b/fs/xfs/libxfs/xfs_trans_resv.h @@ -48,6 +48,7 @@ struct xfs_trans_resv { struct xfs_trans_res tr_qm_dqalloc; /* allocate quota on disk */ struct xfs_trans_res tr_sb; /* modify superblock */ struct xfs_trans_res tr_fsyncts; /* update timestamps on fsync */ + struct xfs_trans_res tr_atomic_ioend; /* untorn write completion */ }; /* shorthand way of accessing reservation structure */ diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 1302783a7157..ba4b02abc6e4 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -576,7 +576,10 @@ xfs_dio_write_end_io( nofs_flag = memalloc_nofs_save(); if (flags & IOMAP_DIO_COW) { - error = xfs_reflink_end_cow(ip, offset, size); + if (iocb->ki_flags & IOCB_ATOMIC) + error = xfs_reflink_end_atomic_cow(ip, offset, size); + else + error = xfs_reflink_end_cow(ip, offset, size); if (error) goto out; } diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index f5d338916098..218dee76768b 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -984,6 +984,62 @@ xfs_reflink_end_cow( return error; } +/* + * Fully remap all of the file's data fork at once, which is the critical part + * in achieving atomic behaviour. + * The regular CoW end path does not use function as to keep the block + * reservation per transaction as low as possible. + */ +int +xfs_reflink_end_atomic_cow( + struct xfs_inode *ip, + xfs_off_t offset, + xfs_off_t count) +{ + xfs_fileoff_t offset_fsb; + xfs_fileoff_t end_fsb; + int error = 0; + struct xfs_mount *mp = ip->i_mount; + struct xfs_trans *tp; + unsigned int resblks; + + trace_xfs_reflink_end_cow(ip, offset, count); + + offset_fsb = XFS_B_TO_FSBT(mp, offset); + end_fsb = XFS_B_TO_FSB(mp, offset + count); + + /* + * Each remapping operation could cause a btree split, so in the worst + * case that's one for each block. + */ + resblks = (end_fsb - offset_fsb) * + XFS_NEXTENTADD_SPACE_RES(mp, 1, XFS_DATA_FORK); + + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_atomic_ioend, resblks, 0, + XFS_TRANS_RESERVE, &tp); + if (error) + return error; + + xfs_ilock(ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, ip, 0); + + while (end_fsb > offset_fsb && !error) { + error = xfs_reflink_end_cow_extent_locked(tp, ip, &offset_fsb, + end_fsb); + } + if (error) { + trace_xfs_reflink_end_cow_error(ip, error, _RET_IP_); + goto out_cancel; + } + error = xfs_trans_commit(tp); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; +out_cancel: + xfs_trans_cancel(tp); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; +} + /* * Free all CoW staging blocks that are still referenced by the ondisk refcount * metadata. The ondisk metadata does not track which inode created the diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index 379619f24247..412e9b6f2082 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -45,6 +45,8 @@ extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count, bool cancel_real); extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); +int xfs_reflink_end_atomic_cow(struct xfs_inode *ip, xfs_off_t offset, + xfs_off_t count); extern int xfs_reflink_recover_cow(struct xfs_mount *mp); extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, From patchwork Tue Apr 15 12:14:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052121 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 B27DB297A42; Tue, 15 Apr 2025 12:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719429; cv=fail; b=CRwfc4vy1LtgMsFj0Y0GnQ6dqEa5Ca+4qNz9gMCM8TlbTXLbT5RRYmHMeemcSLvJ+LoQBD5A69ZUEVfKNRyOiAhgf0NzqTND/dEOBvIdUKC35AyrA5c+PnNIhUfmwNMqpnmpEB6A5xEUDcKESZ4/5zEBuPqWD9zbg3bM/AhrLek= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719429; c=relaxed/simple; bh=d5yCf8JRP2BfzZh5/5rEeBNmu1S/rD5zWnteV7p/pCI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=MQ8SErpoVG+Ye3Oxvjum2LzPjqF/hFKGsjfW0qK6SbmCTl/WatxzSb1hO8qhBrh0A4XDleRSvTTsEhRY5hpGjbAku6DgW7BAEkukGapsOWiVxfKZeonRKMUqO/KZIEBNHeT2Mju13S3767/eHk8kNhF5uIv/sygm9qfQnhGmRpg= 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=ix38LpXv; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=OwC+Wt0A; arc=fail smtp.client-ip=205.220.177.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="ix38LpXv"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="OwC+Wt0A" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6g0GI021298; Tue, 15 Apr 2025 12:14:58 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=RSbfSixaIwWjSP1CCzi/eVtTJd67PSLpI+WWNVt1x9k=; b= ix38LpXvN9oK9huHk6+5PsSFo/pLpYV2AA3goWt98e0Av0TeUIaDTr0hdJzMVajU W6supvI44ee6qWwFB1+exxujxAPVEhP9sRLEm2/w+IhloUPE6VMbJSC/+JaIFRSS oVLTxLRT24mtKjcx7YcuJs9+kCq13DXhQF/tu2MeVWWpGN8wZwnJ+OaXadBtSEfC 5Z/HmkgpzhyCVRLktCMfOdbRqAcz7aojEp2wV5gnLcTIFAdNpYGKBMEhFcIDKkEr PNlAHOEm+0Rm8Yez7o1HTdWjtZmNee/YcJpVHzFS9yY4bA8KNNDo346xejklKpGy IZq7Y8B7DQ+C6ZnOKVjpfQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46185msf8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:58 +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 53FBpWCE005917; Tue, 15 Apr 2025 12:14:57 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazlp17010003.outbound.protection.outlook.com [40.93.13.3]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 460d5v5nwb-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:14:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tvy1v5wDTEZCLZd7fAZLaZz6oV8Wm8jId/JYP0Jdzv3SgdlL163C35IfU4bNjUJ91khciJkmAcgaKrEaUjzStGuvkq8+TQzKfr4zKAedpO7ccHObxbIb2QCMO20TuwNwvQMN+cyM+uO5LaCbLy9Yvt3NYSFwT7lF/VDgqMn0uyvjbpwHmMm6I8O00hgiyMUHPds0dY5n7/c1XL1DoLI4oRvqOm7O/SSbMtBP2MMpg9YNy4yQX8QH+R55fC+L3MZWFdkIwBu9Vxio9zlQKxSvfWZh/GgWT+68u6H1EodloXCHz2RoCGeLIuiWokKWQU+uHurYvCChsBeit6sEmo9jtQ== 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=RSbfSixaIwWjSP1CCzi/eVtTJd67PSLpI+WWNVt1x9k=; b=li6UGAtcYgzf/pbL8N4ZZ4Hm0w/uLMJ/syyA4rIRKnri3ejuYzNGrYbLmXS2LaSfXrj5t6DcKeMZNAbW1rFataADjJzPyjZDtsqHE6mC4fOkOqEhjOWfncnmAu/TmfNRSg8eE9/wTTK1/KX5IyzTg4WqTqGma1DlMw0P6J4SjRBGs2S96a1YN/t/pls2c6ciniph1KAbsLkg+iyUZR5L5KE3excTjBl58AEAWNVgkEeOHg13/eX37TdS19f1+ex3+y3DvrTqwpiZzgnTYs40we8RSDNLxgRkOomfXT/wbj6AoZsZZCQx2TzxF3F9/V8pklzjAfZ3N5oy1b0fAIJahA== 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=RSbfSixaIwWjSP1CCzi/eVtTJd67PSLpI+WWNVt1x9k=; b=OwC+Wt0Ay2zIpf8BhmYTtlyQt3b2N+wP5rHsrXNzsOaVUYm7mfy9wqNPYM8qyT8cKQvwjbGOnEU2CXjstFqdxjB0XbpU+kQ2QpxNvLau6w7Ac8IKQD3QxG+yj2psp05/QPNjT28xxuwTTSU9eSBRDRzduF/Ei+0fEGZHYsMlpvw= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS7PR10MB4991.namprd10.prod.outlook.com (2603:10b6:5:38e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.31; Tue, 15 Apr 2025 12:14:54 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:54 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 11/14] xfs: add xfs_file_dio_write_atomic() Date: Tue, 15 Apr 2025 12:14:22 +0000 Message-Id: <20250415121425.4146847-12-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0253.namprd13.prod.outlook.com (2603:10b6:208:2ba::18) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS7PR10MB4991:EE_ X-MS-Office365-Filtering-Correlation-Id: f797d628-27fc-4b8d-5d59-08dd7c172181 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: LORVigT96QbVKHzBDS40O87Nk11HYp409FH2UBl4oSussgvTeYYvRjwV5Yc92d+Wi0nHXzFozuolaIce1BaDIEjYWcHHOSqMth54yv0MKjZP5wyeyELhle75kSclEvUMhXd9W4Z68xgJ4yRmds6MXAFHsc8eIhSc9lSZJJmyiU9UzQgib+hBXUoySpRnAQMUzpW1z7yzmz9cArF/zFgdRjVagQdCCdU6pMDIxe30/VyPfvLl8CoBmfEfvfGYdmm00CCXclT2hne4az9mRLRGYvz/a0dEAPUo67HBcTPSs9lBPOiePF+pkhIBVgvirWd9ACmnZRbhuZ+ehJLPqGS0Zir7j4PlOLmXH4YYCSmcY4DZtfcSGCj8ErcrSM18Xl43CFYjKHGNJ4ldhQJyyftsjowILbi6ff8o8AR+IMPqsFAJiof1Cy4pT81BqvpLXG8tGHItPDhC2uEVveG/s/f6YycT5yFs/Q5J91AmlO7IgIldoWhT0mZbZuYMxu3g88hRr8+bFEquOuJnSgTSMZK+UTpgCgW5paRzyif/wi4btF5sUgJalPzJWxHbDu2Zh2SncMN9EgyzKn6l6EN4t4sfyAzDQYDo+h8mAnitDggVk259wsmFhUh3lqD/VvxfKTXm8cstCjpSoezZN49no786BVpaBk55RuQ8adVSfg4169j8IJ070qVzoGz1GW4bRAIsJNadWztW/PMcVh0XTHzLis49y1Yqo6xzhk4o/DBWM41+W+TGF8nhyin3pbn12pBoqUv39+ALQJb8DSHbSawyd3TDiZ+58lzpEcUbC+uxL3N2spFaJT9XwouUmFi6Dq5Z08Qu2yUstpufLlR5NfQ1fh/Zgf/0jvC+CkZC6xOc8qq1fLZ2gznlP53YFBhFv2/oprLEfee5gQXA7myeMPHnDHeEgn3heTrI4SJ6RA3r3uhX4yEftjE/H5BnzCMTi9cQWsiJwqjV5ZY12f6aJ8sgX2rKha/TsxyS6vUtQX0KTekMznZs1FXsa69hOwTNXYLpd9Aew+1gMNf1cJ9jos/a0BvAnywuLJPFIdAGNjqtz19M11bR5+eBqDnkxUSmSMHslYM8UbHheTAFQ0gSScy4uQIJ83hThzUOZh8VkqYkEEb76NFNJe1G1BlwHiPqV8ckYyzx5GK9dQssAYYSc2TxrokdO9tMmEzfMbwvU56ONJtCSsULEd1VYTXAMr0YzeeYNnq1+MkQM7N9Wz/s8d70ulmWhMHn9tXNglgjUA7Dr4OcFyBUOf3UKWIN8hpdWl1FblveTpcLN+vyt1GVi5ZjrAAR8hpKKAI8qfwYclQLtJ4sNMScrpVsxR01jfTil6Xx4xaGyEqDB44yWy+k3E9XWmUw+ab67Nzs9XhK0R92cm1m0k3Q/I2Wk0b2elgW598/czrwbiVwO0pZ7ijmmwsRJQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: alRJhDUIMXMY8Gz9j9ZYMl0aThmHvJHqgr2ZCSj4JcB11Z34U3sWANqCUomhskbFxbWoAyIJYeJl/7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oNlPQk/lZIWQ4V8TZYj7BMCT7Dd37rNUARges1a5J1D2KK+WjYA0LQITGx4RXycTAqmJcFWkltLNZtFEO4GRbxer9E0lv0z+0WQ2q61MmSQCuuME3e2T8GF6rYMciXOktJ4hx2g1iAeVMQNyeiFuM5SjN7TMDjH54UrrYEBQxSttJvFXY54BlR8Ggf7zJJtvcGUB2DwzEjnt5VPkPhklXHudkNCcNOF7pnqhTZlmivDyF97kXu3kRzAMGZRTkOODiHjllI4A6/Q+zaQ8BwwyCFT2Dk8jzJrqUEkIYWSg3U+DvFeAFd0XvWl0Zy0yHiZNS0nlzcNq0QTieDf1SBmfjU3Yckj9ckCmw2riandPRmqTFU/wm671Z6ao4hW+Uq9/CZqjiZowWXj0IO9D1tEjX1wqqaFRTxe7Z2p+x38CHlvHIJBt9MwMklPNV+aBI+fAemsBQ/BbnCcYGnmXLLtWoRHsJzBd1mBT8mxCrw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: f/KdewMMj/j8ICmhJo7U8V4+HzYNYWmUJnWhNZFB+TswtohtZHZ90kxknDSjVz47e3m2FYKGZthJ5pMndh7YdKYq8buGkVJQT13KREKlg5ErcO81ybMgxSE58hs1VheZN1R9eAipzzULOahhu6R1uauWWSDEklEhdGZF8z6fcqSaWDddVGPeZhjbIYL/2gSXBRuqCBReCF9dnt9AKDY+eJcwfyEBnb2H5sZFoAZ9sYRRUyvoSpU1AyupKVfpU2hzLiGgGYhqF4zx3XVJNcZptumU1L5tc539919r7WmycIcAXHuGd8HwSxsTQQASCnyocIByJuUsKKorVx3F0Doakntf2hU9bC6VLC+R/uAX3YRAocM6ByH+BjcMwdS7VdV6KQcl9TezdBnU59jGYS85sBPCbZ8IovkOSae30clfwAspfFuZw3SvgP68hC1PrjA5YldnF+GKMX/tOjDoMXJy4zm+HsxVpaI7TMCDVYH+bPrx+20s1HrtCkaGD7dKWTAkn7dQSbNChlwVaAS5wvQt3vZ3M9cL0WzAXBVAuXWDye+WKMz9ABWW9CNH6JWiN6NAAh0ZU1rWYbEIDwZnFVmiXgIRpu/WMElBj/eJZA0WEuk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f797d628-27fc-4b8d-5d59-08dd7c172181 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:54.6126 (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: fUMbdbQZQnLlWMs6IMb1oodMr+if6FZ05CIe1g4+5NUmPBPZepRmaeygdm4XB5rWITGRClWWAZAnfjus2sI/ZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4991 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: DNfVSNxR8gmmHaoJSPCjuFknhwBnNSz1 X-Proofpoint-GUID: DNfVSNxR8gmmHaoJSPCjuFknhwBnNSz1 Add xfs_file_dio_write_atomic() for dedicated handling of atomic writes. The function works based on two operating modes: - HW offload, i.e. REQ_ATOMIC-based - CoW based with out-of-places write and atomic extent remapping The preferred method is HW offload as it will be faster. If HW offload is not possible, then we fallback to the CoW-based method. HW offload would not be possible for the write length exceeding the HW offload limit, the write spanning multiple extents, unaligned disk blocks, etc. Apart from the write exceeding the HW offload limit, other conditions for HW offload can only be detected in the iomap handling for the write. As such, we use a fallback method to issue the write if we detect in the ->iomap_begin() handler that HW offload is not possible. Special code -ENOPROTOOPT is returned from ->iomap_begin() to inform that HW offload not possible. Signed-off-by: John Garry Reviewed-by: "Darrick J. Wong" --- fs/xfs/xfs_file.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ba4b02abc6e4..81a377f65aa3 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -728,6 +728,72 @@ xfs_file_dio_write_zoned( return ret; } +/* + * Handle block atomic writes + * + * Two methods of atomic writes are supported: + * - REQ_ATOMIC-based, which would typically use some form of HW offload in the + * disk + * - COW-based, which uses a COW fork as a staging extent for data updates + * before atomically updating extent mappings for the range being written + * + */ +static noinline ssize_t +xfs_file_dio_write_atomic( + struct xfs_inode *ip, + struct kiocb *iocb, + struct iov_iter *from) +{ + unsigned int iolock = XFS_IOLOCK_SHARED; + ssize_t ret, ocount = iov_iter_count(from); + const struct iomap_ops *dops; + + /* + * HW offload should be faster, so try that first if it is already + * known that the write length is not too large. + */ + if (ocount > xfs_inode_buftarg(ip)->bt_bdev_awu_max) + dops = &xfs_atomic_write_cow_iomap_ops; + else + dops = &xfs_direct_write_iomap_ops; + +retry: + ret = xfs_ilock_iocb_for_write(iocb, &iolock); + if (ret) + return ret; + + ret = xfs_file_write_checks(iocb, from, &iolock, NULL); + if (ret) + goto out_unlock; + + /* Demote similar to xfs_file_dio_write_aligned() */ + if (iolock == XFS_IOLOCK_EXCL) { + xfs_ilock_demote(ip, XFS_IOLOCK_EXCL); + iolock = XFS_IOLOCK_SHARED; + } + + trace_xfs_file_direct_write(iocb, from); + ret = iomap_dio_rw(iocb, from, dops, &xfs_dio_write_ops, + 0, NULL, 0); + + /* + * The retry mechanism is based on the ->iomap_begin method returning + * -ENOPROTOOPT, which would be when the REQ_ATOMIC-based write is not + * possible. The REQ_ATOMIC-based method typically not be possible if + * the write spans multiple extents or the disk blocks are misaligned. + */ + if (ret == -ENOPROTOOPT && dops == &xfs_direct_write_iomap_ops) { + xfs_iunlock(ip, iolock); + dops = &xfs_atomic_write_cow_iomap_ops; + goto retry; + } + +out_unlock: + if (iolock) + xfs_iunlock(ip, iolock); + return ret; +} + /* * Handle block unaligned direct I/O writes * @@ -843,6 +909,8 @@ xfs_file_dio_write( return xfs_file_dio_write_unaligned(ip, iocb, from); if (xfs_is_zoned_inode(ip)) return xfs_file_dio_write_zoned(ip, iocb, from); + if (iocb->ki_flags & IOCB_ATOMIC) + return xfs_file_dio_write_atomic(ip, iocb, from); return xfs_file_dio_write_aligned(ip, iocb, from, &xfs_direct_write_iomap_ops, &xfs_dio_write_ops, NULL); } From patchwork Tue Apr 15 12:14:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052125 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 D8B902951AA; Tue, 15 Apr 2025 12:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719436; cv=fail; b=L1bRYnByG0f3B1Z7gNHwuhhs9Nu32o5ADp9cqWEiZ9htKisR8FyhAQYizutGJ1HoGUIZXcrCOfhNx0RYIN7Pp3Lgf42mvocRU6+0joxy7/o5m597ez3qQIi2Cg7FRl6Y8jMfmf4XAhgISIljKRp+UaaTgN4myO788U04HB3xA5k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719436; c=relaxed/simple; bh=zBQfneQEn9MLPLkN0UENksfgp5YgjItqdq3BwiLZj00=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=u9LIWRKSS8ZyrmZHjz64jxV78j9VGXAj4y4vVpShX/xCcpZkC5ex0ur2YdnEx1X0Tu9z3/wHfHNmh6BDJUroLmm02wRVwLO0fS/elpQ1m9dRfxUxyPXTjdzW8luqxc29zgWjZtR4fW8jNrtaZNIAkuo7T2tPOcVd3pmPNaWgCjU= 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=jZfad1If; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=nQigCMFS; arc=fail smtp.client-ip=205.220.177.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="jZfad1If"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="nQigCMFS" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6fnpr004641; Tue, 15 Apr 2025 12:15:01 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=LltWOGl6SlVjEa7vYqIEd6MsnjZZquN5aMr1VPeFob0=; b= jZfad1If1CI0D6vi4MtgbGHc+YF80+Bzb/w0k4LyBlZ1QRu9sC2py9/wVwhDt9Tf GX0Ogoe8dyQmVkJOH8jIS2Prm7SKAZmuQ8GS9lCrvLm/uT+GWvQddwMY9jInnSr2 urpkp6vq5bf9tk320BYtNQnwOev7rZvwpVmR+dg+cVurMEQOgMOQVSDNu8pcohMt ODW1fz5HRThmnSXHaWiQRpQyv4CpBy0nNbByJYQfIB3j6FqKOH+PUyA469//66ZR wKMrtz9tcEIErmbccynSnLiEQz/EqVq5Xkzcysng7R+w516x57Ui9qOS1DnIBtjY uDxu02WU6Y8B1wp6KcHVbg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46180w9j50-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:15:01 +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 53FC0hr0005663; Tue, 15 Apr 2025 12:15:00 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 460d5v5p17-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:15:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YjfYxOBI45jrosCN/M2WCzg63fC8Ih6ez07+ZaZf0MfYwv4+8JPFY9MrsJdxcAOvbWqOnXB/GPiCW2t2Pm4Zz4QoVGZqn6NToRSflYVgtDqv2zuXPtR5+pIh3Md+eWNZR6jXl1TgY0uz5PhJNMe0OwJcjPMIZ5uV2+uRwB7SEIsVeuSd1vKvkBz/2FPeIQtVsFLfrdu3vuRyIfk7xyLOcfvN/LQGdFXm1ipAJZNwh5LliM6+G2yGJYfugNO/x4Epd42yL1Vmc5wzmz5Ct/jO6OwAaRxWMiylEA2aS01xq6N15DSZLV324sByJ8LV5g0XzfKvhULjRxDFprIikiapuQ== 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=LltWOGl6SlVjEa7vYqIEd6MsnjZZquN5aMr1VPeFob0=; b=RBMN9YagA0XUTbxpUQrLpJaDh8DpOk6OssXxA26YCymD/wzDl1eNqQ+X36BwP8F9akBAr6ajgvZLg6iR6pHa2wPxJOOYaFUsTyN3vbh+Y4RAJSrcd5Ff91yTzf8yOTdWwlxVvARuPhbyPbQMF0iA7ADoeLOi8U3jkQ+B4IbOSZZbt4qiytfnsmhVLB417EiD3F6ZVX2iUwwLVMQnrGLY3XWT33XImSh1zB1fitCKoIFVbp6XIQBmD0NUdJbVf4laxpFXjQbfZcAT2afhn9N4lZy+z7wseJof3SjKd90oORFNENgG3GGqOBLBlpP4w10pohkWo0xrf9mtWPqfsvaV/w== 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=LltWOGl6SlVjEa7vYqIEd6MsnjZZquN5aMr1VPeFob0=; b=nQigCMFSqUUN8OtoUbI0wuTv56XSoXvlRlWjxoTUjpmD54X8iEoVArCLGXxmtpXKTkrAhC5BfqL0sjgPd4hNcikTud77gV56dloEDJnGIPYe4TGMeF3mjDGuSzfcj9lkueaAQTGbVWAZwbaJ9oJ4oHTASWw283YRoBj2xfxIqV8= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6535.namprd10.prod.outlook.com (2603:10b6:303:225::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Tue, 15 Apr 2025 12:14:56 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:56 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 12/14] xfs: add xfs_compute_atomic_write_unit_max() Date: Tue, 15 Apr 2025 12:14:23 +0000 Message-Id: <20250415121425.4146847-13-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BN7PR02CA0030.namprd02.prod.outlook.com (2603:10b6:408:20::43) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6535:EE_ X-MS-Office365-Filtering-Correlation-Id: 46e49d2c-4291-4d31-b62b-08dd7c172255 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: JNjlVOOHKVJwozqI82kEJd85YTHORcdmXKfjT8CbeJI67mjomc5vX5+YmLOo6z8hv5nDmjWvwiRKeeF3Vr2WKXlYbNx4OrLQMZKif6QR3y436whTI1Ux9t4x3Fg4WeEgzZaJB8h5oAx2WpvzW9zevowjw29Kx15PHEN/m7ltcDsWDgrFEiynUZg9TRbLcn6d3ArSXpBuPlle70TgOZS3KhVzQNs+0nI2IGmsO0jybYOmtirzsQ8JVLRDchhcgcDlK8YRHQ1o10K2DUiaeZ7fe7wuevx7xY2U2yH699EQElBUE1u1MGFr/OerGfO13BnBHAFUJ0s9QRHop6PFfRulV7OPSb2koT3ZEaVd6KwwHqT00c/nM1uZLYYJB1GEpPcGqDrOmaMFnPauzHhx89RdXfvHESF7cICnNiBkXgCQaXCySY2M//qSZItkK5wSsAH/rx1Hh62cBXwpTpSc37wYdNS1u0qP01/TDzrIKtkxKUbJ1I8/yytJJwpVO1uWvBCA63yfIhsE3yXwwwPNWW2d7eJApQB1CIAicMfFx+o20g1ijPWoK4YZQdEbT8oaXtF7sH2Jq1nFvXq1hoCjA6slFyV4opB/MPNY8F5dqg7w3V3/i9CWVBRKECshFcDXY5aMXapTy5W7Q7DT2quEtsoJPxPaKii0Px/fSiM9yN3UBa5tqnvYYzZ/NDwuVe19oEskvvvxIo0fwHfJEYk6BwOFzw1DhAHC2TZGHLFX1BAh0bmsjps+Ga9qO8aBU+vTQODc8RT/m4fYDCDV9tAyAUuzDveQV7LWOoE1ALAgmTcZ8sbBj5OZnGLevxzxUfLyCxcpf/RX5mZuBTcSbAocGqzNwBUTBzXfQ3gygrxii1hiEHYi9Hc/AG+OlPAsP3O8n4PFyvZ/R6hkFuK8Bc7sTDz2Em1fSR0g3ezWOLsciYduNUReo//zRb7d+bbDmzwhn184KhAaIYWg+COw5q/fARFC4TCFiFTEIO84dAC+DsQdk2hYr5xJ/K53aueK5Y4ms4M7/KtYxfS1dCJTu/rG/6y2ENakACPz2n7ezK2UiE0ydESvEZNk/1fWGPlko05yKeMu5O9gp6rSMAE26fPRcvEhZrcPFeqDxu83VwRa/+CqdNIU01i9JZ2UVsMhfrjunhVkan+kC29/BykzrrppuLiyTTpc1VTXBJYEC8iR7WNMAz/6H1Z9bf1PrkXnJ5X2foa+2EC8gqkwLhra6mgF236MGLL08e033C8fMCBskCIMGQ7jZNP6+h20khCuGvqe33sXYWJ63titEn2+wjJk+Ua+luZ7GjTOlbjiwVoDwoQe2ihlWfNUh2+Kyny3U3ZoIYXiPPbVGgi0tzfugr3ww5gcn4ogDlXl/mvRILPKvwhkWzXJh5waTrh8IEfGRKzKB/QN4sf0QpnmoznEYcCDfE3ihvXHVsmP+RP3JaBn4Q99/Pc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EasITj/hZXlFsap7CdOCV3+qmlQZcsQ01LC6lJf2gQh+D7MUkQa1MiEZYU6Q+mIlBF4r5JagYqe0aLxs/w5p4mOJ1ciTfjTXtto9R6IGJGjfiYryzJJ3qsfuWXnrm5F6faWpN3o64Qpu1IVr7uYHwHXjPuARup9WG/Ot51DxIZmMdItTHZKjW+wD/jQ3y69HAP4bC7nWEElzvoG5g7ajPONNpkTRNoZxD23vz/ZgiIs+SW3LKvyMppIIom8yMXCmJsM75L6a6q7l93138tk7gCFtUlbAHUf704Em0lNs3O52dxLnnUWikNnTgdVuYPzfOx2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jCGx3IxOxTRoogWOgUgbboq9FxbLyiGklXsL3Zygb0TYI/N2kPEsOeAE0pNOqLLBAYl7hTHQHOFSV47V+T2oTzj/DHMdqwNraEBKBxZ1EQhubPZvPE02NUdnDeGIRw1n1lQ4PcjIspoYxXG/JnPHnUCAmk1Z5A08/83tzdseTn6Ibh4tbTSYKikgf/pHyYulASsgKN2ShxcbZ8zRA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: OAYOIP6pb0LIGsD8q4ixNSQ7VBFFI0htu4+hBUJEKxPCd8boVGESmlQWL+jxEpb2wslwmYx5Nv45Ohw3BPCcZ3fcsU3M4IttR8FMA/NeWSYNzz+GA4/1lQpMJQfMjplfa0J6KAiFAuKK+1MxYqOUZB5VR1d5CwdRJ7AylRbeDqmx3KI+pqNkmVkoaV3vZtcN33KqD4StMYpfhY8PugyBuaFc0LQvegN1DXqPxwU0WsyHXpPZnbISbLzQmOz5vRE7jJmIJDqjTpoO1jiUpqBiVX5lkPz+iKEtQHar5SLHo5zU59YwK7P9BzRX+3eFox4BaglzvKqZ+FGaTO0uNuuAFQGlToChAX6HeqFDP/c0qWAeLOFSixeGzbfyMDhjCUkKukRe6QdvrKp+QtUWE6RHPIUAjZr8bCFbDUOzAxtN5gWx2uOdPYdWldM0nPNq9IlqvGx1QA9VbDsKhyTNc7hN1+KuWOjGAMYVtlLGFC5qfm7VnEcOZhIKEWqDyYWMUuYfy4vkWfMpa7WVe5UmJbJaCNTWofRzUFkeTvWA01vgtCKDmwnWQgxlOaOcRicRJZTIxXG0VyrgS8ERA1DJNUQI9NeUva0Bn3tm3FsDGPlm/Qs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46e49d2c-4291-4d31-b62b-08dd7c172255 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:56.0082 (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: O+IPW87cFtLib29RTrVj1f67b9S3minvPV/6OJHWLFpEe18ahXofmBKqHelltbOYkax5VKFNGR9UWS9nHCe4xg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6535 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: mMgH7on7F0BoqNbdeQ8G1-mM3bemiEfb X-Proofpoint-GUID: mMgH7on7F0BoqNbdeQ8G1-mM3bemiEfb Now that CoW-based atomic writes are supported, update the max size of an atomic write for the data device. The limit of a CoW-based atomic write will be the limit of the number of logitems which can fit into a single transaction. In addition, the max atomic write size needs to be aligned to the agsize. Limit the size of atomic writes to the greatest power-of-two factor of the agsize so that allocations for an atomic write will always be aligned compatibly with the alignment requirements of the storage. Function xfs_atomic_write_logitems() is added to find the limit the number of log items which can fit in a single transaction. Amend the max atomic write computation to create a new transaction reservation type, and compute the maximum size of an atomic write completion (in fsblocks) based on this new transaction reservation. Initially, tr_atomic_write is a clone of tr_itruncate, which provides a reasonable level of parallelism. In the next patch, we'll add a mount option so that sysadmins can configure their own limits. Signed-off-by: John Garry [djwong: use a new reservation type for atomic write ioends] Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" Signed-off-by: John Garry Signed-off-by: "Darrick J. Wong" Reviewed-by: "Darrick J. Wong" --- fs/xfs/libxfs/xfs_trans_resv.c | 90 ++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_trans_resv.h | 2 + fs/xfs/xfs_mount.c | 80 ++++++++++++++++++++++++++++++ fs/xfs/xfs_mount.h | 6 +++ fs/xfs/xfs_reflink.c | 13 +++++ fs/xfs/xfs_reflink.h | 2 + fs/xfs/xfs_trace.h | 60 +++++++++++++++++++++++ 7 files changed, 253 insertions(+) diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index 797eb6a41e9b..f530aa5d72f5 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -22,6 +22,12 @@ #include "xfs_rtbitmap.h" #include "xfs_attr_item.h" #include "xfs_log.h" +#include "xfs_defer.h" +#include "xfs_bmap_item.h" +#include "xfs_extfree_item.h" +#include "xfs_rmap_item.h" +#include "xfs_refcount_item.h" +#include "xfs_trace.h" #define _ALLOC true #define _FREE false @@ -1385,3 +1391,87 @@ xfs_trans_resv_calc( */ resp->tr_atomic_ioend = resp->tr_itruncate; } + +/* + * Return the per-extent and fixed transaction reservation sizes needed to + * complete an atomic write. + */ +STATIC unsigned int +xfs_calc_atomic_write_ioend_geometry( + struct xfs_mount *mp, + unsigned int *step_size) +{ + const unsigned int efi = xfs_efi_log_space(1); + const unsigned int efd = xfs_efd_log_space(1); + const unsigned int rui = xfs_rui_log_space(1); + const unsigned int rud = xfs_rud_log_space(); + const unsigned int cui = xfs_cui_log_space(1); + const unsigned int cud = xfs_cud_log_space(); + const unsigned int bui = xfs_bui_log_space(1); + const unsigned int bud = xfs_bud_log_space(); + + /* + * Maximum overhead to complete an atomic write ioend in software: + * remove data fork extent + remove cow fork extent + map extent into + * data fork. + * + * tx0: Creates a BUI and a CUI and that's all it needs. + * + * tx1: Roll to finish the BUI. Need space for the BUD, an RUI, and + * enough space to relog the CUI (== CUI + CUD). + * + * tx2: Roll again to finish the RUI. Need space for the RUD and space + * to relog the CUI. + * + * tx3: Roll again, need space for the CUD and possibly a new EFI. + * + * tx4: Roll again, need space for an EFD. + * + * If the extent referenced by the pair of BUI/CUI items is not the one + * being currently processed, then we need to reserve space to relog + * both items. + */ + const unsigned int tx0 = bui + cui; + const unsigned int tx1 = bud + rui + cui + cud; + const unsigned int tx2 = rud + cui + cud; + const unsigned int tx3 = cud + efi; + const unsigned int tx4 = efd; + const unsigned int relog = bui + bud + cui + cud; + + const unsigned int per_intent = max(max3(tx0, tx1, tx2), + max3(tx3, tx4, relog)); + + /* Overhead to finish one step of each intent item type */ + const unsigned int f1 = xfs_calc_finish_efi_reservation(mp, 1); + const unsigned int f2 = xfs_calc_finish_rui_reservation(mp, 1); + const unsigned int f3 = xfs_calc_finish_cui_reservation(mp, 1); + const unsigned int f4 = xfs_calc_finish_bui_reservation(mp, 1); + + /* We only finish one item per transaction in a chain */ + *step_size = max(f4, max3(f1, f2, f3)); + + return per_intent; +} + +/* + * Compute the maximum size (in fsblocks) of atomic writes that we can complete + * given the existing log reservations. + */ +xfs_extlen_t +xfs_calc_max_atomic_write_fsblocks( + struct xfs_mount *mp) +{ + const struct xfs_trans_res *resv = &M_RES(mp)->tr_atomic_ioend; + unsigned int per_intent, step_size; + unsigned int ret = 0; + + per_intent = xfs_calc_atomic_write_ioend_geometry(mp, &step_size); + + if (resv->tr_logres >= step_size) + ret = (resv->tr_logres - step_size) / per_intent; + + trace_xfs_calc_max_atomic_write_fsblocks(mp, per_intent, step_size, + resv->tr_logres, ret); + + return ret; +} diff --git a/fs/xfs/libxfs/xfs_trans_resv.h b/fs/xfs/libxfs/xfs_trans_resv.h index 670045d417a6..a6d303b83688 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.h +++ b/fs/xfs/libxfs/xfs_trans_resv.h @@ -121,4 +121,6 @@ unsigned int xfs_calc_itruncate_reservation_minlogsize(struct xfs_mount *mp); unsigned int xfs_calc_write_reservation_minlogsize(struct xfs_mount *mp); unsigned int xfs_calc_qm_dqalloc_reservation_minlogsize(struct xfs_mount *mp); +xfs_extlen_t xfs_calc_max_atomic_write_fsblocks(struct xfs_mount *mp); + #endif /* __XFS_TRANS_RESV_H__ */ diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 00b53f479ece..860fc3c91fd5 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -666,6 +666,79 @@ xfs_agbtree_compute_maxlevels( mp->m_agbtree_maxlevels = max(levels, mp->m_refc_maxlevels); } +static inline unsigned int max_pow_of_two_factor(const unsigned int nr) +{ + return 1 << (ffs(nr) - 1); +} + +static inline void +xfs_compute_atomic_write_unit_max( + struct xfs_mount *mp) +{ + struct xfs_groups *ags = &mp->m_groups[XG_TYPE_AG]; + struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG]; + + /* Maximum write IO size that the kernel allows. */ + const unsigned int max_write = + rounddown_pow_of_two(XFS_B_TO_FSB(mp, MAX_RW_COUNT)); + + /* + * Maximum atomic write ioend that we can handle. The atomic write + * fallback requires reflink to handle an out of place write, so we + * don't support atomic writes at all unless reflink is enabled. + */ + const unsigned int max_ioend = xfs_reflink_max_atomic_cow(mp); + + unsigned int max_agsize; + unsigned int max_rgsize; + + /* + * If the data device advertises atomic write support, limit the size + * of data device atomic writes to the greatest power-of-two factor of + * the AG size so that every atomic write unit aligns with the start + * of every AG. This is required so that the per-AG allocations for an + * atomic write will always be aligned compatibly with the alignment + * requirements of the storage. + * + * If the data device doesn't advertise atomic writes, then there are + * no alignment restrictions and the largest out-of-place write we can + * do ourselves is the number of blocks that user files can allocate + * from any AG. + */ + + if (mp->m_ddev_targp->bt_bdev_awu_min > 0) + max_agsize = max_pow_of_two_factor(mp->m_sb.sb_agblocks); + else + max_agsize = mp->m_ag_max_usable; + + /* + * Reflink on the realtime device requires rtgroups and rt reflink + * requires rtgroups. + * + * If the realtime device advertises atomic write support, limit the + * size of data device atomic writes to the greatest power-of-two + * factor of the rtgroup size so that every atomic write unit aligns + * with the start of every rtgroup. This is required so that the + * per-rtgroup allocations for an atomic write will always be aligned + * compatibly with the alignment requirements of the storage. + * + * If the rt device doesn't advertise atomic writes, then there are + * no alignment restrictions and the largest out-of-place write we can + * do ourselves is the number of blocks that user files can allocate + * from any rtgroup. + */ + if (mp->m_rtdev_targp && mp->m_rtdev_targp->bt_bdev_awu_min > 0) + max_rgsize = max_pow_of_two_factor(rgs->blocks); + else + max_rgsize = rgs->blocks; + + ags->awu_max = min3(max_write, max_ioend, max_agsize); + rgs->awu_max = min3(max_write, max_ioend, max_rgsize); + + trace_xfs_compute_atomic_write_unit_max(mp, max_write, max_ioend, + max_agsize, max_rgsize); +} + /* Compute maximum possible height for realtime btree types for this fs. */ static inline void xfs_rtbtree_compute_maxlevels( @@ -1082,6 +1155,13 @@ xfs_mountfs( xfs_zone_gc_start(mp); } + /* + * Pre-calculate atomic write unit max. This involves computations + * derived from transaction reservations, so we must do this after the + * log is fully initialized. + */ + xfs_compute_atomic_write_unit_max(mp); + return 0; out_agresv: diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 799b84220ebb..c0eff3adfa31 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -119,6 +119,12 @@ struct xfs_groups { * SMR hard drives. */ xfs_fsblock_t start_fsb; + + /* + * Maximum length of an atomic write for files stored in this + * collection of allocation groups, in fsblocks. + */ + xfs_extlen_t awu_max; }; struct xfs_freecounter { diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 218dee76768b..eff560f284ab 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1040,6 +1040,19 @@ xfs_reflink_end_atomic_cow( return error; } +/* Compute the largest atomic write that we can complete through software. */ +xfs_extlen_t +xfs_reflink_max_atomic_cow( + struct xfs_mount *mp) +{ + /* We cannot do any atomic writes without out of place writes. */ + if (!xfs_has_reflink(mp)) + return 0; + + /* atomic write limits are always a power-of-2 */ + return rounddown_pow_of_two(xfs_calc_max_atomic_write_fsblocks(mp)); +} + /* * Free all CoW staging blocks that are still referenced by the ondisk refcount * metadata. The ondisk metadata does not track which inode created the diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index 412e9b6f2082..36cda724da89 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -68,4 +68,6 @@ extern int xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen, bool xfs_reflink_supports_rextsize(struct xfs_mount *mp, unsigned int rextsize); +xfs_extlen_t xfs_reflink_max_atomic_cow(struct xfs_mount *mp); + #endif /* __XFS_REFLINK_H */ diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 9554578c6da4..24d73e9bbe83 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -170,6 +170,66 @@ DEFINE_ATTR_LIST_EVENT(xfs_attr_list_notfound); DEFINE_ATTR_LIST_EVENT(xfs_attr_leaf_list); DEFINE_ATTR_LIST_EVENT(xfs_attr_node_list); +TRACE_EVENT(xfs_compute_atomic_write_unit_max, + TP_PROTO(struct xfs_mount *mp, unsigned int max_write, + unsigned int max_ioend, unsigned int max_agsize, + unsigned int max_rgsize), + TP_ARGS(mp, max_write, max_ioend, max_agsize, max_rgsize), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(unsigned int, max_write) + __field(unsigned int, max_ioend) + __field(unsigned int, max_agsize) + __field(unsigned int, max_rgsize) + __field(unsigned int, data_awu_max) + __field(unsigned int, rt_awu_max) + ), + TP_fast_assign( + __entry->dev = mp->m_super->s_dev; + __entry->max_write = max_write; + __entry->max_ioend = max_ioend; + __entry->max_agsize = max_agsize; + __entry->max_rgsize = max_rgsize; + __entry->data_awu_max = mp->m_groups[XG_TYPE_AG].awu_max; + __entry->rt_awu_max = mp->m_groups[XG_TYPE_RTG].awu_max; + ), + TP_printk("dev %d:%d max_write %u max_ioend %u max_agsize %u max_rgsize %u data_awu_max %u rt_awu_max %u", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->max_write, + __entry->max_ioend, + __entry->max_agsize, + __entry->max_rgsize, + __entry->data_awu_max, + __entry->rt_awu_max) +); + +TRACE_EVENT(xfs_calc_max_atomic_write_fsblocks, + TP_PROTO(struct xfs_mount *mp, unsigned int per_intent, + unsigned int step_size, unsigned int logres, + unsigned int blockcount), + TP_ARGS(mp, per_intent, step_size, logres, blockcount), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(unsigned int, per_intent) + __field(unsigned int, step_size) + __field(unsigned int, logres) + __field(unsigned int, blockcount) + ), + TP_fast_assign( + __entry->dev = mp->m_super->s_dev; + __entry->per_intent = per_intent; + __entry->step_size = step_size; + __entry->logres = logres; + __entry->blockcount = blockcount; + ), + TP_printk("dev %d:%d per_intent %u step_size %u logres %u blockcount %u", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->per_intent, + __entry->step_size, + __entry->logres, + __entry->blockcount) +); + TRACE_EVENT(xlog_intent_recovery_failed, TP_PROTO(struct xfs_mount *mp, const struct xfs_defer_op_type *ops, int error), From patchwork Tue Apr 15 12:14:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052123 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 81D5229A3F7; Tue, 15 Apr 2025 12:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719434; cv=fail; b=Cb7wbUpnhRMpomIEWOkNoBaBf5lTy+kvgWm8VCz7hCEQ4b3sXTYJDyZhIXGKGxJPLCYarMuM/clzA+YFnm+CYH39fE7D1dNsbWRwgj85c/tNGO4XSvo3zXvCySruVTBUFfr7pmO6QDxOEh4YoQXcOa1tgFIeVRDvMbvI12KLO4w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719434; c=relaxed/simple; bh=y3tRoBulLacdYM6HByETphJBqopj9PI5ytX+pysqdNg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=aPF3GY/3unKs9WiEmRwaPhSuulTTHuTJh5HFI4ZR9i/JK/wSLE6hdcZ4rv4BFZ1V4iep4HtfD+4xjALCiYWxestN6ca0yF2BLdnfEALu1Dqx4bkibHQ+xSfHkqEdbirewpiolxdYgFHzqYAFhZMv/eZrfyIC2CwscDGBJZYrVYk= 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=nL5GzUIH; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=lxU/zT0N; arc=fail smtp.client-ip=205.220.177.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="nL5GzUIH"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="lxU/zT0N" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6fnJa004636; Tue, 15 Apr 2025 12:15:02 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=RsCb/GLDPVNfQEvks2acOJYBf+0K6ihFcjuOwJYTRkI=; b= nL5GzUIHJqwYtXZ1e1dqcyLvZk7inmLieFj0PuVW2z9/TYccooAA7RdGbGpFBH18 bmm8vBQoVvbtn8xMFA+rPdnvaCRcA+V/hIxe3JaVJyQcPnow9KwUhdLvo0nhD1td ul8H4vTKCfcDqACP7k/Wh5Goz6beWlMOIYFUaS9P+WqEQHTeBQS0KovwjkSAYdOq ++j7qOpwHmcEgnScIV++sFhDa2PfWxS97wVQBYIJbf9TkT2a2+ZZNoYLbH4uM8ka FzJViwo6hZofz04mP5KDsz5ngliG4BwAAr46mfK5Jm0TO/gejpYy4f11dplTqGEP WM+tjEmY6UKBIX8o8MoLSg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46180w9j51-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:15:02 +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 53FC0hr1005663; Tue, 15 Apr 2025 12:15:01 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 460d5v5p17-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:15:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GvfBYrsjpk3XL50wxKaC4mZi7+HI9nFr2vi4nDkHmfZ+35VwYITJmxydJWrFZ1KLpgiH62/ULJYdmmXENFcZv15XVJ09DV13L0TkcVfxQ+ZMSi/Rs6rvZDYqosHxSyfQpJiV6QhvvPGbRuQyKMd8BdiMPDEXWDxgybsnJvsLAN1JVQ3EIQYt8lpX74Cfw7Meyik119oQiWKpvWSMT+axd9goFgtd+/5trk5dkl7aG0vn+nlw63k7FdQNstEgvnTCsowPGGr50dscoQbcYWYnzrwcRv4MIO8B4HOBqV7sB6T1DnMjItNuAS8Og+miialDPpOkO++Gm6ULqQuH/5VrxQ== 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=RsCb/GLDPVNfQEvks2acOJYBf+0K6ihFcjuOwJYTRkI=; b=VXJqjY775SnDkQBpfRSksNa+3O1hy1jgnSvQX0LiO11nbGhdz24AnnQUUJg215HfZiKZnLkwcp1xf+0t3Wr2MG8UHz9X/Rv30unxjiA7JnvLtdwJuLpPm6mtLoobkDoszal0xyIQpuATK3kXS1FMJqyv7w+BOTNOLxABcnKLU7t9SPKeIZ3trlOxoczJC/1EYKX7nsphJgr0D9pvHbp2mGtpC7v2ApjpPiarCkTcyYB9PKOjndScECYhYIGv3oi+DfLKfgDnSW8lfxW27vz/I6R8alDBUypyH+KioVY4UFBaQ1PBsRoKARJCM8J2w1xCGi2jYf5RgXvJCPgCAfTRZw== 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=RsCb/GLDPVNfQEvks2acOJYBf+0K6ihFcjuOwJYTRkI=; b=lxU/zT0Npze/64bU55tzILtz8XNM+RGA7kEGpsMdI8t8Ty2lT6kL/QxFuFzaTjzBKuGeeDO3hLhP3KVQ/HSjPjHkxE4EijTXabltqlkVQwbjuofba3CVxZjyI0jUnopWxJcgJE15gc+cz/BlKOp/wWyD3v3N511VYaagyJ/+a5Y= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6535.namprd10.prod.outlook.com (2603:10b6:303:225::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Tue, 15 Apr 2025 12:14:57 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:57 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 13/14] xfs: update atomic write limits Date: Tue, 15 Apr 2025 12:14:24 +0000 Message-Id: <20250415121425.4146847-14-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0169.namprd13.prod.outlook.com (2603:10b6:208:2bd::24) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6535:EE_ X-MS-Office365-Filtering-Correlation-Id: c5569280-7be4-471e-f456-08dd7c17232e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: MstwUA7rl5jsm44fnkns3nFBf4j+9VMb864RIgBdnvDPWey6IMA5CYwxdHUVS5XPW43zJBPWJ8kxtqDlJgGqMZGRig6OzeZbyC0vj5MxM6fXyH+43GLVM/LFSrp3U/6RaL0nzRNBzu6PSLssZHx8uCDqU8NonOApmB/ERw9R23RVPAJm60ps6k5DFOa2qYiWT/zdtEMFqe+hXSNkcCmBnp7vPSiWcNZ9mN8F+cMyiUctmfY0RkxNGoiZlxVp6fRoCru/xesrjGvN/OluCpG2h8a5LMaG573abm5T6laSlYpWFGJ48wxUXAICmuBU99eCYTIcG2L9Q0wPgFjCpptwvD8KScLQLLHdoNpdaofxih1dqxSGRVTqf9IFZshuOy5WF4xkfRWmeEIF0tdCNh/WAJmQHqMj36MZ+4Yg4fTWg6GLgMUh1n6+uknE3fLusJRx4sDBYpv3993HHTx6Xcl+Vfz2QqXJk4XTAXI7Ayc5jGxJ/Ux6p+EYCdMXiLKF0B+Q6hAmaK2BGiSdd43ZqpWRD4OXcWzCL7JmzOEJQgA6ByVl9lR0vZ+GogA5ZZgWvhZvr48Q2u9iEsxb5q60HOZI4kYeU31+WlgPQ5wzbkX6Jn/vMULfjQFiYWWdXjL/2j+NNJKB4xi4t41jnF1KUmc9AZ/5JMOvsyq0porpoN06CvhNBHLrCyr6A/9iUr7vofm12eyE+E2iqwT73vFtkG2o9ZF54elXFuDmAwcYHr3GV6XJ62IkZP5Iem86uyv0tXzgj1GmnXXyLGOiuBARlcgq6ftStsOZavqAtEvvTlZSMNh33DgVnswxHjnW7nu4fA3w+v7HiUNBt9QB2Q9ZXF9T3ohagq1Zias6D3uSLduHv7rHnpGSVleGFqy40Kzk/qf7P6muliiGVWB2/97HD7EZUoDLPN8RmB8zfJWQAVoxJ9b3b3vOCXg/H3EFxC+gdJk1HjTYhWouTdX8b+8HYD/KAkqz9rCIpWNoGFsetZdXLxMNhEgxNkTSeX17d+LIss7byoCRtq0NmcuR9wfgekBzAEWXO+snvyrdmrtuwBXSr03cZSqXn638GPECbYbEnPJ9O1PK6zY97Rraf//hhKrOhVuUbZgYrzika7q2frnH1HSRoJO6RGuyziyTzcGKgcCockXcO4qnJ6TR/R8TzzuGLpVSuOt0q9bKSjdjcT2BfJ35el0jBVwMYKyXBj7wTrsmgQkALBclTxQOIHJ5JIJR6TcjWq41SPbTk45eRCNVY6xPEZtJOJ27w7z6Vdm0f7SmSFzeYwfriMe1oiPR1vdoIWuLabnIWUgSYy+sl+EnvTd9lVJ4CcS/Zrl2mE6qutKy4pfmzi3xh+XArdP368dfA9CGRN1zYCsbP6jCqF2KvsPmarQIubvMEZH/VvQUtcIriU27IG2Iq0q5t4kifvvA1wQjWZZvldzWGUqITomfdDQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GhxOhlCsS8Dt/tlOeizAlVlvVjT5xpSJmm2V7Iqb2uZ2q5Lp8E/lwZDFrrtzX5JQuxddxWkPQqrfpcnblM2nGwLstTfETPcHml4GKR3e9p0M2YLYdRMwGv5+gPan/Grd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ocg4ZKeI7ppyescvV229LtpdjAoKJv1+6C39E/Bzmrwu6iztw6wr9l8gZZW5cVBYGA3e2Rxiju5z8/WKIcIDZlW1/8szxyfF6zHNAl2wWHFBC0P0YSNVUE0fcTKKU8QH53A98b5BVemkWWdB2WEg9VlKTlDeN8YtbJXRayHfqz154/xLU0dToAEOVkYmnumuYifXhFsMch5EwSg/dNa9JtarOygUozsDSGkD+gZURGnTGvly8zOavG1CNyIyklTl7rz9adpI4qhelK/yQN6CaD8rStxpxUAO32qD1ipHMp9H7+Sm3DiQ+SsfEP8eKeGT1tTP1aJB6/frYFDU7+Mp7T4+SEJp/4noT0pYQ57B16gj8f9RI+6j6KnZPUreeeXpMrmzTz/1usob8EfTJ/zm52Zue7mIJAYP+f+MA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: UCHeO7h6p0QQuhkVYFdb3yLHpdtih59U+Qbp3qdP3il4X+wpzaGUlTKdY09KPQid55k8WRL0ykzfDzGURojws/ncTOuEHyIAqiVEZOAxqnV506m566KccbV79fbpNl5cHBufnDMFaB6OZfpk3+ef1PTPkF2QzE0V1nKKj91dZ6u7fC1qqHA9ZS5KmwvHcJllzuKmZKkxFB18s8R/3bPLGUO5fSwBwnuYDm9DAkvlV1TKweZLge/aHrlFp+QMMWUgK9nOMBEvLKDzgY0oEv7lkAlCtigJuvuL139nKjzYPRfm0oot7/aVX6H4VnKaUwsBV2WPv+xT+rRoCmxJfhggK1/BCdsjh51kqXUwXyIwgC3qsbfT2H+9p5VdCyYbMhVmBE12IwhjzDmjpOSWJ3lbSz6PXAu8fhB3cCrmCSD9rIguyme53LJx5sS5mbqVTHRGh6dyhEQVceauUrVdvCrfffrjgdzmNE4MnDooPxrswAhmcdie3FVkOSPkjkAvy+MgXWOk41ZxcJG2OZ0/kRlG6PtS8tmxSUaKQpQHdT48FI9F5XVfi4h4cD/pzZ3faFrQqfr5m3mxlNQaQ/ajn5dSfHWVcDxzDT6b6N1b6Xqn+Zc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c5569280-7be4-471e-f456-08dd7c17232e X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:57.4788 (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: VOSc3QpxxIZJS321u/TLYSd7rz/Ecou5kyMWwu5EK7Niob6LltoZp5vfI4t84vMwMvQ8imWo0Ecmb/ohnVf6yA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6535 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-ORIG-GUID: 9u4zNXZNV7UlYgHekGNch42qWB1VJVNM X-Proofpoint-GUID: 9u4zNXZNV7UlYgHekGNch42qWB1VJVNM Update the limits returned from xfs_get_atomic_write_{min, max, max_opt)(). No reflink support always means no CoW-based atomic writes. For updating xfs_get_atomic_write_min(), we support blocksize only and that depends on HW or reflink support. For updating xfs_get_atomic_write_max(), for no reflink, we are limited to blocksize but only if HW support. Otherwise we are limited to combined limit in mp->m_atomic_write_unit_max. For updating xfs_get_atomic_write_max_opt(), ultimately we are limited by the bdev atomic write limit. If xfs_get_atomic_write_max() does not report > 1x blocksize, then just continue to report 0 as before. Reviewed-by: "Darrick J. Wong" [djwong: update comments in the helper functions] Signed-off-by: John Garry Signed-off-by: "Darrick J. Wong" --- fs/xfs/xfs_file.c | 2 +- fs/xfs/xfs_iops.c | 53 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 81a377f65aa3..d1ddbc4a98c3 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1557,7 +1557,7 @@ xfs_file_open( if (xfs_is_shutdown(XFS_M(inode->i_sb))) return -EIO; file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; - if (xfs_inode_can_hw_atomicwrite(XFS_I(inode))) + if (xfs_get_atomic_write_min(XFS_I(inode))) file->f_mode |= FMODE_CAN_ATOMIC_WRITE; return generic_file_open(inode, file); } diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 3b5aa39dbfe9..183524d06bc3 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -605,27 +605,68 @@ unsigned int xfs_get_atomic_write_min( struct xfs_inode *ip) { - if (!xfs_inode_can_hw_atomicwrite(ip)) - return 0; + struct xfs_mount *mp = ip->i_mount; + + /* + * If we can complete an atomic write via atomic out of place writes, + * then advertise a minimum size of one fsblock. Without this + * mechanism, we can only guarantee atomic writes up to a single LBA. + * + * If out of place writes are not available, we can guarantee an atomic + * write of exactly one single fsblock if the bdev will make that + * guarantee for us. + */ + if (xfs_inode_can_hw_atomicwrite(ip) || xfs_has_reflink(mp)) + return mp->m_sb.sb_blocksize; - return ip->i_mount->m_sb.sb_blocksize; + return 0; } unsigned int xfs_get_atomic_write_max( struct xfs_inode *ip) { - if (!xfs_inode_can_hw_atomicwrite(ip)) + struct xfs_mount *mp = ip->i_mount; + + /* + * If out of place writes are not available, we can guarantee an atomic + * write of exactly one single fsblock if the bdev will make that + * guarantee for us. + */ + if (!xfs_has_reflink(mp)) { + if (xfs_inode_can_hw_atomicwrite(ip)) + return mp->m_sb.sb_blocksize; return 0; + } - return ip->i_mount->m_sb.sb_blocksize; + /* + * If we can complete an atomic write via atomic out of place writes, + * then advertise a maximum size of whatever we can complete through + * that means. Hardware support is reported via max_opt, not here. + */ + if (XFS_IS_REALTIME_INODE(ip)) + return XFS_FSB_TO_B(mp, mp->m_groups[XG_TYPE_RTG].awu_max); + return XFS_FSB_TO_B(mp, mp->m_groups[XG_TYPE_AG].awu_max); } unsigned int xfs_get_atomic_write_max_opt( struct xfs_inode *ip) { - return 0; + struct xfs_buftarg *target = xfs_inode_buftarg(ip); + unsigned int awu_max = xfs_get_atomic_write_max(ip); + + /* if the max is 1x block, then just keep behaviour that opt is 0 */ + if (awu_max <= ip->i_mount->m_sb.sb_blocksize) + return 0; + + /* + * Advertise the maximum size of an atomic write that we can tell the + * block device to perform for us. In general the bdev limit will be + * less than our out of place write limit, but we don't want to exceed + * the awu_max. + */ + return min(awu_max, target->bt_bdev_awu_max); } static void From patchwork Tue Apr 15 12:14:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 14052124 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 CAAEF29AAF8; Tue, 15 Apr 2025 12:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719434; cv=fail; b=Og5UzI2lFjp/W+M+gc5LjbkPikKcq9hSvudGAkrzmV8mBc9pCtOEexTxnG6Bq7MzqEuV5cXb/gqDr68pWziK1y38CYZb9Zabavk5mu57gy2pKZof18wR4f4Kff2WN+FDYXot3vyAMB4yO+Qy2fViaM24KnNYzWDHrIC9N7jHnSg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744719434; c=relaxed/simple; bh=Jh5iUFRKCIcKOebhhgoU7BkLO34fDP9Yw37pHR5hsIk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=b4BvXIX5pm3q41xlS7WqEr7YSjP+75tG9ms0gsgc/CANULsN/zMdU0FtYfK2Co/I/ZxUr8uoyqSo5vO5xsDWA8bvXfB8Yi0kjI4pBNA2qmB9v/R7QEa68NW6vZ9FQuMtXmIYmt3TfeSCSLyyuy6uVApMpuXtn8hrS3tf+F1o0n4= 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=dW4mdzCP; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=SuHJqpx3; arc=fail smtp.client-ip=205.220.177.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="dW4mdzCP"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="SuHJqpx3" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6foEU032430; Tue, 15 Apr 2025 12:15:03 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=h1ZK5BElfP9K84jnUICToc5UgKtsks/rbfaeV4TLfbo=; b= dW4mdzCPdppCYE5XnLXznifNgmfdWWe7FcXWOkF28gJILZsMedYh3X0VUitrek81 cvhtRFvuQRnbnpEoMAaN9jghqnICDjHU6EcDWVQo3gAjJV9hfgngwUnLbAjaPg+w ZEpHXVaDte63jEaL9+muCggUaTSZLrh/Ebeel+xKy0XowB9mI1nKnz3P1vTA2PCC BUAkqXwH/CArzuv4bh8y8jktM5dDHtJkPpAsr9bK9O6mQfiPvRYzlcyq/W2ygxul WlCvvbWTm/CWUJ8zajnHbc15eCvBvYfmAiJNWc2AUzWEHj+qNrJqHeWEyjFgeael k0PUGBunieFHGci2LRxNUg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4617ju9k3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:15:03 +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 53FC0hr3005663; Tue, 15 Apr 2025 12:15:02 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 460d5v5p17-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 12:15:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P4OKECPwAKL36xglclfWKYWFxz+MdgMRCoOu6Zi2UVlmdg3YLtf5GSZTRjiHC97KWaM4oOzM3oBOs6lmnALDAANHcTwCsKiNAZZrI1HG5T3ULxgGn5kSFgv0gtBtGAp9ecYxQyZ4z5Ix2F2mTVrG77bKfBLrh3ssz8NNtkz7O8+KY8M8hnadQdWI09kuT3YR8xx49ebNKS/RxtCRgGmvyh468LVve1ZUM1eudRwpjgOUmpbqtM6hl0+nXFrySs0myFuviF1VtOm0/I/oT3v2/WJbtcTKRYj/3sh4yGa6Gt0I/yq165q+jx21QOLU7kalz82lGWqmSG3Nm8d/EMgVXw== 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=h1ZK5BElfP9K84jnUICToc5UgKtsks/rbfaeV4TLfbo=; b=GRCYLp5M24JOix4PP+dH6yISx0NyzF4zBUyd9RSIeWdkC1piD0fSCZb1UizqZSYPWQU1vvAr4jeU7CToJB4PMjSCE6ewH4lU06UEa3QHWPCbZVTjAZCVxS/BIBjYIYMQR8Su2Rn7VE0fwOJb3lypVWTt2PLth1aePiZp8J9jZoKGYBVljqc62ZrN0f+jUaPsdD8Gdix1B7YGr1sWsHWZ2EHVDEIexMmPZAwNGtH2IJPX4C70FGoBzPTDaRJ+FH7TCY/IQORWgMV9YJaJUz0A22S6ANLzeKDpwllFJPDssRNTzs7kyxLnbqK4mxy1cZWYJTrmC7XmSk0Ne4zRdMwMcA== 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=h1ZK5BElfP9K84jnUICToc5UgKtsks/rbfaeV4TLfbo=; b=SuHJqpx3XmaBkmy+ewnq1MdBTiugMQnXUmlLWL4zbIqbZtMg6GyC5NgpQOWw+4ykc1YAVFB26inwB6QJBOMUikoaIPxkmhmBxOny7j6xaQMgKOwnZfupYsFlFYszEXUUcpHt9jRSb4u382tQqRoq9Qc3zTQb7PaUOBEoImg35hg= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6535.namprd10.prod.outlook.com (2603:10b6:303:225::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Tue, 15 Apr 2025 12:14:59 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%4]) with mapi id 15.20.8632.036; Tue, 15 Apr 2025 12:14:58 +0000 From: John Garry To: brauner@kernel.org, djwong@kernel.org, hch@lst.de, viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, ojaswin@linux.ibm.com, ritesh.list@gmail.com, martin.petersen@oracle.com, linux-ext4@vger.kernel.org, linux-block@vger.kernel.org, catherine.hoang@oracle.com, linux-api@vger.kernel.org, John Garry Subject: [PATCH v7 14/14] xfs: allow sysadmins to specify a maximum atomic write limit at mount time Date: Tue, 15 Apr 2025 12:14:25 +0000 Message-Id: <20250415121425.4146847-15-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20250415121425.4146847-1-john.g.garry@oracle.com> References: <20250415121425.4146847-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR08CA0002.namprd08.prod.outlook.com (2603:10b6:208:239::7) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6535:EE_ X-MS-Office365-Filtering-Correlation-Id: bb628e45-34e5-4d8a-31e8-08dd7c1723ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: Q3OyuSMZkIi0tv6I+U2O50KpRvBAWSZEUSbowf/Ldi+W7foDL/B/atb+k8yF9f8OLmMKUvhZ9mB8nvdZl9CSnGT/mqjPby0enFQjvgbSW/IuXpciGgpWNU17lDUHm30FKyVV0RTt7gN1E/jTEoCZlpw1QtAplwFb6bOwW1oJ/eGCyXkjrOe8M+oxTnKHLeFTgAXfiFa9hsveM5r6C+eIC4eBgNwlQpgpQCCthJ1FMLn69faKkNj962jM/4BlJTx0zmVcPPU4GLIz9WBIcQ98b4AKPIsl9xdG+zhcJf0sL/Wfj59/202lXZRVzFpvR48zTGbeLIFJuOlWnR5//bMK+Ph66zXX2iakExC+41m7crE1lwpdXP86kOB8Pf4NEgdN4PLDVYZ3nRWKXtq7CWaMYKcWBr5Ge3mGF41b/EFiqXSw4/h8THy2d6omW2jeDphRy8+Bccag5CiHJmk2e0KPvARKBeUpE14LVhwZCMRaLdChLnPTMgiNPaSHT3aYul2gmJNeTKl1hkRp6vuI081p+3YW+xPmdqWNqu2GvKzWuahabaLN1f9Oohrm38A+bt0D827CGwNKzKjvJ3dkLApnfBxDDQwxKlwnM5vuKmpnK4y11MDl3BlswvdbuTJ7D/ydQ5k6t0gu5S1QSOZhF2nkv6SSPktqFeilfUGW0w3eXm6dM6TMYDsE2bG5LMK6WIY7tHlT+RZJbk/qGNzn68TtJwXddLT8QHQgJBYxEIngmLwWj8niroyizOrbMemUyJJSm/IcHR3esMdpE44EIyWnrchF96ufGU4NlGo0dv7yiZEUUhkJ7WKdo24YXfwXVTncT57yg6PdnIl8BNuU5iI+uTt+JhXZrFRzPpTe5ES40/CDcRRz9GuaQc1Gm262OH3JHJNFAWP9j0Pa8Za+jMToPX4ETdeAbc4tOaAMIvwZLYlpC1WgbkRwQnZD7jKv6Iwz+vHC3/Y9iz+pFNLYhx0m6fRqgEJ0vF5u6sCh+J/UHLiyf7rdcyVcvLSgzH1RRtTRxuh6ll0MW0HDSreq3tcIoayMTQ5YMwKOUGnEvQnjesJHDm+y5/FfYwrV3rUdno+7zVG4Hh6ye1Wd39I2ZRN1497cBm0VMMdYxsdy4WvmMptH80c44NSN6Ebcps+5kMBiu+2kDUkkuK0oklA4eHidQOLlupdSLGbSU5S3SKn6806H23nZOwMij30FzWoA0DYdUKG5DIBgQBvKdyuJyie3+nJQbYpGCPPWfoqQz1lwRAHOll/tAWr5AelDoa58J6/9aar3LecGEZ0/qUaCPcq3cUQeX1L9PJ4d102lPrv/hwQ/zwZKa8jXk9SF9eSgUTnLTMPI9GntOHmF6op6KEefYiO1r4OvyErcV4Y3bBxMuWsCQ2TSy+vCkakKZYhe7VetaIpLZ8LLcnG1pxdkx9UEpABln/y0RJ+8yKVY+7mp3XY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2ba2635Z2jQahk97ASggwFNCNdLCCRWz2n2lf8ONs1l365BQUwc/9jUHFKx6MkdtCHEd1o0cX99hHpHjqX9M3H4scXqsJpX32qDDokUPVSTxUNKhxIaJkkwEpUnvRvOghko3HIO9O227i2PSVzqxyJOVa6xWRsiEJ/0emHZ+VkV86SA8ehhFKb22mquE7EETYSGkeNTOfeSmCtyQ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YtFurMxY0c2zWevjWL0GpnU3OMyDdaMRK8HVm2Gq/5g2YY6v2Rjd8st3IK2IkmkjDdtx5skQxInQcHxN86EhsWuu54Vco7JPpB6enPxXBEkfhZjEAP0AiMQuY8H/DlP5bZOKiWlGi4+4dgynaRnH/HTENTih/M/vUZPF025uOYdOhlLfh2UmIZzaNqZQ8QOjoq1BNDaPmFmendKdKg+pxaO+9/oBSVIvwzJtF2BQVgj4yTAmDVSkramvkP5usPignMzQe41oDFDMO3M3fLGTBCqEdvUbR4No2HVV0nbxYWq8IEuOTnseQ+UlcPtzuwRdUx5q8ZcTdLwsnZGOa6iX+4A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: rAIV3VA3PInnujbfIHtiAB0uN7GrvTSw2eV2ZxMOltbIG4G8aEZTIn90IOWu0zgLD3l/wci2KSxFiWhWZAFqA1B7vV58AQUxGqRCjrinWzHQCl8kJbutiBScGK25Ir6yQfxhSgroYbzkN1tc+8pYOrsVFd/5YxjWOUfcfhWNe0TkCZVzxkAIlmYYHiARkEcdXrObLJ2yr2tGJHhAbx5PQa/2k4K7OZajCUcJAclH6NrLe7AMYh5DggQMimKE66jq1mapbHRw9OZS9kKzDdYTnndQxAhVHG0NSlBKPuJYiZc3mC+ZR4krsm0FYbUbn4wgAyzloV01sohGxlJx4Q7ISe5x8JDIVLrcJ2ZXeWHeDWf2LY9HDb8wnEnkOf6uQQCC0eykACHOE9NuX2g/WWgQKikEsWjp2hR4rUqQDOveeVlYJ3Ovr3Eb/VLpP9H1LkGiPc2oz/GIQulbAuWTaG3Rm/dBvxnVp/JQflASh+16yFLFf60JiK/AY9NQ0P0NySpk8KELxhHIMbwBJbv3KhpI7ACxRsVcp+KOWxD6BV/t6IjxeC4rImlKQedf5rZT0ka1UixaEXhWdUB+C6Koxt4mPK8VyQtYVUCRH0yF1mi/yQE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb628e45-34e5-4d8a-31e8-08dd7c1723ff X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 12:14:58.8303 (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: qBNzRzc97D5G91H60RHaXEsACorFo1976b9mXaNrbiSkrVZbJxebD7XciF9BBk4P1cF2+wbqXyD5Y8JqdZDdRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6535 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_05,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150086 X-Proofpoint-GUID: Q7eosLX6uEvVjgSDmu47mCGeF0pwAss4 X-Proofpoint-ORIG-GUID: Q7eosLX6uEvVjgSDmu47mCGeF0pwAss4 From: "Darrick J. Wong" Introduce a mount option to allow sysadmins to specify the maximum size of an atomic write. When this happens, we dynamically recompute the tr_atomic_write transaction reservation based on the given block size, and then check that we don't violate any of the minimum log size constraints. The actual software atomic write max is still computed based off of tr_atomic the same way it has for the past few commits. Signed-off-by: "Darrick J. Wong" Signed-off-by: John Garry --- Documentation/admin-guide/xfs.rst | 8 +++++ fs/xfs/libxfs/xfs_trans_resv.c | 54 +++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_trans_resv.h | 1 + fs/xfs/xfs_mount.c | 8 ++++- fs/xfs/xfs_mount.h | 5 +++ fs/xfs/xfs_super.c | 28 +++++++++++++++- fs/xfs/xfs_trace.h | 33 +++++++++++++++++++ 7 files changed, 135 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/xfs.rst b/Documentation/admin-guide/xfs.rst index b67772cf36d6..715019ec4f24 100644 --- a/Documentation/admin-guide/xfs.rst +++ b/Documentation/admin-guide/xfs.rst @@ -143,6 +143,14 @@ When mounting an XFS filesystem, the following options are accepted. optional, and the log section can be separate from the data section or contained within it. + max_atomic_write=value + Set the maximum size of an atomic write. The size may be + specified in bytes, in kilobytes with a "k" suffix, in megabytes + with a "m" suffix, or in gigabytes with a "g" suffix. + + The default value is to set the maximum io completion size + to allow each CPU to handle one at a time. + noalign Data allocations will not be aligned at stripe unit boundaries. This is only relevant to filesystems created diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index f530aa5d72f5..36e47ec3c3c2 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -1475,3 +1475,57 @@ xfs_calc_max_atomic_write_fsblocks( return ret; } + +/* + * Compute the log reservation needed to complete an atomic write of a given + * number of blocks. Worst case, each block requires separate handling. + * Returns true if the blockcount is supported, false otherwise. + */ +bool +xfs_calc_atomic_write_reservation( + struct xfs_mount *mp, + int bytes) +{ + struct xfs_trans_res *curr_res = &M_RES(mp)->tr_atomic_ioend; + unsigned int per_intent, step_size; + unsigned int logres; + xfs_extlen_t blockcount = XFS_B_TO_FSBT(mp, bytes); + uint old_logres = + M_RES(mp)->tr_atomic_ioend.tr_logres; + int min_logblocks; + + /* + * If the caller doesn't ask for a specific atomic write size, then + * we'll use conservatively use tr_itruncate as the basis for computing + * a reasonable maximum. + */ + if (blockcount == 0) { + curr_res->tr_logres = M_RES(mp)->tr_itruncate.tr_logres; + return true; + } + + /* Untorn write completions require out of place write remapping */ + if (!xfs_has_reflink(mp)) + return false; + + per_intent = xfs_calc_atomic_write_ioend_geometry(mp, &step_size); + + if (check_mul_overflow(blockcount, per_intent, &logres)) + return false; + if (check_add_overflow(logres, step_size, &logres)) + return false; + + curr_res->tr_logres = logres; + min_logblocks = xfs_log_calc_minimum_size(mp); + + trace_xfs_calc_max_atomic_write_reservation(mp, per_intent, step_size, + blockcount, min_logblocks, curr_res->tr_logres); + + if (min_logblocks > mp->m_sb.sb_logblocks) { + /* Log too small, revert changes. */ + curr_res->tr_logres = old_logres; + return false; + } + + return true; +} diff --git a/fs/xfs/libxfs/xfs_trans_resv.h b/fs/xfs/libxfs/xfs_trans_resv.h index a6d303b83688..af974f920556 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.h +++ b/fs/xfs/libxfs/xfs_trans_resv.h @@ -122,5 +122,6 @@ unsigned int xfs_calc_write_reservation_minlogsize(struct xfs_mount *mp); unsigned int xfs_calc_qm_dqalloc_reservation_minlogsize(struct xfs_mount *mp); xfs_extlen_t xfs_calc_max_atomic_write_fsblocks(struct xfs_mount *mp); +bool xfs_calc_atomic_write_reservation(struct xfs_mount *mp, int bytes); #endif /* __XFS_TRANS_RESV_H__ */ diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 860fc3c91fd5..b8dd9e956c2a 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -671,7 +671,7 @@ static inline unsigned int max_pow_of_two_factor(const unsigned int nr) return 1 << (ffs(nr) - 1); } -static inline void +void xfs_compute_atomic_write_unit_max( struct xfs_mount *mp) { @@ -1160,6 +1160,12 @@ xfs_mountfs( * derived from transaction reservations, so we must do this after the * log is fully initialized. */ + if (!xfs_calc_atomic_write_reservation(mp, mp->m_awu_max_bytes)) { + xfs_warn(mp, "cannot support atomic writes of %u bytes", + mp->m_awu_max_bytes); + error = -EINVAL; + goto out_agresv; + } xfs_compute_atomic_write_unit_max(mp); return 0; diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index c0eff3adfa31..a5037db4ecff 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -236,6 +236,9 @@ typedef struct xfs_mount { bool m_update_sb; /* sb needs update in mount */ unsigned int m_max_open_zones; + /* max_atomic_write mount option value */ + unsigned int m_awu_max_bytes; + /* * Bitsets of per-fs metadata that have been checked and/or are sick. * Callers must hold m_sb_lock to access these two fields. @@ -798,4 +801,6 @@ static inline void xfs_mod_sb_delalloc(struct xfs_mount *mp, int64_t delta) percpu_counter_add(&mp->m_delalloc_blks, delta); } +void xfs_compute_atomic_write_unit_max(struct xfs_mount *mp); + #endif /* __XFS_MOUNT_H__ */ diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index b2dd0c0bf509..f7849052e5ff 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -111,7 +111,7 @@ enum { Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota, Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce, Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum, Opt_max_open_zones, - Opt_lifetime, Opt_nolifetime, + Opt_lifetime, Opt_nolifetime, Opt_max_atomic_write, }; static const struct fs_parameter_spec xfs_fs_parameters[] = { @@ -159,6 +159,7 @@ static const struct fs_parameter_spec xfs_fs_parameters[] = { fsparam_u32("max_open_zones", Opt_max_open_zones), fsparam_flag("lifetime", Opt_lifetime), fsparam_flag("nolifetime", Opt_nolifetime), + fsparam_string("max_atomic_write", Opt_max_atomic_write), {} }; @@ -241,6 +242,9 @@ xfs_fs_show_options( if (mp->m_max_open_zones) seq_printf(m, ",max_open_zones=%u", mp->m_max_open_zones); + if (mp->m_awu_max_bytes) + seq_printf(m, ",max_atomic_write=%uk", + mp->m_awu_max_bytes >> 10); return 0; } @@ -1518,6 +1522,13 @@ xfs_fs_parse_param( case Opt_nolifetime: parsing_mp->m_features |= XFS_FEAT_NOLIFETIME; return 0; + case Opt_max_atomic_write: + if (suffix_kstrtoint(param->string, 10, + &parsing_mp->m_awu_max_bytes)) + return -EINVAL; + if (parsing_mp->m_awu_max_bytes < 0) + return -EINVAL; + return 0; default: xfs_warn(parsing_mp, "unknown mount option [%s].", param->key); return -EINVAL; @@ -2114,6 +2125,16 @@ xfs_fs_reconfigure( if (error) return error; + /* validate new max_atomic_write option before making other changes */ + if (mp->m_awu_max_bytes != new_mp->m_awu_max_bytes) { + if (!xfs_calc_atomic_write_reservation(mp, + new_mp->m_awu_max_bytes)) { + xfs_warn(mp, "cannot support atomic writes of %u bytes", + new_mp->m_awu_max_bytes); + return -EINVAL; + } + } + /* inode32 -> inode64 */ if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) { mp->m_features &= ~XFS_FEAT_SMALL_INUMS; @@ -2140,6 +2161,11 @@ xfs_fs_reconfigure( return error; } + /* set new atomic write max here */ + if (mp->m_awu_max_bytes != new_mp->m_awu_max_bytes) { + xfs_compute_atomic_write_unit_max(mp); + mp->m_awu_max_bytes = new_mp->m_awu_max_bytes; + } return 0; } diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 24d73e9bbe83..d41885f1efe2 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -230,6 +230,39 @@ TRACE_EVENT(xfs_calc_max_atomic_write_fsblocks, __entry->blockcount) ); +TRACE_EVENT(xfs_calc_max_atomic_write_reservation, + TP_PROTO(struct xfs_mount *mp, unsigned int per_intent, + unsigned int step_size, unsigned int blockcount, + unsigned int min_logblocks, unsigned int logres), + TP_ARGS(mp, per_intent, step_size, blockcount, min_logblocks, logres), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(unsigned int, per_intent) + __field(unsigned int, step_size) + __field(unsigned int, blockcount) + __field(unsigned int, min_logblocks) + __field(unsigned int, cur_logblocks) + __field(unsigned int, logres) + ), + TP_fast_assign( + __entry->dev = mp->m_super->s_dev; + __entry->per_intent = per_intent; + __entry->step_size = step_size; + __entry->blockcount = blockcount; + __entry->min_logblocks = min_logblocks; + __entry->cur_logblocks = mp->m_sb.sb_logblocks; + __entry->logres = logres; + ), + TP_printk("dev %d:%d per_intent %u step_size %u blockcount %u min_logblocks %u logblocks %u logres %u", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->per_intent, + __entry->step_size, + __entry->blockcount, + __entry->min_logblocks, + __entry->cur_logblocks, + __entry->logres) +); + TRACE_EVENT(xlog_intent_recovery_failed, TP_PROTO(struct xfs_mount *mp, const struct xfs_defer_op_type *ops, int error),