Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: add sysfs attr /sys/fs/ext4/<disk>/journal_task

This is useful for moving journal thread into cgroup or
for tracing it with ftrace/perf/blktrace.

For now the only way is `pgrep jbd2/$DISK` but this is not reliable:
name may be longer than "comm" limit and any task could mock it.

Attribute shows pid in current pid-namespace or 0 if task is unreachable.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Konstantin Khlebnikov and committed by
Theodore Ts'o
bc1d69d6 231fe82b

+20
+7
Documentation/ABI/testing/sysfs-fs-ext4
··· 109 109 write operation (since a 4k random write might turn 110 110 into a much larger write due to the zeroout 111 111 operation). 112 + 113 + What: /sys/fs/ext4/<disk>/journal_task 114 + Date: February 2019 115 + Contact: "Theodore Ts'o" <tytso@mit.edu> 116 + Description: 117 + This file is read-only and shows the pid of journal thread in 118 + current pid-namespace or 0 if task is unreachable.
+13
fs/ext4/sysfs.c
··· 30 30 attr_feature, 31 31 attr_pointer_ui, 32 32 attr_pointer_atomic, 33 + attr_journal_task, 33 34 } attr_id_t; 34 35 35 36 typedef enum { ··· 126 125 return count; 127 126 } 128 127 128 + static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) 129 + { 130 + if (!sbi->s_journal) 131 + return snprintf(buf, PAGE_SIZE, "<none>\n"); 132 + return snprintf(buf, PAGE_SIZE, "%d\n", 133 + task_pid_vnr(sbi->s_journal->j_task)); 134 + } 135 + 129 136 #define EXT4_ATTR(_name,_mode,_id) \ 130 137 static struct ext4_attr ext4_attr_##_name = { \ 131 138 .attr = {.name = __stringify(_name), .mode = _mode }, \ ··· 197 188 EXT4_RO_ATTR_ES_UI(errors_count, s_error_count); 198 189 EXT4_ATTR(first_error_time, 0444, first_error_time); 199 190 EXT4_ATTR(last_error_time, 0444, last_error_time); 191 + EXT4_ATTR(journal_task, 0444, journal_task); 200 192 201 193 static unsigned int old_bump_val = 128; 202 194 EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); ··· 227 217 ATTR_LIST(errors_count), 228 218 ATTR_LIST(first_error_time), 229 219 ATTR_LIST(last_error_time), 220 + ATTR_LIST(journal_task), 230 221 NULL, 231 222 }; 232 223 ··· 315 304 return print_tstamp(buf, sbi->s_es, s_first_error_time); 316 305 case attr_last_error_time: 317 306 return print_tstamp(buf, sbi->s_es, s_last_error_time); 307 + case attr_journal_task: 308 + return journal_task_show(sbi, buf); 318 309 } 319 310 320 311 return 0;