giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.31k stars 1.39k forks source link

Weird VMS return value #712

Closed jchien14 closed 3 years ago

jchien14 commented 9 years ago

Hey all, getting this in Python with psutil for process memory usage. (18120 has no parent process by the way).

>>> psutil.Process().memory_info()
pmem(rss=5033984L, vms=2569285632L)
>>> psutil.Process().pid
18146
>>> psutil.Process().ppid()
18120

When doing a vmmap though on the two processes, this is the result:

==== Summary for process 18146
ReadOnly portion of Libraries: Total=176.4M resident=0K(0%) swapped_out_or_unallocated=176.4M(100%)
Writable regions: Total=85.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=85.3M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                  2048K        2 
Kernel Alloc Once                    4K        2 
MALLOC guard page                   32K        7 
MALLOC metadata                    356K       10 
MALLOC_LARGE                      2752K        7         see MALLOC ZONE table below
MALLOC_LARGE metadata                4K        2         see MALLOC ZONE table below
MALLOC_SMALL                      32.0M        3         see MALLOC ZONE table below
MALLOC_SMALL (empty)              32.0M        3         see MALLOC ZONE table below
MALLOC_TINY                       8192K        6         see MALLOC ZONE table below
STACK GUARD                       56.0M        2 
Stack                             8192K        2 
__DATA                            8956K      161 
__LINKEDIT                        88.8M       21 
__TEXT                            87.6M      164 
__UNICODE                          552K        2 
shared memory                       12K        4 
===========                     =======  ======= 
TOTAL                            326.8M      382 

                                 VIRTUAL ALLOCATION      BYTES          REGION
MALLOC ZONE                         SIZE      COUNT  ALLOCATED  % FULL   COUNT
===========                      =======  =========  =========  ======  ======
DefaultMallocZone_0x1005db000      74.7M       5398      4456K      5%      16
GFXMallocZone_0x10060c000             0K          0         0K               0
===========                      =======  =========  =========  ======  ======
TOTAL                              74.7M       5398      4456K      5

==== Summary for process 18120
ReadOnly portion of Libraries: Total=105.2M resident=0K(0%) swapped_out_or_unallocated=105.2M(100%)
Writable regions: Total=87.9M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=87.9M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                  2048K        2 
Kernel Alloc Once                    4K        2 
MALLOC guard page                   16K        4 
MALLOC metadata                    180K        6 
MALLOC_LARGE                       768K        2         see MALLOC ZONE table below
MALLOC_LARGE (empty)              1220K        3         see MALLOC ZONE table below
MALLOC_LARGE metadata                4K        2         see MALLOC ZONE table below
MALLOC_SMALL                      64.0M        3         see MALLOC ZONE table below
MALLOC_TINY                       8192K        6         see MALLOC ZONE table below
STACK GUARD                       56.0M        2 
Stack                             8192K        2 
VM_ALLOCATE                       3584K       12 
__DATA                            3640K       80 
__LINKEDIT                        88.1M       31 
__TEXT                            17.0M       78 
__UNICODE                          552K        2 
shared memory                       12K        4 
===========                     =======  ======= 
TOTAL                            252.9M      224 

                                 VIRTUAL ALLOCATION      BYTES          REGION
MALLOC ZONE                         SIZE      COUNT  ALLOCATED  % FULL   COUNT
===========                      =======  =========  =========  ======  ======
DefaultMallocZone_0x10a615000      72.8M       4404      3057K      4%       9

This is the result in Activity Monitor: http://i.imgur.com/RGOHBZT.png

Any ideas why psutil is reporting over 2GB for Virtual Memory? Is this a bug? This is on OSX 10.11, 64-bit Python.

jchien14 commented 9 years ago

May be related to https://github.com/giampaolo/psutil/issues/685 ?

giampaolo commented 8 years ago

Sorry for the huge delay in responding. I'm not sure why VMS is so high on OSX but there is a test which compares VMS result with ps and they match 100%: https://github.com/giampaolo/psutil/blob/b360dcd77bac68cb85fa5bd6f73db17723c0c26b/psutil/tests/test_posix.py#L109 I also see over 2GB memory for basically every process, which is definitively weird (see VSZ column in ps output below). I'm confused.

osx-elcaptain:psutil root# ps aux
USER              PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
root               73   3.6  0.2  2486736  10404   ??  Ss   18Oct16   0:12.27 /usr/libexec/opendirectory
root               98   1.0  0.0  2449364   1324   ??  Ss   18Oct16   0:07.65 /usr/sbin/notifyd
vagrant         39635   0.9  0.0  2451904   1620   ??  S    26Oct16   0:02.07 sshd: vagrant@ttys001 
_securityagent    277   0.8  0.9  2569220  39760   ??  Us   18Oct16   6:25.46 /System/Library/Frameworks
root                1   0.4  0.1  2468540   6128   ??  Ss   18Oct16   1:44.82 /sbin/launchd
_windowserver     161   0.2  0.9  2653096  37320   ??  Ss   18Oct16   3:30.38 /System/Library/Frameworks
root            39686   0.1  0.0  2444656   1284 s001  S    26Oct16   0:00.41 -sh
root            39684   0.0  0.1  2444408   3008 s001  S    26Oct16   0:00.03 sudo su -
vagrant         39636   0.0  0.0  2444652   1372 s001  Ss   26Oct16   0:00.03 -bash
...
no-response[bot] commented 3 years ago

This issue has been automatically closed because there has been no response for more information from the original author. Please reach out if you have or find the answers requested so that this can be investigated further.