Message ID | 20240520055153.136091-10-harshadshirwadkar@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | Ext4 fast commit performance patch series | expand |
Hi Harshad, kernel test robot noticed the following build warnings: https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Harshad-Shirwadkar/ext4-convert-i_fc_lock-to-spinlock/20240520-135501 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev patch link: https://lore.kernel.org/r/20240520055153.136091-10-harshadshirwadkar%40gmail.com patch subject: [PATCH 09/10] ext4: temporarily elevate commit thread priority config: i386-randconfig-141-20240520 (https://download.01.org/0day-ci/archive/20240521/202405210026.5LpHV4Sn-lkp@intel.com/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org> | Closes: https://lore.kernel.org/r/202405210026.5LpHV4Sn-lkp@intel.com/ smatch warnings: fs/ext4/fast_commit.c:1280 ext4_fc_commit() error: uninitialized symbol 'old_ioprio'. vim +/old_ioprio +1280 fs/ext4/fast_commit.c aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1200 int ext4_fc_commit(journal_t *journal, tid_t commit_tid) aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1201 { c30365b90ab26f Yu Zhe 2022-04-01 1202 struct super_block *sb = journal->j_private; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1203 struct ext4_sb_info *sbi = EXT4_SB(sb); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1204 int nblks = 0, ret, bsize = journal->j_blocksize; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1205 int subtid = atomic_read(&sbi->s_fc_subtid); 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1206 int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1207 ktime_t start_time, commit_time; c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1208 int old_ioprio, journal_ioprio; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1209 7f142440847480 Ritesh Harjani 2022-03-12 1210 if (!test_opt2(sb, JOURNAL_FAST_COMMIT)) 7f142440847480 Ritesh Harjani 2022-03-12 1211 return jbd2_complete_transaction(journal, commit_tid); 7f142440847480 Ritesh Harjani 2022-03-12 1212 5641ace54471cb Ritesh Harjani 2022-03-12 1213 trace_ext4_fc_commit_start(sb, commit_tid); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1214 aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1215 start_time = ktime_get(); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1216 aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1217 restart_fc: aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1218 ret = jbd2_fc_begin_commit(journal, commit_tid); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1219 if (ret == -EALREADY) { aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1220 /* There was an ongoing commit, check if we need to restart */ aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1221 if (atomic_read(&sbi->s_fc_subtid) <= subtid && aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1222 commit_tid > journal->j_commit_sequence) aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1223 goto restart_fc; d9bf099cb980d6 Ritesh Harjani 2022-03-12 1224 ext4_fc_update_stats(sb, EXT4_FC_STATUS_SKIPPED, 0, 0, d9bf099cb980d6 Ritesh Harjani 2022-03-12 1225 commit_tid); 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1226 return 0; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1227 } else if (ret) { 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1228 /* 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1229 * Commit couldn't start. Just update stats and perform a 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1230 * full commit. 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1231 */ d9bf099cb980d6 Ritesh Harjani 2022-03-12 1232 ext4_fc_update_stats(sb, EXT4_FC_STATUS_FAILED, 0, 0, d9bf099cb980d6 Ritesh Harjani 2022-03-12 1233 commit_tid); 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1234 return jbd2_complete_transaction(journal, commit_tid); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1235 } 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1236 7bbbe241ec7ce0 Harshad Shirwadkar 2021-12-23 1237 /* 7bbbe241ec7ce0 Harshad Shirwadkar 2021-12-23 1238 * After establishing journal barrier via jbd2_fc_begin_commit(), check 7bbbe241ec7ce0 Harshad Shirwadkar 2021-12-23 1239 * if we are fast commit ineligible. 7bbbe241ec7ce0 Harshad Shirwadkar 2021-12-23 1240 */ 7bbbe241ec7ce0 Harshad Shirwadkar 2021-12-23 1241 if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) { 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1242 status = EXT4_FC_STATUS_INELIGIBLE; 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1243 goto fallback; old_ioprio not initialized. 7bbbe241ec7ce0 Harshad Shirwadkar 2021-12-23 1244 } aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1245 c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1246 /* c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1247 * Now that we know that this thread is going to do a fast commit, c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1248 * elevate the priority to match that of the journal thread. c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1249 */ c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1250 if (journal->j_task->io_context) c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1251 journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1252 else c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1253 journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1254 old_ioprio = get_current_ioprio(); c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1255 set_task_ioprio(current, journal_ioprio); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1256 fc_bufs_before = (sbi->s_fc_bytes + bsize - 1) / bsize; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1257 ret = ext4_fc_perform_commit(journal); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1258 if (ret < 0) { 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1259 status = EXT4_FC_STATUS_FAILED; 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1260 goto fallback; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1261 } aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1262 nblks = (sbi->s_fc_bytes + bsize - 1) / bsize - fc_bufs_before; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1263 ret = jbd2_fc_wait_bufs(journal, nblks); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1264 if (ret < 0) { 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1265 status = EXT4_FC_STATUS_FAILED; 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1266 goto fallback; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1267 } aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1268 atomic_inc(&sbi->s_fc_subtid); 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1269 ret = jbd2_fc_end_commit(journal); c3b2c196d67585 Harshad Shirwadkar 2024-05-20 1270 set_task_ioprio(current, old_ioprio); aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1271 /* 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1272 * weight the commit time higher than the average time so we 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1273 * don't react too strongly to vast changes in the commit time aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1274 */ 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1275 commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time)); d9bf099cb980d6 Ritesh Harjani 2022-03-12 1276 ext4_fc_update_stats(sb, status, commit_time, nblks, commit_tid); 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1277 return ret; 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1278 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1279 fallback: c3b2c196d67585 Harshad Shirwadkar 2024-05-20 @1280 set_task_ioprio(current, old_ioprio); ^^^^^^^^^^ Uninitialized 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1281 ret = jbd2_fc_end_commit_fallback(journal); d9bf099cb980d6 Ritesh Harjani 2022-03-12 1282 ext4_fc_update_stats(sb, status, 0, 0, commit_tid); 0915e464cb2746 Harshad Shirwadkar 2021-12-23 1283 return ret; aa75f4d3daaeb1 Harshad Shirwadkar 2020-10-15 1284 }
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3721daea2890..d52df8a85271 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2287,10 +2287,12 @@ static inline int ext4_forced_shutdown(struct super_block *sb) #define EXT4_DEFM_NODELALLOC 0x0800 /* - * Default journal batch times + * Default journal batch times and ioprio. */ #define EXT4_DEF_MIN_BATCH_TIME 0 #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ +#define EXT4_DEF_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) + /* * Minimum number of groups in a flexgroup before we separate out diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 35c89bee452c..d354839dbf7e 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1205,6 +1205,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) int subtid = atomic_read(&sbi->s_fc_subtid); int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0; ktime_t start_time, commit_time; + int old_ioprio, journal_ioprio; if (!test_opt2(sb, JOURNAL_FAST_COMMIT)) return jbd2_complete_transaction(journal, commit_tid); @@ -1242,6 +1243,16 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) goto fallback; } + /* + * Now that we know that this thread is going to do a fast commit, + * elevate the priority to match that of the journal thread. + */ + if (journal->j_task->io_context) + journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; + else + journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; + old_ioprio = get_current_ioprio(); + set_task_ioprio(current, journal_ioprio); fc_bufs_before = (sbi->s_fc_bytes + bsize - 1) / bsize; ret = ext4_fc_perform_commit(journal); if (ret < 0) { @@ -1256,6 +1267,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) } atomic_inc(&sbi->s_fc_subtid); ret = jbd2_fc_end_commit(journal); + set_task_ioprio(current, old_ioprio); /* * weight the commit time higher than the average time so we * don't react too strongly to vast changes in the commit time @@ -1265,6 +1277,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) return ret; fallback: + set_task_ioprio(current, old_ioprio); ret = jbd2_fc_end_commit_fallback(journal); ext4_fc_update_stats(sb, status, 0, 0, commit_tid); return ret; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 77173ec91e49..18d9d2631559 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1833,7 +1833,6 @@ static const struct fs_parameter_spec ext4_param_specs[] = { {} }; -#define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) #define MOPT_SET 0x0001 #define MOPT_CLEAR 0x0002 @@ -5211,7 +5210,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) /* Set defaults for the variables that will be set during parsing */ if (!(ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO)) - ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO; + ctx->journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; sbi->s_sectors_written_start = @@ -6471,7 +6470,7 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb) ctx->journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; else - ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO; + ctx->journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; }
Unlike JBD2 based full commits, there is no dedicated journal thread for fast commits. Thus to reduce scheduling delays between IO submission and completion, temporarily elevate the committer thread's priority to match the configured priority of the JBD2 journal thread. Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com> --- fs/ext4/ext4.h | 4 +++- fs/ext4/fast_commit.c | 13 +++++++++++++ fs/ext4/super.c | 5 ++--- 3 files changed, 18 insertions(+), 4 deletions(-)