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

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