I am debugging an issue with a game that is consuming large amounts of memory, essentially all of 24GB available RAM and 8GB of swap is gone a few minutes after start. The memory is not associated with the process itself (according to RSS in top
), but seems to be categorized under Shmem
in /proc/meminfo
. This is based on recording the values as this process is executing, which you can see in the graph here (raw data here).
Right now I am trying to break down Shmem
into something more specific. I have looked at the post here which mentions the following are contained under Shmem
:
- tmpfs memory
- SysV shared memory
- POSIX shared memory
- shared anonymous mappings
- pages used for GEM
I quickly put together this script:
import glob
import os
import re
import psutil
shmem_users = []
# tmpfs memory
disks = psutil.disk_partitions(all=True)
paths = [d.mountpoint for d in disks if d.fstype == 'tmpfs']
tmpfs_usage = sum(psutil.disk_usage(p).used for p in paths)
shmem_users.append({
'name': 'tmpfs',
'size': tmpfs_usage
})
# /dev/shm
dev_shm_size = 0
for p in glob.glob('/dev/shm/*'):
try:
sz = os.stat(p).st_size
dev_shm_size += sz
except:
# e.g. permission errors
pass
shmem_users.append({
'name': '/dev/shm',
'size': dev_shm_size
})
# TODO: SysV shared memory
# TODO: shared anonymous mappings
# TODO: GEM allocated pages
with open('/proc/meminfo') as f:
m = re.search(r'Shmem: *(?P<kbs>\d+)', f.read())
if not m:
raise RuntimeError('Could not find Shmem value.')
total_shmem = int(m.group('kbs')) * 1024
print('Total shmem: {}'.format(total_shmem))
total_shmem_accounted_for = sum(u['size'] for u in shmem_users)
print('Total shmem found: {}'.format(total_shmem_accounted_for))
print('Shmem unknown: {}'.format(total_shmem - total_shmem_accounted_for))
I have the process currently SIGSTOP
ped part-way through eating my RAM, and it returns:
Total shmem: 8450904064
Total shmem found: 681805504
Shmem unknown: 7769098560
So still 7 GBs unaccounted for, hardly closer to understanding what is using up memory.
I have been looking at kernel code for a few hours but have made very little headway in figuring out 2, 4, and 5. I can provide notes if needed. My question: Are these the only other values that could be categorized as "shared memory", and how can I get their specific values?
If it matters my system is:
- Ubuntu 16.04.2 LTS (with KDE 5.5.5)
- 24 GB RAM (+8 GB of swap configured)
- Intel Core i3-6100
- 500GB SSD
- Sapphire Radeon RX470 4GB (with AMDGPU-PRO driver, v17.10)