From patchwork Wed Oct 16 00:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catherine Hoang X-Patchwork-Id: 13837464 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 9F8DE1859; Wed, 16 Oct 2024 00:12:30 +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=1729037552; cv=fail; b=aIONO+/EcYs8fNL9JWDBeUObGjIqLIXHey5slfSjRa5ZMRmgf1FHRDmZKPaO2WfrgapgfqsmIHaWPfeVlpGQQhR3G7va3updK/Qi7kReup07a1BGHlT5xFqZ4FqkiXJjBI1mCNdRwwz3rktZt78mcnCmLlqY+KCmCba/KL8QlOs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729037552; c=relaxed/simple; bh=QzPMIzotBrczxSqSMi8BtEqNXdiFkSkAeE9L7FNGvBg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=LqTTGz/doRK0RLNbozckSLAK6AmBnNfecXtf/8tuqiTzGliPsCK4eKsW/iY9dVu7DycCNoIXS7OO2JXAfw8dXWLT20esDv8i7Jvc08GAzAhsayAQGXCKbZaz9WhDGxH+NomnhN35AEpJZgU8OCfH4vYqK8f2IG1St9Cc2gwJMHU= 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=GfN//Xpe; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=zX0f7B1Q; 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="GfN//Xpe"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="zX0f7B1Q" 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 49FHtikB019421; Wed, 16 Oct 2024 00:12:30 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=4yKK90hFvHiC2ND2k51QMNfbbckh0+U5eQ7ymmFQfA4=; b= GfN//Xpe4lmd0MdHYLmOTMSF400s4Yl1elpaEgkxY5oRjFygPcgjYQLJvWVGY6p9 4+XIjZIkvaUeMkwq2YD8Sj5sZnmbZwaZBNj/AlU0NDMe34P7FbGnoRH9kFkIoI4F 6RogygSNfZQppgI1u7GluSny17waaFbUp7hPH9OGWV4jJx9goBP8hNU3zBIBIvHb ekES4gPugDqtuOR0h+2U2RA76SmHXKqGl/fRHO7Qsl9YGQrG+ddivhRP4Cny7g56 eN7DQLT55zMuze/vdqyKHjFFBFF2Fo//iCwXKJBLCWVrVp1T9FSm13/vGfJw8Wvo SiwEq62Dyca9im6OujVidQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427gq7jhqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 00:12:29 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49FLkLwB026369; Wed, 16 Oct 2024 00:12:29 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj85aps-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 00:12:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=en39S8v07A+savMTpy9K8RPvjs8+MPNWgflPN310PcTvNFNk8IwaBpWDUBqUAWobbjxh7icOcfYK7owtb/4rt1p10gCPWAypiX8sl3k+yBBVE1nnijCyhlp7JAUPagoOvI4GUGett+FlQLh1+FKDNljZJas1FwKc/mai+ntRuDATKpSSvsP/PLV8cSwAivj29pAKCjzQPgtSEg1rWrAhDUA2pdSRPcpXi0noLydyKRTN1hF50kIyfQxcHNBHl6G9d2uCSM7s/f7y39B6Srx/85rygkOxwnKLeJ59vP3DlzGBwZBAWawVYUyYD3xZ7QPkN50C9PQGlS9S/NJxdal93Q== 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=4yKK90hFvHiC2ND2k51QMNfbbckh0+U5eQ7ymmFQfA4=; b=UU4gOvFb/qAwUTKPAXRYwHV1MjQZIrt5RmWnLFvEHGsjBlpZeyRVR+EvzcZ/azxpdD+WN3pl2ydPwc6bz3LJIU5ahI8ItCO2wel+1+rrhaC3tHS2uXQZ59cuWlwMQNBwR0/+sapkk3p0WTqpJPduWHYaIdvJgsZBO8viw/4nQ1eg3qKjeqLK9GHZ7qO0YCO/ttRHtCWi1G+9zjUw4S3S5W8Pf0/4KDDQweGYZJD3/ykuXRUA2xOoHCaD1hM9KM8df2kdH/zKA6i5w3h0DkiI8huW2HdSLFjyGVhdw7cyx9pJEUYApxPeB60Hx1SLPtZdftZ4sa56R5B6n/qGo+Euqw== 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=4yKK90hFvHiC2ND2k51QMNfbbckh0+U5eQ7ymmFQfA4=; b=zX0f7B1QC804EMPa/bdrskvdp9syNX4IaitdQIhoc8RXOhz1riZaRe35QarNyyPdGwqA5khhlhPyCb9EGude19pcpevZcIol6kuXJlaer9YSWHdSVrpkPBAK3xm8UuAb/85IwqoFHfUXWArJiLuj3/5pLsFLjdxGn1ruWrp+r/U= Received: from BLAPR10MB5316.namprd10.prod.outlook.com (2603:10b6:208:326::6) by PH0PR10MB4727.namprd10.prod.outlook.com (2603:10b6:510:3f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Wed, 16 Oct 2024 00:12:06 +0000 Received: from BLAPR10MB5316.namprd10.prod.outlook.com ([fe80::a63b:c94b:7ed8:4142]) by BLAPR10MB5316.namprd10.prod.outlook.com ([fe80::a63b:c94b:7ed8:4142%4]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 00:12:06 +0000 From: Catherine Hoang To: stable@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 6.6 19/21] xfs: fix freeing speculative preallocations for preallocated files Date: Tue, 15 Oct 2024 17:11:24 -0700 Message-Id: <20241016001126.3256-20-catherine.hoang@oracle.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241016001126.3256-1-catherine.hoang@oracle.com> References: <20241016001126.3256-1-catherine.hoang@oracle.com> X-ClientProxiedBy: BYAPR05CA0033.namprd05.prod.outlook.com (2603:10b6:a03:c0::46) To BLAPR10MB5316.namprd10.prod.outlook.com (2603:10b6:208:326::6) Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BLAPR10MB5316:EE_|PH0PR10MB4727:EE_ X-MS-Office365-Filtering-Correlation-Id: b3c94bdc-d80a-4700-de11-08dced772afc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: EquHdzs0Pzofk3SylLM2VrUwkx9ZqPUF8IGpep1CzE/yhcitoo3xrLkfSLROrojfk7fse/eLE0D3VUt6d3grN7vdJKZUwSkq4x5DcNaZ2Nwfae5uqwLYe1C13Td4AFmy1nR9EjdhGwJrDcwe3sOUGLhiLCt+fJcqbZrqrlpAkwhqkHQnOPUyhk7G8E67PZv+DxWwvGymhbUbHLmFXVhB3KGqfReTS/lDlwWwBS3KF/BmFLaquYNwB/9ighiITKhMtx5L+wVe1Gqy3rBLDsTAu76jXL2iJOzKZh3IjRvxOZuR61lqdpKAfOxCM7pucEe2gc7e6KOHp2NPgpZbH6zxW+cFMTuq6xkgfIQbj8Sb+DdmT5HBQdiMEYWnkQ7YRKqcGsjRzdBO5/obpHlVedQOpVjNOVTErk1Sk+i+6xfo+Nirg8CniPCblCxTddWcEz/syZzQfVcDPlYgaU3KXZfycXjsp3S32Olw7DxornCArI9nRYuYZTEZ8fnS/HbR9QdFa5zGr4yBk+bnDM0wqlKZ2R1ZE2rDWCC1IST1Euivc9FV4GIBw2UeK3h+NTEtl7R8LAZsR8L/mu8TcFlPUOk2gAfMD4Eo4rRDYS4HuIEsNYjJBpiPF6jhiztmP066/rl2aynrBOG3ZqjCPhhqashZSMHy5WNT+0LBU3ZMGZkZuZU5TcZXlByp0vy5TQC6gr0LotiDsZXlvw0wKI5NH825WgQCPnBbbYnLXUjbFWrnQ4Euq2LOWlS4lwzfWgQOWJ4WLGa2kAQF2q8OnEBoKxIe+3S7wRVSXIUn43/eV3eHYFOGU2zBx6rFQjyJouqgj9aVQz2djOGInL/3F7DD8rnQGPB/djnoIs7bmLy2Mjf+XT9Q3WqPadD9TQgz5HyNo5f4ku7zdq5n30TPNa3EwYKYKgcdHGtQT6ybp1wg+h63JZ01H2TFXdhA+aHLqah73ryNli6s+7dRXqNIr8mi08Hk+TOE1/G0ZQfDCyG1jWhxmwlG7nfFOp2HVdpB0c71BJWtIflLup6dhkj+SbGnDlGTpkRV8FRD6Zzc7dbEEoOlmc/U5oha1yHVQ5f0mPw8GK8BQ3poR+zB6NberqbV2ZpZVOot2L7kZ3GGtaI61kzzTkqfNQuj5Q2qgpU336T/pIqXe79llEyU0LxVFxmZ9kjxA3iPoBnBkp3SJE++lTQp7nk5VODL2+EtyHmyt7fNT8SlTcyC18c0+s6fgW6s01m7wIMlO8agMDSypHpNIT5n6ediF7VofRamnHXelzAsJCtbnUW3AOna1M/Qoxo+/6H/JQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5316.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WxLyntJLOLYvNPlh/OijhpdAZNV/wqC1gjE7vUXjyBu/m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RcXJIQRebR8zOr64wUGTw+zcoK1nFboR5rRqg+xB8g5f/zI2b/vkJPsCe0Sz4/WCcd44S2Uo2LshboGkkMQAYhCu5NAgXSvSZOm0v1MR8gHMwu24gc9YH6/oGCf9iDzRRupguKaFKE8pErEVcAGQQsn6T9lqoiVH9O1d0RBYjRS2VeMi+yWmVGmVDXs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3c94bdc-d80a-4700-de11-08dced772afc X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5316.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 00:12:06.0848 (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: a/lDt1ueyhOZQ4YUuyHP+iEtzXhJxvexSYG2Nn6Lxapy/nB5G6lWsW3nc93YqzVIwbH9vGi6S5MhM8bRaM93fVqp091nQ6gdB3aadmVsF80= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4727 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_19,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410160000 X-Proofpoint-ORIG-GUID: Ouoqn9IgAHKB946_dpMLn8_dhoMnc2H_ X-Proofpoint-GUID: Ouoqn9IgAHKB946_dpMLn8_dhoMnc2H_ From: Christoph Hellwig commit 610b29161b0aa9feb59b78dc867553274f17fb01 upstream. xfs_can_free_eofblocks returns false for files that have persistent preallocations unless the force flag is passed and there are delayed blocks. This means it won't free delalloc reservations for files with persistent preallocations unless the force flag is set, and it will also free the persistent preallocations if the force flag is set and the file happens to have delayed allocations. Both of these are bad, so do away with the force flag and always free only post-EOF delayed allocations for files with the XFS_DIFLAG_PREALLOC or APPEND flags set. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R Signed-off-by: Catherine Hoang Acked-by: Darrick J. Wong --- fs/xfs/xfs_bmap_util.c | 30 ++++++++++++++++++++++-------- fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_inode.c | 14 ++++---------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 4a7d1a1b67a3..f9d72d8e3c35 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -636,13 +636,11 @@ xfs_bmap_punch_delalloc_range( /* * Test whether it is appropriate to check an inode for and free post EOF - * blocks. The 'force' parameter determines whether we should also consider - * regular files that are marked preallocated or append-only. + * blocks. */ bool xfs_can_free_eofblocks( - struct xfs_inode *ip, - bool force) + struct xfs_inode *ip) { struct xfs_bmbt_irec imap; struct xfs_mount *mp = ip->i_mount; @@ -676,11 +674,11 @@ xfs_can_free_eofblocks( return false; /* - * Do not free real preallocated or append-only files unless the file - * has delalloc blocks and we are forced to remove them. + * Only free real extents for inodes with persistent preallocations or + * the append-only flag. */ if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) - if (!force || ip->i_delayed_blks == 0) + if (ip->i_delayed_blks == 0) return false; /* @@ -734,6 +732,22 @@ xfs_free_eofblocks( /* Wait on dio to ensure i_size has settled. */ inode_dio_wait(VFS_I(ip)); + /* + * For preallocated files only free delayed allocations. + * + * Note that this means we also leave speculative preallocations in + * place for preallocated files. + */ + if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { + if (ip->i_delayed_blks) { + xfs_bmap_punch_delalloc_range(ip, + round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), + LLONG_MAX); + } + xfs_inode_clear_eofblocks_tag(ip); + return 0; + } + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); if (error) { ASSERT(xfs_is_shutdown(mp)); @@ -1048,7 +1062,7 @@ xfs_prepare_shift( * Trim eofblocks to avoid shifting uninitialized post-eof preallocation * into the accessible region of the file. */ - if (xfs_can_free_eofblocks(ip, true)) { + if (xfs_can_free_eofblocks(ip)) { error = xfs_free_eofblocks(ip); if (error) return error; diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h index 6888078f5c31..1383019ccdb7 100644 --- a/fs/xfs/xfs_bmap_util.h +++ b/fs/xfs/xfs_bmap_util.h @@ -63,7 +63,7 @@ int xfs_insert_file_space(struct xfs_inode *, xfs_off_t offset, xfs_off_t len); /* EOF block manipulation functions */ -bool xfs_can_free_eofblocks(struct xfs_inode *ip, bool force); +bool xfs_can_free_eofblocks(struct xfs_inode *ip); int xfs_free_eofblocks(struct xfs_inode *ip); int xfs_swap_extents(struct xfs_inode *ip, struct xfs_inode *tip, diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index db88f41c94c6..57a9f2317525 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -1149,7 +1149,7 @@ xfs_inode_free_eofblocks( } *lockflags |= XFS_IOLOCK_EXCL; - if (xfs_can_free_eofblocks(ip, false)) + if (xfs_can_free_eofblocks(ip)) return xfs_free_eofblocks(ip); /* inode could be preallocated or append-only */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 8bfde8fce6e2..7aa73855fab6 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1469,7 +1469,7 @@ xfs_release( if (!xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) return 0; - if (xfs_can_free_eofblocks(ip, false)) { + if (xfs_can_free_eofblocks(ip)) { /* * Check if the inode is being opened, written and closed * frequently and we have delayed allocation blocks outstanding @@ -1685,15 +1685,13 @@ xfs_inode_needs_inactive( /* * This file isn't being freed, so check if there are post-eof blocks - * to free. @force is true because we are evicting an inode from the - * cache. Post-eof blocks must be freed, lest we end up with broken - * free space accounting. + * to free. * * Note: don't bother with iolock here since lockdep complains about * acquiring it in reclaim context. We have the only reference to the * inode at this point anyways. */ - return xfs_can_free_eofblocks(ip, true); + return xfs_can_free_eofblocks(ip); } /* @@ -1741,15 +1739,11 @@ xfs_inactive( if (VFS_I(ip)->i_nlink != 0) { /* - * force is true because we are evicting an inode from the - * cache. Post-eof blocks must be freed, lest we end up with - * broken free space accounting. - * * Note: don't bother with iolock here since lockdep complains * about acquiring it in reclaim context. We have the only * reference to the inode at this point anyways. */ - if (xfs_can_free_eofblocks(ip, true)) + if (xfs_can_free_eofblocks(ip)) error = xfs_free_eofblocks(ip); goto out;