Skip to content

Commit

Permalink
Fix "ps/vm" commands to display the memory usage for exiting tasks
Browse files Browse the repository at this point in the history
When a task is exiting, usually kernel marks its flags as 'PF_EXITING',
but even so, sometimes the mm_struct has not been freed, it might still
be valid. For such tasks, the "ps/vm" commands won't display the memory
usage. For example:

  crash> ps 47070
        PID    PPID  CPU       TASK        ST  %MEM      VSZ      RSS  COMM
      47070       1   0  ffff9ba7c4910000  UN   0.0        0        0  ra_ris.parse
  crash> vm 47070
  PID: 47070    TASK: ffff9ba7c4910000  CPU: 0    COMMAND: "ra_ris.parse"
         MM               PGD          RSS    TOTAL_VM
         0                 0            0k       0k

This is a corner case, but it has already occurred in actual production
environments. Given that, let's allow the "ps/vm" commands to try to
display the memory usage for this case. Note that it does not guarantee
that it can work well at any time, which still depends on how far the
mm_struct deconstruction has proceeded.

With the patch:
  crash> ps 47070
        PID    PPID  CPU       TASK        ST  %MEM      VSZ      RSS  COMM
      47070       1   0  ffff9ba7c4910000  UN  90.8 38461228 31426444  ra_ris.parse
  crash> vm 47070
  PID: 47070    TASK: ffff9ba7c4910000  CPU: 0    COMMAND: "ra_ris.parse"
         MM               PGD          RSS    TOTAL_VM
  ffff9bad6e873840  ffff9baee0544000  31426444k  38461228k
        VMA           START       END     FLAGS FILE
  ffff9bafdbe1d6c8     400000     8c5000 8000875 /data1/rishome/ra_cu_cn_412/sbin/ra_ris.parse
  ...

Reported-by: Buland Kumar Singh <bsingh@redhat.com>
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
  • Loading branch information
lian-bo authored and k-hagio committed Aug 25, 2023
1 parent 1aa93cd commit 3253e5a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion memory.c
Expand Up @@ -4792,10 +4792,11 @@ get_task_mem_usage(ulong task, struct task_mem_usage *tm)
{
struct task_context *tc;
long rss = 0, rss_cache = 0;
int mm_count = 0;

BZERO(tm, sizeof(struct task_mem_usage));

if (IS_ZOMBIE(task) || IS_EXITING(task))
if (IS_ZOMBIE(task))
return;

tc = task_to_context(task);
Expand All @@ -4808,6 +4809,11 @@ get_task_mem_usage(ulong task, struct task_mem_usage *tm)
if (!task_mm(task, TRUE))
return;

mm_count = INT(tt->mm_struct + OFFSET(mm_struct_mm_count));

if (IS_EXITING(task) && mm_count <= 0)
return;

if (VALID_MEMBER(mm_struct_rss))
/*
* mm_struct.rss or mm_struct._rss exist.
Expand Down

0 comments on commit 3253e5a

Please sign in to comment.