From patchwork Tue Sep 10 04:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13797903 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 DEA8F13E02C for ; Tue, 10 Sep 2024 04:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942551; cv=none; b=mk8dbLSbRXp5FwALy4CIX5XfqVhOMr5RoGmkhd8HL/hy72bBSkJvil4wl/Unc4CDNWBjJAbbTGFUCqvaltwZefg39FQ6o4Ki1sPhtb/OLhUIJa3iurEjkW9vQwEuAZDQ6xQol6SYCzjco5UIoePOwuSXD5Eomw50NNdVlHTnVfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942551; c=relaxed/simple; bh=+66Hb0HONJHDXHVkAlm2hGIduTudkweuULhhEx4Rdm4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X5tF2Cf/8vgBQCc3kQ6IKwZlSaHuYCaHS9M5JxVRbZuCAh85w0pFESyn+/ltjjbj7Cmeyq9ob4vAASi1TJtm4Ur39Y+t9e3oP1j1sHa79/S75Gib0+y1NnCBtu1Zy+eZiMGNZzcGhVGkcaNpZQJWvVNBeRlp6M7HYyg6Z5YA3Po= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=HigMMC9w; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="HigMMC9w" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=FrjixrgjMALszalxkCXHoLJyrauGFO7VUPv8RAXYHrw=; b=HigMMC9wIOuXxz4ONLEOXKsmtJ W0eFMw0kuXMIgN5x53lx6jCWkbSj+33X1GZ++IFa/cs/haEKXgf4w33TnPcetcl/MYj/SBlfgVBHi K668+GVzVtcg4roommHGRtMlpPi3x1D6c3hjIhfKQJSgQvdw0KeQOmoHl6yZPCQG/w+0/EXr7Dr7v k09dT4OTCGaOfcUT2K07uaiskwrvwQd77kk76WaJWdy45iQuxdoUqXNnw4hI5VV0fXn48nfcqyj/D /9idiFr2oQoBVIp0dt7z572pCnVkAhFCBD/csWxfIRgEs+higUcLHSOjnV18/ZQG/aAwTRaYqiLmx TYZSPvww==; Received: from ppp-2-84-49-240.home.otenet.gr ([2.84.49.240] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1snsUx-00000004D4r-3lR7; Tue, 10 Sep 2024 04:29:04 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 1/4] xfs: pass the exact range to initialize to xfs_initialize_perag Date: Tue, 10 Sep 2024 07:28:44 +0300 Message-ID: <20240910042855.3480387-2-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910042855.3480387-1-hch@lst.de> References: <20240910042855.3480387-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Currently only the new agcount is passed to xfs_initialize_perag, which requires lookups of existing AGs to skip them and complicates error handling. Also pass the previous agcount so that the range that xfs_initialize_perag operates on is exactly defined. That way the extra lookups can be avoided, and error handling can clean up the exact range from the old count to the last added perag structure. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_ag.c | 23 +++++------------------ fs/xfs/libxfs/xfs_ag.h | 5 +++-- fs/xfs/xfs_fsops.c | 18 ++++++++---------- fs/xfs/xfs_log_recover.c | 5 +++-- fs/xfs/xfs_mount.c | 4 ++-- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 5f0494702e0b55..5186735da5d45a 100644 --- a/fs/xfs/libxfs/xfs_ag.c +++ b/fs/xfs/libxfs/xfs_ag.c @@ -296,27 +296,19 @@ xfs_free_unused_perag_range( int xfs_initialize_perag( struct xfs_mount *mp, + xfs_agnumber_t old_agcount, xfs_agnumber_t agcount, xfs_rfsblock_t dblocks, xfs_agnumber_t *maxagi) { struct xfs_perag *pag; xfs_agnumber_t index; - xfs_agnumber_t first_initialised = NULLAGNUMBER; int error; - /* - * Walk the current per-ag tree so we don't try to initialise AGs - * that already exist (growfs case). Allocate and insert all the - * AGs we don't find ready for initialisation. - */ - for (index = 0; index < agcount; index++) { - pag = xfs_perag_get(mp, index); - if (pag) { - xfs_perag_put(pag); - continue; - } + if (old_agcount >= agcount) + return 0; + for (index = old_agcount; index < agcount; index++) { pag = kzalloc(sizeof(*pag), GFP_KERNEL | __GFP_RETRY_MAYFAIL); if (!pag) { error = -ENOMEM; @@ -353,10 +345,6 @@ xfs_initialize_perag( /* Active ref owned by mount indicates AG is online. */ atomic_set(&pag->pag_active_ref, 1); - /* first new pag is fully initialized */ - if (first_initialised == NULLAGNUMBER) - first_initialised = index; - /* * Pre-calculated geometry */ @@ -381,8 +369,7 @@ xfs_initialize_perag( out_free_pag: kfree(pag); out_unwind_new_pags: - /* unwind any prior newly initialized pags */ - xfs_free_unused_perag_range(mp, first_initialised, agcount); + xfs_free_unused_perag_range(mp, old_agcount, index); return error; } diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h index d9cccd093b60e0..69fc31e7b84728 100644 --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -146,8 +146,9 @@ __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart, xfs_agnumber_t agend); -int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount, - xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); +int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount, + xfs_agnumber_t agcount, xfs_rfsblock_t dcount, + xfs_agnumber_t *maxagi); int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); void xfs_free_perag(struct xfs_mount *mp); diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 3643cc843f6271..de2bf0594cb474 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -87,6 +87,7 @@ xfs_growfs_data_private( struct xfs_mount *mp, /* mount point for filesystem */ struct xfs_growfs_data *in) /* growfs data input struct */ { + xfs_agnumber_t oagcount = mp->m_sb.sb_agcount; struct xfs_buf *bp; int error; xfs_agnumber_t nagcount; @@ -94,7 +95,6 @@ xfs_growfs_data_private( xfs_rfsblock_t nb, nb_div, nb_mod; int64_t delta; bool lastag_extended = false; - xfs_agnumber_t oagcount; struct xfs_trans *tp; struct aghdr_init_data id = {}; struct xfs_perag *last_pag; @@ -138,16 +138,14 @@ xfs_growfs_data_private( if (delta == 0) return 0; - oagcount = mp->m_sb.sb_agcount; - /* allocate the new per-ag structures */ - if (nagcount > oagcount) { - error = xfs_initialize_perag(mp, nagcount, nb, &nagimax); - if (error) - return error; - } else if (nagcount < oagcount) { - /* TODO: shrinking the entire AGs hasn't yet completed */ + /* TODO: shrinking the entire AGs hasn't yet completed */ + if (nagcount < oagcount) return -EINVAL; - } + + /* allocate the new per-ag structures */ + error = xfs_initialize_perag(mp, oagcount, nagcount, nb, &nagimax); + if (error) + return error; if (delta > 0) error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata, diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 1a74fe22672e3e..2af02b32f419c2 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -3346,6 +3346,7 @@ xlog_do_recover( struct xfs_mount *mp = log->l_mp; struct xfs_buf *bp = mp->m_sb_bp; struct xfs_sb *sbp = &mp->m_sb; + xfs_agnumber_t old_agcount = sbp->sb_agcount; int error; trace_xfs_log_recover(log, head_blk, tail_blk); @@ -3393,8 +3394,8 @@ xlog_do_recover( /* re-initialise in-core superblock and geometry structures */ mp->m_features |= xfs_sb_version_to_features(sbp); xfs_reinit_percpu_counters(mp); - error = xfs_initialize_perag(mp, sbp->sb_agcount, sbp->sb_dblocks, - &mp->m_maxagi); + error = xfs_initialize_perag(mp, old_agcount, sbp->sb_agcount, + sbp->sb_dblocks, &mp->m_maxagi); if (error) { xfs_warn(mp, "Failed post-recovery per-ag init: %d", error); return error; diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 460f93a9ce00d1..0f4f56a7f02d9a 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -806,8 +806,8 @@ xfs_mountfs( /* * Allocate and initialize the per-ag data. */ - error = xfs_initialize_perag(mp, sbp->sb_agcount, mp->m_sb.sb_dblocks, - &mp->m_maxagi); + error = xfs_initialize_perag(mp, 0, sbp->sb_agcount, + mp->m_sb.sb_dblocks, &mp->m_maxagi); if (error) { xfs_warn(mp, "Failed per-ag init: %d", error); goto out_free_dir; From patchwork Tue Sep 10 04:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13797904 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 18BC214A4C3 for ; Tue, 10 Sep 2024 04:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942553; cv=none; b=ICDn0CkuPYzf9fIwrSInjbrTDEY0YAg5NKetmyEh8NMNAg/4hRi8w/a5/C8i3Vnd+t0aE444UpFomI9da7K3aZ7rFJUVcntX1i0YXVFCokAsfipqI6CEODVtxJQ+2iNmPOX/A07U98r/2kJtMXjfHljpkzopUteC9qJJtHOMPM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942553; c=relaxed/simple; bh=5nnXUtyYfZ7DLo7NaIxf2PdvDY+fx0h1jl/thkheHFY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=awFOUDFcYxzNM7gSMFt9qKpFY/UK8ARFINQl9E3kcRxYeMRi7+7CXzwGEHMAMab4zfa2BtPDTgTXxxDa/JSItJKZc0OAjWa4YvsZlu7FCZjLFb3uhNo0CeLtO/nrfzpGp83rrFruXYg2e5M8J/gOM0ZUVlpI8uZJ2sEiOe7KsjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=llkx/v6T; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="llkx/v6T" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+cwr44IoqVLLnQZA90U3ZGU+9W7x7ZS5rDhtOUdbAbU=; b=llkx/v6T810smL63+RmZbJdDLL bhapBML8aTE04jNUCQ2/UIQVvuvIk1sbpTkqHPJYi3Fv5cDvb1iV61jGrKJkKZAqdATaOuj6dZxNQ r7DTQ3oFXdr5ZdSIG70WzvYjAJnO4NJMXmmCxEchMbhwtrW8xY4czwR2+RYf7xZs+mYP5y5GvrOSl R70CpGoo7zo/xfgrEkxdIZfS5Ced7Q61HLIYMl3KVgMdPQK9DRk+xD+9k7Z+rBJTXbKHJttdWasC+ 56JKFqcwO73vx22xDodH5BfmBKIHLFgyyCp5//AdqhVoXGjKlGH+ZFBrfy5/8SQNzwAnqKt0A8oli 8k/uNKEA==; Received: from ppp-2-84-49-240.home.otenet.gr ([2.84.49.240] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1snsV2-00000004D5C-27Ci; Tue, 10 Sep 2024 04:29:09 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 2/4] xfs: merge the perag freeing helpers Date: Tue, 10 Sep 2024 07:28:45 +0300 Message-ID: <20240910042855.3480387-3-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910042855.3480387-1-hch@lst.de> References: <20240910042855.3480387-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html There is no good reason to have two different routines for freeing perag structures for the unmount and error cases. Add two arguments to specify the range of AGs to free to xfs_free_perag, and use that to replace xfs_free_unused_perag_range. The addition RCU grace period for the error case is harmless, and the extra check for the AG to actually exist is not required now that the callers pass the exact known allocated range. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_ag.c | 40 ++++++++++------------------------------ fs/xfs/libxfs/xfs_ag.h | 5 ++--- fs/xfs/xfs_fsops.c | 2 +- fs/xfs/xfs_mount.c | 5 ++--- 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 5186735da5d45a..3f695100d7ab58 100644 --- a/fs/xfs/libxfs/xfs_ag.c +++ b/fs/xfs/libxfs/xfs_ag.c @@ -185,17 +185,20 @@ xfs_initialize_perag_data( } /* - * Free up the per-ag resources associated with the mount structure. + * Free up the per-ag resources within the specified AG range. */ void -xfs_free_perag( - struct xfs_mount *mp) +xfs_free_perag_range( + struct xfs_mount *mp, + xfs_agnumber_t first_agno, + xfs_agnumber_t end_agno) + { - struct xfs_perag *pag; xfs_agnumber_t agno; - for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { - pag = xa_erase(&mp->m_perags, agno); + for (agno = first_agno; agno < end_agno; agno++) { + struct xfs_perag *pag = xa_erase(&mp->m_perags, agno); + ASSERT(pag); XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_ref) != 0); xfs_defer_drain_free(&pag->pag_intents_drain); @@ -270,29 +273,6 @@ xfs_agino_range( return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last); } -/* - * Free perag within the specified AG range, it is only used to free unused - * perags under the error handling path. - */ -void -xfs_free_unused_perag_range( - struct xfs_mount *mp, - xfs_agnumber_t agstart, - xfs_agnumber_t agend) -{ - struct xfs_perag *pag; - xfs_agnumber_t index; - - for (index = agstart; index < agend; index++) { - pag = xa_erase(&mp->m_perags, index); - if (!pag) - break; - xfs_buf_cache_destroy(&pag->pag_bcache); - xfs_defer_drain_free(&pag->pag_intents_drain); - kfree(pag); - } -} - int xfs_initialize_perag( struct xfs_mount *mp, @@ -369,7 +349,7 @@ xfs_initialize_perag( out_free_pag: kfree(pag); out_unwind_new_pags: - xfs_free_unused_perag_range(mp, old_agcount, index); + xfs_free_perag_range(mp, old_agcount, index); return error; } diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h index 69fc31e7b84728..6e68d6a3161a0f 100644 --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -144,13 +144,12 @@ __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA) __XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES) __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) -void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart, - xfs_agnumber_t agend); int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount, xfs_agnumber_t agcount, xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); +void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno, + xfs_agnumber_t end_agno); int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); -void xfs_free_perag(struct xfs_mount *mp); /* Passive AG references */ struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno); diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index de2bf0594cb474..b247d895c276d2 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -229,7 +229,7 @@ xfs_growfs_data_private( xfs_trans_cancel(tp); out_free_unused_perag: if (nagcount > oagcount) - xfs_free_unused_perag_range(mp, oagcount, nagcount); + xfs_free_perag_range(mp, oagcount, nagcount); return error; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 0f4f56a7f02d9a..6671ee3849c239 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1044,7 +1044,7 @@ xfs_mountfs( xfs_buftarg_drain(mp->m_logdev_targp); xfs_buftarg_drain(mp->m_ddev_targp); out_free_perag: - xfs_free_perag(mp); + xfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount); out_free_dir: xfs_da_unmount(mp); out_remove_uuid: @@ -1125,8 +1125,7 @@ xfs_unmountfs( xfs_errortag_clearall(mp); #endif shrinker_free(mp->m_inodegc_shrinker); - xfs_free_perag(mp); - + xfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount); xfs_errortag_del(mp); xfs_error_sysfs_del(mp); xchk_stats_unregister(mp->m_scrub_stats); From patchwork Tue Sep 10 04:28:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13797905 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 F19444F218 for ; Tue, 10 Sep 2024 04:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942557; cv=none; b=vCQQMOMYwvZhCmf4Ol6DkLXgVCDMheiRH2/5xO2BtkbPSjk4zSBsLYfJj8ebtPV3aZAeFff7YLijLzhvd9WTaCjufA5RjFXFzyaSZAxWQJlgk3Sq2CKx/9GPzw6WvO/af/Ibu+E4h7l7QOgyNeYHSX3B54eXqt4evunlaqI7+1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942557; c=relaxed/simple; bh=jIpi9wkMryaj2lQ/TmpFrUVbCL8BrCG11AuWi++BUVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UpKb8Op0N2WyH9BIn0HG+9b4DFj0mIqYffgVmF9DlyHrVNEoHHn69femswO6jmCnV2PERjf2Osm6Q3gpTvGZXWpPN/AUVzpuLJpAHIMd3BBeMqhLkh2eWoQS6Zdf4Wz9DwAJAGSkB92imlCgMwJWlX2m67AR7mqgDyjAgd3hKdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bkLGCd4o; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bkLGCd4o" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fHzWSW9D6RgjCkLxa927Ic+d+EEnNxvXQtpxOPO75vI=; b=bkLGCd4oJ5EKytV1lxOHTtXRRm Dx/nyDw7vvIyrd4to2Ucwrm1b+NOcsxd90Tf9gQmocW5TVCmY8txtC0WMcfCRLju1koOlYh0kh1pT RLSJlWY6wkuT2bkWV0+54nWOGKUPqvcRGyTIstXlvReKfF1ifkVmQxNxONYI4325ue5XDDt6fH0WC 62CFNkz82Ez67LSa5M3xn0DuKVUOtIFhnDCaDgWMPRzah8MjlMQRlsZV8nlRKAst4O+P+aoyTtS9p kgQvq92VPk/V5N8Tt8BoJcz0uv1IRklYdBj9UVvFCj0fOQtOKZRMZraniKe1hmrDxWWMjsd1RRn/8 j2vJ8F6Q==; Received: from ppp-2-84-49-240.home.otenet.gr ([2.84.49.240] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1snsV7-00000004D6A-2rxi; Tue, 10 Sep 2024 04:29:14 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 3/4] xfs: create perag structures as soon as possible during log recovery Date: Tue, 10 Sep 2024 07:28:46 +0300 Message-ID: <20240910042855.3480387-4-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910042855.3480387-1-hch@lst.de> References: <20240910042855.3480387-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html An unclean log can contain both the transaction that created a new allocation group and the first transaction that is freeing space from it, in which case the extent free item recovery requires the perag structure to be present. Currently the perag structures are only created after log recovery has completed, leading a warning and file system shutdown for the above case. Fix this by creating new perag structures and updating the in-memory superblock fields as soon a buffer log item that covers the primary super block is recovered. Signed-off-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_log_recover.h | 2 ++ fs/xfs/xfs_buf_item_recover.c | 16 +++++++++ fs/xfs/xfs_log_recover.c | 59 ++++++++++++++------------------- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/fs/xfs/libxfs/xfs_log_recover.h b/fs/xfs/libxfs/xfs_log_recover.h index 521d327e4c89ed..d0e13c84422d0a 100644 --- a/fs/xfs/libxfs/xfs_log_recover.h +++ b/fs/xfs/libxfs/xfs_log_recover.h @@ -165,4 +165,6 @@ void xlog_recover_intent_item(struct xlog *log, struct xfs_log_item *lip, int xlog_recover_finish_intent(struct xfs_trans *tp, struct xfs_defer_pending *dfp); +int xlog_recover_update_agcount(struct xfs_mount *mp, struct xfs_dsb *dsb); + #endif /* __XFS_LOG_RECOVER_H__ */ diff --git a/fs/xfs/xfs_buf_item_recover.c b/fs/xfs/xfs_buf_item_recover.c index 09e893cf563cb9..033821a56b6ac6 100644 --- a/fs/xfs/xfs_buf_item_recover.c +++ b/fs/xfs/xfs_buf_item_recover.c @@ -969,6 +969,22 @@ xlog_recover_buf_commit_pass2( goto out_release; } else { xlog_recover_do_reg_buffer(mp, item, bp, buf_f, current_lsn); + + /* + * Update the in-memory superblock and perag structures from the + * primary SB buffer. + * + * This is required because transactions running after growf + * s may require in-memory structures like the perag right after + * committing the growfs transaction that created the underlying + * objects. + */ + if ((xfs_blft_from_flags(buf_f) & XFS_BLFT_SB_BUF) && + xfs_buf_daddr(bp) == 0) { + error = xlog_recover_update_agcount(mp, bp->b_addr); + if (error) + goto out_release; + } } /* diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 2af02b32f419c2..7d7ab146cae758 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -3334,6 +3334,30 @@ xlog_do_log_recovery( return error; } +int +xlog_recover_update_agcount( + struct xfs_mount *mp, + struct xfs_dsb *dsb) +{ + xfs_agnumber_t old_agcount = mp->m_sb.sb_agcount; + int error; + + xfs_sb_from_disk(&mp->m_sb, dsb); + if (mp->m_sb.sb_agcount < old_agcount) { + xfs_alert(mp, "Shrinking AG count in log recovery"); + return -EFSCORRUPTED; + } + mp->m_features |= xfs_sb_version_to_features(&mp->m_sb); + error = xfs_initialize_perag(mp, old_agcount, mp->m_sb.sb_agcount, + mp->m_sb.sb_dblocks, &mp->m_maxagi); + if (error) { + xfs_warn(mp, "Failed recovery per-ag init: %d", error); + return error; + } + mp->m_alloc_set_aside = xfs_alloc_set_aside(mp); + return 0; +} + /* * Do the actual recovery */ @@ -3343,10 +3367,6 @@ xlog_do_recover( xfs_daddr_t head_blk, xfs_daddr_t tail_blk) { - struct xfs_mount *mp = log->l_mp; - struct xfs_buf *bp = mp->m_sb_bp; - struct xfs_sb *sbp = &mp->m_sb; - xfs_agnumber_t old_agcount = sbp->sb_agcount; int error; trace_xfs_log_recover(log, head_blk, tail_blk); @@ -3371,36 +3391,7 @@ xlog_do_recover( */ xfs_ail_assign_tail_lsn(log->l_ailp); - /* - * Now that we've finished replaying all buffer and inode updates, - * re-read the superblock and reverify it. - */ - xfs_buf_lock(bp); - xfs_buf_hold(bp); - error = _xfs_buf_read(bp, XBF_READ); - if (error) { - if (!xlog_is_shutdown(log)) { - xfs_buf_ioerror_alert(bp, __this_address); - ASSERT(0); - } - xfs_buf_relse(bp); - return error; - } - - /* Convert superblock from on-disk format */ - xfs_sb_from_disk(sbp, bp->b_addr); - xfs_buf_relse(bp); - - /* re-initialise in-core superblock and geometry structures */ - mp->m_features |= xfs_sb_version_to_features(sbp); - xfs_reinit_percpu_counters(mp); - error = xfs_initialize_perag(mp, old_agcount, sbp->sb_agcount, - sbp->sb_dblocks, &mp->m_maxagi); - if (error) { - xfs_warn(mp, "Failed post-recovery per-ag init: %d", error); - return error; - } - mp->m_alloc_set_aside = xfs_alloc_set_aside(mp); + xfs_reinit_percpu_counters(log->l_mp); /* Normal transactions can now occur */ clear_bit(XLOG_ACTIVE_RECOVERY, &log->l_opstate); From patchwork Tue Sep 10 04:28:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13797906 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 348254F218 for ; Tue, 10 Sep 2024 04:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942562; cv=none; b=ThpjAoLQuXWSXmjE49eHTsaHEoCLViSBFuASuyhwY0UNgnw2JkHwnIlkQXDGHjhE+qcBaG18LgYT/owWDMJk8NBPTg8TtOs3PlA4ZevjUXM1YdE56+yPkbhA1i/WUsnd1mSQRvUtkHQtgqjtFQ5Qa5/wiSgNAc+d1ZpqTMZzNj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725942562; c=relaxed/simple; bh=vibFHODPyXyrojWLXyyCmx+KZ5g1as08RQPHjKkL2U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S0W4rfAUzJ2Fh9GtQaoFPawOJK2+hlcIcKAe46U2BRvrwChxeqiHKTp0POWi3WwhY+L2FLDtGXKwzJp2f5RMQTQ6RdHSXlOQw6omrplvFIlNlU0BeBIsrV1VEGWLuWtZfEimhHKm4e2QC2h49JY1h06pkBBQPEXIZ0spr4TOsnI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=x2qKpRMp; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="x2qKpRMp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=3kx0Urg4gMKwHM6v/+uL6M0iwQfWAI2BoAoI4nak4rM=; b=x2qKpRMpkcP4zW7xz9sviGQ86Y Kz1AJC0C8gUeAP7VkC6rTeGYhXbJ0u8mwkahGidP0leTX0K8clvWpnu92iG3JY6ynGu5/apHru2uT 99YZxjO2p0VVtCeJIuUfvc76jYmufcH13J10ZIkfT/8kl0JD2qOdwM9S2CPpK2PvFLsEKxBLS9XNZ rKwQcy4VKH3NEYZAUvnfE4ZgO0aSkLQL3kICw6oj2y7vX6EJLNLYVDlehcHUFiCtia7+/xdRJH9ah cMd6JBeUH+u4teul/1AKiiv4YONFRfJUSmXE7cZXArxSy6JcwbO8CkDynwrf7zMP1wApbIOClMbZj KBM+ZZhw==; Received: from ppp-2-84-49-240.home.otenet.gr ([2.84.49.240] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1snsVC-00000004D7U-1dbt; Tue, 10 Sep 2024 04:29:20 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 4/4] xfs: don't use __GFP_RETRY_MAYFAIL Date: Tue, 10 Sep 2024 07:28:47 +0300 Message-ID: <20240910042855.3480387-5-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910042855.3480387-1-hch@lst.de> References: <20240910042855.3480387-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html __GFP_RETRY_MAYFAIL increases the likelyhood of allocations to fail, which isn't really helpful during log recovery. Remove the flag and stick to the default GFP_KERNEL policies. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_ag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 3f695100d7ab58..f6c666a87dd393 100644 --- a/fs/xfs/libxfs/xfs_ag.c +++ b/fs/xfs/libxfs/xfs_ag.c @@ -289,7 +289,7 @@ xfs_initialize_perag( return 0; for (index = old_agcount; index < agcount; index++) { - pag = kzalloc(sizeof(*pag), GFP_KERNEL | __GFP_RETRY_MAYFAIL); + pag = kzalloc(sizeof(*pag), GFP_KERNEL); if (!pag) { error = -ENOMEM; goto out_unwind_new_pags;