The ksh -x command using high memory.

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 8
  • ksh-20120801-257.el8.x86_64

Issue

  • The ksh -x command using high memory.
Tasks: 140 total,   3 running, 137 sleeping,   0 stopped,   0 zombie
%Cpu(s): 11.9 us, 29.5 sy,  0.0 ni, 55.3 id,  1.1 wa,  0.8 hi,  1.0 si,  0.3 st
MiB Mem :   1274.3 total,     19.1 free,   1224.7 used,     30.6 buff/cache
MiB Swap:   1232.0 total,    823.1 free,    408.9 used.     22.3 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                           
   4453 root      20   0 1424972   1.0g    380 D  53.8  78.6   0:01.64 ksh                          
     60 root      20   0       0      0      0 R  23.6   0.0   0:00.72 kswapd0                           
     32 root      20   0       0      0      0 S   1.6   0.0   0:00.05 kcompactd0                        
   3178 root      20   0   19072     56     56 S   0.7   0.0   0:00.10 bash    

Resolution

  • The issue is been fixed through Errata under private BZ-2226653 through ksh-20120801-259.el8.

Diagnostic Steps

  • Follow the below steps to check for the issue.

    Note: Running the below test script will lead to high memory usage and out of memory situation.

  1. Run the ksh -x with any script which will read the line. Example as below:

    a. Testing script:

   # cat make_test_data.sh
        N=685133
        while (( N > 0 ))
        do
            date >> test.data
            (( N = N - 1 ))
        done

   # sh make_test_data.sh
   # cat tt.sh
        VAR=`cat test.data`
        echo "sizeof(VAR) = ${#VAR}"

b. The make_test_data.sh will create a file test.data. The generated file is scanned through tt.sh which is been executed with ksh shell.

c. Run ksh -x tt.sh.

  1. Run the top command simultaneously on the other terminal to see the usage for the ksh.
Tasks: 101 total,   3 running,  98 sleeping,   0 stopped,   0 zombie
%Cpu(s): 39.8 us, 57.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.3 hi,  2.9 si,  0.0 st
MiB Mem :   3732.0 total,     92.2 free,   3585.7 used,     54.1 buff/cache
MiB Swap:   4052.0 total,   3486.5 free,    565.5 used.      0.4 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                           
2361887 root      20   0 3984008   3.2g   1828 R  76.9  89.2   0:03.31 ksh                               
     52 root      20   0       0      0      0 R  19.9   0.0   0:16.51 kswapd0                           
      1 root      20   0  174936   5432   3144 S   0.0   0.1   0:03.24 systemd                           
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.04 kthreadd 

  • Component
  • ksh

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments