From nobody Thu Apr 2 17:10:50 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AE3838F937 for ; Fri, 27 Mar 2026 06:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774593417; cv=none; b=BAdtmajavruyHodwlUVDuUTraLDZ6/0mXbEBOY6DBg/ctDVGtVoTUrbebaTR8XPWWufXMixIHN9VFJUHPY4YPFu9tWIoKfVzePE3JCOQKdn5Id/QSLbIF+Kox4rX50NDAURJX+pYZQBOXCo0KvtghV/Dqqs1O1IqG1KL+QuhlAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774593417; c=relaxed/simple; bh=6Qjgytl6wg2QArtvD4J05K4KuLLYc3eNsd+FdaB2Rak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ew7yHmu9JT+9K6/6bRLdbI1RB7OrLNoRyd1FwzFtzuHvbxgu6b9kkuJKI2ZaWbec3zl07t7/lKTIzoqaBWx0qn9vwOwc/xhTboQ56Oe9i+Nil2deiXS7A84edjOUrdx97xikazfxxpG++/qDRbb3jNkcOlN0AIAoxKYOtoAIfiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DDX7TihI; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DDX7TihI" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4853a5ffc05so3451375e9.0 for ; Thu, 26 Mar 2026 23:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1774593402; x=1775198202; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nU8qFExDEanhu1yB6N1aCOH6lO0L98OpkQXZxpR303E=; b=DDX7TihIVMkZqG58d3Hm872WYwVg6EBzK2qqhHz8gulUzBqDrSW6WuXrX6k/rbo+k9 iB50AcnPp9WVr77ziZcEbq4EK0L95oNjTo23cvQBvs6jRigLIwFyGJcpunvsqLaY7oKt 4UECb5ATTj3W8lbCOnLVR6LsMzBuMKxeplst7jv3hoN2b1vtcm3SLd6oUupIuvOzeyrO LIjQvDSwg7MoEoUwZhsNapBhuNCRKUAj3reUuL5jbz7KnEvarunSbnmStHJkqJjadHaa FUDIkok4v8vD7yOCKEWAioYDrV2ty4ZQ0C25oamN00LL1x560K0UJqv7YaVbNIjdDGjw p0fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774593402; x=1775198202; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nU8qFExDEanhu1yB6N1aCOH6lO0L98OpkQXZxpR303E=; b=GngEOYyhzDXs/aoaNYH/+bFko9xwgzMiMlFjK+64mE0hNaAT4jP8f13z63xCDB9Iym 1EyBO2qkOL4Xj79BBp0TPMHy9JINp7kZ4xEKKGpIZehWFYliXP7zTHrcfoQej9LZCmhf IPm9MKtXg56QtQsWT5L0vuZFcgRCPzcIAGA7KRBmf3NARWvj8ASNZybF137D690xhg3P MmF7p4uR7Var+1aeAe09GhK3fibYbDHwKMSLoaMQ9ia5z6JtUkfuRypi9lJm7KD3mfmZ fZPBXLBpuz+uRy1MQwaQWbLRNn4TmriJ2RvJ5+m0zFPFE8VOyS/+ojD5xfiy3prP6Cz1 ucWA== X-Forwarded-Encrypted: i=1; AJvYcCX+o2O3xXS7OsW7sBIQd1OVY1azvxuvZWugmle0igD+8UGFmFyLrHhEXv9ZRDc+ke28wx9RjpheOElzzyk=@vger.kernel.org X-Gm-Message-State: AOJu0YzCjl+GgA69LQpoAWnvKr7Dm5FUYtCwjNXq7tJbnrQ15jnUrrSq 4fMq1aIlUcUIhSOE5K9tsoaViGTmBZO1uHFFX00uJ51akxQATbXs6K+PyWHRhUs93gpXYgvbAVA AtPnQamsLqQ== X-Gm-Gg: ATEYQzwBYc3ZTLi9x/KfvnYFBtJhM+n8ssXQslJoAtKdOfQFoIPsy4VaKoBf9Nj/9a/ 99z6CGucO/PCQgnMpgvTJ2jPZ+PT/lSUJ2AZ+UOvtTaoN77KIZP60SQKE5C0LoSSAfVjlpD2fwp psaSqqZSi2s7l+S5revOFV2EWjJS9ITUdATNhhaLL2HZl70sPA4DX47I/MwuQ0nW2P19LczlLSV JUzk7+/dbksVURlvEiJRBvo6usnDoM92xtdoDTfkbn/hdLcykskFjVGZDI2jqu221J1j1aWQ35s gvKdGQQQUhBDx+sHVwNdN7gcOMLod7iyToyTl+y+QOU4wYvo/+iwS1YcAd7BI4S62mekJU7nJue oxlUDv5VZUUMuhwA+6r+57s5RRifj19DI3nzhRvVlH3350+PdXmobuscsYwRbMa1EtllW2QY+gD 9XYUttfD4hEOO6EU1/Rqp/PRNa/16C9TC/AEeL X-Received: by 2002:a05:600c:19d2:b0:485:3177:d80c with SMTP id 5b1f17b1804b1-48727d6fbc6mr11526595e9.2.1774593401599; Thu, 26 Mar 2026 23:36:41 -0700 (PDT) Received: from localhost.localdomain ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c76739311d1sm3849190a12.15.2026.03.26.23.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 23:36:40 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com, jack@suse.cz Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, glass.su@suse.com Subject: [PATCH v5 1/1] ocfs2: split transactions in dio completion to avoid credit exhaustion Date: Fri, 27 Mar 2026 14:36:25 +0800 Message-ID: <20260327063626.10225-2-heming.zhao@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327063626.10225-1-heming.zhao@suse.com> References: <20260327063626.10225-1-heming.zhao@suse.com> 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 Content-Type: text/plain; charset="utf-8" During ocfs2 dio operations, JBD2 may report warnings via following call tr= ace: ocfs2_dio_end_io_write ocfs2_mark_extent_written ocfs2_change_extent_flag ocfs2_split_extent ocfs2_try_to_merge_extent ocfs2_extend_rotate_transaction ocfs2_extend_trans jbd2__journal_restart start_this_handle output: JBD2: kworker/6:2 wants too many credits credits:5450 rsv_= credits:0 max:5449 To prevent exceeding the credits limit, modify ocfs2_dio_end_io_write() to handle extents in a batch of transaction. Additionally, relocate ocfs2_del_inode_from_orphan(). The orphan inode shou= ld only be removed from the orphan list after the extent tree update is comple= te. This ensures that if a crash occurs in the middle of extent tree updates, we won't leave stale blocks beyond EOF. This patch also changes the logic for updating the inode size and removing orphan, making it similar to ext4_dio_write_end_io(). Both operations are performed only when everything looks good. Finally, thanks to Jans and Joseph for providing the bug fix prototype and suggestions. Suggested-by: Jan Kara Suggested-by: Joseph Qi Reviewed-by: Jan Kara Signed-off-by: Heming Zhao --- fs/ocfs2/aops.c | 63 +++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 09146b43d1f0..a542cd0a6f75 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -37,6 +37,8 @@ #include "namei.h" #include "sysfile.h" =20 +#define OCFS2_DIO_MARK_EXTENT_BATCH 200 + static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) { @@ -2277,7 +2279,7 @@ static int ocfs2_dio_end_io_write(struct inode *inode, struct ocfs2_alloc_context *meta_ac =3D NULL; handle_t *handle =3D NULL; loff_t end =3D offset + bytes; - int ret =3D 0, credits =3D 0; + int ret =3D 0, credits =3D 0, batch =3D 0; =20 ocfs2_init_dealloc_ctxt(&dealloc); =20 @@ -2294,18 +2296,6 @@ static int ocfs2_dio_end_io_write(struct inode *inod= e, goto out; } =20 - /* Delete orphan before acquire i_rwsem. */ - if (dwc->dw_orphaned) { - BUG_ON(dwc->dw_writer_pid !=3D task_pid_nr(current)); - - end =3D end > i_size_read(inode) ? end : 0; - - ret =3D ocfs2_del_inode_from_orphan(osb, inode, di_bh, - !!end, end); - if (ret < 0) - mlog_errno(ret); - } - down_write(&oi->ip_alloc_sem); di =3D (struct ocfs2_dinode *)di_bh->b_data; =20 @@ -2326,24 +2316,25 @@ static int ocfs2_dio_end_io_write(struct inode *ino= de, =20 credits =3D ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list); =20 - handle =3D ocfs2_start_trans(osb, credits); - if (IS_ERR(handle)) { - ret =3D PTR_ERR(handle); - mlog_errno(ret); - goto unlock; - } - ret =3D ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, - OCFS2_JOURNAL_ACCESS_WRITE); - if (ret) { - mlog_errno(ret); - goto commit; - } - list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) { + if (!handle) { + handle =3D ocfs2_start_trans(osb, credits); + if (IS_ERR(handle)) { + ret =3D PTR_ERR(handle); + mlog_errno(ret); + goto unlock; + } + ret =3D ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, + OCFS2_JOURNAL_ACCESS_WRITE); + if (ret) { + mlog_errno(ret); + goto commit; + } + } ret =3D ocfs2_assure_trans_credits(handle, credits); if (ret < 0) { mlog_errno(ret); - break; + goto commit; } ret =3D ocfs2_mark_extent_written(inode, &et, handle, ue->ue_cpos, 1, @@ -2351,7 +2342,13 @@ static int ocfs2_dio_end_io_write(struct inode *inod= e, meta_ac, &dealloc); if (ret < 0) { mlog_errno(ret); - break; + goto commit; + } + + if (++batch =3D=3D OCFS2_DIO_MARK_EXTENT_BATCH) { + ocfs2_commit_trans(osb, handle); + handle =3D NULL; + batch =3D 0; } } =20 @@ -2360,10 +2357,20 @@ static int ocfs2_dio_end_io_write(struct inode *ino= de, if (ret < 0) mlog_errno(ret); } + commit: ocfs2_commit_trans(osb, handle); unlock: up_write(&oi->ip_alloc_sem); + + /* everything looks good, let's start the cleanup */ + if (!ret && dwc->dw_orphaned) { + BUG_ON(dwc->dw_writer_pid !=3D task_pid_nr(current)); + + ret =3D ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0); + if (ret < 0) + mlog_errno(ret); + } ocfs2_inode_unlock(inode, 1); brelse(di_bh); out: --=20 2.43.0