0

I have a bunch of .NET Core applications running as systemd units. The host is running out of memory and slowly increasing swap usage to 100% so I suspect one or more of the services has a memory leak.

When I run htop all the services show under the dotnet process so I can't see values for individual services. When I ran systemd-cgtop before and after a reboot (going from 100% swap to almost nothing) the memory values for the applications were similar.

How can I find out which systemd unit is using an ever-increasing amount of swap space?

DaveO
  • 175
  • 1
  • 5
  • 16
  • Although just looking at memory totals should solve your problem, there exists a kernel cmdline option `swapaccount=1` to enable swap accounting per cgroup (typically disabled because its costly) – anx Oct 10 '20 at 23:45

1 Answers1

1

Get the pid of the dotnet processes sorted by memory

ps -o pid,user,%mem,command ax | grep dotnet | grep -v grep | sort -b -k3 -r

To find the systemd-unit you than ask systemctl

systemctl status -l <pid>

Or to just get the process with most memory used:

systemctl status -l $(ps -o pid,user,%mem,command ax | grep dotnet | grep -v grep | sort -b -k3 -r | tail -n +2 | head -n 1 | awk '{print $1}')

Ben
  • 160
  • 9