76 lines
2.6 KiB
Diff
76 lines
2.6 KiB
Diff
|
From 3253e5ac87c67dd7742e2b2bd9d912f21c1d2711 Mon Sep 17 00:00:00 2001
|
||
|
From: Lianbo Jiang <lijiang@redhat.com>
|
||
|
Date: Fri, 25 Aug 2023 14:23:27 +0800
|
||
|
Subject: [PATCH 30/30] Fix "ps/vm" commands to display the memory usage for
|
||
|
exiting tasks
|
||
|
|
||
|
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>
|
||
|
---
|
||
|
memory.c | 8 +++++++-
|
||
|
1 file changed, 7 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/memory.c b/memory.c
|
||
|
index 5d76c5d7fe6f..86ccec5e2bac 100644
|
||
|
--- a/memory.c
|
||
|
+++ b/memory.c
|
||
|
@@ -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);
|
||
|
@@ -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.
|
||
|
--
|
||
|
2.37.1
|
||
|
|