diff options
author | KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> | 2012-03-23 18:02:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-23 19:58:42 -0400 |
commit | bda7bad62bc4c4e0783348e8db51abe094153c56 (patch) | |
tree | c62650a3da656ba18aebe170df7d554158ae5fc5 /fs/proc/array.c | |
parent | 1ac101a5d675aca2426c5cd460c73fb95acb8391 (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/proc/array.c')
-rw-r--r-- | fs/proc/array.c | 119 |
1 files changed, 64 insertions, 55 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c index c602b8d20f06..fbb53c249086 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
@@ -462,59 +462,56 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, | |||
462 | /* convert nsec -> ticks */ | 462 | /* convert nsec -> ticks */ |
463 | start_time = nsec_to_clock_t(start_time); | 463 | start_time = nsec_to_clock_t(start_time); |
464 | 464 | ||
465 | seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \ | 465 | seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state); |
466 | %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \ | 466 | seq_put_decimal_ll(m, ' ', ppid); |
467 | %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld %lu %lu %lu\n", | 467 | seq_put_decimal_ll(m, ' ', pgid); |
468 | pid_nr_ns(pid, ns), | 468 | seq_put_decimal_ll(m, ' ', sid); |
469 | tcomm, | 469 | seq_put_decimal_ll(m, ' ', tty_nr); |
470 | state, | 470 | seq_put_decimal_ll(m, ' ', tty_pgrp); |
471 | ppid, | 471 | seq_put_decimal_ull(m, ' ', task->flags); |
472 | pgid, | 472 | seq_put_decimal_ull(m, ' ', min_flt); |
473 | sid, | 473 | seq_put_decimal_ull(m, ' ', cmin_flt); |
474 | tty_nr, | 474 | seq_put_decimal_ull(m, ' ', maj_flt); |
475 | tty_pgrp, | 475 | seq_put_decimal_ull(m, ' ', cmaj_flt); |
476 | task->flags, | 476 | seq_put_decimal_ull(m, ' ', cputime_to_clock_t(utime)); |
477 | min_flt, | 477 | seq_put_decimal_ull(m, ' ', cputime_to_clock_t(stime)); |
478 | cmin_flt, | 478 | seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cutime)); |
479 | maj_flt, | 479 | seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cstime)); |
480 | cmaj_flt, | 480 | seq_put_decimal_ll(m, ' ', priority); |
481 | cputime_to_clock_t(utime), | 481 | seq_put_decimal_ll(m, ' ', nice); |
482 | cputime_to_clock_t(stime), | 482 | seq_put_decimal_ll(m, ' ', num_threads); |
483 | cputime_to_clock_t(cutime), | 483 | seq_put_decimal_ull(m, ' ', 0); |
484 | cputime_to_clock_t(cstime), | 484 | seq_put_decimal_ull(m, ' ', start_time); |
485 | priority, | 485 | seq_put_decimal_ull(m, ' ', vsize); |
486 | nice, | 486 | seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0); |
487 | num_threads, | 487 | seq_put_decimal_ull(m, ' ', rsslim); |
488 | start_time, | 488 | seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0); |
489 | vsize, | 489 | seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0); |
490 | mm ? get_mm_rss(mm) : 0, | 490 | seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0); |
491 | rsslim, | 491 | seq_put_decimal_ull(m, ' ', esp); |
492 | mm ? (permitted ? mm->start_code : 1) : 0, | 492 | seq_put_decimal_ull(m, ' ', eip); |
493 | mm ? (permitted ? mm->end_code : 1) : 0, | 493 | /* The signal information here is obsolete. |
494 | (permitted && mm) ? mm->start_stack : 0, | 494 | * It must be decimal for Linux 2.0 compatibility. |
495 | esp, | 495 | * Use /proc/#/status for real-time signals. |
496 | eip, | 496 | */ |
497 | /* The signal information here is obsolete. | 497 | seq_put_decimal_ull(m, ' ', task->pending.signal.sig[0] & 0x7fffffffUL); |
498 | * It must be decimal for Linux 2.0 compatibility. | 498 | seq_put_decimal_ull(m, ' ', task->blocked.sig[0] & 0x7fffffffUL); |
499 | * Use /proc/#/status for real-time signals. | 499 | seq_put_decimal_ull(m, ' ', sigign.sig[0] & 0x7fffffffUL); |
500 | */ | 500 | seq_put_decimal_ull(m, ' ', sigcatch.sig[0] & 0x7fffffffUL); |
501 | task->pending.signal.sig[0] & 0x7fffffffUL, | 501 | seq_put_decimal_ull(m, ' ', wchan); |
502 | task->blocked.sig[0] & 0x7fffffffUL, | 502 | seq_put_decimal_ull(m, ' ', 0); |
503 | sigign .sig[0] & 0x7fffffffUL, | 503 | seq_put_decimal_ull(m, ' ', 0); |
504 | sigcatch .sig[0] & 0x7fffffffUL, | 504 | seq_put_decimal_ll(m, ' ', task->exit_signal); |
505 | wchan, | 505 | seq_put_decimal_ll(m, ' ', task_cpu(task)); |
506 | 0UL, | 506 | seq_put_decimal_ull(m, ' ', task->rt_priority); |
507 | 0UL, | 507 | seq_put_decimal_ull(m, ' ', task->policy); |
508 | task->exit_signal, | 508 | seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task)); |
509 | task_cpu(task), | 509 | seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime)); |
510 | task->rt_priority, | 510 | seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime)); |
511 | task->policy, | 511 | seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0); |
512 | (unsigned long long)delayacct_blkio_ticks(task), | 512 | seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0); |
513 | cputime_to_clock_t(gtime), | 513 | seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0); |
514 | cputime_to_clock_t(cgtime), | 514 | seq_putc(m, '\n'); |
515 | (mm && permitted) ? mm->start_data : 0, | ||
516 | (mm && permitted) ? mm->end_data : 0, | ||
517 | (mm && permitted) ? mm->start_brk : 0); | ||
518 | if (mm) | 515 | if (mm) |
519 | mmput(mm); | 516 | mmput(mm); |
520 | return 0; | 517 | return 0; |
@@ -542,8 +539,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, | |||
542 | size = task_statm(mm, &shared, &text, &data, &resident); | 539 | size = task_statm(mm, &shared, &text, &data, &resident); |
543 | mmput(mm); | 540 | mmput(mm); |
544 | } | 541 | } |
545 | seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n", | 542 | /* |
546 | size, resident, shared, text, data); | 543 | * For quick read, open code by putting numbers directly |
544 | * expected format is | ||
545 | * seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n", | ||
546 | * size, resident, shared, text, data); | ||
547 | */ | ||
548 | seq_put_decimal_ull(m, 0, size); | ||
549 | seq_put_decimal_ull(m, ' ', resident); | ||
550 | seq_put_decimal_ull(m, ' ', shared); | ||
551 | seq_put_decimal_ull(m, ' ', text); | ||
552 | seq_put_decimal_ull(m, ' ', 0); | ||
553 | seq_put_decimal_ull(m, ' ', text); | ||
554 | seq_put_decimal_ull(m, ' ', 0); | ||
555 | seq_putc(m, '\n'); | ||
547 | 556 | ||
548 | return 0; | 557 | return 0; |
549 | } | 558 | } |