Re: [PATCH] Remove ptype command from "ps -t" option to reduce memory and time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 19, 2022 at 4:27 PM HAGIO KAZUHITO(萩尾 一仁) <k-hagio-ab@xxxxxxx> wrote:
With some vmlinux e.g. RHEL9 ones, the first execution of the gdb ptype
command heavily consumes memory and time.  The "ps -t" option uses it
in start_time_timespec() and it can be replaced with crash macros.
This can reduce about 1.4 GB memory and 6 seconds time comsumption in
the following test:

  $ echo "ps -t" | time crash vmlinux vmcore

  Without the patch:
  11.60user 0.43system 0:11.94elapsed 100%CPU (0avgtext+0avgdata 1837964maxresident)k
  0inputs+400outputs (0major+413636minor)pagefaults 0swaps

  With the patch:
  5.40user 0.16system 0:05.46elapsed 101%CPU (0avgtext+0avgdata 417896maxresident)k
  0inputs+384outputs (0major+41528minor)pagefaults 0swaps

Although the ptype command and similar ones cannot be fully removed,
but removing some of them will make the use of crash safer, especially
for an automatic crash analyzer.

Signed-off-by: Kazuhito Hagio <k-hagio-ab@xxxxxxx>
---
 task.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/task.c b/task.c
index 263a8344dd94..a79ed0d96fb5 100644
--- a/task.c
+++ b/task.c
@@ -4662,8 +4662,6 @@ show_task_times(struct task_context *tcp, ulong flags)
 static int
 start_time_timespec(void)
 {
-        char buf[BUFSIZE];
-
        switch(tt->flags & (TIMESPEC | NO_TIMESPEC | START_TIME_NSECS))
        {
        case TIMESPEC:
@@ -4677,24 +4675,11 @@ start_time_timespec(void)

        tt->flags |= NO_TIMESPEC;

-        open_tmpfile();
-        sprintf(buf, "ptype struct task_struct");
-        if (!gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR)) {
-                close_tmpfile();
-                return FALSE;
-        }
-
-        rewind(pc->tmpfile);
-        while (fgets(buf, BUFSIZE, pc->tmpfile)) {
-                if (strstr(buf, "start_time;")) {
-                       if (strstr(buf, "struct timespec")) {
-                               tt->flags &= ~NO_TIMESPEC;
-                               tt->flags |= TIMESPEC;
-                       }
-               }
-        }
-
-        close_tmpfile();
+       if (VALID_MEMBER(task_struct_start_time) &&
+           STREQ(MEMBER_TYPE_NAME("task_struct", "start_time"), "timespec")) {
+                       tt->flags &= ~NO_TIMESPEC;
+                       tt->flags |= TIMESPEC;
+       }

        if ((tt->flags & NO_TIMESPEC) && (SIZE(task_struct_start_time) == 8)) {
                tt->flags &= ~NO_TIMESPEC;
--
2.27.0
 
For this one:
Acked-by: Lianbo Jiang <lijiang@xxxxxxxxxx>
 
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux