Issue with 252c651a4c85 ("blk-cgroup: stop using seq_get_buf")
Subsystems (4)
I can see in the latest tip, if we have devices with no statistics, we'll print the maj:min and then nothing else, which can end up looking weird, (e.g. like below.) I see that in older kernels, we avoided printing the device name at all if there were no stats, and it looks like this behavior was silently broken by 252c651a4c85 ("blk-cgroup: stop using seq_get_buf"), where before we prepared the whole line then decided at the end whether to commit it or not.
I do see a patch "blk-cgroup: always terminate io.stat lines" that addresses this by just unconditionally printing the newline (though it looks like that patch never landed). I'm wondering if it's worth trying to bring back the old behavior of not printing these devices at all if they have no statistics. (e.g. by having the "first" stats-haver writing out the bdev name, or going back to scnprintf)
9:0 8:0 rbytes=16720896 wbytes=905216 rios=768 wios=67 dbytes=0 dios=0 1:15 1:14 1:13 1:12 1:11 1:10 1:9 1:8 1:7 1:6 1:5 1:4 1:3 1:2 1:1 1:0
Quoted 3 lines · Khazhy Kumykov
all if they have no statistics. (e.g. by having the "first" stats-haver writing out the bdev name, or going back to scnprintf)
It might be cleaner (at least here where we want to conditionally write a prefix) if we were allowed to "rewind" seq_file (see following), though I'm not that familiar with seq_file to know if this is actually a good idea :) In principle, it doesn't seem too different from seq_get_buf/seq_commit, except we now have the checks in seq_printf preventing overruns
RFC PATCH 1/1 blkcg: rewind seq_file if no stats
In lieu of get_seq_buf + seq_commit, provide a way to "undo" writes if we use seq_printf
--- block/blk-cgroup.c | 5 +++++ fs/seq_file.c | 14 ++++++++++++++ include/linux/seq_file.h | 2 ++ 3 files changed, 21 insertions(+)
block/blk-cgroup.c +5 -0
@@ -909,6 +909,7 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)const char *dname;unsigned seq;int i; +int scookie;if (!blkg->online)return ;
@@ -917,6 +918,8 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)if (!dname)return ; + scookie =seq_checkpoint (s); +seq_printf (s,"%s " , dname); do {
@@ -956,6 +959,8 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)if (has_stats)seq_printf (s,"\n" ); +else +seq_restore (s, scookie); }static int blkcg_print_stat (struct seq_file *sf,void *v)
fs/seq_file.c +14 -0
@@ -408,6 +408,20 @@ void seq_printf(struct seq_file *m, const char *f, ...) }EXPORT_SYMBOL (seq_printf); +int seq_checkpoint (struct seq_file *m) +{ +return m->count; +} +EXPORT_SYMBOL (seq_checkpoint); + +void seq_restore (struct seq_file *m,int count) +{ +if (WARN_ON_ONCE (count > m->count || count > m->size)) +return ; + m->count = count; +} +EXPORT_SYMBOL (seq_restore); +#ifdef CONFIG_BINARY_PRINTF void seq_bprintf (struct seq_file *m,const char *f,const u32 *binary) {
include/linux/seq_file.h +2 -0
@@ -117,6 +117,8 @@ __printf(2, 0)void seq_vprintf (struct seq_file *m,const char *fmt,va_list args); __printf(2, 3)void seq_printf (struct seq_file *m,const char *fmt, ...); +int seq_checkpoint (struct seq_file *m); +void seq_restore (struct seq_file *m,int count);void seq_putc (struct seq_file *m,char c);void seq_puts (struct seq_file *m,const char *s); void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter,
Signature · 1 line
2.36.0.550.gb090851708-goog
Tejun Heo
maintainerRe: [RFC PATCH] blkcg: rewind seq_file if no stats
Quoted 4 lines · Khazhismel Kumykov
In lieu of
get_seq_buf+seq_commit, provide a way to "undo" writes if we useseq_printfFixes 252c651a4c85 ("blk-cgroup: stop using seq_get_buf")
I don't hate it but can you please repost with Christoph Hellwig <[email protected]>? He might have an a lot stronger opinion on it.
Thanks.
tejun
RFC PATCH 1/1 blkcg: rewind seq_file if no stats
In reply to Khazhy KumykovRestores the previous behavior of only displaying devices for which we have statistics (and removes the current, broken, behavior of printing devname with no newline if no statistics)
In lieu of get_seq_buf + seq_commit, provide a way to "undo" writes if we use seq_printf
--- block/blk-cgroup.c | 5 +++++ fs/seq_file.c | 14 ++++++++++++++ include/linux/seq_file.h | 2 ++ 3 files changed, 21 insertions(+)
block/blk-cgroup.c +5 -0
@@ -909,6 +909,7 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)const char *dname;unsigned seq;int i; +int scookie;if (!blkg->online)return ;
@@ -917,6 +918,8 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)if (!dname)return ; + scookie =seq_checkpoint (s); +seq_printf (s,"%s " , dname); do {
@@ -956,6 +959,8 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)if (has_stats)seq_printf (s,"\n" ); +else +seq_restore (s, scookie); }static int blkcg_print_stat (struct seq_file *sf,void *v)
fs/seq_file.c +14 -0
@@ -408,6 +408,20 @@ void seq_printf(struct seq_file *m, const char *f, ...) }EXPORT_SYMBOL (seq_printf); +int seq_checkpoint (struct seq_file *m) +{ +return m->count; +} +EXPORT_SYMBOL (seq_checkpoint); + +void seq_restore (struct seq_file *m,int count) +{ +if (WARN_ON_ONCE (count > m->count || count > m->size)) +return ; + m->count = count; +} +EXPORT_SYMBOL (seq_restore); +#ifdef CONFIG_BINARY_PRINTF void seq_bprintf (struct seq_file *m,const char *f,const u32 *binary) {
include/linux/seq_file.h +2 -0
@@ -117,6 +117,8 @@ __printf(2, 0)void seq_vprintf (struct seq_file *m,const char *fmt,va_list args); __printf(2, 3)void seq_printf (struct seq_file *m,const char *fmt, ...); +int seq_checkpoint (struct seq_file *m); +void seq_restore (struct seq_file *m,int count);void seq_putc (struct seq_file *m,char c);void seq_puts (struct seq_file *m,const char *s); void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter,
Signature · 1 line
2.36.0.550.gb090851708-goog
Re: [RESEND][RFC PATCH] blkcg: rewind seq_file if no stats
Quoted 1 line · Khazhismel Kumykov
+void
seq_restore(struct seq_file *m, int count)
(Yes, this and elsewhere should be size_t to match m->count)
Quoted 4 lines
fs/seq_file.c +4
-0+{ +if (WARN_ON_ONCE (count > m->count || count > m->size)) +return ; + m->count = count;
Re: [RESEND][RFC PATCH] blkcg: rewind seq_file if no stats
In reply to Khazhismel KumykovQuoted 6 lines · Khazhismel Kumykov
Restores the previous behavior of only displaying devices for which we have statistics (and removes the current, broken, behavior of printing devname with no newline if no statistics)
In lieu of
get_seq_buf+seq_commit, provide a way to "undo" writes if we useseq_printf
I have to say I much prefer the simpler fix from Wolfgang. But if we want to go down this route it needs to split into a patch for the seq_file infrastruture and a separate one for the blk-cgroup code.
Re: [RESEND][RFC PATCH] blkcg: rewind seq_file if no stats
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Khazhismel Kumykov
Restores the previous behavior of only displaying devices for which we have statistics (and removes the current, broken, behavior of printing devname with no newline if no statistics)
In lieu of
get_seq_buf+seq_commit, provide a way to "undo" writes if we useseq_printfI have to say I much prefer the simpler fix from Wolfgang. But
Wolfgang's fix still results in a change in behavior, and in my opinion a worse behavior - we don't need to print out the device names if there are no stats.
Quoted 3 lines
if we want to go down this route it needs to split into a patch for the
seq_fileinfrastruture and a separate one for the blk-cgroup code.
Of course - I can spin this into a series if we think it's worthwhile
Quoted 11 lines · Khazhy Kumykov
I can see in the latest tip, if we have devices with no statistics, we'll print the maj:min and then nothing else, which can end up looking weird, (e.g. like below.) I see that in older kernels, we avoided printing the device name at all if there were no stats, and it looks like this behavior was silently broken by
252c651a4c85("blk-cgroup: stop usingseq_get_buf"), where before we prepared the whole line then decided at the end whether to commit it or not.I do see a patch "blk-cgroup: always terminate io.stat lines" that addresses this by just unconditionally printing the newline (though it looks like that patch never landed).
It should really go in, I just sent a ping for it.