Blame SOURCES/0006-Remove-ptype-command-from-ps-t-option-to-reduce-memo.patch

e64a0b
From 2ebd8c5ecf1f077975b82325a38dd777b594d0a9 Mon Sep 17 00:00:00 2001
e64a0b
From: Kazuhito Hagio <k-hagio-ab@nec.com>
e64a0b
Date: Wed, 19 Jan 2022 16:24:49 +0900
e64a0b
Subject: [PATCH 06/10] Remove ptype command from "ps -t" option to reduce
e64a0b
 memory and time
e64a0b
e64a0b
With some vmlinux e.g. RHEL9 ones, the first execution of the gdb ptype
e64a0b
command heavily consumes memory and time.  The "ps -t" option uses it in
e64a0b
start_time_timespec(), and it can be replaced with the crash macros.
e64a0b
e64a0b
This can reduce about 1.4 GB memory and 6 seconds time comsumption in
e64a0b
the following test:
e64a0b
e64a0b
  $ echo "ps -t" | time crash vmlinux vmcore
e64a0b
e64a0b
  Without the patch:
e64a0b
  11.60user 0.43system 0:11.94elapsed 100%CPU (0avgtext+0avgdata 1837964maxresident)k
e64a0b
  0inputs+400outputs (0major+413636minor)pagefaults 0swaps
e64a0b
e64a0b
  With the patch:
e64a0b
  5.40user 0.16system 0:05.46elapsed 101%CPU (0avgtext+0avgdata 417896maxresident)k
e64a0b
  0inputs+384outputs (0major+41528minor)pagefaults 0swaps
e64a0b
e64a0b
Although the ptype command and similar ones cannot be fully removed,
e64a0b
but removing some of them will make the use of crash safer, especially
e64a0b
for an automatic crash reporter.
e64a0b
e64a0b
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
e64a0b
---
e64a0b
 task.c | 25 +++++--------------------
e64a0b
 1 file changed, 5 insertions(+), 20 deletions(-)
e64a0b
e64a0b
diff --git a/task.c b/task.c
e64a0b
index 263a8344dd94..a79ed0d96fb5 100644
e64a0b
--- a/task.c
e64a0b
+++ b/task.c
e64a0b
@@ -4662,8 +4662,6 @@ show_task_times(struct task_context *tcp, ulong flags)
e64a0b
 static int
e64a0b
 start_time_timespec(void)
e64a0b
 {
e64a0b
-        char buf[BUFSIZE];
e64a0b
-
e64a0b
 	switch(tt->flags & (TIMESPEC | NO_TIMESPEC | START_TIME_NSECS))
e64a0b
 	{
e64a0b
 	case TIMESPEC:
e64a0b
@@ -4677,24 +4675,11 @@ start_time_timespec(void)
e64a0b
 
e64a0b
 	tt->flags |= NO_TIMESPEC;
e64a0b
 
e64a0b
-        open_tmpfile();
e64a0b
-        sprintf(buf, "ptype struct task_struct");
e64a0b
-        if (!gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR)) {
e64a0b
-                close_tmpfile();
e64a0b
-                return FALSE;
e64a0b
-        }
e64a0b
-
e64a0b
-        rewind(pc->tmpfile);
e64a0b
-        while (fgets(buf, BUFSIZE, pc->tmpfile)) {
e64a0b
-                if (strstr(buf, "start_time;")) {
e64a0b
-			if (strstr(buf, "struct timespec")) {
e64a0b
-				tt->flags &= ~NO_TIMESPEC;
e64a0b
-				tt->flags |= TIMESPEC;
e64a0b
-			}
e64a0b
-		}
e64a0b
-        }
e64a0b
-
e64a0b
-        close_tmpfile();
e64a0b
+	if (VALID_MEMBER(task_struct_start_time) &&
e64a0b
+	    STREQ(MEMBER_TYPE_NAME("task_struct", "start_time"), "timespec")) {
e64a0b
+			tt->flags &= ~NO_TIMESPEC;
e64a0b
+			tt->flags |= TIMESPEC;
e64a0b
+	}
e64a0b
 
e64a0b
 	if ((tt->flags & NO_TIMESPEC) && (SIZE(task_struct_start_time) == 8)) {
e64a0b
 		tt->flags &= ~NO_TIMESPEC;
e64a0b
-- 
e64a0b
2.20.1
e64a0b