aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/array.c
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@openvz.org>2018-04-10 19:31:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-11 13:28:33 -0400
commitd0f02231222b313d1b49278cd2e3c7e7406fea6d (patch)
tree697b842799a294ccd856891458cb4820ebd22fee /fs/proc/array.c
parent48dffbf82d2f17bc6dd3c2b7fd733738ea567914 (diff)
proc: replace seq_printf by seq_put_smth to speed up /proc/pid/status
seq_printf() works slower than seq_puts, seq_puts, etc. == test_proc.c int main(int argc, char **argv) { int n, i, fd; char buf[16384]; n = atoi(argv[1]); for (i = 0; i < n; i++) { fd = open(argv[2], O_RDONLY); if (fd < 0) return 1; if (read(fd, buf, sizeof(buf)) <= 0) return 1; close(fd); } return 0; } == $ time ./test_proc 1000000 /proc/1/status == Before path == real 0m5.171s user 0m0.328s sys 0m4.783s == After patch == real 0m4.761s user 0m0.334s sys 0m4.366s Link: http://lkml.kernel.org/r/20180212074931.7227-4-avagin@openvz.org Signed-off-by: Andrei Vagin <avagin@openvz.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc/array.c')
-rw-r--r--fs/proc/array.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 851ec0915e4c..ae2c807fd719 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -174,7 +174,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
174 174
175 if (umask >= 0) 175 if (umask >= 0)
176 seq_printf(m, "Umask:\t%#04o\n", umask); 176 seq_printf(m, "Umask:\t%#04o\n", umask);
177 seq_printf(m, "State:\t%s", get_task_state(p)); 177 seq_puts(m, "State:\t");
178 seq_puts(m, get_task_state(p));
178 179
179 seq_put_decimal_ull(m, "\nTgid:\t", tgid); 180 seq_put_decimal_ull(m, "\nTgid:\t", tgid);
180 seq_put_decimal_ull(m, "\nNgid:\t", ngid); 181 seq_put_decimal_ull(m, "\nNgid:\t", ngid);
@@ -300,8 +301,8 @@ static void render_cap_t(struct seq_file *m, const char *header,
300 301
301 seq_puts(m, header); 302 seq_puts(m, header);
302 CAP_FOR_EACH_U32(__capi) { 303 CAP_FOR_EACH_U32(__capi) {
303 seq_printf(m, "%08x", 304 seq_put_hex_ll(m, NULL,
304 a->cap[CAP_LAST_U32 - __capi]); 305 a->cap[CAP_LAST_U32 - __capi], 8);
305 } 306 }
306 seq_putc(m, '\n'); 307 seq_putc(m, '\n');
307} 308}
@@ -355,7 +356,8 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
355 356
356static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm) 357static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)
357{ 358{
358 seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state); 359 seq_put_decimal_ull(m, "CoreDumping:\t", !!mm->core_state);
360 seq_putc(m, '\n');
359} 361}
360 362
361int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, 363int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
@@ -491,7 +493,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
491 /* convert nsec -> ticks */ 493 /* convert nsec -> ticks */
492 start_time = nsec_to_clock_t(task->real_start_time); 494 start_time = nsec_to_clock_t(task->real_start_time);
493 495
494 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state); 496 seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
497 seq_puts(m, " (");
498 seq_puts(m, tcomm);
499 seq_puts(m, ") ");
500 seq_putc(m, state);
495 seq_put_decimal_ll(m, " ", ppid); 501 seq_put_decimal_ll(m, " ", ppid);
496 seq_put_decimal_ll(m, " ", pgid); 502 seq_put_decimal_ll(m, " ", pgid);
497 seq_put_decimal_ll(m, " ", sid); 503 seq_put_decimal_ll(m, " ", sid);