aboutsummaryrefslogtreecommitdiffstats
path: root/fs/seq_file.c
diff options
context:
space:
mode:
authorKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>2012-03-23 18:02:54 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 19:58:42 -0400
commitbda7bad62bc4c4e0783348e8db51abe094153c56 (patch)
treec62650a3da656ba18aebe170df7d554158ae5fc5 /fs/seq_file.c
parent1ac101a5d675aca2426c5cd460c73fb95acb8391 (diff)
procfs: speed up /proc/pid/stat, statm
Process accounting applications as top, ps visit some files under /proc/<pid>. With seq_put_decimal_ull(), we can optimize /proc/<pid>/stat and /proc/<pid>/statm files. This patch adds - seq_put_decimal_ll() for signed values. - allow delimiter == 0. - convert seq_printf() to seq_put_decimal_ull/ll in /proc/stat, statm. Test result on a system with 2000+ procs. Before patch: [kamezawa@bluextal test]$ top -b -n 1 | wc -l 2223 [kamezawa@bluextal test]$ time top -b -n 1 > /dev/null real 0m0.675s user 0m0.044s sys 0m0.121s [kamezawa@bluextal test]$ time ps -elf > /dev/null real 0m0.236s user 0m0.056s sys 0m0.176s After patch: kamezawa@bluextal ~]$ time top -b -n 1 > /dev/null real 0m0.657s user 0m0.052s sys 0m0.100s [kamezawa@bluextal ~]$ time ps -elf > /dev/null real 0m0.198s user 0m0.050s sys 0m0.145s Considering top, ps tend to scan /proc periodically, this will reduce cpu consumption by top/ps to some extent. [akpm@linux-foundation.org: checkpatch fixes] Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r--fs/seq_file.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 7d19816c4cc9..55c293f7024d 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -659,7 +659,8 @@ int seq_put_decimal_ull(struct seq_file *m, char delimiter,
659 if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ 659 if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */
660 goto overflow; 660 goto overflow;
661 661
662 m->buf[m->count++] = delimiter; 662 if (delimiter)
663 m->buf[m->count++] = delimiter;
663 664
664 if (num < 10) { 665 if (num < 10) {
665 m->buf[m->count++] = num + '0'; 666 m->buf[m->count++] = num + '0';
@@ -677,6 +678,24 @@ overflow:
677} 678}
678EXPORT_SYMBOL(seq_put_decimal_ull); 679EXPORT_SYMBOL(seq_put_decimal_ull);
679 680
681int seq_put_decimal_ll(struct seq_file *m, char delimiter,
682 long long num)
683{
684 if (num < 0) {
685 if (m->count + 3 >= m->size) {
686 m->count = m->size;
687 return -1;
688 }
689 if (delimiter)
690 m->buf[m->count++] = delimiter;
691 num = -num;
692 delimiter = '-';
693 }
694 return seq_put_decimal_ull(m, delimiter, num);
695
696}
697EXPORT_SYMBOL(seq_put_decimal_ll);
698
680/** 699/**
681 * seq_write - write arbitrary data to buffer 700 * seq_write - write arbitrary data to buffer
682 * @seq: seq_file identifying the buffer to which data should be written 701 * @seq: seq_file identifying the buffer to which data should be written