From patchwork Thu Aug 15 19:32:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13765188 Received: from dwarf.ash.relay.mailchannels.net (dwarf.ash.relay.mailchannels.net [23.83.222.53]) (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 72C9214F9D6 for ; Thu, 15 Aug 2024 21:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.222.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723757082; cv=pass; b=V/VQUJuhlwPaKuM4FZ0X1gWyEr+WQjjtz/XW+J5+01grlh8xRE30bfDEQlGsjh0zzA8lAiiG4fuMi0VtAuPbvPCcm8YziVMPeKBU1y3l/XzscSmNrKZOtLRamtl30XlNr4mWCcHo3kY7xQPyt1gd+pb5AfprAXdVRqB64T58ElA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723757082; c=relaxed/simple; bh=oN/PUDnAjVWq+DgxdfEgfhbKENytoMooS7/fbncWYqE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oeGWFLHKw6BuTvsFKURnjPZiFZPumd5MClezKDs0xcSrEeb9zBSuLlMC5b6X9WHv2DPh1mWXeIfhsERquIQaEyNgTWXo4NxZI8D9GkBaMmM6oI/C7ZWPxnedKscQIUhVMDHGWkKVe1MFGOmf12Q3W6JEEogin/a2QxmFCLNAgh8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=MwOsakGs; arc=pass smtp.client-ip=23.83.222.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="MwOsakGs" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 000CD7A7ABB for ; Thu, 15 Aug 2024 21:17:30 +0000 (UTC) Received: from pdx1-sub0-mail-a258.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A75CE7A7BED for ; Thu, 15 Aug 2024 21:17:29 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1723756649; a=rsa-sha256; cv=none; b=cy/UWW2N3T6Ow04rBV6pmKQ/arXHTyXvRLOXVdPXNZqh7NQeQd9Jd3YFtCK972Abk6XDYT FGSDC6twwXIBlEfVEA9WwtKBgAET3ekAhZaoKLgg95AVoQt3P2SN5kUMdybAPjgIw2+34U hI4tRHdH9sPYIfWLJahqRt7pDs2UWC23MX32PecEDLw3nbb53jrA+fTjamHu4FWjohSEGG jGHZLnejVHkScD0JXczBWL87WFdLhdYR4TGxkHVMP4e0mmAMGQt2kpcVw/406VpMRUVbMq /3wYKkCKU392ROrNExTBSMdYb7OGUdbasZetWupW+e7gEN6ZR9NtBS1toYa0vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1723756649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: resent-to:resent-from:resent-message-id:in-reply-to:in-reply-to: references:references:dkim-signature; bh=ONJXDFMJbMD3oLnJMrIEFCbjfNXrSfx2YBc+dEYC7bM=; b=JIzEK7DqCq83awuhQwTVlrBhz1oHBePyXQn41M4/j51p6S/Wd4bPHB+CDS+bNYDdWHggxm VqpANlmMkilv/fmbDLZldlDL4Zdxx1v1mtRiEQT6Z5VtzGkJMLpxUZwwCIUdbFArWmZoZR ylXkXvsBCXd5vQL6ITt76blkJoNkXSnK/bcoTyv6ar2LY6HmV3GWtnSiXikr/9+727kfQe pBerbABxKVYWEeVTmSeY9RKSlJj2nZN8zq6jKo+7v86MQ19B96gHRw5MHqng5pE22mC8m6 MUGtuaf1aL9VMtK4nHpg1C0s7Eq8Yl4n5dZoOia4O8jXyVmXNveVpEjkoG/e9A== ARC-Authentication-Results: i=1; rspamd-587694846-t85ng; auth=pass smtp.auth=dreamhost smtp.mailfrom=johansen@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Thread-Snatch: 3d5a9e1f13012ce2_1723756649898_3258734874 X-MC-Loop-Signature: 1723756649898:3609826451 X-MC-Ingress-Time: 1723756649898 Received: from pdx1-sub0-mail-a258.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.101.250.139 (trex/7.0.2); Thu, 15 Aug 2024 21:17:29 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a258.dreamhost.com (Postfix) with ESMTPSA id 4WlHyK35VwzYv for ; Thu, 15 Aug 2024 14:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1723756649; bh=ONJXDFMJbMD3oLnJMrIEFCbjfNXrSfx2YBc+dEYC7bM=; h=Date:From:To:Cc:Subject:Content-Type; b=MwOsakGsMmWhxb6mJdJE1vGK1VyAxnyMpD6CFAGwrdT4T/4jVMfb9UJEZSl/kLQH0 dBp9KHY+47QFyRp0k7aS4UwPox26GFxbcPKqlkDxp2YVmNwe2sOnfsOnyNMrGYy9Ac Fy4z9wbjm2V2Ym9L2csFGG2Vu9Wc85uTaO2joa3twUami9zwPtqomkiCDGMeSuRXaT N7AQ4Y3dcyT6KG8rlRGU7hhABeyg3MeWDtkuImTJQlsnb6iYUNRXZ/C3mGaicKhEJL FKAPup8V+JE+sDgwGKWJHNuLmWV8iRZQQzkUHIYvdD8cdp2TGDias8cXGQTqqEfcfm 2TQDYesJCEurA== Received: from johansen (uid 1000) (envelope-from johansen@templeofstupid.com) id e0064 by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 15 Aug 2024 14:17:28 -0700 Resent-From: Krister Johansen Resent-Date: Thu, 15 Aug 2024 14:17:28 -0700 Resent-Message-ID: <20240815211728.GA1957@templeofstupid.com> Resent-To: linux-xfs@vger.kernel.org Date: Thu, 15 Aug 2024 12:32:45 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Dave Chinner , Zorro Lang , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 2/5] xfs: move calculation in xfs_alloc_min_freelist to its own function Message-ID: <7e4310e32168cc4aa9f3a0782a6f6fabcaf476d5.1723688622.git.kjlx@templeofstupid.com> References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: This splits xfs_alloc_min_freelist into two pieces. The piece that remains in the function determines the appropriate level to pass to the calculation function. The calcution is extracted into its own inline function so that it can be used in multiple locations in xfs_alloc. No functional change. A subsequent patch will leverage this split. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_alloc.c | 75 +++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 59326f84f6a5..17e029bb1b6d 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -79,6 +79,46 @@ xfs_prealloc_blocks( return XFS_IBT_BLOCK(mp) + 1; } +static inline unsigned int +xfs_alloc_min_freelist_calc( + const unsigned int bno_level, + const unsigned int cnt_level, + const unsigned int rmap_level) +{ + unsigned int min_free; + + /* + * For a btree shorter than the maximum height, the worst case is that + * every level gets split and a new level is added, then while inserting + * another entry to refill the AGFL, every level under the old root gets + * split again. This is: + * + * (full height split reservation) + (AGFL refill split height) + * = (current height + 1) + (current height - 1) + * = (new height) + (new height - 2) + * = 2 * new height - 2 + * + * For a btree of maximum height, the worst case is that every level + * under the root gets split, then while inserting another entry to + * refill the AGFL, every level under the root gets split again. This is + * also: + * + * 2 * (current height - 1) + * = 2 * (new height - 1) + * = 2 * new height - 2 + */ + + /* space needed by-bno freespace btree */ + min_free = bno_level * 2 - 2; + /* space needed by-size freespace btree */ + min_free += cnt_level * 2 - 2; + /* space needed reverse mapping used space btree */ + if (rmap_level) + min_free += rmap_level * 2 - 2; + + return min_free; +} + /* * The number of blocks per AG that we withhold from xfs_dec_fdblocks to * guarantee that we can refill the AGFL prior to allocating space in a nearly @@ -152,7 +192,6 @@ xfs_alloc_ag_max_usable( return mp->m_sb.sb_agblocks - blocks; } - static int xfs_alloc_lookup( struct xfs_btree_cur *cur, @@ -2449,39 +2488,13 @@ xfs_alloc_min_freelist( const unsigned int bno_level = pag ? pag->pagf_bno_level : 1; const unsigned int cnt_level = pag ? pag->pagf_cnt_level : 1; const unsigned int rmap_level = pag ? pag->pagf_rmap_level : 1; - unsigned int min_free; ASSERT(mp->m_alloc_maxlevels > 0); - /* - * For a btree shorter than the maximum height, the worst case is that - * every level gets split and a new level is added, then while inserting - * another entry to refill the AGFL, every level under the old root gets - * split again. This is: - * - * (full height split reservation) + (AGFL refill split height) - * = (current height + 1) + (current height - 1) - * = (new height) + (new height - 2) - * = 2 * new height - 2 - * - * For a btree of maximum height, the worst case is that every level - * under the root gets split, then while inserting another entry to - * refill the AGFL, every level under the root gets split again. This is - * also: - * - * 2 * (current height - 1) - * = 2 * (new height - 1) - * = 2 * new height - 2 - */ - - /* space needed by-bno freespace btree */ - min_free = min(bno_level + 1, mp->m_alloc_maxlevels) * 2 - 2; - /* space needed by-size freespace btree */ - min_free += min(cnt_level + 1, mp->m_alloc_maxlevels) * 2 - 2; - /* space needed reverse mapping used space btree */ - if (xfs_has_rmapbt(mp)) - min_free += min(rmap_level + 1, mp->m_rmap_maxlevels) * 2 - 2; - return min_free; + return xfs_alloc_min_freelist_calc( + min(bno_level + 1, mp->m_alloc_maxlevels), + min(cnt_level + 1, mp->m_alloc_maxlevels), + xfs_has_rmapbt(mp) ? min(rmap_level + 1, mp->m_rmap_maxlevels) : 0); } /* From patchwork Thu Aug 15 19:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13765117 Received: from cross.elm.relay.mailchannels.net (cross.elm.relay.mailchannels.net [23.83.212.46]) (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 E609A13C906 for ; Thu, 15 Aug 2024 19:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.212.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723751678; cv=pass; b=nVqbmbnq1AoN9DG8IJ8cVgA8uO3GBnDmPY58jW0pPMG6uNZjZ/mzsN1z5YtGfzGmgfAq8PHe+qhB0vYkRuWrSbM9K6iGyGUGV1GaM6SbnTmC45YvjkFGlxqQ4ZZm4rl6I7AGDBRo9unqlkzaN5B+0mNW6zVg6ZtjxNnWyFx2gFY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723751678; c=relaxed/simple; bh=f/ym/HhI+ad2ud3xHFvHvQqkvkiRfRFQ2kpUJ75CE8Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kmnV5VjdwjnZG+8BZUbGZ0cLcMEj+DUfMsr0AswA1QfJ+YP9EdSAm76JucGA5dIgo00hJbBy6A8w5S4js6oyfpTZ3yIq7jTtjjV7Gj+SYgK672elXyXhbc3q9wZcHqQmofUhOwmjv6KBY3GYtLvmSjNa4wSTRsuE/QqBs5z/xbU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=pxOM23Vb; arc=pass smtp.client-ip=23.83.212.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="pxOM23Vb" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6198A2C3EDA for ; Thu, 15 Aug 2024 19:34:51 +0000 (UTC) Received: from pdx1-sub0-mail-a210.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 16F1A2C50EC for ; Thu, 15 Aug 2024 19:34:51 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1723750491; a=rsa-sha256; cv=none; b=rB8zjbkFp88Y5F21MvPTbS8VXmU8TMYD0oN9enjSt8v0cXpUV4wvWYOul0/14h5TzREWix gkSlj5YJcFvNjN34YjsnEOg/TVGnD4HcwYrlyKdbrxbdj/ogTj9Ok2kCZ331inaPakZz/D s1bc+UXWBsQ5tuMYYZm6OHWxwSJLD8u38zsv8As5ljtMzVNl2s8+uPVdGpPDTSC0NQav5B ETSvut8+PBzIH2jb8QVswjnMh0HKidl/JSFhfDNzaQUU31Sgn2Nz/S8lJjUV28kIH7lJFg SQe4hXyd7TSrKI3MfmQnQFW2czwt87Cq0BSKGY249C//57VJXQEjezZkovEDsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1723750491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OTZU2GHi0cFIUNIMsupcprXCrGD2KiplaAerMY4u130=; b=Iuk5ETnxxyNKmCItKgAP8QgX7cJIQ3DI26dqHIT0f4kt9Uh34HAkKY7CTjOWDZQGJTjJkv 246Ujm/Yfp6hHxtWNeAVvSdy8/3gu6CHFvZOnf44aTKCV4qwfsVOTFqpzw1YIuQvCkP8aB aYEoQVwkUsr93OCmnfDZjJ2zyV2mA+LDAcirNjamvV0oC8tjfgbSK9+bRwRI/J9wKUiCt5 lgvsWN9ycxD1ZdIb6NRA7MHEkNNWQXwmJPASC2pUwhTH+fEEdTx9G506L4y22PE4Ou/boD aFpAgwu068BmfHuAJXgwGcwbmRBHvbbWoBa/lNXA9VUXpnfPieWNBKyLHVhSOQ== ARC-Authentication-Results: i=1; rspamd-587694846-cqc8b; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Average-Absorbed: 2b146f883df8cb89_1723750491308_2652576341 X-MC-Loop-Signature: 1723750491308:1308885418 X-MC-Ingress-Time: 1723750491308 Received: from pdx1-sub0-mail-a210.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.117.75.38 (trex/7.0.2); Thu, 15 Aug 2024 19:34:51 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a210.dreamhost.com (Postfix) with ESMTPSA id 4WlFgt6W1Cz1x for ; Thu, 15 Aug 2024 12:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1723750490; bh=OTZU2GHi0cFIUNIMsupcprXCrGD2KiplaAerMY4u130=; h=Date:From:To:Cc:Subject:Content-Type; b=pxOM23VbFZ6DXUgMDDvc0LdqXLWbOzjUlhG+McdghFZxE0Y4NytFtQwusPsn6mSAo DaHIjTCIZnfWiReQwLhLKHO5H7jGWS6Cx2aJ4V4bo+E7axCdR+X6OwVIVOF0992J8d OAq4XoNA4vUOuyFvEW6en57/Jvdv/tdJLR02iIiph8zXXxj5Gg+Ecgk/HHfHGf2qQF wuaMnHPWBm3HeiDDxyBJjXHkMlZbzxSsYL0OMSKEsKUROc+AZ7M6omOL7M9qY2avZN T3lWWc3c/mpCd70GDyI1vuhKOm49t1MgWdwH2/7zBerm+S8UOxv89MGhc/UEr73hnb Uu3iPPcGpO6UQ== Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e0064 by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 15 Aug 2024 12:34:49 -0700 Date: Thu, 15 Aug 2024 12:34:49 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Dave Chinner , Zorro Lang , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 4/5] xfs: push the agfl set aside into xfs_alloc_space_available Message-ID: References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The blocks that have been set aside for dependent allocations and freelist refilling at reservation induced ENOSPC are deducted from m_ag_max_usable, which prevents them from being factored into the longest_free_extent and maxlen calculations. However, it's still possible to eat into this space by making multiple small allocations. Catch this case by withholding the space that's been set aside in xfs_alloc_space_available's available space calculation. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_alloc.c | 15 +++++++++++++-- fs/xfs/libxfs/xfs_alloc.h | 1 + fs/xfs/xfs_mount.c | 1 + fs/xfs/xfs_mount.h | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 826f527d20f2..4dd401d407c2 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -153,7 +153,7 @@ xfs_alloc_min_freelist_calc( * middle of dependent allocations when they are close to hitting the * reservation-induced limits. */ -static unsigned int +unsigned int xfs_allocbt_agfl_reserve( struct xfs_mount *mp) { @@ -2593,6 +2593,7 @@ xfs_alloc_space_available( xfs_extlen_t reservation; /* blocks that are still reserved */ int available; xfs_extlen_t agflcount; + xfs_extlen_t set_aside = 0; if (flags & XFS_ALLOC_FLAG_FREEING) return true; @@ -2605,6 +2606,16 @@ xfs_alloc_space_available( if (longest < alloc_len) return false; + /* + * Withhold from the available space any that has been set-aside as a + * reserve for refilling the AGFL close to ENOSPC. In the case where a + * dependent allocation is in progress, allow that space to be consumed + * so that the dependent allocation may complete successfully. Without + * this, we may ENOSPC in the middle of the allocation chain and + * shutdown the filesystem. + */ + if (args->tp->t_highest_agno == NULLAGNUMBER) + set_aside = args->mp->m_ag_agfl_setaside; /* * Do we have enough free space remaining for the allocation? Don't * account extra agfl blocks because we are about to defer free them, @@ -2612,7 +2623,7 @@ xfs_alloc_space_available( */ agflcount = min_t(xfs_extlen_t, pag->pagf_flcount, min_free); available = (int)(pag->pagf_freeblks + agflcount - - reservation - min_free - args->minleft); + reservation - min_free - args->minleft - set_aside); if (available < (int)max(args->total, alloc_len)) return false; diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index fae170825be0..7e92c4c455a1 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -70,6 +70,7 @@ typedef struct xfs_alloc_arg { /* freespace limit calculations */ unsigned int xfs_alloc_set_aside(struct xfs_mount *mp); unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp); +unsigned int xfs_allocbt_agfl_reserve(struct xfs_mount *mp); xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag, xfs_extlen_t need, xfs_extlen_t reserved); diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index ec1f7925b31f..1bc80983310a 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1002,6 +1002,7 @@ xfs_mountfs( */ mp->m_alloc_set_aside = xfs_alloc_set_aside(mp); mp->m_ag_max_usable = xfs_alloc_ag_max_usable(mp); + mp->m_ag_agfl_setaside = xfs_allocbt_agfl_reserve(mp); /* * Now we are mounted, reserve a small amount of unused space for diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 800788043ca6..4a9321424954 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -220,6 +220,11 @@ typedef struct xfs_mount { * one. */ uint m_ag_resblk_count; + /* + * Blocks set aside to refill the agfl at ENOSPC and satisfy any + * dependent allocation resulting from a chain of BMBT splits. + */ + uint m_ag_agfl_setaside; struct delayed_work m_reclaim_work; /* background inode reclaim */ struct dentry *m_debugfs; /* debugfs parent */ struct xfs_kobj m_kobj; From patchwork Thu Aug 15 19:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13765187 Received: from skyblue.cherry.relay.mailchannels.net (skyblue.cherry.relay.mailchannels.net [23.83.223.167]) (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 2250814E2F5 for ; Thu, 15 Aug 2024 21:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.223.167 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723757080; cv=pass; b=a/2A+kwZxyKMya3CtiZmkczT1Vwb5YuHIrZgZosEeR+kWkuTbzFnZAVDwKg/q/wH0AUHTJTWn7HONrAOg5zgYkqegJ2vdseCHpt36zezV5KzFoBPkhmD24S7T4qq/D7V5+wEoniWFkn8lglsdXQPcdC0cb/zvTqFTCxyjtvxOzw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723757080; c=relaxed/simple; bh=QQK6GS69aXX+74krEAXspDA0eQU5MIwzbpRH8P40iVE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Sp8+iTT/ER4r/1VbGYSjcKIg0geggIKS4xV+cLN+2PLiroL5kh9vrmdDsvVmhlBCBmuhEvdfKscrekA1bwsBIUuQigYBTYsqjDo+H01Z+jszOePlWS41ckI6WCclus8UvDYyrJfxmmsqRGDn/8UtOHm0jIrcArNFcx5RlNlTXOQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=O/+YGfyH; arc=pass smtp.client-ip=23.83.223.167 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="O/+YGfyH" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id CD33F14613F for ; Thu, 15 Aug 2024 21:17:29 +0000 (UTC) Received: from pdx1-sub0-mail-a258.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 81400146C0D for ; Thu, 15 Aug 2024 21:17:29 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1723756649; a=rsa-sha256; cv=none; b=nxQvxtewhG2BaKD/pdRZK5phDLTPSfiZ0Y6MQ538AlVO6w8BzkdbuQy5T8kDHIsGn0Pk1r TcPP5I8HLxG7GbbB+KvmQdH6CQib+gGogt/wcZyV6BDp71qJTNTBC4L5q6MrtMnW7upWs8 wVlGUq4h8tiJYWm4A1Ad6MvKWyh1a64/4OOSleQo85S78ZIx6qGC3NJkzXs+5DJSTNNrPE F9wG9ta01TvLC5Ubqv3WfWm1+Dv4HSy11q4LCiMYwtYUFWZn2t/aPZgnMieWdxMJlGJ5vW o+GLKgFLaxurXNQCNp9JfMEPEP4Og6FsyKhRSE5wVFR98U+Z0KquvcgyUAP7qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1723756649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: resent-to:resent-from:resent-message-id:in-reply-to:in-reply-to: references:references:dkim-signature; bh=RBN71pbRJTwK1EZaifhgiID77GSAsx/n1jmj9UaAqpI=; b=2CqNyczV59PLXvLgagoUvj4QyPCSfnOGdlOh+ku4D72HSVuaK0VgQHmCORfZKJ8ujYieya vfG4w7YYSSo2ioNzMYWAs1bEpEv2cKv6aGNg/ZmaT/OH9dPfUi3aXkwd/6NO47XH0tyBRW pe7lWuzjxLuOBhdi/rS7RfVWxNqw6cIQIx5sSibG47ldspXw2KAgAbM1lvJheR/vbfYRve Ee21rsEB7dIvcRTiNZYQF146zqFLWr3deMNy9TB2J/1ec85RW8D89VnaS6hR0gFu3YTRI1 lYc4veZAGDhba/RLBsdjnpJmBI9qexusjZUTBc+j31e/QQmdyw6TQFa/bDqawA== ARC-Authentication-Results: i=1; rspamd-587694846-7tw8q; auth=pass smtp.auth=dreamhost smtp.mailfrom=johansen@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Inform-Shoe: 3cb03cdb7cff3d28_1723756649742_1857344380 X-MC-Loop-Signature: 1723756649742:687845733 X-MC-Ingress-Time: 1723756649741 Received: from pdx1-sub0-mail-a258.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.111.125.119 (trex/7.0.2); Thu, 15 Aug 2024 21:17:29 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a258.dreamhost.com (Postfix) with ESMTPSA id 4WlHyK2LLRz6H for ; Thu, 15 Aug 2024 14:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1723756649; bh=RBN71pbRJTwK1EZaifhgiID77GSAsx/n1jmj9UaAqpI=; h=Date:From:To:Cc:Subject:Content-Type; b=O/+YGfyHlzTvlKzSr38H4uCzJ0747UU0fN9j5F4r34ZWFO/bXi4+jWq0fCMHI6Ilo oWsMLu0/1OUJQdoNQonCWWRj4sclbykuIQIXu+U/eQsJF37uMsiKqE6mMYqDwcVnov VMZ8ShagWqNPY2hcJvEon0I7lOmhEJmH64kdnIujzNuymnQQM6UzoWjthAyqIHmREt yb9dZKbvbtlZ1pFJEuMCBCSmB7+pnstI+ivATJ8HocydjzI7F72Shfh4RngPcFWWVq eJH+E5wV3VWxKXCQD4K6H/4QqNTN9UOOKekgi+Fl5XiiKk8gJz/ncEhnuBeSeRomdU 9PL8Cf6DSXKgg== Received: from johansen (uid 1000) (envelope-from johansen@templeofstupid.com) id e0138 by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 15 Aug 2024 14:17:28 -0700 Resent-From: Krister Johansen Resent-Date: Thu, 15 Aug 2024 14:17:28 -0700 Resent-Message-ID: <20240815211728.GB1957@templeofstupid.com> Resent-To: linux-xfs@vger.kernel.org Date: Thu, 15 Aug 2024 12:35:49 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Dave Chinner , Zorro Lang , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 5/5] xfs: include min freelist in m_ag_max_usable Message-ID: <4b9b30af3719389701c2dd00f8cb20f12043b3ee.1723688622.git.kjlx@templeofstupid.com> References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: If agfl_reserve blocks are conditionally withheld from consideration in xfs_alloc_space_available, then m_ag_max_usable overstates the amount of max available space on an empty filesystem by the amount of blocks that mkfs placed into the AGFL on our behalf. While this space _is_ technically free, it's not usable for a maximum sized allocation on an empty filesystem, because the blocks must remain in the AGFL in order for an allocation to succeed. Without this, stripe aligned allocations on an empty AG pick a size that they can't actually get which leads to allocations which can't be satisfied and that consequently come back unaligned. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_alloc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 4dd401d407c2..26447e6061b3 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -246,7 +246,9 @@ xfs_alloc_set_aside( * - the AG superblock, AGF, AGI and AGFL * - the AGF (bno and cnt) and AGI btree root blocks, and optionally * the AGI free inode and rmap btree root blocks. - * - blocks on the AGFL according to xfs_alloc_set_aside() limits + * - blocks on the AGFL when the filesystem is empty + * - blocks on needed to AGFL while performing dependent allocations close + * to ENOSPC as given by xfs_allocbt_agfl_reserve() * - the rmapbt root block * * The AG headers are sector sized, so the amount of space they take up is @@ -259,6 +261,13 @@ xfs_alloc_ag_max_usable( unsigned int blocks; blocks = XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)); /* ag headers */ + /* + * Minimal freelist length when filesystem is completely empty. + * xfs_alloc_min_freelist needs m_alloc_maxlevels so this is computed in + * our second invocation of xfs_alloc_ag_max_usable + */ + if (mp->m_alloc_maxlevels > 0) + blocks += xfs_alloc_min_freelist(mp, NULL); blocks += xfs_allocbt_agfl_reserve(mp); blocks += 3; /* AGF, AGI btree root blocks */ if (xfs_has_finobt(mp))