diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-05 03:07:40 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-05 03:07:40 +0200 |
| commit | d647d8aabafbaa301c6a607d4ceb891fd62d8ff7 (patch) | |
| tree | ff62604989af7336231147151b3c2f1984fab2de /procps | |
| parent | c229982b330177fecb4879bb70e6062b35aae777 (diff) | |
| download | busybox-w32-d647d8aabafbaa301c6a607d4ceb891fd62d8ff7.tar.gz busybox-w32-d647d8aabafbaa301c6a607d4ceb891fd62d8ff7.tar.bz2 busybox-w32-d647d8aabafbaa301c6a607d4ceb891fd62d8ff7.zip | |
top: show RSS instead of VSF, virtual mapped size is often meaningless
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
| -rw-r--r-- | procps/top.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/procps/top.c b/procps/top.c index 395edc2af..8719af8b3 100644 --- a/procps/top.c +++ b/procps/top.c | |||
| @@ -120,7 +120,7 @@ | |||
| 120 | #define ESC "\033" | 120 | #define ESC "\033" |
| 121 | 121 | ||
| 122 | typedef struct top_status_t { | 122 | typedef struct top_status_t { |
| 123 | unsigned long vsz; | 123 | unsigned long memsize; |
| 124 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 124 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 125 | unsigned long ticks; | 125 | unsigned long ticks; |
| 126 | unsigned pcpu; /* delta of ticks */ | 126 | unsigned pcpu; /* delta of ticks */ |
| @@ -241,8 +241,8 @@ static int pid_sort(top_status_t *P, top_status_t *Q) | |||
| 241 | static int mem_sort(top_status_t *P, top_status_t *Q) | 241 | static int mem_sort(top_status_t *P, top_status_t *Q) |
| 242 | { | 242 | { |
| 243 | /* We want to avoid unsigned->signed and truncation errors */ | 243 | /* We want to avoid unsigned->signed and truncation errors */ |
| 244 | if (Q->vsz < P->vsz) return -1; | 244 | if (Q->memsize < P->memsize) return -1; |
| 245 | return Q->vsz != P->vsz; /* 0 if ==, 1 if > */ | 245 | return Q->memsize != P->memsize; /* 0 if ==, 1 if > */ |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | 248 | ||
| @@ -362,7 +362,7 @@ static void do_stats(void) | |||
| 362 | 362 | ||
| 363 | get_jiffy_counts(); | 363 | get_jiffy_counts(); |
| 364 | total_pcpu = 0; | 364 | total_pcpu = 0; |
| 365 | /* total_vsz = 0; */ | 365 | /* total_memsize = 0; */ |
| 366 | new_hist = xmalloc(sizeof(new_hist[0]) * ntop); | 366 | new_hist = xmalloc(sizeof(new_hist[0]) * ntop); |
| 367 | /* | 367 | /* |
| 368 | * Make a pass through the data to get stats. | 368 | * Make a pass through the data to get stats. |
| @@ -394,7 +394,7 @@ static void do_stats(void) | |||
| 394 | i = (i+1) % prev_hist_count; | 394 | i = (i+1) % prev_hist_count; |
| 395 | /* hist_iterations++; */ | 395 | /* hist_iterations++; */ |
| 396 | } while (i != last_i); | 396 | } while (i != last_i); |
| 397 | /* total_vsz += cur->vsz; */ | 397 | /* total_memsize += cur->memsize; */ |
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | /* | 400 | /* |
| @@ -609,7 +609,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) | |||
| 609 | }; | 609 | }; |
| 610 | 610 | ||
| 611 | top_status_t *s; | 611 | top_status_t *s; |
| 612 | unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ | 612 | unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_memsize? */ |
| 613 | /* xxx_shift and xxx_scale variables allow us to replace | 613 | /* xxx_shift and xxx_scale variables allow us to replace |
| 614 | * expensive divides with multiply and shift */ | 614 | * expensive divides with multiply and shift */ |
| 615 | unsigned pmem_shift, pmem_scale, pmem_half; | 615 | unsigned pmem_shift, pmem_scale, pmem_half; |
| @@ -641,13 +641,13 @@ typedef struct { unsigned quot, rem; } bb_div_t; | |||
| 641 | 641 | ||
| 642 | /* what info of the processes is shown */ | 642 | /* what info of the processes is shown */ |
| 643 | printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, | 643 | printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, |
| 644 | " PID PPID USER STAT VSZ %VSZ" | 644 | " PID PPID USER STAT RSS %RSS" |
| 645 | IF_FEATURE_TOP_SMP_PROCESS(" CPU") | 645 | IF_FEATURE_TOP_SMP_PROCESS(" CPU") |
| 646 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU") | 646 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU") |
| 647 | " COMMAND"); | 647 | " COMMAND"); |
| 648 | lines_rem--; | 648 | lines_rem--; |
| 649 | 649 | ||
| 650 | /* %VSZ = s->vsz / MemTotal * 100% | 650 | /* %RSS = s->memsize / MemTotal * 100% |
| 651 | * Calculate this with multiply and shift. Example: | 651 | * Calculate this with multiply and shift. Example: |
| 652 | * shift = 12 | 652 | * shift = 12 |
| 653 | * scale = 100 * 0x1000 / total_memory | 653 | * scale = 100 * 0x1000 / total_memory |
| @@ -658,7 +658,7 @@ typedef struct { unsigned quot, rem; } bb_div_t; | |||
| 658 | */ | 658 | */ |
| 659 | pmem_shift = BITS_PER_INT-11; | 659 | pmem_shift = BITS_PER_INT-11; |
| 660 | pmem_scale = UPSCALE*(1U<<(BITS_PER_INT-11)) / total_memory; | 660 | pmem_scale = UPSCALE*(1U<<(BITS_PER_INT-11)) / total_memory; |
| 661 | /* s->vsz is in kb. we want (s->vsz * pmem_scale) to never overflow */ | 661 | /* s->memsize is in kb. we want (s->memsize * pmem_scale) to never overflow */ |
| 662 | while (pmem_scale >= 512) { | 662 | while (pmem_scale >= 512) { |
| 663 | pmem_scale /= 4; | 663 | pmem_scale /= 4; |
| 664 | pmem_shift -= 2; | 664 | pmem_shift -= 2; |
| @@ -707,10 +707,10 @@ typedef struct { unsigned quot, rem; } bb_div_t; | |||
| 707 | int n; | 707 | int n; |
| 708 | char *ppu; | 708 | char *ppu; |
| 709 | char ppubuf[sizeof(int)*3 * 2 + 12]; | 709 | char ppubuf[sizeof(int)*3 * 2 + 12]; |
| 710 | char vsz_str_buf[8]; | 710 | char memsize_str_buf[8]; |
| 711 | unsigned col; | 711 | unsigned col; |
| 712 | 712 | ||
| 713 | CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); | 713 | CALC_STAT(pmem, (s->memsize*pmem_scale + pmem_half) >> pmem_shift); |
| 714 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 714 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 715 | CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); | 715 | CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); |
| 716 | #endif | 716 | #endif |
| @@ -720,7 +720,7 @@ typedef struct { unsigned quot, rem; } bb_div_t; | |||
| 720 | */ | 720 | */ |
| 721 | SANITIZE(pmem); | 721 | SANITIZE(pmem); |
| 722 | 722 | ||
| 723 | smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); | 723 | smart_ulltoa5(s->memsize, memsize_str_buf, " mgtpezy"); |
| 724 | /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ | 724 | /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ |
| 725 | n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid)); | 725 | n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid)); |
| 726 | ppu = ppubuf; | 726 | ppu = ppubuf; |
| @@ -755,7 +755,7 @@ typedef struct { unsigned quot, rem; } bb_div_t; | |||
| 755 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) | 755 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) |
| 756 | " ", | 756 | " ", |
| 757 | ppu, | 757 | ppu, |
| 758 | s->state, vsz_str_buf, | 758 | s->state, memsize_str_buf, |
| 759 | SHOW_STAT(pmem) | 759 | SHOW_STAT(pmem) |
| 760 | IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) | 760 | IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) |
| 761 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu)) | 761 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu)) |
| @@ -951,7 +951,7 @@ enum { | |||
| 951 | TOP_MASK = 0 | 951 | TOP_MASK = 0 |
| 952 | | PSSCAN_PID | 952 | | PSSCAN_PID |
| 953 | | PSSCAN_PPID | 953 | | PSSCAN_PPID |
| 954 | | PSSCAN_VSZ | 954 | | PSSCAN_RSS |
| 955 | | PSSCAN_STIME | 955 | | PSSCAN_STIME |
| 956 | | PSSCAN_UTIME | 956 | | PSSCAN_UTIME |
| 957 | | PSSCAN_STATE | 957 | | PSSCAN_STATE |
| @@ -1270,7 +1270,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
| 1270 | top = xrealloc_vector(top, 6, ntop++); | 1270 | top = xrealloc_vector(top, 6, ntop++); |
| 1271 | top[n].pid = p->pid; | 1271 | top[n].pid = p->pid; |
| 1272 | top[n].ppid = p->ppid; | 1272 | top[n].ppid = p->ppid; |
| 1273 | top[n].vsz = p->vsz; | 1273 | top[n].memsize = p->rss; |
| 1274 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 1274 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 1275 | top[n].ticks = p->stime + p->utime; | 1275 | top[n].ticks = p->stime + p->utime; |
| 1276 | #endif | 1276 | #endif |
