Skip to content

Instantly share code, notes, and snippets.

@Chester-Gillon
Last active July 13, 2025 13:22
Show Gist options
  • Save Chester-Gillon/7ea220c73e11d062e06ebe4df5f2bcc4 to your computer and use it in GitHub Desktop.
Save Chester-Gillon/7ea220c73e11d062e06ebe4df5f2bcc4 to your computer and use it in GitHub Desktop.
MATLAB parallel pool maximum RSS

0. Introduction

Notes about trying to track the maximum RSS (Resident Set Size) for a MATLAB parallel pool.

This is using: Ubuntu 24.04.2 LTS with the following installed:

>> ver
-----------------------------------------------------------------------------------------------------------
MATLAB Version: 9.8.0.1873465 (R2020a) Update 8
MATLAB License Number: <redacted>
Operating System: Linux 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.8         (R2020a)
Simulink                                              Version 10.1        (R2020a)
Parallel Computing Toolbox                            Version 7.2         (R2020a)

1. time doesn't seem to record the RSS of parallel workers

Performed the sequence:

  1. Start top -o RES so sorts on RSS
  2. Start MATLAB under time with the verbose output
  3. In MATLAB run parpool, which reports created 12 workers:
    >> parpool
    Starting parallel pool (parpool) using the 'local' profile ...
    Connected to the parallel pool (number of workers: 12).
    
    ans = 
    
      ProcessPool with properties: 
    
                Connected: true
               NumWorkers: 12
                  Cluster: local
            AttachedFiles: {}
        AutoAddClientPath: true
              IdleTimeout: 30 minutes (30 minutes remaining)
              SpmdEnabled: true
    
  4. Once the parallel pool has been started Ctrl-C on top to stop the output.
  5. Exit MATLAB

The top output. The 1st PID 7230 is the MATLAB main process, and the following 12 are the parallel pool workers:

%Cpu(s):  1.3 us,  1.1 sy,  0.0 ni, 97.3 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st 
MiB Mem :  32049.6 total,  17361.8 free,   9689.6 used,   5534.8 buff/cache     
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.  22360.0 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND  
   7230 mr_half+  20   0   10.0g   1.4g 409236 S   5.3   4.5   1:28.58 MATLAB   
   7824 mr_half+  20   0 5969588 768988 236544 S   0.7   2.3   0:11.50 MATLAB   
   7829 mr_half+  20   0 5902008 768272 235904 S   0.7   2.3   0:11.60 MATLAB   
   7827 mr_half+  20   0 5968568 766684 235776 S   0.3   2.3   0:11.55 MATLAB   
   8205 mr_half+  20   0 5968568 766300 235520 S   0.3   2.3   0:11.40 MATLAB   
   7876 mr_half+  20   0 6042300 765952 236160 S   0.3   2.3   0:11.33 MATLAB   
   7910 mr_half+  20   0 5968568 765132 235904 S   0.0   2.3   0:11.35 MATLAB   
   8246 mr_half+  20   0 5894836 765064 235904 S   0.7   2.3   0:11.39 MATLAB   
   8146 mr_half+  20   0 6042300 764944 235520 S   0.3   2.3   0:11.42 MATLAB   
   8097 mr_half+  20   0 5968568 764484 235392 S   0.7   2.3   0:11.31 MATLAB   
   8049 mr_half+  20   0 6042300 764296 235520 S   0.7   2.3   0:11.59 MATLAB   
   8017 mr_half+  20   0 5968568 735956 236160 S   1.0   2.2   0:11.33 MATLAB   
   7957 mr_half+  20   0 5894836 708964 235648 S   0.3   2.2   0:11.56 MATLAB   
   6283 mr_half+  20   0   33.0g 423216 334472 R   3.3   1.3   0:19.43 chrome   
   6448 mr_half+  20   0 1408.4g 231032 133104 S   0.0   0.7   0:17.90 chrome   
   6425 mr_half+  20   0 1410.0g 209188 132344 S   0.3   0.6   0:02.61 chrome   
   7606 mr_half+  20   0 2459012 198304  58912 S   2.6   0.6   0:07.20 jcef_he+ 

And the time output:

$ /usr/bin/time --verbose /usr/local/MATLAB/R2020a/bin/matlab
MATLAB is selecting SOFTWARE OPENGL rendering.
	Command being timed: "/usr/local/MATLAB/R2020a/bin/matlab"
	User time (seconds): 217.40
	System time (seconds): 24.60
	Percent of CPU this job got: 193%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 2:04.81
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 1467744
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 152
	Minor (reclaiming a frame) page faults: 4835222
	Voluntary context switches: 269541
	Involuntary context switches: 334108
	Swaps: 0
	File system inputs: 25864
	File system outputs: 16856
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

Based upon the output, time has only recorded the maximum RSS of the main MATLAB process, and not included the parallel pool workers.

pgrep -P confirms the parllel pool worker processes have the parent PID of that of the main MATLAB process.

Does the time command include the memory claimed by forked processes? explains the cause of the behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment