From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E6D52153BE9 for ; Mon, 26 Jan 2026 06:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769409137; cv=none; b=oMVcxFNzOelkDV1rUWgL6r53It7EDXJGEG8dRaruh6idoxawkiGNJdpUs+s5/auAGR/ZjxWZ2LSptWE17QsNcGzTD/aHAHN9UR9VQcgWN3tHJVrOCeClF+X165HAMJCTbXfRbc7qYR9EgmHY7ememd7Ae666TglvaMQBd9wkjFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769409137; c=relaxed/simple; bh=PXX7h2KzrCDJdUP4xzjsQwYMg3oUCSesD9/lxOwHPJg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cmXpk2Lp8gD/ih/H1Rqjwh9f+IX0BC8JepM57GlYPqD4u14L1VD5XqWX2Z1Z9N5JAKKNGUE5F2/tHm9EiWtg3Xe1NgAhLBU60KtV70/tBT+dxRKW3uXXENg0IucH558RiFUUIbugGqNJBy1n6N+Hv991SH53UJJjfKn/T8CEZ+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GirhOv4h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GirhOv4h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D271C19422; Mon, 26 Jan 2026 06:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769409136; bh=PXX7h2KzrCDJdUP4xzjsQwYMg3oUCSesD9/lxOwHPJg=; h=From:To:Cc:Subject:Date:From; b=GirhOv4hF6LMjEDW7FVzzHILSYZHBJfdZt1zwblgaK5emZIu0zYQs6oN0DchMmvEu UxEhpWgb7xu4U5erVFOt3t2L0baw3jW+fH/Dzn8seSLnos9ojap6miLSGqi+CJJkdw OtnzMBRoaVSw3gcvB2YnTBPEjgVdTBvq7TKQkunfrAt4x6DcG5r1cD48Hl6tPdZoid Aa/ysRUwfE9c96A/+yyqVtilMhEzgOe5JuEruVkmyonB8GCRzarMwWXc88k7f0jvXA q/EfqFSTciRhrQe4riw+btwx3IbRcJpWSrcGzLCl4vCCxi07I5JOm5ZRV0ik10pIQM k2UU2jBrGKRhQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v3 1/2] f2fs: check skipped write in f2fs_enable_checkpoint() Date: Mon, 26 Jan 2026 06:32:03 +0000 Message-ID: <20260126063203.1508295-1-chao@kernel.org> X-Mailer: git-send-email 2.53.0.rc1.217.geba53bf80e-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch introduces sbi->nr_pages[F2FS_SKIPPED_WRITE] to record any skipped write during data flush in f2fs_enable_checkpoint(). So in the loop of data flush, if there is any skipped write in previous flush, let's retry sync_inode_sb(), otherwise, all dirty data written before f2fs_enable_checkpoint() should have been persisted, then break the retry loop. Signed-off-by: Chao Yu --- v3: - fix to adjust s_flag[MAX_SBI_FLAG] to avoid compile warning fs/f2fs/data.c | 19 +++++++++++++++++++ fs/f2fs/debug.c | 1 + fs/f2fs/f2fs.h | 2 ++ fs/f2fs/super.c | 37 +++++++++++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d509172b51df..25b4d3f21fa7 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3495,6 +3495,16 @@ static inline void account_writeback(struct inode *inode, bool inc) f2fs_up_read(&F2FS_I(inode)->i_sem); } +static inline void update_skipped_write(struct f2fs_sb_info *sbi, + struct writeback_control *wbc) +{ + long skipped = wbc->pages_skipped; + + if (is_sbi_flag_set(sbi, SBI_ENABLE_CHECKPOINT) && skipped && + wbc->sync_mode == WB_SYNC_ALL) + atomic_add(skipped, &sbi->nr_pages[F2FS_SKIPPED_WRITE]); +} + static int __f2fs_write_data_pages(struct address_space *mapping, struct writeback_control *wbc, enum iostat_type io_type) @@ -3559,10 +3569,19 @@ static int __f2fs_write_data_pages(struct address_space *mapping, */ f2fs_remove_dirty_inode(inode); + + /* + * f2fs_write_cache_pages() has retry logic for EAGAIN case which is + * common when racing w/ checkpoint, so only update skipped write + * when ret is non-zero. + */ + if (ret) + update_skipped_write(sbi, wbc); return ret; skip_write: wbc->pages_skipped += get_dirty_pages(inode); + update_skipped_write(sbi, wbc); trace_f2fs_writepages(mapping->host, wbc, DATA); return 0; } diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 032683835569..8e1040e375a7 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -423,6 +423,7 @@ static const char *s_flag[MAX_SBI_FLAG] = { [SBI_IS_RESIZEFS] = "resizefs", [SBI_IS_FREEZING] = "freezefs", [SBI_IS_WRITABLE] = "writable", + [SBI_ENABLE_CHECKPOINT] = "enable_checkpoint", }; static const char *ipu_mode_names[F2FS_IPU_MAX] = { diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 035239758e33..52cec6b3ecf0 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1238,6 +1238,7 @@ enum count_type { F2FS_RD_META, F2FS_DIO_WRITE, F2FS_DIO_READ, + F2FS_SKIPPED_WRITE, /* skip or fail during f2fs_enable_checkpoint() */ NR_COUNT_TYPE, }; @@ -1476,6 +1477,7 @@ enum { SBI_IS_RESIZEFS, /* resizefs is in process */ SBI_IS_FREEZING, /* freezefs is in process */ SBI_IS_WRITABLE, /* remove ro mountoption transiently */ + SBI_ENABLE_CHECKPOINT, /* indicate it's during f2fs_enable_checkpoint() */ MAX_SBI_FLAG, }; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 97c2264ec7fe..0afe9f829058 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2690,6 +2690,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) long long start, writeback, end; int ret; struct f2fs_lock_context lc; + long long skipped_write, dirty_data; f2fs_info(sbi, "f2fs_enable_checkpoint() starts, meta: %lld, node: %lld, data: %lld", get_pages(sbi, F2FS_DIRTY_META), @@ -2698,17 +2699,45 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) start = ktime_get(); + set_sbi_flag(sbi, SBI_ENABLE_CHECKPOINT); + /* we should flush all the data to keep data consistency */ do { + skipped_write = get_pages(sbi, F2FS_SKIPPED_WRITE); + dirty_data = get_pages(sbi, F2FS_DIRTY_DATA); + sync_inodes_sb(sbi->sb); f2fs_io_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT); - } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); + + f2fs_info(sbi, "sync_inode_sb done, dirty_data: %lld, %lld, " + "skipped write: %lld, %lld, retry: %d", + get_pages(sbi, F2FS_DIRTY_DATA), + dirty_data, + get_pages(sbi, F2FS_SKIPPED_WRITE), + skipped_write, retry); + + /* + * sync_inodes_sb() has retry logic, so let's check dirty_data + * in prior to skipped_write in case there is no dirty data. + */ + if (!get_pages(sbi, F2FS_DIRTY_DATA)) + break; + if (get_pages(sbi, F2FS_SKIPPED_WRITE) == skipped_write) + break; + } while (retry--); + + clear_sbi_flag(sbi, SBI_ENABLE_CHECKPOINT); writeback = ktime_get(); - if (unlikely(get_pages(sbi, F2FS_DIRTY_DATA))) - f2fs_warn(sbi, "checkpoint=enable has some unwritten data: %lld", - get_pages(sbi, F2FS_DIRTY_DATA)); + if (unlikely(get_pages(sbi, F2FS_DIRTY_DATA) || + get_pages(sbi, F2FS_SKIPPED_WRITE))) + f2fs_warn(sbi, "checkpoint=enable unwritten data: %lld, skipped data: %lld, retry: %d", + get_pages(sbi, F2FS_DIRTY_DATA), + get_pages(sbi, F2FS_SKIPPED_WRITE), retry); + + if (get_pages(sbi, F2FS_SKIPPED_WRITE)) + atomic_set(&sbi->nr_pages[F2FS_SKIPPED_WRITE], 0); f2fs_down_write_trace(&sbi->gc_lock, &lc); f2fs_dirty_to_prefree(sbi); -- 2.49.0