Description

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.

Symptoms

Below are some bullets which could lead to swap space usages. Also this can be a combination of those items.

  • The system memory is does not meet the application demands, typically scaling related
  • The system memory usage in steady state is already operating at 80-90% of memory utilisation and needs more memory during convergence and make-before-break events.
  • The system memory usage is steady growing over time due to memory leak of one or more processes.
  • The system memory usage is increasing over time due to memory fragmentation. This looks like a leak but is due to heavy state change and memory gets fragmented. Typically a long term phenomena.

Solution

  • If the system peaked into the swap space due to shortage of memory and falls back, the swap space usage is not considered to be an issue. Always compare the swap utilisation usage against the Free Memory and Inactive Memory which is presented by the CLI command show system memory | match memory
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.
 

  • If the system does constant paging data in and out of swap, would be a concern or if complete processes are swapped out.
  • Once the system is running out of swap space with the message swap_pager_getswapspace the system is under sever pressure and system operation might be impacted. The OOM ( Out-ofMemory) Management will kick in and might restart certain processes based on some heuristics like largest process and how often swap_pager_getswapspace was recorded.

 

Can we clear swap space?

  • The FreeBSD system does handle this at best on its own and there is no manual intervention needed. As already stated, there is no concern at all if unused pages stay at the swap space and there is Free Memory available which fits the operational needs. Keep it at swap space if not needed. The fact that swap space is used is already a sign of memory resource constraints.
  • In this example 2.2GB of Swap is used and 9GB free physical memory. The swap pages are not moved back to the physical memory which is not demanded at this time. In this scenario you could enforce to page-in the content by turning off swap and back-on with the swapoff -a/swapon -a command.

Mem: 5393M Active, 114M Inact, 13M Laundry, 1418M Wired, 531M Buf, 8941M Free

Swap: 8192M Total, 2279M Used, 5913M Free, 27% Inuse

 

  • Turning off swap would not work in condition when Used space is higher then the free space in kernel and the swapoff command would be rejected.
  • Also rebooting the routing engine will release swap memory and the default memory allocation will be returned.  Kindly perform the action under the maintenance window. 

 



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

 

 

 

Modification History

2024-05-30 : Article Created