From nobody Sat Jul 25 21:59:20 2026 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 BCDDA2750FB for ; Mon, 13 Jul 2026 05:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783922243; cv=none; b=RgVGd+nwpOcAmseVFql0WGAbYR4WoYYVtTDiwj/qKvi47gSJqtkYkx2cA8X54NzWiF/0t7VJh2zDZy+zuSbZ5nifY0wSGS5Y3E6w9I1KyiKcnrSmBNqfeyJPx5IOngfMhbsXvdTggJVmSkSM7mlvK+0rVh2FjirOBKXVx1dh9+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783922243; c=relaxed/simple; bh=bwTAq8bR+d3v8AJZ8aEy8pI67mRzuPv88MILdF//Me8=; h=Mime-Version:Subject:From:To:CC:Message-ID:Date:Content-Type: References; b=atxW6UpAa9VhzN3R7QwRl6VwRqFE2KSt4agd05WIDM/Zsb+n4MSuyt7hbIiONO25pqut0fVFJpw2tZDmxNmDlY4WTtdB1ycPOQpTUQmGUJ4NgLb7pYg8W9kVHoK5HX84Y7h9bjY0o/0tM3z3SqqExFgjFoEln0x4oak4INxI2Ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=hGG0sqd+; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="hGG0sqd+" Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260713055712epoutp014f80822ee8650a35c866e0d2382d5ced~Bw9GoKsyz1308313083epoutp01W for ; Mon, 13 Jul 2026 05:57:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260713055712epoutp014f80822ee8650a35c866e0d2382d5ced~Bw9GoKsyz1308313083epoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1783922232; bh=weRZOxR+KQTuAh8kZhURaaciCfLqo4AauSDjmWHo/iM=; h=Subject:Reply-To:From:To:CC:Date:References:From; b=hGG0sqd+wnETTyms84gJTf+Wp1Vmr1wIQ+pymRjLBDIa7lXhdl5KVutNPOH5dRgut CsJYjXAnZHeH7uPHy8+6HJAcUNQadZMQhr0/WkaKm3XFfGvkIu3wfymOkYYbCqv0WF u9TxyCTzsKy2WIDz5H5Vo73aaU+6rCNTxp40tmss= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPS id 20260713055712epcas2p4f229b0be13f9e4f6b777c650cced947f~Bw9GVyMSU1460414604epcas2p4E; Mon, 13 Jul 2026 05:57:12 +0000 (GMT) Received: from epcas2p1.samsung.com (unknown [182.195.38.205]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4gzBXm0mSbz6B9mL; Mon, 13 Jul 2026 05:57:12 +0000 (GMT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Subject: [PATCH] f2fs: issue multi-device flushes in parallel Reply-To: yonggil.song@samsung.com Sender: Yonggil Song From: Yonggil Song To: "jaegeuk@kernel.org" , "chao@kernel.org" CC: "linux-f2fs-devel@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" , Dongjin Kim , Daejun Park X-Priority: 3 X-Content-Kind-Code: NORMAL X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20260713055711epcms2p712e7add62211e42e995c54a92fd4ff0c@epcms2p7> Date: Mon, 13 Jul 2026 14:57:11 +0900 X-CMS-MailID: 20260713055711epcms2p712e7add62211e42e995c54a92fd4ff0c Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P cpgsPolicy: CPGSC10-223,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260713055711epcms2p712e7add62211e42e995c54a92fd4ff0c References: On a multi-device setup, submit_flush_wait() walked the dirty devices in order and aborted the whole loop on the first device whose flush failed, leaving the remaining dirty devices un-flushed. Each device still needs its own data made durable, so a failure on one device must not skip the others. It also waited for one device's flush to complete before issuing the next, even though the devices have independent flush queues and could be flushed concurrently. Flush every dirty device best-effort and in parallel instead: build one PREFLUSH bio per dirty device, submit them all, then wait for every completion, returning the first error seen (0 if all succeed). This bounds the flush window by the slowest device rather than the sum of all of them. No caller depends on the previous early-abort behaviour -- fsync only checks whether the return value is zero (fs/f2fs/file.c). The checkpoint path (f2fs_flush_device_cache) is unaffected; this only touches the fsync flush path. Signed-off-by: Yonggil Song --- fs/f2fs/segment.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d71ddb3ee918..51d7f76e3d1d 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -566,24 +566,96 @@ static int __submit_flush_wait(struct f2fs_sb_info *s= bi, return ret; } =20 -static int submit_flush_wait(struct f2fs_sb_info *sbi, nid_t ino) +static void f2fs_flush_end_io(struct bio *bio) +{ + complete(bio->bi_private); +} + +struct f2fs_flush_bio { + struct bio bio; + struct completion wait; +}; + +/* + * Flush every dirty device best-effort: a failure on one device must not + * skip the flush on the remaining dirty devices, since each device still + * needs its own data made durable. Report the first error. + */ +static int submit_flush_wait_serial(struct f2fs_sb_info *sbi, nid_t ino) { int ret =3D 0; int i; =20 - if (!f2fs_is_multi_device(sbi)) - return __submit_flush_wait(sbi, sbi->sb->s_bdev); + for (i =3D 0; i < sbi->s_ndevs; i++) { + int err; + + if (!f2fs_is_dirty_device(sbi, ino, i, FLUSH_INO)) + continue; + err =3D __submit_flush_wait(sbi, FDEV(i).bdev); + if (err && !ret) + ret =3D err; + } + return ret; +} + +/* + * Same best-effort/first-error contract as submit_flush_wait_serial(), but + * issue every dirty device's flush before waiting for any of them, so the + * per-device flush latencies overlap instead of adding up in series. Fall + * back to the serial path if the bio array cannot be allocated. + */ +static int submit_flush_wait_parallel(struct f2fs_sb_info *sbi, nid_t ino) +{ + struct f2fs_flush_bio *flush_bio; + unsigned long devices =3D 0; + int ret =3D 0; + int i; + + flush_bio =3D kcalloc(sbi->s_ndevs, sizeof(*flush_bio), GFP_NOFS); + if (!flush_bio) + return submit_flush_wait_serial(sbi, ino); =20 for (i =3D 0; i < sbi->s_ndevs; i++) { if (!f2fs_is_dirty_device(sbi, ino, i, FLUSH_INO)) continue; - ret =3D __submit_flush_wait(sbi, FDEV(i).bdev); - if (ret) - break; + + bio_init(&flush_bio[i].bio, FDEV(i).bdev, NULL, 0, + REQ_OP_WRITE | REQ_PREFLUSH); + init_completion(&flush_bio[i].wait); + flush_bio[i].bio.bi_private =3D &flush_bio[i].wait; + flush_bio[i].bio.bi_end_io =3D f2fs_flush_end_io; + submit_bio(&flush_bio[i].bio); + devices |=3D BIT(i); + } + + for (i =3D 0; i < sbi->s_ndevs; i++) { + int err; + + if (!(devices & BIT(i))) + continue; + + wait_for_completion(&flush_bio[i].wait); + err =3D blk_status_to_errno(flush_bio[i].bio.bi_status); + trace_f2fs_issue_flush(FDEV(i).bdev, test_opt(sbi, NOBARRIER), + test_opt(sbi, FLUSH_MERGE), err); + if (!err) + f2fs_update_iostat(sbi, NULL, FS_FLUSH_IO, 0); + else if (!ret) + ret =3D err; + bio_uninit(&flush_bio[i].bio); } + kfree(flush_bio); return ret; } =20 +static int submit_flush_wait(struct f2fs_sb_info *sbi, nid_t ino) +{ + if (!f2fs_is_multi_device(sbi)) + return __submit_flush_wait(sbi, sbi->sb->s_bdev); + + return submit_flush_wait_parallel(sbi, ino); +} + static int issue_flush_thread(void *data) { struct f2fs_sb_info *sbi =3D data; --=20 2.43.0