On a Junos device facing a memory-related issue, we observe swap memory is used:
Mem: 2106M Active, 635M Inact, 579M Wired, 114M Cache, 91M Buf, 61M Free Swap: 4096M Total, 242M Used, 3854M Free, 5% Inuse
This article explains the possible scenarios which could lead swap memory usage and provides troubleshooting tips.
Below are some bullets which could lead to swap space usages. Also this can be a combination of those items.
System memory usage distribution: Total memory: 3640740 Kbytes (100%) Reserved memory: 61428 Kbytes ( 1%) Wired memory: 605908 Kbytes ( 16%) Active memory: 838108 Kbytes ( 23%) Inactive memory: 1920716 Kbytes ( 52%) Cache memory: 129632 Kbytes ( 3%) Free memory: 84948 Kbytes ( 2%)
In many cases, where the existing physical memory on the device is less than what is required, as a last resort an upgrade would be needed in order for the hardware and software to increase available memory for the system.
Can we clear swap space?
Mem: 5393M Active, 114M Inact, 13M Laundry, 1418M Wired, 531M Buf, 8941M Free
Swap: 8192M Total, 2279M Used, 5913M Free, 27% Inuse
Why is swap space always used despite free physical memory?
FreeBSD will page memory in and out of swap if there is a need to. Typically of a process many pages are not needed for regular operation and only the portion which is active used will moved into the Kernel. This means in the example below the system has 1GB on free physical memory. This needs to be read as a good system performance tuning element. Once the system is under memory pressure move pages out of the kernel which are not needed.
show system processes extensive no-forwarding
Mem: 9339M Active, 1180M Inact, 2312M Wired, 412K Cache, 1342M Buf, 1089M Free
Swap: 3072M Total, 2122M Used, 950M Free, 69% Inuse