From nobody Wed Dec 17 12:13:34 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 537EC1F0987; Tue, 18 Mar 2025 07:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742284400; cv=none; b=KNmtwg9aYi0asrodUvC/7zmuxMBEoqfD+1H61HMfz6OfpOM6OoR0tHDSW6Tc3YBsGlURxYaRegifkQaUAIb6epa1+C+hx0d23GkTcnRgfr+Q80rRs9Th43q4GAe54G6Bg0MhSgyBnc4OW04dOKvproHyDOmZ6lCC5A3EmRaK68E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742284400; c=relaxed/simple; bh=6WbkmCGvrc6kAX4NXuaifadcZdcD9FoFIjvoPYwJ8nA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=grwhkujGnZ6ygtznEZ6FLa+RJSHGBI9BDCSn1s6HTYPRBF/mI3c0YWirVhvCxG3Amwv7iodJR9BHKBuEi51eStMYzvdJBCA57pszeIEXSBi1rR6Sswb9ZV69IdXq1xY+OwPZlTWYp1K2GpNL0Zvn2HW1n/R4nYxu2lNCIIddKGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=X/50o8K0; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="X/50o8K0" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52HKZgL8027943; Tue, 18 Mar 2025 07:53:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=AM75vNikby5nBoUvo tgh7VAbZ5edQqh/5gUJk8S84lM=; b=X/50o8K0aDuioC/yjtvzg2n4USXmvAOdp 1QCVKhZ9cbhaMZTMo69hrGlgVp/nQy6DpZ8MfQ9PwpGMDC3hPzTz4s+JGm2kSvT6 CzQ2NcVLNN4w6XT4ic55gE90wJ8r3CHGyr5WiS5FMHGPaRLEX28hJIyyU9qEMfhQ 8RqQKdPm4T7McDwNK2GZ2x8jkJzwBZzV8zKShSrt97q3Jb1CP95GdOFFIUC20+sF +YIs/W45WQ3L3QrjsiTWHwNamEOPYCMmPDnMCb4lEisB8o5/PEr2aKGxWje4A4eg 83pjYjUZuTn8cGJJ1MpEBbzz5LWyTH9v9DbERxpY02PkLshl+xywA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45etwqaa5g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:08 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52I7n75q005233; Tue, 18 Mar 2025 07:53:07 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45etwqaa5e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:07 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52I6jMKG008973; Tue, 18 Mar 2025 07:53:07 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45dm8ytt94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:06 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52I7r5FG52887858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Mar 2025 07:53:05 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 05BFC20043; Tue, 18 Mar 2025 07:53:05 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B52320040; Tue, 18 Mar 2025 07:53:03 +0000 (GMT) Received: from li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com (unknown [9.39.27.85]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 18 Mar 2025 07:53:03 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Jan Kara , Baokun Li , Ritesh Harjani , linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] ext4: define ext4_journal_destroy wrapper Date: Tue, 18 Mar 2025 13:22:55 +0530 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 2D-PUpnezalEnv8MgtYIDnLZyTW1WQ2A X-Proofpoint-ORIG-GUID: ybJT6RHJT2zbGYHnja4gZmc5kIup-uX1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_03,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 clxscore=1015 impostorscore=0 mlxscore=0 malwarescore=0 phishscore=0 adultscore=0 mlxlogscore=745 suspectscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503180052 Content-Type: text/plain; charset="utf-8" Define an ext4 wrapper over jbd2_journal_destroy to make sure we have consistent behavior during journal destruction. This will also come useful in the next patch where we add some ext4 specific logic in the destroy path. Reviewed-by: Jan Kara Reviewed-by: Baokun Li Signed-off-by: Ojaswin Mujoo --- fs/ext4/ext4_jbd2.h | 14 ++++++++++++++ fs/ext4/super.c | 16 ++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 3f2596c9e5f2..9b3c9df02a39 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -429,4 +429,18 @@ static inline int ext4_should_dioread_nolock(struct in= ode *inode) return 1; } =20 +/* + * Pass journal explicitly as it may not be cached in the sbi->s_journal i= n some + * cases + */ +static inline int ext4_journal_destroy(struct ext4_sb_info *sbi, journal_t= *journal) +{ + int err =3D 0; + + err =3D jbd2_journal_destroy(journal); + sbi->s_journal =3D NULL; + + return err; +} + #endif /* _EXT4_JBD2_H */ diff --git a/fs/ext4/super.c b/fs/ext4/super.c index a963ffda692a..8ad664d47806 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1297,8 +1297,7 @@ static void ext4_put_super(struct super_block *sb) =20 if (sbi->s_journal) { aborted =3D is_journal_aborted(sbi->s_journal); - err =3D jbd2_journal_destroy(sbi->s_journal); - sbi->s_journal =3D NULL; + err =3D ext4_journal_destroy(sbi, sbi->s_journal); if ((err < 0) && !aborted) { ext4_abort(sb, -err, "Couldn't clean up the journal"); } @@ -4960,8 +4959,7 @@ static int ext4_load_and_init_journal(struct super_bl= ock *sb, out: /* flush s_sb_upd_work before destroying the journal. */ flush_work(&sbi->s_sb_upd_work); - jbd2_journal_destroy(sbi->s_journal); - sbi->s_journal =3D NULL; + ext4_journal_destroy(sbi, sbi->s_journal); return -EINVAL; } =20 @@ -5652,8 +5650,7 @@ failed_mount8: __maybe_unused if (sbi->s_journal) { /* flush s_sb_upd_work before journal destroy. */ flush_work(&sbi->s_sb_upd_work); - jbd2_journal_destroy(sbi->s_journal); - sbi->s_journal =3D NULL; + ext4_journal_destroy(sbi, sbi->s_journal); } failed_mount3a: ext4_es_unregister_shrinker(sbi); @@ -5958,7 +5955,7 @@ static journal_t *ext4_open_dev_journal(struct super_= block *sb, return journal; =20 out_journal: - jbd2_journal_destroy(journal); + ext4_journal_destroy(EXT4_SB(sb), journal); out_bdev: bdev_fput(bdev_file); return ERR_PTR(errno); @@ -6075,8 +6072,7 @@ static int ext4_load_journal(struct super_block *sb, EXT4_SB(sb)->s_journal =3D journal; err =3D ext4_clear_journal_err(sb, es); if (err) { - EXT4_SB(sb)->s_journal =3D NULL; - jbd2_journal_destroy(journal); + ext4_journal_destroy(EXT4_SB(sb), journal); return err; } =20 @@ -6094,7 +6090,7 @@ static int ext4_load_journal(struct super_block *sb, return 0; =20 err_out: - jbd2_journal_destroy(journal); + ext4_journal_destroy(EXT4_SB(sb), journal); return err; } =20 --=20 2.48.1 From nobody Wed Dec 17 12:13:34 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 7D71C1EF364; Tue, 18 Mar 2025 07:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742284399; cv=none; b=L9sOx/aTfmKG4+OSIa7WzAiWVOERJkbaHK2PKAM+4pxBowe9bmmGmkbHPxRbm2l+Jpfl7QyUt5He0zndKtmqA+SyQernLnh1fQlxFC4ewGHb62vS8nC0Y4cF0S8mZ1mIAfEDH1SYeVQ+yLN741TGu8kNgswlFnKWRpTP65Fgy/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742284399; c=relaxed/simple; bh=MWVJnHV5Pf8i5TQixb0q/aekZTCIFymMpGEtB1mVjWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aBuxsbxUnDwGFyJaOV+Q0yxu1YuBmUE188eAft4UnOtWUonV/22zJZmcmlt04o5KJ3/4LDwPEae13c/Qku7qhbgXg9xyD/NnpSbRtPJyvgVJc2kil/cGTnEu+jMIPrQUwDoCAgl+6i9AD2cNo0IdxxysoZNBmH9WU6BivZEI4Gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=pGrQ77Bx; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="pGrQ77Bx" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52HKqTgY012179; Tue, 18 Mar 2025 07:53:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=E+cmUdSTSMh8Di7xc in945MPCv4UupI+TetQCtjDwtU=; b=pGrQ77BxXvHL2rp4elUZ/QBLBEi+arHGL dRmGJ9p1X5El0xPQvoWWmCOR2SigjJu33cMl9VK8qWbU3PT2r+4BsL/6AjDsMG5P GNCZ3hOBVtsRCawwoHnAGAu1C3GsH7JhYOrZVyT98o2hOZX27fQyuIf9wJfRGHLN waOIo/bYsW5CKn5PvG356ge6Fua5zhedvZvt6h2FNpBwbXcvZe2qcOf9dUVZURK5 7VDZms9LBvHD4uiWDar7fptBZb0bWTlmPzsBFYOpjAwA9FB3GqLWjIxRlaTScHUB 3r5OrM+vYvrUFOo3h5OE5cRC//2rUJEl7O7y1geal8+ho+CdSGArw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45eu55t8ax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:10 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52I7rAws003545; Tue, 18 Mar 2025 07:53:10 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45eu55t8av-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:10 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52I4Bji0001076; Tue, 18 Mar 2025 07:53:09 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 45dp3kjegy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:09 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52I7r79j50332074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Mar 2025 07:53:07 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A709020040; Tue, 18 Mar 2025 07:53:07 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE3B220043; Tue, 18 Mar 2025 07:53:05 +0000 (GMT) Received: from li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com (unknown [9.39.27.85]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 18 Mar 2025 07:53:05 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Jan Kara , Baokun Li , Ritesh Harjani , linux-kernel@vger.kernel.org, Mahesh Kumar Subject: [PATCH v4 2/3] ext4: avoid journaling sb update on error if journal is destroying Date: Tue, 18 Mar 2025 13:22:56 +0530 Message-ID: <9613c465d6ff00cd315602f99283d5f24018c3f7.1742279837.git.ojaswin@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: eyISuN_Gjy7nB416ZjLR8azaD-kWGOlz X-Proofpoint-GUID: PjGfiTZ7RDnmkI_YfDUUYk528kI7Yu-u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_03,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 suspectscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503180052 Content-Type: text/plain; charset="utf-8" Presently we always BUG_ON if trying to start a transaction on a journal ma= rked with JBD2_UNMOUNT, since this should never happen. However, while ltp runni= ng stress tests, it was observed that in case of some error handling paths, it= is possible for update_super_work to start a transaction after the journal is destroyed eg: (umount) ext4_kill_sb kill_block_super generic_shutdown_super sync_filesystem /* commits all txns */ evict_inodes /* might start a new txn */ ext4_put_super flush_work(&sbi->s_sb_upd_work) /* flush the workqueue */ jbd2_journal_destroy journal_kill_thread journal->j_flags |=3D JBD2_UNMOUNT; jbd2_journal_commit_transaction jbd2_journal_get_descriptor_buffer jbd2_journal_bmap ext4_journal_bmap ext4_map_blocks ... ext4_inode_error ext4_handle_error schedule_work(&sbi->s_sb_upd_work) /* work queue kicks in */ update_super_work jbd2_journal_start start_this_handle BUG_ON(journal->j_flag= s & JBD2_UNMOUNT) Hence, introduce a new mount flag to indicate journal is destroying and onl= y do a journaled (and deferred) update of sb if this flag is not set. Otherwise,= just fallback to an un-journaled commit. Further, in the journal destroy path, we have the following sequence: 1. Set mount flag indicating journal is destroying 2. force a commit and wait for it 3. flush pending sb updates This sequence is important as it ensures that, after this point, there is n= o sb update that might be journaled so it is safe to update the sb outside the journal. (To avoid race discussed in 2d01ddc86606) Also, we don't need a similar check in ext4_grp_locked_error since it is on= ly called from mballoc and AFAICT it would be always valid to schedule work he= re. Fixes: 2d01ddc86606 ("ext4: save error info to sb through journal if availa= ble") Reported-by: Mahesh Kumar Signed-off-by: Ojaswin Mujoo Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 3 ++- fs/ext4/ext4_jbd2.h | 15 +++++++++++++++ fs/ext4/super.c | 16 ++++++++-------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2b7d781bfcad..0685bb68e64a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1823,7 +1823,8 @@ static inline int ext4_valid_inum(struct super_block = *sb, unsigned long ino) */ enum { EXT4_MF_MNTDIR_SAMPLED, - EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */ + EXT4_MF_FC_INELIGIBLE, /* Fast commit ineligible */ + EXT4_MF_JOURNAL_DESTROY /* Journal is in process of destroying */ }; =20 static inline void ext4_set_mount_flag(struct super_block *sb, int bit) diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 9b3c9df02a39..3221714d9901 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -437,6 +437,21 @@ static inline int ext4_journal_destroy(struct ext4_sb_= info *sbi, journal_t *jour { int err =3D 0; =20 + /* + * At this point only two things can be operating on the journal. + * JBD2 thread performing transaction commit and s_sb_upd_work + * issuing sb update through the journal. Once we set + * EXT4_JOURNAL_DESTROY, new ext4_handle_error() calls will not + * queue s_sb_upd_work and ext4_force_commit() makes sure any + * ext4_handle_error() calls from the running transaction commit are + * finished. Hence no new s_sb_upd_work can be queued after we + * flush it here. + */ + ext4_set_mount_flag(sbi->s_sb, EXT4_MF_JOURNAL_DESTROY); + + ext4_force_commit(sbi->s_sb); + flush_work(&sbi->s_sb_upd_work); + err =3D jbd2_journal_destroy(journal); sbi->s_journal =3D NULL; =20 diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 8ad664d47806..46f7c9922cda 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -704,9 +704,13 @@ static void ext4_handle_error(struct super_block *sb, = bool force_ro, int error, * In case the fs should keep running, we need to writeout * superblock through the journal. Due to lock ordering * constraints, it may not be safe to do it right here so we - * defer superblock flushing to a workqueue. + * defer superblock flushing to a workqueue. We just need to be + * careful when the journal is already shutting down. If we get + * here in that case, just update the sb directly as the last + * transaction won't commit anyway. */ - if (continue_fs && journal) + if (continue_fs && journal && + !ext4_test_mount_flag(sb, EXT4_MF_JOURNAL_DESTROY)) schedule_work(&EXT4_SB(sb)->s_sb_upd_work); else ext4_commit_super(sb); @@ -1291,7 +1295,6 @@ static void ext4_put_super(struct super_block *sb) ext4_unregister_li_request(sb); ext4_quotas_off(sb, EXT4_MAXQUOTAS); =20 - flush_work(&sbi->s_sb_upd_work); destroy_workqueue(sbi->rsv_conversion_wq); ext4_release_orphan_info(sb); =20 @@ -1301,7 +1304,8 @@ static void ext4_put_super(struct super_block *sb) if ((err < 0) && !aborted) { ext4_abort(sb, -err, "Couldn't clean up the journal"); } - } + } else + flush_work(&sbi->s_sb_upd_work); =20 ext4_es_unregister_shrinker(sbi); timer_shutdown_sync(&sbi->s_err_report); @@ -4957,8 +4961,6 @@ static int ext4_load_and_init_journal(struct super_bl= ock *sb, return 0; =20 out: - /* flush s_sb_upd_work before destroying the journal. */ - flush_work(&sbi->s_sb_upd_work); ext4_journal_destroy(sbi, sbi->s_journal); return -EINVAL; } @@ -5648,8 +5650,6 @@ failed_mount8: __maybe_unused sbi->s_ea_block_cache =3D NULL; =20 if (sbi->s_journal) { - /* flush s_sb_upd_work before journal destroy. */ - flush_work(&sbi->s_sb_upd_work); ext4_journal_destroy(sbi, sbi->s_journal); } failed_mount3a: --=20 2.48.1 From nobody Wed Dec 17 12:13:34 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 69F271F8BC8; Tue, 18 Mar 2025 07:53:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742284405; cv=none; b=Iq53OPZU7+UJ5SK0FqlRjwhnFBfZaQ5khdvQDNUVOpVi8pNN24LCKEPgKCVEL/K/k5lN6InjVZMyqtFJU/XnyGvhLFSQCmj2Rd78NvP/ZglWTCSPWnM9oKhGp4alUZ5GI2NHpv3DfRCKB7b7RhUmnuzgWlCNwWXz8I70X+5hnJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742284405; c=relaxed/simple; bh=q2OwfxgRjGh91mTahI8LZQUk+azBTZ7cYx/q5/OpsKE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TG8p+nNUE3TXv+D5ITE6qgYvOW9JeVkeIxWnEj9untDo4oZtNu1Ffd3fHdc1ecX0R47zl7ABndmyKVqzOd1o4h4j9B3RIeV43Uqvj8TDKVHGcOvVdbyNd9BzKfwG/1p4nsoOEug6i52FapXzUXS7aD1kLe6Rjyie2pNRVWRICgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ML4VGJW/; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ML4VGJW/" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52I3l6Hc008001; Tue, 18 Mar 2025 07:53:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=3zgakYw2K9UFcdfiJ +AO9Ho3GVZeBGE5KAVqvmCsad4=; b=ML4VGJW/LG03ETqBSUwOE3Kv5pU090vA0 mWPW9LmfPaIvscjmFewuxMMtZxGFZGwpNwDcfxsda06N5Z3RURqN02G+oFIMRyDz njEdPPQC5tJSvS0Gr8hBG7MiCaL4Vop3s54UgGb7PR5nP570BUOj72uxH5nNuHZc wYZbDEYakNQtPUPm8t4ljiMC8AK+BLbnLlo9kokDvndriRgMl7DvvGxh6T3vkS7l n/aiArFm7kouo0WlijFa0VoqZyXhERhvJj3okHcImIptEk1IfwUm66BwIVpYv02J ZaqSjkDjWYjcFT/yqlrX/E8ha81QwfN/XN7dlP4j+mQzsTVi/Gt1Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45f179gy4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:13 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52I7nLj3022075; Tue, 18 Mar 2025 07:53:13 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45f179gy49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:13 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52I6Jr8H032041; Tue, 18 Mar 2025 07:53:12 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 45dkvtaw33-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Mar 2025 07:53:12 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52I7rAPl57541006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Mar 2025 07:53:10 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B53DF20043; Tue, 18 Mar 2025 07:53:10 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 16C6420040; Tue, 18 Mar 2025 07:53:08 +0000 (GMT) Received: from li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com (unknown [9.39.27.85]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 18 Mar 2025 07:53:07 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Jan Kara , Baokun Li , Ritesh Harjani , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] ext4: Make sb update interval tunable Date: Tue, 18 Mar 2025 13:22:57 +0530 Message-ID: <950fb8c9b2905620e16f02a3b9eeea5a5b6cb87e.1742279837.git.ojaswin@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: j2KjzhG2yprpH0bCWeJtj-G5b79K-bJQ X-Proofpoint-ORIG-GUID: c-jQOWcQRDlElResoWwRTorixkiB07gX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_03,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 adultscore=0 mlxlogscore=644 bulkscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503180052 Content-Type: text/plain; charset="utf-8" Currently, outside error paths, we auto commit the super block after 1 hour has passed and 16MB worth of updates have been written since last commit. This is a policy decision so make this tunable while keeping the defaults same. This is useful if user wants to tweak the superblock behavior or for debugging the codepath by allowing to trigger it more frequently. We can now tweak the super block update using sb_update_sec and sb_update_kb files in /sys/fs/ext4// Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani (IBM) Reviewed-by: Baokun Li Signed-off-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/super.c | 15 ++++++++------- fs/ext4/sysfs.c | 4 ++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 0685bb68e64a..5259825396c4 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1608,6 +1608,8 @@ struct ext4_sb_info { unsigned int s_mb_prefetch; unsigned int s_mb_prefetch_limit; unsigned int s_mb_best_avail_max_trim_order; + unsigned int s_sb_update_sec; + unsigned int s_sb_update_kb; =20 /* stats for buddy allocator */ atomic_t s_bal_reqs; /* number of reqs with len > 1 */ @@ -2280,6 +2282,13 @@ static inline int ext4_forced_shutdown(struct super_= block *sb) #define EXT4_DEF_MIN_BATCH_TIME 0 #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ =20 +/* + * Default values for superblock update + */ +#define EXT4_DEF_SB_UPDATE_INTERVAL_SEC (3600) /* seconds (1 hour) */ +#define EXT4_DEF_SB_UPDATE_INTERVAL_KB (16384) /* kilobytes (16MB) */ + + /* * Minimum number of groups in a flexgroup before we separate out * directories into the first block group of a flexgroup diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 46f7c9922cda..9eb1ae2e84bb 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -447,9 +447,6 @@ static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi) #define ext4_get_tstamp(es, tstamp) \ __ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi) =20 -#define EXT4_SB_REFRESH_INTERVAL_SEC (3600) /* seconds (1 hour) */ -#define EXT4_SB_REFRESH_INTERVAL_KB (16384) /* kilobytes (16MB) */ - /* * The ext4_maybe_update_superblock() function checks and updates the * superblock if needed. @@ -457,8 +454,10 @@ static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi) * This function is designed to update the on-disk superblock only under * certain conditions to prevent excessive disk writes and unnecessary * waking of the disk from sleep. The superblock will be updated if: - * 1. More than an hour has passed since the last superblock update, and - * 2. More than 16MB have been written since the last superblock update. + * 1. More than sbi->s_sb_update_sec (def: 1 hour) has passed since the la= st + * superblock update + * 2. More than sbi->s_sb_update_kb (def: 16MB) kbs have been written sinc= e the + * last superblock update. * * @sb: The superblock */ @@ -479,7 +478,7 @@ static void ext4_maybe_update_superblock(struct super_b= lock *sb) now =3D ktime_get_real_seconds(); last_update =3D ext4_get_tstamp(es, s_wtime); =20 - if (likely(now - last_update < EXT4_SB_REFRESH_INTERVAL_SEC)) + if (likely(now - last_update < sbi->s_sb_update_sec)) return; =20 lifetime_write_kbytes =3D sbi->s_kbytes_written + @@ -494,7 +493,7 @@ static void ext4_maybe_update_superblock(struct super_b= lock *sb) */ diff_size =3D lifetime_write_kbytes - le64_to_cpu(es->s_kbytes_written); =20 - if (diff_size > EXT4_SB_REFRESH_INTERVAL_KB) + if (diff_size > sbi->s_sb_update_kb) schedule_work(&EXT4_SB(sb)->s_sb_upd_work); } =20 @@ -5248,6 +5247,8 @@ static int __ext4_fill_super(struct fs_context *fc, s= truct super_block *sb) sbi->s_commit_interval =3D JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; sbi->s_min_batch_time =3D EXT4_DEF_MIN_BATCH_TIME; sbi->s_max_batch_time =3D EXT4_DEF_MAX_BATCH_TIME; + sbi->s_sb_update_kb =3D EXT4_DEF_SB_UPDATE_INTERVAL_KB; + sbi->s_sb_update_sec =3D EXT4_DEF_SB_UPDATE_INTERVAL_SEC; =20 /* * set default s_li_wait_mult for lazyinit, for the case there is diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index ddb54608ca2e..987bd00f916a 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -254,6 +254,8 @@ EXT4_ATTR(journal_task, 0444, journal_task); EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks); +EXT4_RW_ATTR_SBI_UI(sb_update_sec, s_sb_update_sec); +EXT4_RW_ATTR_SBI_UI(sb_update_kb, s_sb_update_kb); =20 static unsigned int old_bump_val =3D 128; EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); @@ -305,6 +307,8 @@ static struct attribute *ext4_attrs[] =3D { ATTR_LIST(mb_prefetch), ATTR_LIST(mb_prefetch_limit), ATTR_LIST(last_trim_minblks), + ATTR_LIST(sb_update_sec), + ATTR_LIST(sb_update_kb), NULL, }; ATTRIBUTE_GROUPS(ext4); --=20 2.48.1