Skip to content

Commit bc1d69d

Browse files
koct9itytso
authored andcommitted
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>
1 parent 231fe82 commit bc1d69d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Documentation/ABI/testing/sysfs-fs-ext4

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,10 @@ Description:
109109
write operation (since a 4k random write might turn
110110
into a much larger write due to the zeroout
111111
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.

fs/ext4/sysfs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef enum {
3030
attr_feature,
3131
attr_pointer_ui,
3232
attr_pointer_atomic,
33+
attr_journal_task,
3334
} attr_id_t;
3435

3536
typedef enum {
@@ -125,6 +126,14 @@ static ssize_t trigger_test_error(struct ext4_sb_info *sbi,
125126
return count;
126127
}
127128

129+
static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
130+
{
131+
if (!sbi->s_journal)
132+
return snprintf(buf, PAGE_SIZE, "<none>\n");
133+
return snprintf(buf, PAGE_SIZE, "%d\n",
134+
task_pid_vnr(sbi->s_journal->j_task));
135+
}
136+
128137
#define EXT4_ATTR(_name,_mode,_id) \
129138
static struct ext4_attr ext4_attr_##_name = { \
130139
.attr = {.name = __stringify(_name), .mode = _mode }, \
@@ -188,6 +197,7 @@ EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
188197
EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
189198
EXT4_ATTR(first_error_time, 0444, first_error_time);
190199
EXT4_ATTR(last_error_time, 0444, last_error_time);
200+
EXT4_ATTR(journal_task, 0444, journal_task);
191201

192202
static unsigned int old_bump_val = 128;
193203
EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
@@ -217,6 +227,7 @@ static struct attribute *ext4_attrs[] = {
217227
ATTR_LIST(errors_count),
218228
ATTR_LIST(first_error_time),
219229
ATTR_LIST(last_error_time),
230+
ATTR_LIST(journal_task),
220231
NULL,
221232
};
222233

@@ -304,6 +315,8 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
304315
return print_tstamp(buf, sbi->s_es, s_first_error_time);
305316
case attr_last_error_time:
306317
return print_tstamp(buf, sbi->s_es, s_last_error_time);
318+
case attr_journal_task:
319+
return journal_task_show(sbi, buf);
307320
}
308321

309322
return 0;

0 commit comments

Comments
 (0)